Why TIME SHIFTING is not happening? (Thank you in advance!)

조회 수: 1 (최근 30일)
Kartikey Rai
Kartikey Rai 2019년 9월 30일
답변: Steven Lord 2019년 9월 30일
As you can see, I am defining the value to be 1 after n = 1, t=1.
But if you look at the output, it is still starting from 0 in both cases.
The code is as follows-
close all
a = 0;
a1 = a + 1;
n1 = -5;
n2 = 5;
n = n1:n2;
x1(n>=a1) = 1;
stem(n,x1);
title('Unit Step Signal - Discrete')
xlabel('t')
ylabel('ust')
axis([-5 5 0 2])
grid on
n3 = 5;
t = 0:n3;
x2(t>=a1) = 1;
plot(t,x2)
title('Unit Step Signal - Continuous')
xlabel('t')
ylabel('ust')
axis([-5 5 0 2])
grid on
Screenshot (36).png
  댓글 수: 1
darova
darova 2019년 9월 30일
It is something wrong with MATLAB i think
img1.png
DId you try to write to MathWorks Support?

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

답변 (2개)

the cyclist
the cyclist 2019년 9월 30일
Both of the plots show exactly what I would expect from your code.
Which plot do you think is incorrect -- the discrete, or the continuous?
Making a guess at the solution:
In your continuous plot, you are drawing a connecting line between each plotted data point. So, you have a connecting line from (t==0, x2==0) to (t==1,x2==1). There are no data points in between, so it looks like there is a gradual increase, where there is not.
If instead of
t = 0:n3;
you use
t = 0:0.01:n3;
then you will have something more akin to a continuum of points, and the jump will happen between 0.99 and 1. Maybe this is closer to what you expected?

Steven Lord
Steven Lord 2019년 9월 30일
Instead of using plot for your continuous plot, I think you want to use a stairs plot.
figure
a = 0;
a1 = a + 1;
n3 = 5;
t = 0:n3;
x2(t>=a1) = 1;
stairs(t,x2) % Instead of plot
title('Unit Step Signal - Continuous')
xlabel('t')
ylabel('ust')
axis([-5 5 0 2])
grid on
In the Plots gallery (the Plots tab on the Toolstrip) one of the categories is named "MATLAB STEM AND STAIR PLOTS", so they're in some sense related.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by