how to plot this function
이전 댓글 표시

댓글 수: 4
darova
2019년 5월 17일
Do you have any attempts?
HADIMARGO
2019년 5월 17일
HADIMARGO
2019년 5월 17일
Walter Roberson
2019년 5월 18일
(n<-2 & n>2)
is never true. However, since you are multiplying that by 0, if it somehow did match it would contribute 0 anyhow. You can just leave out that term.
Your x axis is wrong. You are effectively using your n as your frequency, including negative n. If you are going to plot negative frequencies then you need to fftshift() . And use more points.
Read the first example of fft() to see how to properly plot.
답변 (2개)
Sulaymon Eshkabilov
2019년 5월 18일
n = -5:1:5;
x=1*(n>=-2 & n<=2)+0*(n<-2 & n>2);
L = length(n); Fs = 1;
Nblock = 128; % Block size
Y = fft(x, Nblock)/L;
f = Fs/2*linspace(0,5, Nblock/2+1);
plot(f, 2*abs(Y(1:Nblock/2+1)))
xlabel('frequency, [Hz]'), ylabel('Amplitude')
title('Single-sided Spectrum'), shg
댓글 수: 3
madhan ravi
2019년 5월 18일
편집: madhan ravi
2019년 5월 18일
x=1*(n>=-2 & n<=2)+0*(n<-2 & n>2); % what is the necessity to multiply it by zero ??
% Hint: Not necessary
HADIMARGO
2019년 5월 18일
HADIMARGO
2019년 5월 18일
Sulaymon Eshkabilov
2019년 5월 18일
Hi,
Here is the full spectrum calculation:
n = -5:1:5;
x=1*(n>=-2 & n<=2);
L = length(n); Fs = 1;
Nblock = 128; % Block size
Y = fft(x, Nblock)/L;
f = Fs/2*linspace(0,5, Nblock);
plot(f, 2*abs(Y(1:Nblock)))
xlabel('frequency, [Hz]'), ylabel('Amplitude')
title('Single-sided Spectrum'), shg
Good luck.
댓글 수: 4
HADIMARGO
2019년 5월 18일
Walter Roberson
2019년 5월 18일
fftshift()
HADIMARGO
2019년 5월 19일
Walter Roberson
2019년 5월 19일
t = linspace(0,10);
ft = fft(t);
subplot(1,2,1); plot(abs(ft)); %what you are doing now
subplot(1,2,2); plot(abs(fftshift(ft))); %what you need to do in order to get the 0 in the center
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



