%Example 2.5
%Step response and Frequency response for
%Plant: T=(-s+z)/(s+z)(tau*s+1), z=0.1, tau=1, and S=1-T
%
%Figure 2.14
%Step response 
%
figure(1);clf;
tau=1;z=0.1;
num=[-1 z];den=conv([1 z],[tau 1]);clf
step(num,den);hold;plot([0 50],[0 0],'w:');
ylabel('y');
tau=1;z=0.1;omega=logspace(-2,1,101);
t1 = nd2sys([-1 z],[1 z]); t2 = nd2sys(1,[tau 1]);
t = mmult(t1,t2);
s = msub(1,t);

%Work out margins, peak values and frequencies.
%
[Gm,Pm,W180,Wc]=margin([-1 z],[tau tau*z+2 0]);
mt=hinfnorm(t,1.e-4);ms=hinfnorm(s,1.e-4);
omega=logspace(-2,1,301);
t_f=frsp(t,omega);
s_f=frsp(s,omega);
[x,x,x,Wb]=imargin(abs(vunpck(s_f)/0.707),angle(vunpck(s_f)),omega);
[x,x,x,Wbt]=imargin(abs(vunpck(t_f)/0.707),angle(vunpck(t_f)),omega);
disp(sprintf('[Gm,Pm,Ms,Mt]=[%4.1f,%5.1f,%5.2f,%4.1f ]',Gm,Pm,ms(1),mt(1)));
disp(sprintf('[W180,Wc,Wb,Wbt]=[%5.2f,%6.3f,%6.3f,%4.1f ]',W180,Wc,Wb,Wbt));

%Figure 2.15
%Frequency response
%
figure(2);clf;
line=[0.707 0.01;0.707 0.036;1 0.036;0.707 0.036;0.707 1;1 1;6 Inf];
subplot(111),vplot('liv,lm',t_f,s_f,1,'w:',line,'w:');
axis([.01,10,.1,4]);


