Simulink state space observer output issue

Hello everyone. For my simulink state space observer system, I set up two models based on the same system. One model that doesn't use the 'state space block', and another one that uses the 'state space block'. The 'state space block' was configured (with the A, B, C, D matrices) to be the equivalent to my graphical interconnected blocks observer system model.
The output of the graphical interconnected block observer model is mostly satisfactory - except, I notice that the plotted output always spikes or rockets up to large value at the 'end time'. So if I choose a simulation end-time of 0.5 seconds, then the spike occurs at 0.5 seconds. And if I choose the simulation end time to end at 10 seconds, then the spike will occur at 10 seconds, while the general output response is satisfactory for times well below 10 seconds. Same if I were to choose an end time of 20 seconds. The spike would occur at 20 seconds.
However, for the compact 'state space block' model of the observer system. Equivalent system. The output never gets that spiking (which is good).
Woud anyone have any ideas about the reason for spiking seen only at the end-time? And anything we can try - so that the spike at the end time doesn't occur for the blocks-connected observer model? Thanks all!

4 Comments

It looks like a parameter drift in the state estimation.
Need more mathematical info about the plant, the controller, and the observer to compare and to investigate.
Kenny
Kenny on 1 Aug 2023
Edited: Kenny on 1 Aug 2023
Thanks Sam!
For this case, the issue seems to be related to the chosen end (stop) time only. So if I choose a stop time of 20 seconds, then the output is as expected (as in normal) until the simulation reaches somewhere around the stop time. If I choose 50 seconds stop time, then the output is as expected - until that chosen stop time is reached.
It appears to be looking like the issue isn't with my constructed models - because the outputs of both of my models are as expected in general - and the deviation from expected seems to depend on the chosen end (stop) time. Or at least that is what it looks like at the moment.
I'll just upload my matlab/simulink 2019b simulation file here - for you and everybody to see what's happening there. Thanks again Sam.
Is there any difference between the two Simulink diagrams shown above?
What is implemented in the A,B,C,D matrices in the State Space block in the lower right of the block diagrams?
Kenny
Kenny on 3 Aug 2023
Edited: Kenny on 3 Feb 2025
Hi @Paul ! I just spent ages - typing a reply to you in the editor. Only to find that my time was totally wasted - because at the very end of my long reply, I was simply trying to upload screenshots. And when I dragged an image to the uploader window, a pop-up window arose and prompted - 'leave page, or stay on page'. Now I realise that this editor has drag-drop for files, but no 'drag-drop' for images. I assumed I needed to just click on 'leave page' and let the software do whatever it was trying to do. And surprisingly - and disappointingly - it went to another page - so the reply that I typed was just completely lost. No trace of it when I used the 'back' (arrow) in the web-browser.
That's ok. The state space block in the lower right was meant to model the combination of a simulated actual second order system, plus the observer (estimator) system, and also the observer error system. Those three systems combined.
With Sam's help, I now realise that my design of the observer gain matrix L was using the wrong approach. Instead of designing 'L' based on [A - LC] system matrix, I incorrectly based the design on {[A-BK] - LC}, where the A-BK is effectively a state feedback system matrix. Sam showed that the error system matrix to use for design of L is indeed just A - LC, where 'A' does not involve the state feedback.
Also, I found in my calculations for 'L', that I used incorrect coefficients - calculation error. I have corrected the calculations - and now getting satisfactory results now.
I will upload the amended simulink project file here, and add the screenshots again. This time, I will select all of my text and copy to buffer memory -- just in case!
Thanks for your question Paul!

Sign in to comment.

 Accepted Answer

See my analysis below:
A = [0 1; 0 -32]; % state matrix
B = [0; 8]; % input matrix
C = [1 0]; % output matrix
D = 0; % direct matrix
K = [256 4]; % controller gain matrix
L = [64; -4096]; % observer gain matrix
a1 = A - B*K;
a2 = B*K;
a3 = zeros(2);
a4 = A - L*C;
Aa = [a1 a2; a3 a4] % state matrix of feedback system with a controller-observer.
Aa = 4×4
0 1 0 0 -2048 -64 2048 32 0 0 -64 1 0 0 4096 -32
% Eigenvalues of the closed-loop system with observed-state feedback
eig(Aa)
ans =
1.0e+02 * -0.3200 + 0.3200i -0.3200 - 0.3200i -1.1397 + 0.0000i 0.1797 + 0.0000i
As you can see, one eigenvalue has the positive real part. This explains why the trajectory is unstable.

