%  Example 2.12.  Generate the observer feedback controller and simulate.
clear
%  Define the state model matrices.
A=[0  1
   0 -1];
B=[0
   1];
C=[1 0];
D=0;
%  Define the state feedback pole locations.
p=[-2+2*j -2-2*j];
%  Generate the state feedback gain matrix.
K=place(A,B,p);
%  Define the desired observer pole locations.
po=[-8 -8];
%  Generate the observer.
G=acker(A',C',po)';
F=A-G*C;
H=B-G*D;
%  Form the closed loop state model:
Acl=[ A   -B*K
     G*C F-B*K];
Bcl=[0 0 0 0]';
Ccl=eye(4);
Dcl=[0 0 0 0]';
%  Set the plant initial condition.
X0=[1 -2 0 0]';
%  Simulate the closed loop system.
t=0:0.01:3;
[y,x]=initial(Acl,Bcl,Ccl,Dcl,X0,t);
%  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,x(:,3),'r-.',t,x(:,4),'r:')
grid
xlabel('Time (sec)')
ylabel('Amplitude')
legend('Angle','Angle rate','Est. angle','Est. angle rate')
