%Example 2.6, Loop-shaping design for plant (2.26)
%
% Plant (2.26), G(s)=3(-2s+1)/(5s+1)(10s+1)
Eq2_26

%Loopshaping controller

int = nd2sys(1,[1 0.0001],1); 
kc=0.05;tauf=0.33;c2=nd2sys([10 1],[2 1]); c3=nd2sys([5 1],[tauf 1],kc);
c = mmult(int,c2,c3);

% ANALYSIS OF CONTROLLERS

gc=mmult(g,c);gc=sysbal(gc);
s = minv(madd(1,gc));
t = msub(1,s);
y1 = trsp(t,1,50,0.1);
%input signal
gs = mmult(c,s); u1=trsp(gs,1,50,0.1);

gc_f = frsp(gc,omega);
c_f = frsp(c,omega);

figure(1) %Figure 2.16
clf
[A,B,C,D]=unpck(gc);margin(A,B,C,D);
axis([0.001 10 -360 0]);
h=get(gcf,'children');axes(h(2));axis([0.001 10 -50 50])
ms=hinfnorm(s);
mt=hinfnorm(t);
disp(sprintf('[Ms,Mt]=[%5.2f,%5.2f ]',ms(1),mt(1)));

figure(2) %Figure 2.17
clf
subplot(111),vplot(y1,u1,1,':')
axis([0 50 -0.5 2.5]);
text(40,1.2,'OUTPUT (y)');text(40,0.1,'INPUT (u)');
xlabel('Time');%ylabel('y');
title('Figure 2.17');


figure(3) %Firgure 2.18
clf
subplot(211),vplot('liv,lm',c_f,1,':')
ylabel('Magnitude')
xlabel('Frequency')
title('Figure 2.18');
axis([.001,10,.1,100])



