I suppose the issue is: what is correct? Or is it a matter of definition?
I don't have Stoica and Moses, but Bendat and Piersol eqn 11.102:
One_Sided_PSD = 2/(n_d * N * dt) * Sum(FFT^2)
where there are n_d is the number of averages and N is the number of points in the FFT.
That seems to be scaling by the length? I'm fairly certain that the factor of two (as shown
above) is required for a one-sided PSD, as that comes from 'removing' the negative
Note that Matlab shows such scaling (by 2/L) even when computing the power spectra directly
from a raw (unaveraged) FFT:
To me, as Matplotlib is striving to be Matlab-compatible, the default behaviour should be to
give results as close to the Matlab implementation as possible. One could always have an
option to turn off the scaling.
Note that the Matplotlib results also seem to have significantly less frequency resolution than
the Matlab results. Is this the case, or am I not using noffset, nfft, and pad_to correctly?
Thanks for your help,
From: Ryan May [rmay31@...]
Sent: Monday, December 01, 2008 1:58 PM
To: Fago, Matt - AES
Cc: Matplotlib Users
Subject: Re: [Matplotlib-users] Matplotlib PSD bug?
Fago, Matt - AES wrote:
> I cannot really compute the example without the pad_to support in svn. Nevertheless, using something similar (nfft=128, noffset=64) gives similarly erroneous results.
> Did you add 'pad_to'? If so, thanks!
Good to know. I recently (within the last month) did a bunch of work on
psd, based in a large part on work done by one of my colleagues, Sean
Arms. I was worried some of this had broken existing code, but it
appears more likely that this was already a problem.
After much playing, and reading the Matlab docs, it looks like the
difference is that Matlab normalizes by the sampling frequency. Also,
if a one-sided psd is returned, it multiplies everything by 2. If I
apply these two scaling factors, I get results in line with those
produced by Matlab.
Now, this scaling was not performed by the old code, so this is not a
new incompatibility (bug?) with Matlab. Also, while I have not reviewed
the reference specified in the docstring (Bendat and Piersol 1986), the
book I have handy (Stoica and Moses 2005) does not mention scaling by
the sampling frequency, nor does the included Matlab code perform any
So what should be done here? I would be opposed to making such scaling
the default, as IMHO it tries to do too much and I would have to work
around it to get the more "raw" numbers. However, I am not opposed to
adding (yet another) option to do such scaling.
Graduate Research Assistant
School of Meteorology
University of Oklahoma
This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender.
Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.