DCS Lab 8 Report (Zain, Umer, Abdullah)
DCS Lab 8 Report (Zain, Umer, Abdullah)
DCS Lab 8 Report (Zain, Umer, Abdullah)
Lab #8 Report
Objectives:
• Design an observer in MATLAB
• Implement state feedback with observer in Simulink
Model
Exercise 1:
Using MATLAB, test the controllability and observability of the system. Some commands of
interest are: ctrb(), obsv(), rank()
MATLAB Code:
% Exercise 1
% System Matrices
A = [1 2; 7 1];
B = [0; 1];
C = [1 0];
D = 0;
% State-Space Model
sys = ss(A,B,C,D);
% Test controllability
ctrb_matrix = ctrb(sys)
controllability_rank = rank(ctrb_matrix)
if controllability_rank == size(A, 1)
disp('The system is controllable.');
else
disp('The system is not controllable.');
end
% Test observability
obsv_matrix = obsv(sys)
observability_rank = rank(obsv_matrix)
if observability_rank == size(A, 1)
disp('The system is observable.');
else
disp('The system is not observable.');
end
MATLAB Output:
ctrb_matrix =
0 2
1 1
controllability_rank =
obsv_matrix =
1 0
1 2
observability_rank =
Exercise 2:
Design the state feedback gain matrix K, such that the closed loop poles meet the following
criteria:
MATLAB Output:
The desired closed-loop poles are:
9.5003 4.0000
Exercise 3:
Design the observer gain matrix L, such that the eigen values of A-LC are at -1 and -1.5.
MATLAB Code:
%% Exercise 3
MATLAB Output:
Observer gain matrix L:
4.5000
9.5000
Exercise 4:
Double click on the integrator block and set the initial condition to [-1 -1].
Double click on the gain block. Enter the name of the gain matrix e.g. ‘A’ and select the
multiplication type as Matrix(K*u). Note that over here K denotes the gain matrix of this block
and u denotes the input to this block. This should not be confused with the state feedback gain K
and the input to the plant.
Now connect the state feedback controller as shown in the figure below. I have used different
colors to differentiate between the plant and the controller.
We also need to specify the values of different matrices. This can be done by going to
File>> model properties >> callbacks >>InitFcn and filling in the values of the matrices.
Run the simulation and see the signals on the scope. Is the plant stable?
Simulink Implementation:
Simulink Output:
The plant is stable because the output has zero steady state error. It takes 6 seconds for the plant
output to become stable.
Exercise 5:
Now make an observer in Simulink as shown in the figure below:
Set the initial value of the estimated states to be [0 0]. In this exercise we are not using the
estimated states for feedback. We will just examine the difference between the estimated and the
observed states.
Using a summer block find the difference of the estimated state and the actual state. Plot this
error on a Scope. This summer and scope are shown in blue color in the lower right corner of the
diagram.
Using an observer gain matrix L such that the eigen values of A-LC are at [-1,-1.5], examine
whether the error is converging to zero or not. Try this again a few times with a different
placement of eigen values, such as [-2,-2.5], [-5,-5.5], [-10,-10.5].
Exercise 6:
In a physical plant, the actual states are not always available. In you Simulink file, instead of
using the states of the actual system for feedback, use the estimated/observed states for feedback.
Look at the actual states or the output of the system to see whether it is stable or not. You may
try different eigen value placements of A-LC.
Simulink Implementation:
Simulink Output:
Run the simulation and compare ‘the states of the physical system with actual state feedback’
and ‘the states of the physical system with observed state feedback’. Is there a difference
between these states? Try this for different Eigen value placements of A-LC.
Simulink Outputs:
Comparison of Outputs:
• The system with observed state feedback takes longer to stabilize as compared to the system
with actual state feedback.
• It can also be seen that the observed state feedback system has a higher overshoot when
compared with the actual state feedback system.
Conclusion:
In this lab, we learned how to check the controllability and observability of a system to
determine if that system can be controlled and observed. We learned how to design the state
feedback gain matrix and observer gain matrix. Additionally, we learned how to create a system
with actual state feedback and observed state feedback in Simulink. For these systems we were
able to perceive their outputs via the scope and determine how different eigen values affected
observer state feedback system performance.