Borrar filtros
Borrar filtros

How to plot delta dirac and unit step functions

81 visualizaciones (últimos 30 días)
Steven Artzer
Steven Artzer el 22 de Sept. de 2020
Respondida: Idin Motedayen-Aval el 23 de Mayo de 2024
Hey all, I am having trouble trying to plot (via stem) some delta dirac and unit step functions for my Digital Signal Processing class!
The ones in particular I am trying to plot are as follows:
Thanks!
  9 comentarios
Steven Artzer
Steven Artzer el 24 de Sept. de 2020
Okay then I guess I'm mostly trying to figure out how to plot the functions listed... Like how exactly I find or write a function in Matlab for those.
Walter Roberson
Walter Roberson el 24 de Sept. de 2020
Editada: Walter Roberson el 24 de Sept. de 2020
I already showed you how to plot the functions. What I posted above was actual code.
Further example of plotting.
t = 1 : 10;
y = randi([0 1], 1, 10);
stem(t, y);
I think you should concentrate on writing functions that implement dirac delta and unit step.

Iniciar sesión para comentar.

Respuestas (2)

Kiran Felix Robert
Kiran Felix Robert el 4 de Nov. de 2020
Hi Steven,
The Examples shown above can be used to plot the functions using stem.
Refer the documentation of Dirac-delta(Dirac)and unit-step(heaviside) they point to the MATLAB Built-in functions for the unit-step and Dirac-Delta Functions. You can use these Built-in functions to write your required expression and plot using stem.
Kiran Felix Robert

Idin Motedayen-Aval
Idin Motedayen-Aval el 23 de Mayo de 2024
This question is old, and the comments contain good hints on how to solve it, but I thought it might be instructive to put the code that solves this specific problem.
The code below shows a possible implementation of dirac and unit step functions, and uses them to plot the two functions given.
(The functions dirac and heaviside are from Symbolic Math Toolbox, and will require careful treatment to be used in this context, so I'm not using them below.)
n = -4:1:4;
fn1 = myDirac(n)+2.*myDirac(n-1);
fn2 = (4-n).*myUnit(n).*myUnit(3-n);
stem(n, fn1);
figure
stem(n, fn2);
function y = myDirac(x)
% return 1 only in places where x is zero
% return zero everywhere else
y = zeros(size(x));
y(x==0)=1;
end
function y = myUnit(x)
% return zero for x values less than 0
% return 1 for x >= 0
y = zeros(size(x));
y(x>=0) = 1;
end

Categorías

Más información sobre Special Functions en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by