K1=288; K3=3.968;
G1=5;
G2=tf(10,[1,20,0]);
Gc=tf([K3,K1],1);;%PD控制器传递函数
Gp=tf(72.58,[1,72.58]);%前置滤波传递函数
G3=series(G1,Gc);;%前置滤波传递函数
G=series(G3,G2);
G4=feedback(G,1);%无前置滤波时系统的闭环传递函数
G5=series(Gp,G4);%有前置滤波时系统的闭环传递函数
G6=feedback(G2,G3);%系统的闭环扰动传递函数
[y,t]=step(G4);
figure(1)
plot(t,y,'Linewidth',2) % 画无前置滤波时系统的闭环阶跃函数
hold on
C=dcgain(G4); %求阶跃响应的终值
Step=1; %单位阶跃输入
essp=Step-C; %位置误差
hold on
[Y,k]=max(y);
tp=(t(k)*100)/100; %求峰值时间
plot([tp tp],[0 Y],'--r','Linewidth',1.5);
plot([0 tp],[Y Y],'--r','Linewidth',1.5);
plot(tp,0,'o', 'MarkerEdgeColor','k', 'MarkerFaceColor','k','MarkerSize',6); %画出峰值时间的时间点
% C=dcgain(feedback(G,1)); %求系统稳态值
M=(1000*(Y-C)/C)/10; %求超调量
n=1;
while y(n)<0.1*C %通过循环,求取输出第一次到达终值的10%的时间
n=n+1;
end
m=k;
while y(n)>0.9*C %通过循环,求取输出第一次到达终值的90%时间
m=m-1;
end
risetime=(100*(t(m)-t(n)))/100; %求上升时间
i=length(t);
while (y(i)>0.98*C)&(y(i)<1.02*C)
i=i-1;
end
Settingtime=(100*t(i))/100; %求调节时间
plot(Settingtime,0,'o', 'MarkerEdgeColor','k', 'MarkerFaceColor','m','MarkerSize',6); %显示调节时间的时间点
hold off
[F,h]=findpeaks(y);
che=length(F);
if(che>=2)
rate=fix(100*(F(1)-C)/(F(2)-C))/100; %求衰减比
end
grid on
xlabel('Time(s)')
ylabel('Y(t)')
title('无前置滤波闭环系统阶跃响应曲线');
figure(2);step(G5);grid
xlabel('Time(s)')
ylabel('Y(t)')
title('有前置滤波闭环系统阶跃响应曲线');
figure(3);step(G6);grid
xlabel('Time(s)')
ylabel('Y(t)')
title('系统扰动阶跃响应曲线');