How to plot delta dirac and unit step functions
이전 댓글 표시
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
Walter Roberson
2020년 9월 22일
What function did you find to implement dirac delta?
What function did you find to implement unit step function?
Steven Artzer
2020년 9월 22일
Walter Roberson
2020년 9월 23일
What have you accomplished so far? What particular parts are you looking for assistance with?
Steven Artzer
2020년 9월 23일
Steven Artzer
2020년 9월 23일
Walter Roberson
2020년 9월 23일
편집: Walter Roberson
2020년 9월 24일
DIRAC = @whatever_dirac_delta_function_you_find;
UNITSTEP = @whatever_unit_step_function_you_find;
t = linspace(-50, 50, 500);
Example3 = UNITSTEP(3-T);
stem(t, Example3);
That shows you the syntax . Now you have to find or write a function that implements dirac delta, and find or write a function that implements unit step function.
Steven Artzer
2020년 9월 24일
Walter Roberson
2020년 9월 24일
편집: Walter Roberson
2020년 9월 24일
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.
답변 (3개)
Idin Motedayen-Aval
2024년 5월 23일
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
Kiran Felix Robert
2020년 11월 4일
0 개 추천
Hi Steven,
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
Carlos M. Velez S.
2025년 7월 24일
The examples above refer to the Kronecker delta function for discrete signals. If you want to apply the Dirac delta function in simulation to continuous-time systems, the following code is enough:
function y = delta_dirac(u)
[n,m] = size(u);
if max(n,m) ==1
dt = 1e-6; % Define a small time increment for the delta function
else
dt = u(2) - u(1);
end
y = zeros(n,m);
for i=1:max(m,n)
if u(i) == 0
y(i) = 1/dt;
else
y(i) = 0;
end
end
카테고리
도움말 센터 및 File Exchange에서 Bartlett에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
