[Scilab-users] Frequency response
Tan Chin Luh
chinluh at tritytech.com
Mon Sep 17 09:39:41 CEST 2018
Hi,
I was facing similar issue sometime ago while trying to translate from
matlab to scilab, as both of them have diff way of representation.
In Matlab/Octave, when we are using polynomial, we are defining them in
vector/matrix form such as : num = [1 2 3 4]. The catch is here: when we
use the s-domain, it represent 1*s^3 + 2*s^2+3*s+4, while if it is used
in the function in z-domain, it will become 1 + 2*z^-1 + 3*z^-2 + 4*z^-3.
while in Scilab, the polynomial is represented in polynomial datatype.
So, consider following simple example:
h = [1 2 3 4]; % this is coefficient in 1 + 2*z^-1 + 3*z^-2 + 4*z^-3
fs = 1000;
Nfft = 128;
[H,F] = freqz(h,1,Nfft,fs);
plot(F,H);
In Scilab
h = [1 2 3 4];
fs = 1000;
b = poly(h($:-1:1),"z","coeff");
a = %z^(length(h)-1);
Gz = syslin('d',b,a);
Gz.dt = 1/fs;
[F,H]=repfreq(Gz,0,500,0.01);
plot(F,H);
in line 3 - b = poly(h($:-1:1),"z","coeff"); we create b in poly using
the coefficients, we have to take note that:
--> order of h must be reversed, as poly take the coeff in ascending order
--> this line will create b as 4 +3*z +2*z^2 +z^3
To match the z-domain format, our a would not be 1 anymore, but z^3 as
in line 4 of the code above
--> (4 +3*z +2*z^2 +z^3) / z^3 --> 1 + 2*z^-1 + 3*z^-2 + 4*z^-3
After this, the remaining codes should be straight forward.
Hope this helps.
p/s: help zpk will help u on the definition i guess.
Thanks.
rgds,
Chin Luh
More information about the users
mailing list