Unit Step Funtion Without using heaviside function

How can I plot the u(t) = u(t-1)+u(t-2)+u(t-3)+u(t-4)-u(t+1)-u(t+2)-u(t+3)-u(t+4) ?
I would like to have the plot going up on both sides without using the heaviside func.
Thank you!

댓글 수: 4

Is there a particular reason you want to avoid Heaviside?
yeah, that was the requirement for the assignment.
I see. Thanks for your clarification. The general idea is to create a function that produce the same output like the Heaviside function. For example, let's create a SAM function (square and minus) 😄
sam = @(x) x.^2 - x;
A = sam(5)
A = 20
Try creating one by referring to Heaviside step function. If you have trouble, come back again.
hint: something >= 0

댓글을 달려면 로그인하십시오.

답변 (1개)

Jonas
Jonas 2022년 6월 21일
편집: Jonas 2022년 6월 21일
you could go over the integration of the delta function, which is the heaviside function:
t=-5:5;
ds=[0 1 1 1 1 0 -1 -1 -1 -1 0];
s=cumsum(ds);
stairs(t,s)
edit: ok, i think ds needs to be multiplied with -1:
ds=[0 -1 -1 -1 -1 0 1 1 1 1 0];

댓글 수: 2

Yup, can't find any difference between them.
% Code directly using Heaviside function
t = linspace(-5, 5, 10001);
u = heaviside(t - 1) + heaviside(t - 2) + heaviside(t - 3) + heaviside(t - 4) - heaviside(t + 1) - heaviside(t + 2) - heaviside(t + 3) - heaviside(t + 4);
plot(t, u, 'linewidth', 1.5)
grid on
xlabel('t')
% Code indirectly depending on Heaviside function
A = gradient(u);
k = 1;
for j = 1:1000:10001
dS(k) = 2*A(j);
k = k + 1;
end
S = cumsum(dS); % integration of the delta function
T = -5:5;
stairs(T, S, 'r-', 'linewidth', 1.5)
grid on
xlabel('t')
there may be no visual difference but the difference lies in the detail. Heaviside is defined as 0.5 at 0 and the cumsum version is already 1 there.

댓글을 달려면 로그인하십시오.

질문:

2022년 6월 21일

댓글:

2022년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by