%  Example 9.4.  Steady-state Hinf estimation.
clear
%  Define the bound on the disturbance input.
Wbound=0.1;
%  Define the plant model (with normalized inputs).
A=-1; B=100*[Wbound 0];
Cm=1; Cy=1; D=[0 1];
%  Form the dual of the plant model.
P=pck(A',[Cy' Cm'], B',[zeros(size(B')) D']);
%  Solve for the steady-state estimator gain.
[k,g,gfin,ax,hamx]=hinffi(P,1,1.1,1.1,.1);
G=-k(1);
%  Generate an augmented state model combining the plant and observer.
Aa=[-1   0
     G -1-G];
Ba=[100 100 0
    100  0  G];
Ca=eye(2);
Da=zeros(size(Ba));
%  Define the time vector.
t=0:.01:5;
%  Define the inputs.
u=10*ones(size(t));
w=0.1*sin(2*pi*2*t);
v=ones(size(t));
U=[u' w' v'];
%  Initialize the plant state and the estimator state.
X0=[1000 1000]';
%  Simulate the plant and the estimator.
ya=lsim(Aa,Ba,Ca,Da,U,t,X0);
%  Plot the results.
set(0,'DefaultAxesFontName','times')
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultTextFontName','times')
figure(1)
clf
plot(t,ya(:,1),'r-',t,ya(:,2),'r-.')
xlabel('Time (sec)')
ylabel('Motor shaft velocity')
grid
legend('Actual','Estimated')
set(gca,'YTick',[999 1000 1001 1002])
