From: Fago, Matt  AES <Matt.F<ago@it...>  20081208 15:10:50

So what is to be done here? It seems to me that at least the factor of two should be fixed for onesided 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 [rmay31@...] Sent: Monday, December 01, 2008 3:31 PM To: Fago, Matt  AES Cc: Matplotlib Users Subject: Re: [Matplotlibusers] 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 onesided 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/technotes/1700/1702.html > > To me, as Matplotlib is striving to be Matlabcompatible, 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 onesided 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 Matlabcompatible waywhen 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 email 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 email in error please notify the sender. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this email and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this email. 