syms b_1
Z=[];
P=[0,-10,-5];
K=1500;
G_0=zpk(Z,P,K); %G_0为校正前系统开环传递函数
[num,den]=tfdata(G_0);
%求解b,T
[Gm,Pm,wg_0,wc_0]=margin(G_0); %Pm为校正前的幅值裕度,
gamma=60; %确定校正后的相角裕度
Phi_c=-6; %校正后的截止频率下Gc(s)的相角,一般取-6°
temp=gamma-Phi_c-180;%相角裕度60°时的相位
[mag,phase,w]=bode(num,den);
wc=spline(phase,w,temp); %求解校正后的截止频率
mag_1=spline(w,mag,wc);
mag_db1=20*log10(mag_1); %求对数
ans=solve(-20*log10(b_1)==mag_db1,b_1);
b=double(ans); %利用double将原本ans为syms类型转化为数值型
T=1/(0.1*wc*b);
G_c=tf([b*T,1],[T,1]);
printsys([b*T,1],[T,1],'s');
G=G_0*G_c;
[Gm1,Pm1,wg1,wc1]=margin(G)
bode(G_0);hold on;grid on;
bode(G);