系统传递函数:
对传递函数做Z变换:
采样时间0.1s:
获得的离散系统为:
运行之后结果为:
对离散函数通过脚本实现:
clc
clear
ts = 0.1;
sys1 = tf(1,[1,1]);
sysd1 = c2d(sys1,ts,'z');
[num1,den1]=tfdata(sysd1,'v');
sys2 = tf(1,[1,0]);
sysd2 = c2d(sys2,ts,'z');
[num2,den2]=tfdata(sysd2,'v');
ref_val = 1;
t_end = 10;
t = 0:ts:t_end;
u1 = 0;
u2 = 0;
for it = 1:length(t)
error = (ref_val-u2);
u1 = (-u1*den2(2) + error*num2(2))/den2(1); //Z变换传递函数转换为差分方程
u2 = (-u2*den1(2) + u1*num1(2))/den1(1);
position(it) = u2;
end
figure(1)
stairs(t,position)
grid on
获得的结果为: