lsim() vs step() : are different responses expected?

43 Ansichten (letzte 30 Tage)
John
John am 12 Apr. 2023
Kommentiert: Paul am 22 Apr. 2023
Are different responses expected if running lsim() and step(), both with the same unit step inputs?
I have a state-space system representing a closed-loop system, that gives the expected output with a unit step input to lsim() -- but not with a unit step input to step().
Even if the system itself is incorrectly built, i'd have expected equivalent responses from step() and lsim().
Background:
The system is attached in sys.mat, and is shown at the end of the post as well. The .m file that plots these is also attached.
The states are: x = [x1, x2, xi, x1^, x2^, xi^], where ^ are estimated states. x1,x2 are pos/vel, and xi is the integral action state.
x1, x1^ , and x2, x2^ , and xi^ are all as expected.
But xi is not as expected. For some reason, with the same ref step input of 1,
step() gives an unexpected xi=0, and
lsim() gives the expected xi .
Questions:
What's the difference between step() and lsim() -- if the same system and same ref inputs are used -- that would cause outputs to differ?
Are step() and lsim() both inputting the ref to u? If they are both setting u = 1, then shouldn't sys.B provide inputs to both xi and xi^ level even when using step(), since B is [0;0;1, 0;0;1]?
For step(): see 2nd subplot, blue line = 0.
For lsim(): both plots seem as expected.
The details are perhaps not important: regardless of whether the system is correctly built or not, i'd have expected equivalent responses from step() and lsim()
But in case it matters, in the state space sys, the two relevant rows are xi, and xi^:
xi_dot = -C*x + 1*u
xi^_dot = -C*x^ + 1*u
with u = reference step input, and -C*x = y (theta) and -C*x^ = y^ (theta^)
Here's the system. It's also in the attached .mat file.
sysCl_lqgi =
A =
theta angVel xi theta^ angVel^ xi^
theta 0 1 0 0 0 0
angVel -6.317e+04 -160 0 -4.468e+07 -6.376e+04 1.596e+10
xi -1 0 0 0 0 0
theta^ 4.212e+04 0 0 -4.212e+04 1 0
angVel^ 4.398e+08 0 0 -4.845e+08 -6.392e+04 1.596e+10
xi^ 0 0 0 -1 0 0
B =
u F
theta 0 0
angVel 0 1e+05
xi 1 0
theta^ 0 0
angVel^ 0 0
xi^ 1 0
C =
theta angVel xi theta^ angVel^ xi^
theta 1 0 0 0 0 0
D =
u F
theta 0 0
Continuous-time state-space model.

Akzeptierte Antwort

Paul
Paul am 18 Apr. 2023
Bearbeitet: Paul am 18 Apr. 2023
I was able to recreate your strange result on R2022a.
After some investigation, I think I know what's happening.
load sys.mat
sys = sysCl_lqgi;
The six states of this system are:
sys.StateName.'
ans = 1×6 cell array
{'theta'} {'angVel'} {'xi'} {'theta^'} {'angVel^'} {'xi^'}
After examining the state space matrices and based on the state names, it looks like you started with a 2-state model, augmented it with an integrator, then designed an observer for the augmented plant (including the integrator) and then closed the loop through the control applied to the estimated states, where the external reference signal forms the error that feeds xidot and xihatdot. However, the third column of sys.A is all zeros, so even if xi is excited by the reference input, xi will have no effect on the output, which is theta. Same thing with xi being excited by the disturbance input. Consequently, xi can be eliminated from the system with no impact on the input/output response. This elimination is called structural minimal realization sminreal.
msys = sminreal(sys);
msys.StateName.'
ans = 1×5 cell array
{'theta'} {'angVel'} {'theta^'} {'angVel^'} {'xi^'}
Note that sminreal eliminates the third state.
I'm 99% certain (can't be 100% because I ran into a function that was implemented in p-code and so I couldn't examine it) that deep in the bowels of the code that computes the step response, it does a structural minimal realization (after converting the input sys to its discrete time approximation) of the system. But, in the outputs returned to the user, the eliminated state(s) is filled with zeros, so as to keep the dimensions of the state vector output of step() aligned with the definitions of sys. I don't have 2023a installed locally and so can't see what changed in 2023a.
You can test this by changing the C matrix to
sys.c = [0 0 1 0 0 0];
In so doing, that third state can't be eliminated because it's needed for the output
msys = sminreal(sys);
msys.StateName.'
ans = 1×6 cell array
{'theta'} {'angVel'} {'xi'} {'theta^'} {'angVel^'} {'xi^'}
You'll see that if you run your code with this sys that you get the step response plots you expect for the state vector.
  5 Kommentare
