From: <ry...@us...> - 2008-11-11 17:56:13
|
Revision: 6390 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6390&view=rev Author: ryanmay Date: 2008-11-11 17:56:07 +0000 (Tue, 11 Nov 2008) Log Message: ----------- Update the axes.psd() method to reflect the new options available in mlab.psd. Add an example to show how the options change things. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/pylab_examples/psd_demo2.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-11-11 16:30:03 UTC (rev 6389) +++ trunk/matplotlib/CHANGELOG 2008-11-11 17:56:07 UTC (rev 6390) @@ -1,3 +1,7 @@ +2008-11-11 Update the axes.psd() method to reflect the new options + available in mlab.psd. Add an example to show how the + options change things. - RM + 2008-11-11 Add 'pad_to' and 'sides' parameters to mlab.psd() to allow controlling of zero padding and returning of negative frequency components, respecitively. These are Added: trunk/matplotlib/examples/pylab_examples/psd_demo2.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/psd_demo2.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/psd_demo2.py 2008-11-11 17:56:07 UTC (rev 6390) @@ -0,0 +1,39 @@ +#This example shows the effects of some of the different PSD parameters +import numpy as np +import matplotlib.pyplot as plt + +dt = np.pi / 100. +fs = 1. / dt +t = np.arange(0, 8, dt) +y = 10. * np.sin(2 * np.pi * 4 * t) + 5. * np.sin(2 * np.pi * 4.25 * t) +y = y + np.random.randn(*t.shape) + +#Plot the raw time series +fig = plt.figure() +ax = fig.add_subplot(2, 1, 1) +ax.plot(t, y) + +#Plot the PSD with different amounts of zero padding. This uses the entire +#time series at once +ax2 = fig.add_subplot(2, 3, 4) +ax2.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs) +ax2.psd(y, NFFT=len(t), pad_to=len(t)*2, Fs=fs) +ax2.psd(y, NFFT=len(t), pad_to=len(t)*4, Fs=fs) +plt.title('Effect of zero padding') + +#Plot the PSD with different block sizes, Zero pad to the length of the orignal +#data sequence. +ax3 = fig.add_subplot(2, 3, 5, sharex=ax2, sharey=ax2) +ax3.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs) +ax3.psd(y, NFFT=len(t)//2, pad_to=len(t), Fs=fs) +ax3.psd(y, NFFT=len(t)//4, pad_to=len(t), Fs=fs) +plt.title('Effect of block size') + +#Plot the PSD with different amounts of overlap between blocks +ax4 = fig.add_subplot(2, 3, 6, sharex=ax2, sharey=ax2) +ax4.psd(y,NFFT=len(t)//2, pad_to=len(t), noverlap=0, Fs=fs) +ax4.psd(y,NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.05*len(t)/2.), Fs=fs) +ax4.psd(y,NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.2*len(t)/2.), Fs=fs) +plt.title('Effect of overlap') + +plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-11-11 16:30:03 UTC (rev 6389) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-11-11 17:56:07 UTC (rev 6390) @@ -6525,7 +6525,8 @@ hist.__doc__ = cbook.dedent(hist.__doc__) % martist.kwdocd def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, - window=mlab.window_hanning, noverlap=0, **kwargs): + window=mlab.window_hanning, noverlap=0, pad_to=None, + sides='default', **kwargs): """ call signature:: @@ -6595,7 +6596,8 @@ .. plot:: mpl_examples/pylab_examples/psd_demo.py """ if not self._hold: self.cla() - pxx, freqs = mlab.psd(x, NFFT, Fs, detrend, window, noverlap) + pxx, freqs = mlab.psd(x, NFFT, Fs, detrend, window, noverlap, pad_to, + sides) pxx.shape = len(freqs), freqs += Fc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |