Reputation: 273
I'm comparing the time response of a continuous (s-domain) transfer function with its equivalent discrete (z-domain) functions. I used the c2d function to discretize the TF using all 5 methods Tustin
, ZOH
, FOH
, Impulse-Invariant
and Matched
.
The function for step response works fine for all transfer functions (both continuous and discrete), but when I came to ramp response, MATLAB doesn't have a ramp()
function.
A simple trick I found online was to use step()
and divide the TF by s
and it should simulate a ramp response, step(G/s)
.
This worked fine for the continuous TF but gives an error for the rest discrete TF's.
Error using / (line 65) Sampling times must agree.
How do I fix this error?
Here is my code, problem at line 58 (last line)
clc
clear all
close all
s=tf('s') %Defining s as laplace domain vairable
Ts=0.1 %Sample Time
%Continuous Transfer Function
G = (-40824*s^2 - 122472*s + 1.497*10^8)/(s^4 + 186*s^3 + 4.67*10^4*s^2 + 3.71*10^6*s + 1.452*10^8)
%Continuous to Discrete conversion
Gt = c2d(G,Ts, 'tustin')
Gi = c2d(G, Ts, 'impulse')
Gz = c2d(G, Ts, 'zoh')
Gf = c2d(G, Ts, 'foh')
Gm = c2d(G,Ts,'matched')
%Bode Plot (Frequency Response) for all methods
bode(G,Gt,Gi,Gz,Gf,Gm)
legend('Continuous','Tustin (Bilinear)','Impulse Invariant','Zero-Order Hold','First-Order Hold','Matched')
%Step (Time Response) for all methods
figure; step(G,Gt,Gi,Gz,Gf,Gm)
legend('Continuous','Tustin (Bilinear)','Impulse Invariant','Zero-Order Hold','First-Order Hold','Matched')
%Impulse (Time Response) for all methods
figure; impulse(G,Gt,Gi,Gz,Gf,Gm)
legend('Continuous','Tustin (Bilinear)','Impulse Invariant','Zero-Order Hold','First-Order Hold','Matched')
%Root-Locus for continuous TF
figure; rlocus(G)
legend('Continuous')
%Root-Locus for Tustin method TF
figure; rlocus(Gt)
legend('Tustin (Bilinear)')
%Root-Locus for Impulse Invariant method TF
figure; rlocus(Gi)
legend('Impulse Invariant')
%Root-Locus for Zero-Order Hold method TF
figure; rlocus(Gz)
legend('Zero-Order Hold')
%Root-Locus for First-Order Hold method TF
figure; rlocus(Gf)
legend('First-Order Hold')
%Root-Locus for Matched method TF
figure; rlocus(Gm)
legend('Matched')
%Ramp Response for continuous TF
step(G/s)
%Ramp Response for Tustin method TF
step(Gt/s)
Upvotes: 0
Views: 2025
Reputation: 26
For ramp response you can use this:
t=0:0.1:10;
r=t; %this is your input -u
Ts=0.1 ;
lsim(G,r,t);
figure
Gt = c2d(G,Ts, 'tustin');
lsim(Gt,r)
where G is continous TF .
Upvotes: 1