Confusion in figuring out the relation between actual frequency values and FFT plot indexes in MATLAB

大兔子大兔子 提交于 2019-12-01 06:29:02

You need to generate the frequency array yourself and plot your FFT result against it.

Like this:

function [Ycomp, fHz] = getFFT(data, Fs)
     len = length(data);
     NFFT = 2^nextpow2(len);
     Ydouble = fft(data, NFFT)/len; % Double-sided FFT
     Ycomp = Ydouble(1:NFFT/2+1); % Single-sided FFT, complex
     fHz = Fs/2*linspace(0,1,NFFT/2+1); % Frequency array in Hertz.
     semilogx(fHz, abs(Ycomp))
end

You will see peaks at 500 Hz and Fs - 500 Hz (i.e. 44100 - 500 = 43600 Hz in your particular case).

This is because the real-to-complex FFT output is complex conjugate symmetric - the top half of the spectrum is a "mirror image" of the bottom half when you are just looking at the magnitude and is therefore redundant.

Note that of plotting power spectra you can usually save yourself a lot of work by using MATLAB's periodogram function rather than dealing directly with all the details of FFT, window functions, plotting, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!