Model a first order system with input delay - Padé approximant?

Hello,

I would like to model a 1st order system with delay in Scilab (not XCos).

It was previously (in old versions of Scilab) possible to do

s = poly(0, 's');
H = syslin('c', 1*exp(-1.5*s) / (1+4*s))
time = linspace(0, 20, 51);
rep = csim('step', time, H);
plot(time, rep);

but it doesn’t seem to work anymore because of the delay exp(-1.5*s)

How to model such a system in Scilab?

Is the Padé approximant the most practical solution?

How to implement it in Scilab? Is there built-in function for that purpose?

Kind regards

Hello Sebastien,

That’s good to hear from you again, welcome to this new great Scilab place!

Scilab itself does no handle pure delays in transfer functions but there a toolbox that should at least partly implement them (I did not tested it yet) with several overloadings:

A priori, this toolbox uses Padé approximants, but this has to be checked.

S.

Thanks Stephane for this prompt answer

ATOMS doesn’t seems to provide a search function. That’s sad :wink:
(I mean inside Scilab… not https://atoms.scilab.org/ )

This code works

s = poly(0, 's');

// 1st order system
Gs = 1 // static gain
tau = 4 // time constant
H = syslin('c', Gs / (1 + tau * s))

// Delay
Tr = 1.5
// R = syslin('c', (1 - Tr / 2 * s) / (1 + Tr / 2 * s))  // approximation du retard pur par approximation de Padé à l'ordre 1
// R = syslin('c', (1 - Tr / 2 * s + Tr^2 * s^2 / 12) / (1 + Tr / 2 * s + Tr^2 * s^2 / 12))  // approximation du retard pur par approximation de Padé à l'ordre 2
R = syslin('c', (1 - Tr / 2 * s + Tr^2 * s^2 / 10 - Tr^3 * s^3 / 120) / (1 + Tr / 2 * s + Tr^2 * s^2 / 10 + Tr^3 * s^3 / 120))  // approximation du retard pur par approximation de Padé à l'ordre 3

T = H * R

// Heaviside step response
temps = linspace(0, 20, 51);
rep = csim('step', temps, T);
plot(temps, rep);

but not this one

s = poly(0, 's');

// 1st order system
Gs = 1 // static gain
tau = 4 // time constant
H = syslin('c', Gs / (1 + tau * s))

// Delay
Tr = 1.5

T = iodelay(H, Tr)

// Heaviside step response
temps = linspace(0, 20, 51);
rep = csim('step', temps, T);
plot(temps, rep);

Any idea what is wrong ?

Yes, this toolbox overloads simple algebraic operations and only some macros, namely

bode, black, nyquist

No state-space simulation is supported, that’s why csim does not work. In fact no rational approximation of delays is implemented.

S.

I noticed in a Julia library some code for pade approximant

Maybe it could be worth to implement a pade function in Scilab.

Here is code

function [coeffs]=pade_coeffs(n)
    coeffs = []
    for i = 0:n
        coeffs(i+1) = nchoosek(n, i) * prod(n+1:2*n-i)
    end
endfunction

function [coeffs_scaled]=_linscale_coeffs(coeffs, a)
    a_pow = 1
    coeffs_scaled(1) = coeffs(1)
    for k = 2:length(coeffs)
        a_pow = a * a_pow
        coeffs_scaled(k) = coeffs(k) * a_pow
    end
endfunction

function [T]=pade(tau, n)
    coeffs = pade_coeffs(n)
    coeffs_scaled = _linscale_coeffs(coeffs, tau)
    num = poly(_linscale_coeffs(coeffs, -tau), "s", "coeff")
    den = poly(_linscale_coeffs(coeffs, tau), "s", "coeff")    
    T = syslin("c", num, den)
endfunction

//p = poly(coeffs, "x", "coeff")

s = poly(0, 's')
Gs = 1 // static gain
tau = 4 // time constant
H = syslin('c', Gs / (1 + tau * s))

Td = 2.0  // delay
Hd =  pade(Td, 10)

T = H * Hd

time = linspace(0, 20, 51);
rep = csim('step', time, T);
plot(time, rep);

image

What about integrating it into Scilab?

Yes, e.g. in the cacsd module, but a help page is also needed (in the spirit of Padé approximation of models with time delay - MATLAB pade - MathWorks France). In the source of pade() you should control the type of input arguments by using the new mechanism (see https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0). When you have all these elements working in your fork you can create a merge request.

S.

Αnd if you think that iodelay toolbox is actually used, you could take into account the syntax

sysp = pade(sys,...)

when sys has delays.

S.

Sorry but I can’t find repository of iodelay - see ATOMS : iodelay toolbox details

I looked at cacsd module scilab/modules/cacsd · minor · scilab / scilab · GitLab

There is so many things! not sure I can handle that.

I wonder if you @mottelet or other contributors can handle that ? Pinging @vincent.couvert @davidcl @adeline.carnis @cedric.delamarre @antoine.elias (seeing latest contributions in code)

You are contributor to other open source projects (Python, Julia), I am sure you can do it :slight_smile:

S.