Confusion in determining the relationship between actual frequency values ​​and FFT graph indices in MATLAB

I know that there are many similar questions, I still can not understand the answer. Let's say we have a time signal in MATLAB:

t=0:1/44100:1 

and cosine signal with a frequency of 500 Hz:

 x=cos(2*pi*500*t); 

Now I am trying to plot the amplitude spectrum obtained with the fft from signal x

 FFT=abs(fft(x)) plot(FFT) 

According to the theory, we should get two peaks on the graph, one at -500 Hz and the other at 500 Hz. I don’t understand that I have two peaks, but I can’t understand at what frequencies these peaks are. I know there is a way to figure out the frequency using the FFT index, input signal length and sample rate, but I still can’t calculate the frequency.

I know that there are methods for aligning FFT graphs, so that the peaks lie on the index number of the frequency they represent using the fftshift function, but I want to find out the frequency using the graph as a result of a simple call to this function:

 FFT=fft(x) 

In this case, I already know that the signal contains a cosine of 500 Hz, but what if the signal that we want to receive the FFT is unknown before. How can we get the peak frequency values ​​in this sample using the output from the fft function?

+4
source share
2 answers

You need to generate the frequency array yourself and apply the FFT result to 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 
+1
source

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

This is due to the fact that the FFT output signal is complex symmetrical - the upper half of the spectrum is a "mirror image" of the lower half when you simply look at the value and therefore are redundant.

Please note that when building power spectra you can usually save a lot of work by using the MATLAB periodogram function and not directly access all the FFT details, window functions, printing, etc.

+1
source

All Articles