Given n=[-1:0.01:10]. Plot the discrete time domain signal: y[n]=e^(-n)*u(n).
Below is my program but i'm not sure if it's correct since this is my fisrt time learning Matlab. Please help. Thanks!
n=-1:0.01:10;
y=exp(-n).*heaviside(n);
stem(t,y)

댓글 수: 1

Paul
Paul 2021년 2월 14일
편집: Paul 2021년 2월 15일
Be careful using heaviside for u[n]. In control systems and signal processing the function u[n] is the unit step function that is (typically) defined as
u[n] = 1 for n >= 0
u[n] = 0 for n < 0.
However, the default defintion of the heaviside function in Matlab has heaviside(0) = 0.5., which is clearly seen in the plot. Is that the desired answer?
Also, it looks a bit peculiar to have non-integer values of n. Please make sure that's the correct problem statement.

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

 채택된 답변

Paul Hoffrichter
Paul Hoffrichter 2021년 2월 14일

0 개 추천

I recommend using following substitutions:
plot(t,y)
axis( [-1 10 0 1])

댓글 수: 6

Jinquan Li
Jinquan Li 2021년 2월 14일
I need to plot discrete time signals so I have to use “Stem”, right?
Paul Hoffrichter
Paul Hoffrichter 2021년 2월 14일
편집: Paul Hoffrichter 2021년 2월 14일
Your program looks OK. It is your choice (or an instructor's choice) as to whether you should use plot or stem. Here is an explanation of the differences.
With your x-limits, you cannot make out the stem distinct lines. If you zoom in, you will be able to see the stem vertical lines better.
If you want to use plot and also see the distinct discrete y-values, you can do this so that each (t,y) value has a dot that are connected with lines to the next dot.
plot(t,y, '-b.)
Jinquan Li
Jinquan Li 2021년 2월 14일
Thanks a lot!
Paul Hoffrichter
Paul Hoffrichter 2021년 2월 14일
Your very welcome!
Paul Hoffrichter
Paul Hoffrichter 2021년 2월 15일
Just be careful as to how u(n) is defined. As @Paul mentioned, "heaviside(0) = 0.5., which is clearly seen in the plot. Is that the desired answer?". As you know, e^(-0) is 1, not 0.5, so it is up to you to decide whether your u(n) is defined the way you want it to be defined. If it is a unit step function, where u(0) is 1, then using the heaviside without adjustments leads to an incorrect value for y(n) when n is 0.
Take a look at
The following defines the myStep function so that myStep(0) is 0 instead of 0.5.
myStep = @(n) (n>0);
If you wanted a value of 1 at n = 0, then you could use this instead:
myStep1 = @(n) (n>=0);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Labels and Styling에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2021년 2월 14일

댓글:

2021년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by