lsim() vs step() : are different responses expected?
Ältere Kommentare anzeigen
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
Weitere Antworten (1)
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))];
[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
Here you go. I just copied the code out of testPaulStepPost.m and ran it here with no changes.
clear all
close all
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');
Before doing anything, what output do you get from these commands?
load sys.mat
% step()
sys = sysCl_lqgi;
which step(sys);
Paul
am 13 Apr. 2023
I have no idea why you'd be getting such a different result. To answer your question from above, I'm running everything right here, on Answers. If you do file a service request, you can inlude a link to this thread.
John
am 13 Apr. 2023
Can you check the transfer function of
on your machine using my code below?
should the 3rd state from input 1 to output.
load('sys.mat')
A = sysCl_lqgi.A;
B = sysCl_lqgi.B;
C = eye(6);
D = 0;
sys = ss(A, B, C, D);
G = tf(sys)
step(G, 0.02)
dcgain(G)
Gtest = G(3,1) % transfer function of Xi(s)/U(s)
[num, den] = tfdata(Gtest, 'v')
num(7)
Actually, I got a different value on an older machine, but I still same output as Paul did, at least up to 0.02 sec.


Walter Roberson
am 14 Apr. 2023
/Applications/MATLAB_R2022b.app/toolbox/shared/controllib/engine/@DynamicSystem/step.m % ss method
is the R2022b output on a MacOS system for the same source as
/MATLAB/toolbox/shared/controllib/engine/@DynamicSystem/step.m % ss method
The only difference is the installation directory prefix, /MATLAB in one case an /Applications/MATLAB_R2022b.app in the other case.
John
am 14 Apr. 2023
Verschoben: Walter Roberson
am 14 Apr. 2023
John
am 17 Apr. 2023
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






