Plotting lsim directly results in different plot when writing to variables first
Mostrar comentarios más antiguos
Hello, I have come across this issue when simulating a system.
lsim provides an output directly, which appears as expected with 'discrete steps'. But when I write the output of lsim to variables for later use, the plotting of those variables results in a smooth output. Is this expected? I have checked to see if plot is interpolating between the discrete points, there is a function 'stairs' which stops this interpolation, but I don't think that should be necessary. Is this due to using a discrete transfer function?
Edit. Just to clarify, I am expecting to see the same plot when using lsim(GVelD, u), or using [VelD, toutVD] = lsim(GVelD, u); plot(toutVD, VelD).
Ts = 0.07; % Sampling rate
GVelC = tf([6.33], [(1/(2*pi*0.54)) 1]) % S Domain TF
GVelD = c2d(GVelC, Ts, 'zoh') % Z Domain TF
% Generate a square wave for 7 cycles.
P=ones(1,20);
N=zeros(1,20);
PN=[P N];
u=[PN PN PN PN PN PN PN];
t = 0:Ts:Ts*length(u)-Ts;
%% Plot lsim directly
clf;
lsim(GVelD, u);
%% Or write lsim to variables first, then plot
clf;
[VelD, toutVD] = lsim(GVelD, u);
plot(toutVD, VelD);
2 comentarios
Sulaymon Eshkabilov
el 1 de Jun. de 2021
Yes, the stair type graph is due to discrete system (c2d) simulation. You can adjust it by changing your discrete time step.
If you plot just the continuous system tf (GVelC), then those stair type of jagged shapes won't be there.
Thomas Battye-Smith
el 1 de Jun. de 2021
Respuestas (1)
Paul
el 1 de Jun. de 2021
0 votos
plot() is a general purpose plotting function and has no way of knowing that the inputs to be plotted represent sample times and sample outputs from a discrete time system. It just plots the data.
On the other hand, lsim() knows that it's plotting the output of a discrete time system and plots the output appropriately.
1 comentario
Thomas Battye-Smith
el 1 de Jun. de 2021
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!