 echo on
%
%   HIMAT_EX6
%
%  It assumes that either HIMAT_X4 or HIMAT_X5 has been run.
%
%  This MATLAB script file compares time response of the 'best' 
%   control law synthesized using mu-synthesis techniques and 
%   a loopshape control design. From mu-analysis  and the 
%   output sensitivity and input complementary sensitivity, 
%   we have seen that the mu control law appears to be better.
%   Let's look at their time responses in the nominal case
%   with a constant level of uncertainty.
  
 pause    % strike any key to continue

%   We will compare the two designs, with no error or 
%   uncertainty weights, for the nominal case and with an 
%   uncertainty block [0.1 0;0 -0.1] 
%   fedback around the input multiplicative uncertainty. 
 
%  The time response will be from 0 to 2 seconds with a 
%  sample time of 0.01 seconds. We'll look at a unit step 
%  input into the first channel.
 
 mkhimat;
 mkklp;
 himat_idn = himat_ic;
 g_muidn = starp(himat_idn,k4,2,2);
 g_lpidn = starp(himat_idn,klp,2,2);
 g_muinS = sel(g_muidn,[3:4],[3:4]);
 g_lpinS = sel(g_lpidn,[3:4],[3:4]);

 pause     % strike any key to continue
 
 t = 0.:.01:2.;
 u = ones(t);
 in = [u' 0*t' t';0 201 inf];
 in = transp(in);
 out_munS = trsp(g_muinS,in,2.,0.01);
 out_lpnS = trsp(g_lpinS,in,2.,0.01);
 clg
 
% plot the time histories of nominal systems
%
%  both controllers perform very well.
  
 echo off;
 axis;
 subplot(211), axis([0 2 -2 2]);
 subplot(212), axis([0 2 -2 2]);
 subplot(211), vplot('iv,d',out_lpnS)
 subplot(211), title('Nominal response of loop-shape control law')
 subplot(211), text(.2,.86,'Unit step input','sc');
 subplot(211), grid ;
 subplot(212), vplot('iv,d',out_munS)
 subplot(212), title('Nominal response of mu control law')
 subplot(212), grid; xlabel('Time (secs)') ;
 pause
 echo on;
 clear out_lpnS out_munS

  pause      % strike any key to continue
  clg;
 
% plot time histories of the perturbed system with uncertainty added
%   notice that the size of the uncertainty, delta, is 0.1.
%
% The loop-shape controller performs poorly with a small perturbation
%   in the input signal where as the mu controller exhibits little
%   degradation in its performance. 
 
 delta = [.1 0;0 -.1];
 g_muidS = starp(delta,g_muidn,2,2);
 g_lpidS = starp(delta,g_lpidn,2,2);
 out_mudS = trsp(g_muidS,in,2.,0.01);
 out_lpdS = trsp(g_lpidS,in,2.,0.01);

 echo off;
 subplot(211), axis([0 2 -4 2]);
 subplot(212), axis([0 2 -4 2]);
 subplot(211), vplot('iv,d',out_lpdS)
 subplot(211), title('Perturbed system response with loop-shape control law')
 subplot(211), text(.2,.86,'Unit step input','sc');
 subplot(211), grid ;
 subplot(212), vplot('iv,d',out_mudS)
 subplot(212), title('Perturbed system response with mu control law')
 subplot(212), grid; xlabel('Time (secs)') ;

 pause     % strike any key to continue
 clear out_lpdS out_mudS a b c delta in t u ptest
 echo on;
 clg;
%
%       This concludes the HIMAT example 
%
% Copyright MUSYN INC 1991,  All Rights Reserved
