%Figure 5.4

% This example illustrates the trade-off between bandwith requirements
% and the peak of the sensitivity function S. The bandwith is 
% increased by increasing the controller gain, k, for a plant with a RHP 
% zero at z=2. It is demonstrated that this results in an increase in the 
% peak of s (infinity norm)

% constants
  k1=0.1;
  k2=0.5;
  k3=1;
  k4=2;
  points=301;
  omega=logspace(-3,1,points);

% plant g(s) = (2-s)/(2+s)
  g=nd2sys([-1 2],[1 2]);

% minimal realization of loop transfer function with controller k(s) = k/s
  l1=sysbal(mmult(g,nd2sys(k1,[1 1e-10])));
  l2=sysbal(mmult(g,nd2sys(k2,[1 1e-10])));
  l3=sysbal(mmult(g,nd2sys(k3,[1 1e-10])));
  l4=sysbal(mmult(g,nd2sys(k4,[1 1e-10])));

% frequency response of sensitivity function: s=1/(1+L)
 s1_f=frsp(minv(madd(1,l1)),omega);
 s2_f=frsp(minv(madd(1,l2)),omega);
 s3_f=frsp(minv(madd(1,l3)),omega);
 s4_f=frsp(minv(madd(1,l4)),omega);

vplot('liv,lm',s1_f,s2_f,s3_f,s4_f,1,':')
xlabel('Frequency')
ylabel('Magnitude of S')
axis([0.0100   10.0000    0.1000   30.0000]);
text(0.12,1.2,'k = 0.1')
text(0.35,1.5,'k = 0.5')
text(0.55,2.5,'k = 1.0')
text(0.75,10,'k = 2.0')
text(0.7,7.5,'(unstable)')


