Plotting lsim directly results in different plot when writing to variables first
显示 更早的评论
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 个评论
Sulaymon Eshkabilov
2021-6-1
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
2021-6-1
回答(1 个)
Paul
2021-6-1
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Digital Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!