%  Example 2.11.  Generate the observer and simulate.
clear
%  Define the state model matrices.
A=[0  1
   0 -1];
B=[0
   1];
C=[1 0];
D=0;
%  Define the desired observer pole locations.
p=[-8 -8];
%  Generate the observer.
G=acker(A',C',p)'
F=A-G*C
H=B-G*D
%  Set the plant initial condition.
X0=[1 -2]';
%  Generate the plant initial condition response.
t=0:.01:5;
[y,x]=initial(A,B,C,D,X0,t);
%  Set the observer initial condition.
Xhat0=[0 0]';
%  Simulate the observer.
[yh,xh]=lsim(F,G,C,D,y,t,Xhat0);
%  Plot the results.
set(0,'DefaultAxesFontName','times')
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultTextFontName','times')
figure(1)
clf
plot(t,x(:,1),'r-',t,x(:,2),'r--',t,xh(:,1),'r-.',t,xh(:,2),'r:')
grid
xlabel('Time (sec)')
ylabel('Amplitude')
legend('Angle','Angle rate','Est. angle','Est. angle rate')
