Plotting system outputs together with different time intervals for each system? HELP!

3 views (last 30 days)
Hello everyone,
I have 5 state space systems (time domain) that I'm trying to plot.
sys1 should run from t = 0 to t = a and after t=a the magnitude should be 0.
sys2 should run from t = 0 to t = b (where b > a) and after t=b the magnitude should be 0.
The same goes for sys3 sys4 and sys5 (t = c, d, e respectively where e>d>c>b>a).
Does anyone have any ideas how I can restrict the system outputs in the plot area?
Here is my code:
% Create the step responses for the Transfer Function & Simulink systems
t = linspace(0,t_cutoff,51);
y1 = step(sys1,t);
y2 = step(sys2,t);
y3 = step(sys3,t);
y4 = step(sys4,t);
y5 = step(sys5,t);
% Plot these step responses vs. time
plot(t,y1,'ro',t,y2,'b-',t,y3,':squarek',t,y4,'-*g',t,y5,'-xb'),grid
My code definitely works thus far, it plots all of the functions but it plots them longer than the intervals they are supposed to cover (i.e. system 1's only sensible operation range is between t=0 and t=a, no other interval is even feasible)
Any help you can contribute is greatly appreciated! Thank you!
-Alex

Answers (1)

Sam Chak
Sam Chak on 2 Sep 2023
The lsim() function offers better control than the step() function.
t = 0:0.001:15;
Ts = [1 2 3 4 5];
w = 4./Ts;
for j = 1:length(w)
G = tf(w(j), [1 w(j)]);
u = heaviside(t) - heaviside(t - (Ts(j) + 2));
lsim(G, u, t), hold on
end
hold off, grid on
legend('G1', 'G2', 'G3', 'G4', 'G5')

Categories

Find more on Simulink in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!