%Example 9.3 Glover-McFarlane H_inf loop shaping
clear all
close all

dist=1; time=3;
omega=logspace(-2,3,401);

%Plant (9.75):
Gd = nd2sys(1,[10 1],100);
g1 = nd2sys(1,[10 1],200); g2 = nd2sys(1,[0.05 1]); 
G = mmult(g1,g2,g2);               % g(0)=200

% Weight (9.76)
W1 = nd2sys([1 2],[1 1.e-4],1);  
Gs = sysbal(mmult(G,W1));

[a,b,c,d]=unpck(Gs);
%  Robustify this shaped plant with respect to coprime uncertainty
gammarel=1.1;
[Ac,Bc,Cc,Dc]=coprimeunc(a,b,c,d,gammarel);
Ks=pck(Ac,-Bc,Cc,-Dc);
K = mmult(W1,Ks); 
Lr = mmult(G,K);

L=Gs;
S = minv(madd(1,L));
Sgd = mmult(S,Gd);
Lf=abs(frsp(L,omega));
SGd = mmult(S,Gd); 
ys = trsp(SGd,dist,time); 

l=Lr;
s = minv(madd(1,l));
sgd = mmult(s,Gd);
Lrf=abs(frsp(l,omega));
sgd = mmult(s,Gd);
yr = trsp(sgd,dist,time);

subplot(221); vplot('liv,lm',Lrf,Lf,'--',1,':');
axis([.01,100,.01,10000]); 
xlabel('Frequency')
ylabel('Magnitude')
text(0.3,800,'Gs');
text(0.05,200,'GsKs');
drawnow;

subplot(222),vplot(yr,ys, '--',0,':')
axis([0,3,-0.5,1]);
xlabel('Time');

