plot a delta function

조회 수: 17 (최근 30일)
HADIMARGO
HADIMARGO 2019년 5월 18일
답변: Ghenam Dahmane 2020년 3월 10일
hi guys.
i want to plot this simple delta function.
pls plot this with delta function code.
question.jpg

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 18일
use stem() instead of plot() and you'll get it as shown in your image.
n=-10:10; % E.g. use any space
N1 = 2; % E.g. set up at any value
x = zeros(size(n));
for jj=1:numel(n)
if abs(n(jj))<=N1
x(jj)=1;
else
x(jj)=0;
end
end
stem(n, x)
title('\delta function'), shg
  댓글 수: 2
HADIMARGO
HADIMARGO 2019년 5월 18일
thank you sir.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 18일
Hi Hadimargo,
You are most welcome. It is a pleasure. Good luck.

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

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 18일
Hi,
here is one of the possible solutions:
n=-10:10; % E.g. use any space
N1 = 2; % E.g. set up at any value
x = zeros(size(n));
for jj=1:numel(n)
if abs(n(jj))<=N1
x(jj)=1;
else
x(jj)=0;
end
end
plot(n, x, 'k-', 'linewidth', 2), grid on
title('\delta function'), shg
Good luck.
  댓글 수: 1
HADIMARGO
HADIMARGO 2019년 5월 18일
tnx for answering . but the shape is not correct:
correct shape is :

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


Ghenam Dahmane
Ghenam Dahmane 2020년 3월 10일
take this solution
n = -5:1:5;
s = zeros(size(n));
for i = 1:length(n)
if n(i)< -2
s(i) = 0;
elseif -2<=n(i)& n(i)<=2
s(i) = 1;
else
s(i) = 0;
end
end
stem(n,s,'black','Linewidth',1.5), grid on

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by