MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Quixotic
on 21 Dec 2012

i'm doing my assignment project which is to display Glag lead compensator bode plot. i've already done the program. but somehow it does not show the output that i expected. it display the value of Glag compensator and Glead compensator, however, the value of Glag lead compensator is zero. can you please tell me what is wrong with my program...

'( LAG-LEAD COMPENSATOR BODE PLOT)' %Display label pos=0.63; '(Type %OS)' %input desired percent overshoot Tp=0.9222; '(Type peak time)' %input desired peak time Kv=10; '(Type value of K)' %input desired Kv numg=[1]; %define numerator of G(s) deng=poly([0,-5,-11]); %define denominator of G(s) G=tf(numg,deng); %create G(s) without K s=tf([10],1); %create transfer function, 's' sG=s*G; %cancel common factors K=dcgain(Kv/sG); %solve for K 'G(s)' %display label G=tf(K*numg,deng); %put K into G(s) G=zpk(G) %convert G(s) to factored form and display z=(-log(pos/100))/(sqrt(pi^2+log(pos/100)^2)); %calculate required damping ratio Pmreq=atan(2*z/(sqrt(-2*z^2+sqrt(1+4*z^4))))*(180/pi); %calculate required phase margin wn=pi/(Tp*sqrt(1-z^2)); %calculate required natural frequency wBW=wn*sqrt((1-2*z^2)+sqrt(4*z^4-4*z^2+2)); %determine require bandwidth wpm=0.8*wBW; %choose new phase margin frequency [M,P]=bode(G,wpm); %get bode data Pmreqc=Pmreq-(180+P)+5; %find phase contribution required %from lead compensator %with additional 5 deg beta=(1-sin(Pmreqc*pi/180))/(1+sin(Pmreqc*pi/180)); %find beta %design lag compensator %zero, pole and gain zclag=wpm/10; %calculate zero of lag compensator. pclag=zclag*beta; %calculate pole of lag compensator. Kclag=beta; %calculate gain of lag compensator. 'Lag compensator, Glag(s)' %display label Glag=tf(Kclag*[1 zclag],[1 pclag]); %Create lag compensator. Glag=zpk(Glag) %Convert Glag(s) to factored form %and display. %Design lead %compensator zero,pole %and gain. zclead=wpm*sqrt(beta); %Calculate zero of lead compensator. pclead=zclead/beta; %Calculate pole of lead compensator. Kclead=1/beta; %Calculate gain of lead compensator. 'Lead compensator' %Display label. Glead=tf(Kclead*[1 zclead],[1 pclead]); %Create lead compensator. Glead=zpk(Glead) %Convert Glead(s) to factored form and display. 'Lag-Lead Compensated Ge(s)' %Display label. Ge=G*Glag*Glead %Created compensated system, %Ge(s)=G(s)Glag(s)Glead(s). sGe=s*Ge; %Create sGe(s). sGe=minreal(sGe); %Cancel common factors. Kv=dcgain(sGe) %Calculate Kv T=feedback(Ge,1); %find T(s). step(T) %Generate closed-loop, lag-lead-compensated step response. title('Lag-Lead-Compensated Step Response') % This displays a Bode plot. %Add title to %lag-lead-compensated pause %step response.

and this is the result that i get...

ns =

( LAG-LEAD COMPENSATOR BODE PLOT)

ans =

(Type %OS)

ans =

(Type peak time)

ans =

(Type value of K)

ans =

G(s)

Zero/pole/gain: 0

ans =

Lag compensator, Glag(s)

Zero/pole/gain: 74.6983 (s+0.4169) ------------------ (s+31.14)

ans =

Lead compensator

Zero/pole/gain: 0.013387 (s+36.03) ------------------ (s+0.4824)

ans =

Lag-Lead Compensated Ge(s)

Zero/pole/gain: 0

Kv =

0

thank you for helping me..

*No products are associated with this question.*

## 1 Comment

## Ryan G (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/57182#comment_118550

At what part of the code do you see the problem? You should try to narrow down the code to a few lines and try again, or post those few lines. You'll have trouble getting help dumping your code here.