Product Support
1703 - What is the Proper Scaling of FFT Magnitude for a Signal with Two Frequencies?
Question
Why isn't the FFT magnitude of a signal with two frequency components of equal amplitude equal for both frequencies?
Answer
The reason the FFT magnitude is not the same for a signal with two frequencies of the same magnitude is because the FFT is calculated at discrete points. Therefore, if the frequency of interest is not represented exactly at one of the discrete points where the FFT is calculated, the FFT magnitude is lower. The FFT is calculated for every discrete point of the frequency vector described by
f = Fs*(0:NFFT-1)/NFFT
where Fs is the sampling frequency and NFFT is the number of FFT points taken. Below is an example that illustrates the problem.
% Sampling frequency: Fs = 1000;
% Time vector; t = 0:1/Fs:2-1/Fs;
% To create exactly 2000 points, % we have subtracted 1/Fs
% Signal y = sin(2*pi*t*50);
% Frequency vector % NFFT = length(y) f = Fs*(0:length(y)-1)/length(y);
If you display the frequency vector f, you'll notice that the value 50 is listed. Hence, 50 is a discrete frequency at which the FFT is calculated, which means that the magnitude is correct for a 50Hz signal (taking into consideration that the power is divided by two, and that the FFT magnitude is a function of the number of FFT points. See Technical Note 1702, "Using FFT to Obtain Simple Spectral Analysis Plots", for more on information.
plot(f,abs(fft(y)))
For a signal with two different frequencies, the frequency vector must contain both frequencies (of the signal) in order for the FFT magnitude to be the same for both frequencies. For the following example, both frequencies, 50Hz and 60Hz, must be values in the frequency vector in order for the FFT algorithm to calculate the FFT magnitude for both of these frequencies exactly. The frequency vector, f, contains the values 50 and 60, so the FFT magnitude is evaluated at 50 and 60.
% Signal with two % frequencies y=sin(2*pi*t*50) + sin(2*pi*t*60);
Therefore, the FFT magnitude for both signals is equal.
plot(f,abs(fft(y)))
If we choose a signal with two frequencies where one of the frequencies is not a discrete value in the frequency vector, then the FFT magnitude for this frequency is lower. For example, let's create a signal with the following two frequencies:
% Sampling % frequency Fs = 1000;
% Time vector t = 0:1/Fs:2-1/Fs;
% Signal with two frequencies y = sin(2*pi*t*50) + sin(2*pi*t*60.4);
% Frequency vector % NFFT = length(y) f = Fs*(0:length(y)-1)/length(y);
We see that the value 60.4 is not part of the frequency vector f. Therefore, the magnitude of the 60.4Hz signal is smaller than the magnitude of the 50Hz signal and some energy for the 60.4 frequency may be in neighboring frequency bins.
plot(f,abs(fft(y)))
The FFT magnitude result contains a value for 60 and 60.5, but not 60.4, therefore, the FFT magnitude of the 60.4Hz signal is lower.
Store