FFT example on MATLAB help
古いコメントを表示
Hi everybody, I am trying to learn FFT in MATLAB by understanding the example available in help file(<http://www.mathworks.co.uk/help/techdoc/ref/fft.html>). I don't know why in the line : Y = fft(y,NFFT)/L; the fft result is divided by L.
your help is apreciated
採用された回答
その他の回答 (4 件)
E K
2012 年 8 月 3 日
0 投票
when you write the command Y=fft(y,NFFT) you calculate the fft of y on NFFT and when you divide it by L you just divide the FFT matrix.
lets say a=fft(y,NFFT) what you are doing basicly
a/L.
Honglei Chen
2012 年 8 月 3 日
This is basically done to preserve the power at each frequency sample point. The original series has L samples in it. At each frequency sample point, L copies of signal at corresponding frequency are coherently added together via FFT. So to preserve the power, you need to divide by L.
This is best seen when there is no noise involved
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
x = 0.7*sin(2*pi*Fs/8*t) + sin(2*pi*Fs/4*t);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(x,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
2 件のコメント
Alzapoa
2012 年 8 月 3 日
Honglei Chen
2012 年 8 月 3 日
Yes and No. There are N samples added together. But because your L is less than N, the signal is zero-padded. Therefore, in terms of power, you only have L effective samples. That's why you need to divide by L, not N to preserve the power.
Since you bring up the DC point, I have to mention that the way the DC is treated is not entirely correct in the example. To get the one-sided spectrum, you don't need to scale both DC and Nyquist frequency as these two points are unique.
Wayne King
2012 年 8 月 3 日
編集済み: Wayne King
2012 年 8 月 3 日
Both Honglei and Rick have given you good responses. If you want the magnitudes recovered from the DFT to equal the time domain amplitudes: yes, you have to scale by the length of the input vector and multiply by 2 if you have a real-valued signal, because the real-valued signal results in complex exponentials scaled by 1/2.
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = 0.7*cos(2*pi*50*t)+ cos(2*pi*100*t);
xdft = fft(x);
% the DFT bin for 50 Hz is 51
% the DFT bin for 100 Hz is 101
amp50 = 2/length(x)*xdft(51);
amp100 = 2/length(x)*xdft(101);
abs(amp50)
abs(amp100)
ajay munaga
2021 年 11 月 10 日
0 投票
Compute the 8 point DFT of the sequence x(n)={ 1, 0, 1, 0, 0.5, 0, 0.5, 0} using radix-2 DIF FFT algorithm. Implement using MATLAB
カテゴリ
ヘルプ センター および File Exchange で Fourier Analysis and Filtering についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!