# FFT Characteristics?

I'm looking at this regarding a simple spectrogram

1)

 % Take the square of the magnitude of fft of x.
mx = mx.^2;


why do you need to take the square of the FFT after you take the absolute value?

2) Is the Nyquist point the point at which the FFT should be symmetric and it is thrown out because of this? How do you calculate it in an odd-N FFT (an FFT done on an odd number of points) since it is the midpoint of the FFT?

3) How do you apply a window function with regards to the FFT?

Edit: With regard to number three, this gave a nice answer

Thanks!

1) When you compute the FFT you get units of magnitude (although they are complex). The referenced procedure describes how to compute the power spectrum, which has units of magnitude squared. That is why the values are squared. The example code could just as easily have used the complex conjugate:

fftx = fft(x,nfft);
NumUniquePts = ceil((nfft+1)/2);
fftx = fftx(1:NumUniquePts);
mx = fftx/length(x)
mx = mx .* conj(mx);


2) You should not throw out the $n/2$ point at the Nyquist frequency. It represents the highest frequency point of the spectrum. (Note: You should not double the values at $0$ or $n/2$, but the other values from $1$ to $n/2 -1$ should be doubled.) Normally FFTs by definition deal with $N=2^k$ points so it would be unusual to have an odd number of points. If you did you would not have spectrum line at the Nyquist frequency.

3) Multiply your signal by a window function prior to computation of the FFT. If your time history is $x(k)$ for $k=1,...,N-1$ and $w(k)$ is your window function, then compute $FFT(w(k)x(k))$. Normally windowing functions are applied in an averaging technique where your time history is sliced into $M$ segments of equal lengths (sometimes with overlap) and each segment has its FFT computed. Each segment's FFT is then converted to power or more commonly to power density (by dividing by the $\Delta f = \frac{1}{N\Delta t}$ and then averaged together.

• 1) my question is why is the absolute value taken after the absolute value. Then what is the point of the absolute value? Thanks though! – Eiyrioü von Kauyf Apr 13 '12 at 1:34
• Because the power spectrum is only about magnitude. The absolute value discards the phase information. The result is then squared to get power. This could just as easily have been computed by multiplying by the complex conjugate after dividing out the length. – Tpofofn Apr 13 '12 at 2:07

1) You don't "need" to take the square. Usually the form with best visibility is chosen, depending on what you use the output for. Absolute value is useful if you want to know exact value(say 5V) of a certain sinusoid. In case you want to just compare spectrum components you might display the output in dB.

2) I suppose you talk about real FFT. If you compute FFT for a complex set of input values there is no symmetry. For odd N, since real FFT is symmetric, F(k) = F(N-k)*, and yes, F(0) is real, but F(N/2) does not exist(obvious, N odd =>N/2 does not exist).

3)There are formulas for windows on Wikipedia(Hann, Blackmann, sinc, triangular etc). Depending on N you compute a set of coefficients. The number of coefficients will be N, and the number of input values for FFT is the same N. So you multiply each input value with it's corresponding coefficient.