Revision: 8803
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8803&view=rev
Author:   ryanmay
Date:     2010-11-17 04:13:31 +0000 (Wed, 17 Nov 2010)

Log Message:
-----------
Some cosmetic changes to _spectral_helper(). Biggest change is to update the 
documentation to indicate that NFFT should *not* be used for zero padding, 
otherwise scaling will be incorrect.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/mlab.py

Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py     2010-11-15 10:40:58 UTC (rev 
8802)
+++ trunk/matplotlib/lib/matplotlib/mlab.py     2010-11-17 04:13:31 UTC (rev 
8803)
@@ -245,12 +245,6 @@
         raise ValueError("sides must be one of: 'default', 'onesided', or "
             "'twosided'")
 
-    # MATLAB divides by the sampling frequency so that density function
-    # has units of dB/Hz and can be integrated by the plotted frequency
-    # values. Perform the same scaling here.
-    if scale_by_freq:
-        scaling_factor /= Fs
-
     if cbook.iterable(window):
         assert(len(window) == NFFT)
         windowVals = window
@@ -260,7 +254,7 @@
     step = NFFT - noverlap
     ind = np.arange(0, len(x) - NFFT + 1, step)
     n = len(ind)
-    Pxy = np.zeros((numFreqs,n), np.complex_)
+    Pxy = np.zeros((numFreqs, n), np.complex_)
 
     # do the ffts of the slices
     for i in range(n):
@@ -278,16 +272,18 @@
 
     # Scale the spectrum by the norm of the window to compensate for
     # windowing loss; see Bendat & Piersol Sec 11.5.2.
-    Pxy *= 1 / (np.abs(windowVals)**2).sum()
+    Pxy /= (np.abs(windowVals)**2).sum()
 
     # Also include scaling factors for one-sided densities and dividing by the
     # sampling frequency, if desired. Scale everything, except the DC component
     # and the NFFT/2 component:
     Pxy[1:-1] *= scaling_factor
 
-    #But do scale those components by Fs, if required
+    # MATLAB divides by the sampling frequency so that density function
+    # has units of dB/Hz and can be integrated by the plotted frequency
+    # values. Perform the same scaling here.
     if scale_by_freq:
-        Pxy[[0,-1]] /= Fs
+        Pxy /= Fs
 
     t = 1./Fs * (ind + NFFT / 2.)
     freqs = float(Fs) / pad_to * np.arange(numFreqs)
@@ -306,6 +302,8 @@
       *NFFT*: integer
           The number of data points used in each block for the FFT.
           Must be even; a power 2 is most efficient.  The default value is 256.
+          This should *NOT* be used to get zero padding, or the scaling of the
+          result will be incorrect. Use *pad_to* for this instead.
 
       *Fs*: scalar
           The sampling frequency (samples per time unit).  It is used


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to