How to plot signal with unit step?

I want to plot the following signal in matlab but I am not sure how to do this with the unit step response involved.
x[n] = ((4/5)^n)u[n]
-5 < n < 20

 Respuesta aceptada

Hamoon
Hamoon el 15 de Sept. de 2015
You can use heaviside function:
n = -5:1:20;
x = ((4/5).^n).*heaviside(n);
stem(n,x)
Bet be aware heaviside(0)=0.5

3 comentarios

Bilal  Siddiqui
Bilal Siddiqui el 15 de Sept. de 2015
excellent. Thank You. I was missing '.' before * so was getting an error.
Hamoon
Hamoon el 15 de Sept. de 2015
you can also use this if you want to have u[0]=0:
n = -5:1:20;
myStep = @(n) (n>0);
x = ((4/5).^n).*myStep(n);
stem(n,x)
Hamoon
Hamoon el 15 de Sept. de 2015
My Pleasure...

Iniciar sesión para comentar.

Más respuestas (2)

Kamalika Saha
Kamalika Saha el 5 de En. de 2022

0 votos

n = -5:1:20;
x = ((4/5).^n).*heaviside(n);
stem(n,x)
Divine
Divine el 3 de Nov. de 2023

0 votos

n = -5:1:20;
x = ((4/5).^n).*heaviside(n);
stem(n,x)

Preguntada:

el 15 de Sept. de 2015

Respondida:

el 3 de Nov. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by