Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10e73c3

Browse files
committed
Update the axes.csd() to match the new options added to mlab.csd(). Move some of the docs from axes.psd() to the common place in mlab.
svn path=/trunk/matplotlib/; revision=6393
1 parent 68ba01d commit 10e73c3

3 files changed

Lines changed: 80 additions & 78 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2008-11-11 Update the axes.csd() to match the new options added to
2+
mlab.csd(). Move some of the docs from axes.psd() to
3+
the common place in mlab. - RM
4+
15
2008-11-11 Update the mlab.csd() to match the new options added to
26
mlab.psd(). Factor out the keyword argument docs so that
37
they can be shared between the two functions. - RM

lib/matplotlib/axes.py

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6531,9 +6531,10 @@ def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
65316531
call signature::
65326532
65336533
psd(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
6534-
window=mlab.window_hanning, noverlap=0, **kwargs)
6534+
window=mlab.window_hanning, noverlap=0, pad_to=None,
6535+
sides='default', **kwargs)
65356536
6536-
The power spectral density by Welches average periodogram
6537+
The power spectral density by Welch's average periodogram
65376538
method. The vector *x* is divided into *NFFT* length
65386539
segments. Each segment is detrended by function *detrend* and
65396540
windowed by function *window*. *noverlap* gives the length of
@@ -6542,41 +6543,14 @@ def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
65426543
scaling to correct for power loss due to windowing. *Fs* is the
65436544
sampling frequency.
65446545
6545-
Keyword arguments:
6546-
6547-
*NFFT*: integer
6548-
The length of the fft segment, must be a power of 2
6549-
6550-
*Fs*: integer
6551-
The sampling frequency.
6546+
%(PSD)s
65526547
65536548
*Fc*: integer
65546549
The center frequency of *x* (defaults to 0), which offsets
65556550
the x extents of the plot to reflect the frequency range used
65566551
when a signal is acquired and then filtered and downsampled to
65576552
baseband.
65586553
6559-
*detrend*:
6560-
The function applied to each segment before fft-ing,
6561-
designed to remove the mean or linear trend. Unlike in
6562-
matlab, where the *detrend* parameter is a vector, in
6563-
matplotlib is it a function. The :mod:`~matplotlib.pylab`
6564-
module defines :func:`~matplotlib.pylab.detrend_none`,
6565-
:func:`~matplotlib.pylab.detrend_mean`, and
6566-
:func:`~matplotlib.pylab.detrend_linear`, but you can use
6567-
a custom function as well.
6568-
6569-
*window*:
6570-
The function used to window the segments. *window* is a
6571-
function, unlike in matlab where it is a vector.
6572-
:mod:`~matplotlib.pylab` defines
6573-
:func:`~matplotlib.pylab.window_none`, and
6574-
:func:`~matplotlib.pylab.window_hanning`, but you can use
6575-
a custom function as well.
6576-
6577-
*noverlap*: integer
6578-
Gives the length of the overlap between segments.
6579-
65806554
Returns the tuple (*Pxx*, *freqs*).
65816555
65826556
For plotting, the power is plotted as
@@ -6615,17 +6589,24 @@ def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
66156589
self.set_yticks(ticks)
66166590

66176591
return pxx, freqs
6618-
psd.__doc__ = cbook.dedent(psd.__doc__) % martist.kwdocd
6592+
6593+
psd_doc_dict = dict()
6594+
psd_doc_dict.update(martist.kwdocd)
6595+
psd_doc_dict.update(mlab.kwdocd)
6596+
psd_doc_dict['PSD'] = cbook.dedent(psd_doc_dict['PSD'])
6597+
psd.__doc__ = cbook.dedent(psd.__doc__) % psd_doc_dict
66196598

66206599
def csd(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
6621-
window=mlab.window_hanning, noverlap=0, **kwargs):
6600+
window=mlab.window_hanning, noverlap=0, pad_to=None,
6601+
sides='default', **kwargs):
66226602
"""
66236603
call signature::
66246604
66256605
csd(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
6626-
window=window_hanning, noverlap=0, **kwargs)
6606+
window=mlab.window_hanning, noverlap=0, pad_to=None,
6607+
sides='default', **kwargs)
66276608
6628-
The cross spectral density :math:`P_{xy}` by Welches average
6609+
The cross spectral density :math:`P_{xy}` by Welch's average
66296610
periodogram method. The vectors *x* and *y* are divided into
66306611
*NFFT* length segments. Each segment is detrended by function
66316612
*detrend* and windowed by function *window*. The product of
@@ -6637,6 +6618,14 @@ def csd(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
66376618
(complex valued), and :math:`10\log_{10}|P_{xy}|` is
66386619
plotted.
66396620
6621+
%(PSD)s
6622+
6623+
*Fc*: integer
6624+
The center frequency of *x* (defaults to 0), which offsets
6625+
the x extents of the plot to reflect the frequency range used
6626+
when a signal is acquired and then filtered and downsampled to
6627+
baseband.
6628+
66406629
References:
66416630
Bendat & Piersol -- Random Data: Analysis and Measurement
66426631
Procedures, John Wiley & Sons (1986)
@@ -6654,7 +6643,8 @@ def csd(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
66546643
For a description of the optional parameters.
66556644
"""
66566645
if not self._hold: self.cla()
6657-
pxy, freqs = mlab.csd(x, y, NFFT, Fs, detrend, window, noverlap)
6646+
pxy, freqs = mlab.csd(x, y, NFFT, Fs, detrend, window, noverlap,
6647+
pad_to, sides)
66586648
pxy.shape = len(freqs),
66596649
# pxy is complex
66606650
freqs += Fc
@@ -6672,7 +6662,8 @@ def csd(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
66726662
self.set_yticks(ticks)
66736663

66746664
return pxy, freqs
6675-
csd.__doc__ = cbook.dedent(csd.__doc__) % martist.kwdocd
6665+
csd.__doc__ = cbook.dedent(csd.__doc__) % psd_doc_dict
6666+
del psd_doc_dict #So that this does not become an Axes attribute
66766667

66776668
def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
66786669
window=mlab.window_hanning, noverlap=0, **kwargs):

