%  defines the system model and the observer model
% ############ Parameter ############
kAB=1.5;
kBC=3;
kCB=2;
dvdt=1;
VR=10;
A_plant = [-kAB-dvdt/VR 0 0; kAB -kBC-dvdt/VR kCB; 0 kBC -kCB-dvdt/VR];
StateNoiseGain = [1 1 1]*2; % state noise
MeasurementNoiseGain = 1;   % measurement noise

% ############ Observer Model ############
% A_obsv = A_plant for it is assumed that there is no plant-model mismatch.
A_obsv=A_plant; 
B=[dvdt/VR;0;0];
C = [0 1 0];
% ############ Observability #############
isobsv = rank(obsv(A_obsv,C));
% ############## Initial Conditions #############
Initial = [0 0 0];
Initial_obsv = [0.2 0.2 0.2];
[V,D] = eig(A_obsv); % D = [-0.1 -5.1 -1.6], poles of the system

% ####################################### 
% ############ slow observer ############
observer_poles = [-0.1 -5.1 -1.6];
K=place(A_obsv',C',observer_poles);
K = K';
sim('Plant_observed_luenberger',100);
plot_luenberger_observer;

pause
% ####################################### 
% ############ fast observer ############
observer_poles = [-1 -51 -16];
K=place(A_obsv',C',observer_poles);
K = K';
sim('Plant_observed_luenberger',100);
plot_luenberger_observer;

pause
% ####################################### 
% ############ besser adjusted ##########
[V,D] = eig(A_obsv);
observer_poles = [-1 -5.1 -1.6];
K=place(A_obsv',C',observer_poles);
K = K';
sim('Plant_observed_luenberger',100);
plot_luenberger_observer;