%% hinfstruct Tuning of a Control System in MATLAB
%% Load the plant

load hinfstruct_demo G

%
%% Create Tunable Model of PI controller

C = tunablePID('C','pi');

%
%% Create Tunable Model of Low-Pass Filter

a = realp('a',1);    
F = tf(a,[1 a]);

%
%% Specify Target Loop shape

wc = 1000;  
s = tf('s');
LS = (1+0.001*s/wc)/(0.001+s/wc);

%
%% Label inputs and outputs of components

Wn = 1/LS;
Wn.InputName = 'nw';
Wn.OutputName = 'n';
We = LS;
We.InputName = 'e';
We.OutputName = 'ew';
C.InputName = 'e';
C.OutputName = 'u';
F.InputName = 'yn';
F.OutputName = 'yf';

%
%% Specify Summing Junctions

Sum1 = sumblk('e = r - yf');
Sum2 = sumblk('yn = y + n');

%
%% Connect the elements

T0 = connect(G,Wn,We,C,F,Sum1,Sum2,{'r','nw'},{'y','ew'});

%
%% Examine T0 blocks

T0.Blocks

%
%% Tune model

[T,gamma,info] = hinfstruct(T0);

%
%% Tuned closed-loop step response

Try = getIOTransfer(T,'r','y');
step(Try)

% Copyright 2012 The MathWorks, Inc.