I need to get an output like below.
But this is the output I get as a result of the code I wrote.
clc
clear all
close all
N = 5;
n = -N-2: 1 : N+2;
u = unit(n+N/2)-unit(n-N/2);
subplot(2,1,1);
stem(n,u);
grid
title('x(t)');
X = fftshift(fft(u));
subplot(2,1,2)
plot(n,abs(X))
grid
title('|X(w)|')
How can I do this, thank you very much for your help.

 채택된 답변

dpb
dpb 2021년 6월 2일

0 개 추천

Look at documentation for nextpow2

댓글 수: 4

Kutlu Yigitturk
Kutlu Yigitturk 2021년 6월 2일
How can I ımplement it
dpb
dpb 2021년 6월 2일
Follow the last example there, although you'll have to use at least nextpow2(5) in order to have enough resolution so smooth out the plot -- experiment to see what can get by with.
dpb
dpb 2021년 6월 2일
편집: dpb 2021년 6월 3일
subplot(2,1,1)
stem(-7:7,u)
subplot(2,1,2)
Y=abs(fft(u));
hL=plot(fftshift((Y)));
xlim([1 numel(Y)])
hold on
Y=abs(fft(u,2^nextpow2(u)));
hL(2)=plot(linspace(0,15,numel(Y)),fftshift((Y)));
Y=abs(fft(u,32));
hL(3)=plot(linspace(0.5,15,numel(Y)),fftshift((Y)));
ylim([0 5])
legend('N=15','N=16','N=32','location','northeast')
gives
You'll want to fix up legends to make the points match your above; I just normalized to the range of the first set of points; whether is exactly symmetric in indices in output vector depends on whether is even/odd number of points, of course.
Paul
Paul 2021년 6월 3일
Keep in mind that the output of fft() will need to be adjusted if desired to have the phase of the end result approximate the phase of the DTFT of u.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

질문:

2021년 6월 2일

댓글:

2021년 6월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by