Paul
Paul am 21 Apr. 2023
I think a better approach would be
sys = ss(a,b,[c;eye(size(a))],[d;zeros(size(a,1),size(b,2))]);
[y,tout,x] = step(sys);
which preserves the original outputs specified by the user as the first elements in y.
Paul
Paul am 22 Apr. 2023
I wonder why the update in 2023a is not listed as bug fix or as a change in behavior in the Release Notes

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Paul
Paul am 12 Apr. 2023
The code and the system in the .mat file does not recreate the step plot. There is also an undefined variable.
load sys.mat
% step()
sys = sysCl_lqgi;
[y,tout,x] = step(sys);
figure
subplot(2, 1, 1);
plot(tout, x(:, 1, 1), 'b', 'LineWidth', 1.5);
hold on
plot(tout, x(:, 4, 1), 'k:', 'LineWidth', 2.5)
grid on;
title('x1', 'FontSize', 14)
legend({'$x_1$', '$\hat{x_1}$'},'Interpreter','latex', 'FontSize', 16);
xlim([0, 0.02]);
subplot(2, 1, 2);
plot(tout, x(:, 3, 1), 'b', 'LineWidth', 1.5);
hold on
plot(tout, x(:, 6, 1), 'k:', 'LineWidth', 2.5);
grid on;
title('xi', 'FontSize', 14)
legend({'$x_i$', '$\hat{x}_i$'},'Interpreter','latex', 'FontSize', 16);
xlim([0, 0.02]);
xlabel('Time [s]', 'FontSize', 14)
sgtitle('STEP(): Ref response');
% lsim()
step inputs a step simultaneously to both inputs. So the second column of u should also be ones, not zeros.
u = [ones(size(t)) zeros(size(t))];
Unrecognized function or variable 't'.
[y, tout, x] = lsim(sys, u, t, zeros(6,1));
figure;
subplot(2, 1, 1);
plot(t, x(:, 1, 1), 'b', 'LineWidth', 1.5);
hold on;
plot(t, x(:, 4, 1), 'k:', 'LineWidth', 2.5);
grid on;
title('x1')
legend({'$x_1$', '$\hat{x_1}$'},'Interpreter','latex', 'FontSize', 16);
xlim([0, 0.02]);
subplot(2, 1, 2);
plot(t, x(:, 3, 1), 'b', 'LineWidth', 1.5);
hold on;
plot(t, x(:, 6, 1), 'k:', 'LineWidth', 2.5);
grid on;
title('xi', 'FontSize', 14);
legend({'$x_i$', '$\hat{x}_i$'},'Interpreter','latex', 'FontSize', 16);
xlim([0, 0.02]);
xlabel('Time [s]', 'FontSize', 14)
sgtitle('LSIM(): Ref response', 'FontSize', 14)
  16 Kommentare
John
John am 17 Apr. 2023
@Paul @Sam Chak @Walter Roberson Just to update as requested, this is the response from Mathworks so far:
"Thank you for your patience in awaiting my reply. I was able to reproduce this issue. I am unsure as to the cause of this. The error arises in R2022b and all previous versions but disappears in R2023a onwards. The only ostensible change in "step" in R2023a is that the default start time is not limited to t = 0. This does not apply to your script, since the time array started at 0.
Some of my colleagues and I are taking a look at the moment. I will get back to you when I have further information to share."
Sam Chak
Sam Chak am 17 Apr. 2023
Hi @John, thanks for your update. It's good that you pointed out the issue. Luckily in my work, I seldom use high-value parameters.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by