我正在比较连续(s域)传递函数与其等效离散(z域)函数的时间响应。我使用c2d函数通过所有5种方法(Tustin,ZOH,FOH,冲量不变,匹配)离散化TF。 阶跃响应函数对于所有传递函数(都是连续的离散函数)都可以正常工作,但是当我要进行斜率响应时,MATLAB没有斜率()函数。 我在网上发现的一个简单技巧是使用step()并将TF除以s,它应该模拟斜坡响应step(G / s)。 这对于连续TF来说效果很好,但对于其余离散TF却给出了错误
使用/时出错(第65行) 采样时间必须一致。
如何解决此错误?
这是我的代码,第58行(最后一行)出现问题
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)
答案 0 :(得分:1)
对于斜坡响应,您可以使用以下方法:
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)
其中G是连续TF。