close all;clc;clear;
%transfer function
s=tf('s');
G=1/((s+.5)*(s+1.5));
%closeloop response without any controller
step(G/(1+G));
grid on
legend('closeloop response without any controller');
pole(G/(1+G));
stepinfo(G/(1+G))
%Controller Design
zita=0.7;
wn=5.71;
poles=roots([1 2*zita*wn wn^2]); %期望阻尼和频率
%Root locus
figure;
rlocus(G);
legend('Root Locus');
%calculate the Shortage Phase
syms s1
G1=1/((s1+0.5)*(s1+1.5));
phi=double(angle(subs(G1,s1,-4+4.08i)))*180/pi;
sphi=180-phi;
%T , a
z=-4;
p=-4-4.01/tand(90-sphi);
%%
%shart andazeh
Gc1=(s1-z)/(s1-p);
kc=1/(double(abs(subs(Gc1*G1,-4+4.01i))));
%simulatuion
Gc=(s-z)/(s-p);
Gcloseloop=kc*Gc*G/(1+kc*Gc*G);
figure;
rlocus(Gc*G);
figure;
step(Gcloseloop);
% hold on
% step(G/(1+G));
grid on;
legend('step response with controller');
stepinfo(Gcloseloop)
figure
step(G/(1+G));
hold on
step(Gcloseloop);
legend('无超前校正','有超前校正')
grid on