lib/matplotlib/mlab.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -310,48 +310,55 @@ def psd(x, NFFT=256, Fs=2, detrend=detrend_none,
310310
#Split out these keyword docs so that they can be used elsewhere
311311
kwdocd = dict()
312312
kwdocd['PSD'] ="""
313-
*NFFT*
314-
The number of data points used in each block for the FFT.
315-
Must be even; a power 2 is most efficient. The default value is 256.
316-
317-
*Fs*
318-
The sampling frequency (samples per time unit). It is used
319-
to calculate the Fourier frequencies, freqs, in cycles per time
320-
unit. The default value is 2.
321-
322-
*detrend*
323-
Any callable function (unlike in matlab where it is a vector).
324-
For examples, see :func:`detrend`, :func:`detrend_none`, and
325-
:func:`detrend_mean`. The default is :func:`detrend_none`.
326-
327-
*window*
328-
A function or a vector of length *NFFT*. To create window
329-
vectors see :func:`window_hanning`, :func:`window_none`,
330-
:func:`numpy.blackman`, :func:`numpy.hamming`,
331-
:func:`numpy.bartlett`, :func:`scipy.signal`,
332-
:func:`scipy.signal.get_window`, etc. The default is
333-
:func:`window_hanning`. If a function is passed as the
334-
argument, it must take a data segment as an argument and
335-
return the windowed version of the segment.
336-
337-
*noverlap*
338-
The number of points of overlap between blocks. The default value
339-
is 0 (no overlap).
340-
341-
*pad_to*
342-
The number of points to which the data segment is padd when
343-
performing the FFT. This can be different from *NFFT*, which
344-
specifies the number of data points used. While not increasing
345-
the actual resolution of the psd (the minimum distance between
346-
resolvable peaks), this can give more points in the plot,
347-
allowing for more detail. This corresponds to the *n* parameter
348-
in the call to fft(). The default is None, which sets *pad_to*
349-
equal to *NFFT*
350-
351-
*sides* [ 'default' | 'onesided' | 'twosided' ]
352-
Specifies which sides of the PSD to return. Default gives the
353-
default behavior, which returns one-sided for real data and both
354-
for complex data. 'one' forces the return of a one-sided PSD, while
313+
Keyword arguments:
314+
315+
*NFFT*: integer
316+
The number of data points used in each block for the FFT.
317+
Must be even; a power 2 is most efficient. The default value is 256.
318+
319+
*Fs*: scalar
320+
The sampling frequency (samples per time unit). It is used
321+
to calculate the Fourier frequencies, freqs, in cycles per time
322+
unit. The default value is 2.
323+
324+
*detrend*: callable
325+
The function applied to each segment before fft-ing,
326+
designed to remove the mean or linear trend. Unlike in
327+
matlab, where the *detrend* parameter is a vector, in
328+
matplotlib is it a function. The :mod:`~matplotlib.pylab`
329+
module defines :func:`~matplotlib.pylab.detrend_none`,
330+
:func:`~matplotlib.pylab.detrend_mean`, and
331+
:func:`~matplotlib.pylab.detrend_linear`, but you can use
332+
a custom function as well.
333+
334+
*window*: callable or ndarray
335+
A function or a vector of length *NFFT*. To create window
336+
vectors see :func:`window_hanning`, :func:`window_none`,
337+
:func:`numpy.blackman`, :func:`numpy.hamming`,
338+
:func:`numpy.bartlett`, :func:`scipy.signal`,
339+
:func:`scipy.signal.get_window`, etc. The default is
340+
:func:`window_hanning`. If a function is passed as the
341+
argument, it must take a data segment as an argument and
342+
return the windowed version of the segment.
343+
344+
*noverlap*: integer
345+
The number of points of overlap between blocks. The default value
346+
is 0 (no overlap).
347+
348+
*pad_to*: integer
349+
The number of points to which the data segment is padd when
350+
performing the FFT. This can be different from *NFFT*, which
351+
specifies the number of data points used. While not increasing
352+
the actual resolution of the psd (the minimum distance between
353+
resolvable peaks), this can give more points in the plot,
354+
allowing for more detail. This corresponds to the *n* parameter
355+
in the call to fft(). The default is None, which sets *pad_to*
356+
equal to *NFFT*
357+
358+
*sides*: [ 'default' | 'onesided' | 'twosided' ]
359+
Specifies which sides of the PSD to return. Default gives the
360+
default behavior, which returns one-sided for real data and both
361+
for complex data. 'one' forces the return of a one-sided PSD, while
355362
'both' forces two-sided.
356363
"""
357364
psd.__doc__ = psd.__doc__ % kwdocd

0 commit comments

Comments
 (0)