So what is to be done here? It seems to me that at least the factor of two 
should be
fixed for one-sided PSDs, and the 1/fs normalization difference with Matlab
documented. Ideally, I'd think this normalization would be on by default, with 
the
option to turn it off.

Are you planning to submit a patch, or shall I look into it? If I submit a 
patch, does matplotlib
require a copyright assignment?

Thanks,
Matt

________________________________________
From: Ryan May [EMAIL PROTECTED]
Sent: Monday, December 01, 2008 3:31 PM
To: Fago, Matt - AES
Cc: Matplotlib Users
Subject: Re: [Matplotlib-users] Matplotlib PSD bug?

Fago, Matt - AES wrote:
> 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
> frequency range.
>
> Note that Matlab shows such scaling (by 2/L) even when computing the power 
> spectra directly
> from a raw (unaveraged) FFT:
>
>    http://www.mathworks.com/support/tech-notes/1700/1702.html
>
> 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.

Yeah, scaling by a factor of two for one-sided is definitely correct now
that I think about it.  Note, however, that the scaling by the length is
not the problem. In fact, the current psd implementation does this
correctly when it corrects for the power in the window.  The problem
stems from matlab scaling by the sampling frequency.  Stoica and Moses
don't do this, nor does Welch 1967.  I'm all for doing things in a
Matlab-compatible way--when they're correct.  One of the reasons I
stopped using Matlab was that it tried to be too smart for me.

> 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?

It's not that you're using those incorrectly, but rather that you failed
to notice that the default window is the Hanning window, not
rectangular.  Try adding window=mlab.window_none to the call. (Sorry, I
meant to mention that before in my reply.

Ryan

--
Ryan May
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.

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to