MATLAB Answers

c2d function 'zoh' method formula

96 views (last 30 days)
Tamas Toth-K
Tamas Toth-K on 4 Oct 2020
Commented: Tamas Toth-K on 7 Oct 2020
Hi!
My following question would be, say i have a continuous time PI controller:
and i apply the function c2d(,,'zoh'), then it appears that matlab uses he substitution:
.
Which is completly fine, however if i have a transfer function like:
then when applying the c2d function c2d(,,'zoh'), it appears that the previous substitution in this case changes (s!=(z-1)/Ts)depending on the value of . I would like to know why Matlab does this, and what is its algebraic formula if possible?
Thank you!

  0 Comments

Sign in to comment.

Accepted Answer

Paul
Paul on 4 Oct 2020
I suspect that in your first case for C the substitution you cite is only applicable because of the form of C. In general, the ZOH approximation does not use that substitution. Though probably not implemented this way, the genaral form for the ZOH approximation can be implemented as shown below, and compared to what Matlab produces
P=5;Ti=6;Ts=.1; % example data
C=tf(P*[Ti 1],[Ti 0]);
Cz=c2d(C,Ts,'zoh');
Cznew = minreal(c2d(C*tf(1,[1 0]),Ts,'impulse')*tf([1 -1],[1 0],Ts)/Ts);
[Cz Cznew]
ans =
From input 1 to output:
5 z - 4.917
-----------
z - 1
From input 2 to output:
5 z - 4.917
-----------
z - 1
Sample time: 0.1 seconds
Discrete-time transfer function.
R=10;Te = 5; W=tf(1,[R*Te 1]);
Wz=c2d(W,Ts,'zoh');
Wznew = minreal(c2d(W*tf(1,[1 0]),Ts,'impulse')*tf([1 -1],[1 0],Ts)/Ts);
[Wz Wznew]
ans =
From input 1 to output:
0.001998
---------
z - 0.998
From input 2 to output:
0.001998
---------
z - 0.998
Sample time: 0.1 seconds
Discrete-time transfer function.
Th substitution you cite, s = (z -1)/Ts, the forward rectangular rule, which appears to be an allowable, albeit undocumented, method input to c2d.

  4 Comments

Show 1 older comment
Tamas Toth-K
Tamas Toth-K on 7 Oct 2020
Although i believed i would be able to go on from this, i must say i am stuck once again, i somewhat understand what is happening, but it is not clear to me what 'impulse' does in Matlab as in mathematica no method within function ToDiscreteTimeModel gives quite the results back as matlab does with 'zoh'.
Furthermore i am studying control theory but no combination of BWD FWD LSR RSR or tustin methods or even using step response equvilent method give what matlab does, (which uses something like 'impulse' as you discribed), i am trying to find an algebraic equation how the Matlab function works as i would need it in mathematica, but i had no success, do you possibly know the answer?
Paul
Paul on 7 Oct 2020
I don't know anything about Mathematica, but it seems to give the same results as Matlab as far as I can tell. Using the example on this page:
sys=tf([1 0],[1 1 1]);
sysd=c2d(sys,0.4,'tustin')
sysd =
0.1613 z^2 - 0.1613
----------------------
z^2 - 1.548 z + 0.6774
Sample time: 0.4 seconds
Discrete-time transfer function.
Note that Mathematica doesn't scale the coeffiecient of z^2 to unity. So multiply the top and bottom to match the Mathematica result:
>> sysd.num{:} = sysd.num{:}*4.96;sysd.den{:} = sysd.den{:}*4.96;
>> sysd
sysd =
0.8 z^2 - 0.8
------------------------
4.96 z^2 - 7.68 z + 3.36
Sample time: 0.4 seconds
Discrete-time transfer function.
Which is the same as the Mathematica result for Tustin (or blinear). Now do the same for ZOH:
>> sysd=c2d(sys,0.4,'zoh')
sysd =
0.321 z - 0.321
---------------------
z^2 - 1.54 z + 0.6703
Sample time: 0.4 seconds
Discrete-time transfer function.
Which is the same as the Mathematica result. Can you show an example where Mathemeatica and Matlab give different results?
In Matlab, c2d supports several methods. The 'impulse' method is the z-transform of the samples of the continuous time impulse response of the system. Based on its doc page, it appears that Mathematica does not support the 'impulse' method.
What exactly are you trying to do?
Tamas Toth-K
Tamas Toth-K on 7 Oct 2020
Thank you, very much! after you said it is he same I took another look and realized that out of the many substituted variables one was incorrect, after the fix it is the same :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!