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 Center および File Exchange2-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