DFT Magnitude/Power Spectra
I often get confused about the scaling of magnitude and power spectra. I think I’ve worked it out so I’m puttin it here for my own benefit, and maybe the benefit of someone on the internet. If I’m wrong, please tell me.
Let’s take a unit-amplitude sinusoid at 100 Hz, and do a Fourier transform. If we look at the amplitude we’d get two components at 100 Hz and -100 Hz, each with amplitude 1/2. Something like this.
Now, if we do the same with a DFT we will get basically the same thing, except we’ll see the effects of discretization of course. But depending on which variation of the DFT you’re using, the magnitude of the components will be either about 1/2 or about N/2. The difference is, of course, the 1/N factor that you included or left out. In the case of the fft function in Octave (and I assume MATLAB), it’s without the 1/N factor.
max(abs(fft(x,1024)))
ans = 443.23
The power spectrum is the magnitude spectrum squared. abs(fft(x)).^2 or (abs(fft(x))/N).^2. Why would you want to square it? Well there are of course many reasons but the nature of audio signals makes most of the ones I know about moot. Furthermore the relative shape of the power spectrum and the magnitude spectrum is the same.
Try this. Take an audio signal (something more interesting than a single sinusoid) and plot the magnitude spectrum in dB, then plot the power spectrum also in dB, e.g.
plot(20*log10(abs(fft(x))))
figure
plot(20*log10(abs(fft(x)).^2))
They have a different scale, but they have the same shape. If you were doing something like peak-picking, it wouldn’t matter which you used if you’re working in dB.
April 16th, 2009 at 13:33
In the last bit
plot(20*log10(abs(fft(x))))
plot(20*log10(abs(fft(x)).^2))
I believe these are wrong. The first one will give the the Power in dB.
Second one is squared twice.
See the 20 log rule in the following.
http://en.wikipedia.org/wiki/Decibel
April 16th, 2009 at 14:26
That’s a good point, Ely. So you’re saying that the standard 20*log10 of the magnitude gives you dB power anyway – is that right? So then I should be comparing 10*log10(X) to 10*log10(X.^2)? Of course that’s just a linear difference from what I had before.
If we compare 20*log10(X) to 10*log10(X.^2) then of course they’re the same – they’re the same mathematically.
December 16th, 2009 at 10:53
my friend
i have signals stored in text file (each file contains 2 signals represents the left and right hands)
which method is better for me to calculate and plot the PSD for each one?
your comments is highly appreciated
best wishes,
Josef