How to plot this square signal without sum?
Show older comments

3 Comments
KSSV
on 7 Jul 2023
What have you attempted?
Armin
on 7 Jul 2023
Angelo Yeo
on 7 Jul 2023
Edited: Angelo Yeo
on 7 Jul 2023
I have already responded in the reddit post below.
https://www.reddit.com/r/matlab/comments/14sxpg2/how_to_plot_this_square_signal_without_sum/
Accepted Answer
More Answers (1)
You could use the heaviside function of the symbolic variable toolbox,I'm attaching a link for your reference:
The link to syms is:
The link to subs is:
The following code snippet shows how you could use the above function:
% t1 and t2 are the limits as specified in the question
t2=0.5;
t1=-0.5;
%domain is kept a little wider so that the signal can be analysed with a
%little more ease
domain=t1-1:0.01:t2+1;
%syms is used to generate a symbolic variable,refer to the above link for any
%clarifications
syms t;
signal=heaviside(t+t2)-heaviside(t+t1);
%subs is used to substitute range of values into symbolic variables
y=subs(signal,t,domain);
plot(domain,y)
xlim([-2 2])
ylim([-1 2])
grid on
The output to the above code is the following:

Hope this helps!
Categories
Find more on Assumptions 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!