# FFT step by step help

13 views (last 30 days)
William Osborne on 17 Oct 2019
Edited: William Osborne on 17 Oct 2019
Hello all,
I have been trying to figure out what each step is in the FFT process as shown below. It is to perform an FFT on a WAV file.
Essentially I want to know why this is how to do it, rather than just taking it for what it is. Step by step.
%% FFT
xdft = xdft/length(x);
xdft(2:end-1) = 2*xdft(2:end-1);
amplitude= abs(xdft);

Edited: Adam on 17 Oct 2019
The lpad part is a little suspicious. If you have an odd length of signal it will not work as is.
Apart from that though:
The fft line simply runs the fft. Passing in the length of signal as the number of points is superfluous, but if you were using a different number of points (e.g. next power of 2, which is common) then that would be input there.
fft results in a 2-sided spectrum, with negative frequencies (or equiv nyquist to sample frequency) as well as positive frequencies (if you want to know more about this look for a resource online). Generally we aren't interested in the negative spectrum so we clip that off to give a one-sided spectrum.
fft returns its results as [0, positiveFrequencies, nyquist, negativeFrequencies]. We want to keep the nyquist frequency, hence n/2 + 1 rather than n/2.
xdft = xdft/length(x);
scales the result to maintain the amplitudes of the time domain. I always forget exactly what this step should be, but I am assuming you have it right here. Certainly this is scaling the result, whether correctly or not.
xdft(2:end-1) = 2*xdft(2:end-1);
Because we threw away half the spectrum we multiply the remaining half by 2 to maintain the same total power.
In order to view the spectrum meaningfully you need to create your vector of frequencies. Obviously it needs to be the same length as the result and runs from 0 to Nyquist (which, if you remember is the range we kept from the spectrum).
amplitude= abs(xdft);
The result of the fft is a complex one. To view the power spectrum you want the absolute value. Often this is also squared, but just taking the abs is also fine, depending what you wish to interpret from it.

#### 1 Comment

William Osborne on 17 Oct 2019
Excellent, thank you very much. I have been trying to piece together all the parts and this really helps.