Revision: 7121
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7121&view=rev
Author:   ryanmay
Date:     2009-05-18 20:50:20 +0000 (Mon, 18 May 2009)

Log Message:
-----------
Move code for wrapping negative frequencies from specgram() into 
_spectral_helper(), so that psd(), csd(), and cohere() can benefit from this 
functionality as well. While this changes API a little, this is much more 
sensible behavior.

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/doc/api/api_changes.rst
    trunk/matplotlib/lib/matplotlib/mlab.py

Added Paths:
-----------
    trunk/matplotlib/examples/pylab_examples/psd_demo_complex.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-05-18 19:19:33 UTC (rev 7120)
+++ trunk/matplotlib/CHANGELOG  2009-05-18 20:50:20 UTC (rev 7121)
@@ -1,4 +1,7 @@
-2009-05-18 Fix the linespacing bug of multiline text (#1239682). See 
+2009-05-18 Make psd(), csd(), and cohere() wrap properly for complex/two-sided
+           versions, like specgram() (SF #2791686) - RMM
+
+2009-05-18 Fix the linespacing bug of multiline text (#1239682). See
            examples/pylab_examples/multiline.py -JJL
 
 2009-05-18 Add *annotation_clip* attr. for text.Annotation class.

Modified: trunk/matplotlib/doc/api/api_changes.rst
===================================================================
--- trunk/matplotlib/doc/api/api_changes.rst    2009-05-18 19:19:33 UTC (rev 
7120)
+++ trunk/matplotlib/doc/api/api_changes.rst    2009-05-18 20:50:20 UTC (rev 
7121)
@@ -19,6 +19,12 @@
 
 Changes for 0.98.x
 ==================
+* psd(), csd(), and cohere() will now automatically wrap negative
+  frequency components to the beginning of the returned arrays.
+  This is much more sensible behavior and makes them consistent
+  with specgram().  The previous behavior was more of an oversight
+  than a design decision.
+
 * Added new keyword parameters *nonposx*, *nonposy* to
   :class:`matplotlib.axes.Axes` methods that set log scale
   parameters.  The default is still to mask out non-positive

Added: trunk/matplotlib/examples/pylab_examples/psd_demo_complex.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/psd_demo_complex.py                
                (rev 0)
+++ trunk/matplotlib/examples/pylab_examples/psd_demo_complex.py        
2009-05-18 20:50:20 UTC (rev 7121)
@@ -0,0 +1,38 @@
+#This is a ported version of a Matlab example from the signal processing
+#toolbox that showed some difference at one time between Matplotlib's and
+#MatLab's scaling of the PSD.  This differs from psd_demo3.py in that
+#this uses a complex signal, so we can see that complex PSD's work properly
+import numpy as np
+import matplotlib.pyplot as plt
+import matplotlib.mlab as mlab
+
+fs = 1000
+t = np.linspace(0, 0.3, 301)
+A = np.array([2, 8]).reshape(-1, 1)
+f = np.array([150, 140]).reshape(-1, 1)
+xn = (A * np.exp(2j * np.pi * f * t)).sum(axis=0) + 5 * 
np.random.randn(*t.shape)
+
+yticks = np.arange(-50, 30, 10)
+xticks = np.arange(-500,550,100)
+plt.subplots_adjust(hspace=0.45, wspace=0.3)
+ax = plt.subplot(1, 2, 1)
+
+plt.psd(xn, NFFT=301, Fs=fs, window=mlab.window_none, pad_to=1024,
+    scale_by_freq=True)
+plt.title('Periodogram')
+plt.yticks(yticks)
+plt.xticks(xticks)
+plt.grid(True)
+plt.xlim(-500, 500)
+
+plt.subplot(1, 2, 2, sharex=ax, sharey=ax)
+plt.psd(xn, NFFT=150, Fs=fs, window=mlab.window_none, noverlap=75, pad_to=512,
+    scale_by_freq=True)
+plt.title('Welch')
+plt.xticks(xticks)
+plt.yticks(yticks)
+plt.ylabel('')
+plt.grid(True)
+plt.xlim(-500, 500)
+
+plt.show()

Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py     2009-05-18 19:19:33 UTC (rev 
7120)
+++ trunk/matplotlib/lib/matplotlib/mlab.py     2009-05-18 20:50:20 UTC (rev 
7121)
@@ -327,6 +327,11 @@
     t = 1./Fs * (ind + NFFT / 2.)
     freqs = float(Fs) / pad_to * np.arange(numFreqs)
 
+    if (np.iscomplexobj(x) and sides == 'default') or sides == 'twosided':
+        # center the frequency range at zero
+        freqs = np.concatenate((freqs[numFreqs//2:] - Fs, freqs[:numFreqs//2]))
+        Pxy = np.concatenate((Pxy[numFreqs//2:, :], Pxy[:numFreqs//2, :]), 0)
+
     return Pxy, freqs, t
 
 #Split out these keyword docs so that they can be used elsewhere
@@ -485,11 +490,6 @@
         noverlap, pad_to, sides, scale_by_freq)
     Pxx = Pxx.real #Needed since helper implements generically
 
-    if (np.iscomplexobj(x) and sides == 'default') or sides == 'twosided':
-        # center the frequency range at zero
-        freqs = np.concatenate((freqs[NFFT/2:]-Fs,freqs[:NFFT/2]))
-        Pxx   = np.concatenate((Pxx[NFFT/2:,:],Pxx[:NFFT/2,:]),0)
-
     return Pxx, freqs, t
 
 specgram.__doc__ = specgram.__doc__ % kwdocd


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

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to