Hello! Welcome to our next lesson.
In our previous session, we mathematically confirmed the Separation Principle. We constructed the combined system matrix and proved that its eigenvalues are simply the union of the controller poles and the observer poles. This was a crucial theoretical checkpoint.
Today, we're moving from that eigenvalue analysis to a full-scale simulation. Our goal is to implement a complete observer-controller system and watch it in action. We will build a single, combined state-space model that includes both the plant and the observer, and then simulate its time-domain response. This will allow us to visualize the observer's estimates converging to the true system states and see how the controller uses these estimates to stabilize the system. This lesson is the capstone of our work on pole placement and observer design.
1. The Architecture of an Observer-Based Controller
Before we write any code, let's visualize how the components fit together. The controller is no longer using the true state for feedback. Instead, it relies entirely on the observer's estimate, .
The signal flow is as follows:
- The observer takes the system's control input and measured output as its inputs.
- It continuously computes the state estimate, .
- The control law is now calculated using this estimate: .
- This control input is then applied to the actual system (the "plant").
This closed-loop structure is depicted in the block diagram below.

2. Building the Combined System for Simulation
To simulate this entire system, we need to describe it with a single set of state-space equations. The most intuitive way to do this is to create an augmented state vector that includes both the plant's true states and the observer's estimated states .
Let our new augmented state vector be . This vector has states, where is the number of states in our original system.
Let's derive the state equations for this augmented system.
-
Plant dynamics: The plant's state equation is . Since the control law is , we can substitute it in:
-
Observer dynamics: The observer's state equation is . We can substitute , , and :
Rearranging this by grouping terms with and gives:
Now, we can combine these two equations into a single matrix equation for our augmented state vector :
This equation, , describes the complete, closed-loop system dynamics under state-estimate feedback. This is the model we will implement and simulate.
For a detailed walkthrough of forming this combined system, especially for the inverted pendulum example, the following resource is excellent.
Inverted Pendulum: State-Space Methods for Controller Design
The 'Observer-based control' section of this CTMS page for the inverted pendulum provides a concise summary of the combined system equations and how to implement them in MATLAB.
Please read the section titled 'Observer-based control', focusing on the matrix equations presented for the closed-loop system (just before the MATLAB code block). Notice how they construct a large state-space system (Ace, Bce, etc. in their notation) to represent the combined plant and observer.
3. Step-by-Step MATLAB Implementation
Let's outline the process for simulating the system's response to an initial perturbation. This is the standard way to verify that both the controller and the observer are working as designed. We'll assume you have your system matrices A, B, C, and have already designed your controller gain K and observer gain L.
Step 1: Define the Augmented System
First, construct the closed-loop matrix A_cl in MATLAB.
% A, B, C, K, L are assumed to be defined
n = size(A, 1); % Number of states
A_cl = [ A, -B*K;
L*C, A - B*K - L*C ];
Step 2: Define Outputs for Plotting
We want to be able to plot both the true states and the estimated states . We can define an augmented output matrix C_cl that selects all states.
C_cl = eye(2*n);
D_cl = zeros(2*n, size(B,2)); % Assuming D=0 and no external input
Step 3: Create the State-Space Object
Now, create a single ss object representing the entire system.
sys_cl = ss(A_cl, [], C_cl, []); % No B or D matrix since we'll use initial conditions
The empty brackets [] for the B and D matrices signify that we are simulating a system with no external input, responding only to initial conditions.
Step 4: Set Initial Conditions
This is the most important step for testing the observer. We must give the plant and the observer different initial conditions to see if the observer can converge. A common practice is to give the plant a non-zero initial state and start the observer at zero, simulating a scenario where the observer is turned on with no prior knowledge.
x0 = [0.1; 0; 0; 0]; % Example: Initial 10cm position error for the plant
x_hat0 = [0; 0; 0; 0]; % Observer starts from zero
z0 = [x0; x_hat0]; % Combined initial state vector
Step 5: Simulate and Plot
Use MATLAB's initial command to simulate the response and then plot the results.
t = 0:0.01:5; % Time vector for simulation
[z, t] = initial(sys_cl, z0, t);
% Extract true and estimated states
x = z(:, 1:n);
x_hat = z(:, n+1:2*n);
% Plotting (example for state 1)
figure;
plot(t, x(:,1), 'b-', 'LineWidth', 2);
hold on;
plot(t, x_hat(:,1), 'r--', 'LineWidth', 2);
grid on;
title('State 1: True vs. Estimated');
xlabel('Time (s)');
ylabel('State value');
legend('True State (x1)', 'Estimated State (x1_hat)');
You would repeat the plotting for all states to verify convergence for each one.
Test your understanding!
In our simulation setup, why is it crucial to set x0 and x_hat0 to different values? What would you expect to see if you ran the simulation with x_hat0 = x0?
Show answer
Setting different initial conditions simulates the realistic case where the observer starts with an incorrect guess of the system's true state. The purpose of the simulation is to verify that the estimation error, , converges to zero.
If you set x_hat0 = x0, the initial estimation error e(0) would be zero. In an ideal simulation with no noise or model mismatch, the error dynamics would mean the error remains zero for all time. You would see the estimated states perfectly tracking the true states from the very beginning, but you would not have verified the observer's ability to correct for an initial error.
4. A Practical Simulation Walkthrough
The following video provides a great walkthrough of simulating an observer-based system in MATLAB. It uses a slightly different, but very powerful, method involving an ODE solver (ode45). This approach is more general as it can also be used for nonlinear systems. The core principles of setting up the state derivatives remain the same.
Simulating Observer Based Feedback Control in MATLAB
This video, 'Simulating Observer Based Feedback Control in MATLAB', demonstrates how to create a MATLAB function for the system's dynamics and use an ODE solver to simulate the response.
Please watch from 4:31 to 8:20 to see how the augmented state vector and its derivative are defined. Then, watch from 8:51 to 14:59 to see how different initial conditions are set for the plant and observer, and how the results are simulated and plotted to show convergence.
Watching this will give you a concrete feel for how these simulations are coded and what the results should look like.
Conclusion
Today, you've learned how to take a designed controller and observer and bring them together into a single, functional, and simulatable system. This is the final step in validating a pole-placement-based control design.
Key Takeaways:
- An observer-based controller uses the state estimate for feedback, with the control law .
- To simulate the complete system, we create an augmented state-space model with state vector .
- The system matrix for this combined model is .
- Verifying observer performance requires simulating with different initial conditions for the plant () and the observer ().
- The goal is to plot the true vs. estimated states and confirm that the estimation error converges to zero while the overall system remains stable.
Preview of the Next Module:
We have now fully mastered the pole placement design technique. However, you might have noticed that choosing "good" pole locations can be somewhat arbitrary. It requires experience and iteration. What if there were a more systematic method to design a controller that is "optimal" according to some performance criteria?
In our next module, we will begin exploring just that with the Linear Quadratic Regulator (LQR). LQR allows us to find an optimal controller gain by balancing state regulation against control effort, providing a powerful and elegant alternative to pole placement.