You are on page 1of 2

Expriment No.

: 2

%Lead compensator using Bode plot.

clc
pos=input('Type %os ');
Tp=input('Type peak time ');
Kv=input('Type value of Kv ');
numg=[100];
deng=poly([0 -36 -100]);
G=tf(numg,deng);
s=tf([1 0],1);
sG=s*G;
sG=minreal(sG);
K=dcgain(Kv/sG);
'G(s)'
G=zpk(K*G)
z=(-log(pos/100))/(sqrt(pi^2+log(pos/100)^2));
Pm=atan(2*z/(sqrt(-2*z^2+sqrt(1+4*z^4))))*(180/pi);
wn=pi/(Tp*sqrt(1-z^2));
wBW=wn*sqrt((1-2*z^2)+sqrt(4*z^4-4*z^2+2));
w=0.01:0.5:1000;
[M,P]=bode(G,w);
[Gm,Pm,Wcg,Wcp]=margin(G);
Pmreq=atan(2*z/(sqrt(-2*z^2+sqrt(1+4*z^4))))*(180/pi);
Pmreqc=Pmreq+10;
Pc=Pmreqc-Pm;
beta=(1-sin(Pc*pi/180))/(1+sin(Pc*pi/180));
magpc=1/sqrt(beta);
for K=1:1:length(M);
if M(K)-(1/magpc)<=0;
wmax=w(K);
break
end
end
zc=wmax*sqrt(beta);
pc=zc/beta;
Kc=1/beta;
'Gc(s)'
Gc=tf(Kc*[1 zc],[1 pc]);
Gc=zpk(Gc)
'Ge(s)=G(s)Gc(s)'
Ge=G*Gc
sGe=s*Ge;
sGe=minreal(sGe);
Kv=dcgain(sGe)
T=feedback(Ge,1);
step(T)
title('Lead Compensated Step Response')

Output:

Type %os 20
Type peak time 0.1
Type value of Kv 40

ans =

G(s)
Lead Compensated Step Response
1.4

1.2

0.8
Amplitude

0.6

0.4

0.2

0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35
Time (sec)

Zero/pole/gain:
144000
----------------
s (s+100) (s+36)

ans =

Gc(s)

Zero/pole/gain:
2.3794 (s+25.29)
----------------
(s+60.17)

ans =

Ge(s)=G(s)Gc(s)

Zero/pole/gain:
342633.433 (s+25.29)
--------------------------
s (s+100) (s+60.17) (s+36)

Kv =

40.0000

You might also like