# What frequency range does fft compute?

10 views (last 30 days)
Calvin He on 28 Jul 2022
Commented: Paul on 28 Jul 2022
So according to the documentation, the fft function for a time series of n samples computes the following: The question is what are the values of k and how is it ordered from the output of fft? Looking at the example code, they truncate the fft output by about a half to get the "positive" frequencies. When I plot out the full fft output without truncating the vector, it appears that the negative frequencies are shown on the right half of the fft output, i.e., values of k would be [0:n/2-1,-n/2:-1] where n>2. Is this correct?
If so, why the offset in the negative frequencies, and what about frequencies for ? Are those frequencies ignored because they are not practical due to the sampling theorem?

Star Strider on 28 Jul 2022
The first element of the output of the fft function is the constant or DC offsets (mean values) of the original time domain vector. As a general rule, the second half of the original vector is the flipped complex conjugate of the first half of the vector. For a one-sided Fourier transform, the frequencies go from 0 Hz (DC) to the Nyquist frequency (half the sampling frequency). The sampling frequency (assuming a time vector with uniform increments, so a constant sampling frequency) is the inverse of the common sampling interval.
For a two-sided fft result (after using the fftshift function so that the centre frequency is 0 Hz) the frequency vector is:
Fv = linspace(-Fs/2, Fs/2-Fs/length(s), length(s)); % EVEN 'length(s)' (Asymmetric)
Fv = linspace(-Fs/2, Fs/2, length(s)); % ODD 'length(s)' (Symmetric)
This results in a two-sided Fourier transform with the ‘negative’ frequencies to the left of centre and the positive frequencies to the right of centre.
I generally zero-pad the fft argument using:
NFFT = 2^nextpow2(L);
FTs = fft(s, NFFT)/L;
where ‘L’ is the length of the associated time vector (since the signal can be either a vector or a column-oriented matrix where each column is a separate signal) and ‘s’ is the signal (vector or matrix). This improves the efficiency of the fft calculation, and also makes the subsequent analysis a bit easier.
.
##### 1 CommentShowHide None
Paul on 28 Jul 2022
Hi Star,
For an odd length sequence I believe that Fv is
Fv = linspace(-F2/2, Fs/2, length(s)) * (length(s) - 1)/length(s)

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!