%
% Example 9.4
%
den=[1 6 11 6]
num=[50 300]
[Gm,Pm,wcp,wcg]=margin(num,den)
bode(num,den)
% estimate Phimax with Pmd = desired phase margin
Pmd=input('enter desired value for phase margin');
Phimax=Pmd-Pm+10;
% convert Phimax into radians
Phirad=(Phimax/180)*pi;
a=(1+sin(Phirad))/(1-sin(Phirad));
% Find amplification at high frequencies, DG
DG=20*log10(a);
% estimate value for pole -pc from Step 5
pc=input('enter estimated value for pole pc');
% form compensator's numerator
nc=[a pc]
% form compensator's denominator
dc=[1 pc]
% find the compensated system transfer function
numc=conv(num,nc);
denc=conv(den,dc);
[Gmc,Pmc,wcp,wcg]=margin(numc,denc)
bode(numc,denc)
pause
% closed-loop step response
[cnum,cden]=feedback(num,den,1,1,-1);
% -1 indicates a negative feedback
[cnumc,cdenc]=feedback(numc,denc,1,1,-1);
t=0:0.01:2;
[y,x]=step(cnum,cden,t);
[yc,xc]=step(cnumc,cdenc,t);
plot(t,y,'--',t,yc)
axis([0 2 0 2])
end