5 Comments

Kenny
Kenny on 2 Aug 2023
Edited: Kenny on 2 Aug 2023
@Sam Chak -- Hi Sam! Thanks very much for your help with looking into the eigenvalues!
For that script that you very kindly made -- there is a line that says:
a4 = A - L*C
Should that line be a4 = a1 - L*C?
Because there is state feedback, the system matrix for state feedback will be a1 = A - B*K. That is good.
And a4 will then be a1 - L*C, instead of A - L*C.
One situation I'm focusing on is - when we choose a simulation time of 10 seconds (for example), then the divergence occurs at that time (in the vicinity of 10 seconds). If we choose an end time of say 100 seconds, then we see a similar pattern. The divergent behaviour will occur in the vicinity of 100 seconds. So will be interesting to see why the divergent behaviour only occurs at the end-time only, while the output is otherwise normal.
Thanks again Sam. Thanks for your help again! Greatly appreciated.
Without finding the technical cause, it is difficult to explain the divergent behavior from simulation time alone. However, from your block diagram, I reconstructed the math:
The Plant
The Observer
When Eq. (3) is subtracted from Eq. (1),
From Eq. (2),
Since the error vector, , then
I don't see at the end of the derivations. At least, we can show that the one of the eigenvalues has positive real part, leading the divergent behavior.
Kenny
Kenny on 2 Aug 2023
Edited: Kenny on 2 Aug 2023
Hi @Sam Chak! 'u' is the waveform at the input to the B matrix.
And the actual input to this observer system is .. for example 'r', which is on the left-hand side of the differencing (subtraction) block.
So u = r - K.x
Replace the 'u' of eqn 1 and eqn 3 with r - K.x, and it will lead to feedback system matrix being
a1 = A - B.K, and observer error system matrix being
[A-B.K] - L.C, which is a1 - L.C
Thanks for your clarification, @Kenny
If a4 = a1 - L*C, all eigenvalues have negative real parts. However, this theoretical stable result contradicts with the divergent behavior as seen in Simulink.
A = [0 1; 0 -32]; % state matrix
B = [0; 8]; % input matrix
C = [1 0]; % output matrix
D = 0; % direct matrix
K = [256 4]; % controller gain matrix
L = [64; -4096]; % observer gain matrix
a1 = A - B*K;
a2 = B*K;
a3 = zeros(2);
a4 = a1 - L*C; % <--- according to Kenny
Aa = [a1 a2; a3 a4]; % state matrix of feedback system with a controller-observer.
eig(Aa)
ans =
1.0e+02 * -0.3200 + 0.3200i -0.3200 - 0.3200i -0.1875 + 0.0000i -1.0925 + 0.0000i
Correct me if I'm wrong. I tried substituting , but it got eliminated at the end, leading to the orignal result presented above. I believe there must be something that explains the divergent (unstable) behavior.
When Eq. (3) is subtracted from Eq. (1),
Kenny
Kenny on 2 Aug 2023
Edited: Kenny on 31 Jan 2025
Thanks for adding those details above. Earlier, I did write u = r - Kx. I had overlooked the situation - where the state-feedback to the two sub-systems is based on the estimated state vector 'x_hat', instead of state vector 'x'.
Thanks to you Sam, as I overlooked that condition. So 'u' will correctly be r - K.x_hat
So the difference x_dot - x_hatdot will indeed be [A - LC].(x - x_hat), as you correctly had it from the beginning.
I'll redesign the observer gain matrix elements in L based on the correct observer error system matrix
[A - LC], and will get some simulink simulations to add here.
Also - fully agree with you about the divergent behaviour - difficult to explain based on the behaviour occuring in the vicinity of the end-time for simulations. Absolutely and genuinely appreciated (and appreciating) your help. I would have continued to assume (without knowing for some indefinite amount of time) that the observer error system matrix is incorrect {[A-BK] - LC}, when it really is [A - LC]. Thanks Sam.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 1 Aug 2023

Edited:

on 3 Feb 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!