1

I'm looking at this regarding a simple spectrogram

1)

my question is about this line

 % 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!

2 Answers2

3

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.

Tpofofn
  • 4,771
  • 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 02:07
  • 1
    This may be helpful: The frequency spectrum to take absolute value is to utilize advantage to remove the time-shifting or phase effect; and to take squared value (complex conjugate square) is to disregard the amplitude sign also in a similarity to power. The unit turns to be in terms of the square of the signal, as this would always be proportional to the actual power delivered by that signal into a given impedance. Also see https://en.wikipedia.org/wiki/Spectral_density#Units. – MathArt Dec 04 '23 at 09:59
  • @MathArt, You should post this as an answer. – Tpofofn Dec 12 '23 at 11:49
  • @Tpofofn, Thank you. This might be the greatest $X$mas gift to me :-)! – MathArt Dec 14 '23 at 07:56