Why TIME SHIFTING is not happening? (Thank you in advance!)
1 回表示 (過去 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
1 件のコメント
darova
2019 年 9 月 30 日
It is something wrong with MATLAB i think
DId you try to write to MathWorks Support?
回答 (2 件)
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?
0 件のコメント
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!