How to simulate Observer Desing in MathLab

Control Systems & Robotics Topics
Post Reply
User avatar
Magneto
Major
Major
Posts: 430
Joined: Wed Jul 15, 2009 1:52 pm
Location: London

How to simulate Observer Desing in MathLab

Post by Magneto » Wed Oct 14, 2009 5:32 pm

ob_1.JPG
ob_1.JPG (18.83 KiB) Viewed 2659 times
When we can't measure all the states x (as is commonly the case), we can build an observer to estimate them, while measuring only the output y = C x. For the magnetic ball example, we will add three new, estimated states to the system. The schematic is as follows

The observer is basically a copy of the plant; it has the same input and almost the same differential equation. An extra term compares the actual measured output y to the estimated output y_bar ; this will cause the estimated states x_bar to approach the values of the actual states x. The error dynamics of the observer are given by the poles of (A-L*C).

First we need to choose the observer gain L. Since we want the dynamics of the observer to be much faster than the system itself, we need to place the poles at least five times farther to the left than the dominant poles of the system. If we want to use place, we need to put the three observer poles at different locations.

op1 = -100;
op2 = -101;
op3 = -102;

Because of the duality between controllability and observability, we can use the same technique used to find the control matrix, but replacing the matrix B by the matrix C and taking the transposes of each matrix (consult your text book for the derivation):

L = place(A',C',[op1 op2 op3])

The equations in the block diagram above are given for x_bar. It is conventional to write the combined equations for the system plus observer using the original state x plus the error state: e = x - x_bar. We use as state feedback u = -K.x_bar After a little bit of algebra (consult your textbook for more details), we arrive at the combined state and error equations with the full-state feedback and an observer:

At = [A - B*K B*K
zeros(size(A)) A - L*C];

Bt = [ B*Nbar
zeros(size(B))];

Ct = [ C zeros(size(C))];

To see how the response looks to a nonzero initial condition with no reference input, add the following lines into your m-file. We typically assume that the observer begins with zero initial condition,x_bar =0. This gives us that the initial condition for the error is equal to the initial condition of the state.
lsim(At,Bt,Ct,0,zeros(size(t)),t,[x0 x0])

Ct = [ C zeros(size(C))];
ob_2.JPG
ob_2.JPG (11.19 KiB) Viewed 2659 times
Responses of all the states are plotted below. Recall that lsim gives us x and e; to get x_bar. we need to compute x-e.
ob_3.JPG
ob_3.JPG (12.29 KiB) Viewed 2659 times
Zoom in to see some detail
ob_4.JPG
ob_4.JPG (14.76 KiB) Viewed 2659 times
The blue solid line is the response of the ball position , the blue dotted line is the estimated state .
The green solid line is the response of the ball speed , the green dotted line is the estimated state.
The red solid line is the response of the current, the red dotted line is the estimated state .

We can see that the observer estimates the states quickly and tracks the states reasonably well in the steady-state.

The plot above can be obtained by using the plot command.
Post Reply

Return to “Control Systems & Robotics”