matplotlib.mlab
¶Numerical python functions written for compatibility with MATLAB
commands with the same names. Most numerical python functions can be found in
the numpy
and scipy
libraries. What remains here is code for performing
spectral computations.
cohere
csd
detrend
psd
specgram
complex_spectrum
magnitude_spectrum
angle_spectrum
phase_spectrum
detrend_mean
detrend_linear
detrend_none
stride_windows
stride_repeat
apply_window
matplotlib.mlab.
GaussianKDE
(dataset, bw_method=None)[source]¶Bases: object
Representation of a kerneldensity estimate using Gaussian kernels.
Parameters: 


Attributes: 

Methods
kde.evaluate(points)  (ndarray) Evaluate the estimated pdf on a provided set of points. 
kde(points)  (ndarray) Same as kde.evaluate(points) 
covariance_factor
(self)¶evaluate
(self, points)[source]¶Evaluate the estimated pdf on a set of points.
Parameters: 


Returns: 

Raises: 

matplotlib.mlab.
angle_spectrum
(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the angle of the frequency spectrum (wrapped phase spectrum) of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
Parameters: 


Returns: 

See also
complex_spectrum
complex_spectrum
.magnitude_spectrum
phase_spectrum
specgram
matplotlib.mlab.
apply_window
(x, window, axis=0, return_window=None)[source]¶Apply the given window to the given 1D or 2D array along the given axis.
Parameters: 


matplotlib.mlab.
cohere
(x, y, NFFT=256, Fs=2, detrend=<function detrend_none at 0x7f7b242faa60>, window=<function window_hanning at 0x7f7b242fa400>, noverlap=0, pad_to=None, sides='default', scale_by_freq=None)[source]¶The coherence between x and y. Coherence is the normalized cross spectral density:
Parameters: 


Returns: 

matplotlib.mlab.
complex_spectrum
(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the complexvalued frequency spectrum of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
Parameters: 


Returns: 

See also
magnitude_spectrum
angle_spectrum
phase_spectrum
specgram
matplotlib.mlab.
csd
(x, y, NFFT=None, Fs=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None)[source]¶Compute the crossspectral density.
The cross spectral density \(P_{xy}\) by Welch's average periodogram method. The vectors x and y are divided into NFFT length segments. Each segment is detrended by function detrend and windowed by function window. noverlap gives the length of the overlap between segments. The product of the direct FFTs of x and y are averaged over each segment to compute \(P_{xy}\), with a scaling to correct for power loss due to windowing.
If len(x) < NFFT or len(y) < NFFT, they will be zero padded to NFFT.
Parameters: 


Returns: 

See also
psd
y = x
.References
Bendat & Piersol  Random Data: Analysis and Measurement Procedures, John Wiley & Sons (1986)
matplotlib.mlab.
demean
(x, axis=0)[source]¶[Deprecated] Return x minus its mean along the specified axis.
Parameters: 


See also
detrend_mean
demean
except for the default axis.Notes
Deprecated since version 3.1.
matplotlib.mlab.
detrend
(x, key=None, axis=None)[source]¶Return x with its trend removed.
Parameters: 


See also
detrend_mean
detrend_linear
detrend_none
matplotlib.mlab.
detrend_linear
(y)[source]¶Return x minus best fit line; 'linear' detrending.
Parameters: 


See also
detrend_mean
detrend_none
detrend
matplotlib.mlab.
detrend_mean
(x, axis=None)[source]¶Return x minus the mean(x).
Parameters: 


See also
detrend_linear
detrend_none
detrend
matplotlib.mlab.
detrend_none
(x, axis=None)[source]¶Return x: no detrending.
Parameters: 


See also
detrend_mean
detrend_linear
detrend
matplotlib.mlab.
magnitude_spectrum
(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the magnitude (absolute value) of the frequency spectrum of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
Parameters: 


Returns: 

See also
psd
complex_spectrum
complex_spectrum
.angle_spectrum
phase_spectrum
specgram
matplotlib.mlab.
phase_spectrum
(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the phase of the frequency spectrum (unwrapped angle spectrum) of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
Parameters: 


Returns: 

See also
complex_spectrum
complex_spectrum
.magnitude_spectrum
angle_spectrum
specgram
matplotlib.mlab.
psd
(x, NFFT=None, Fs=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None)[source]¶Compute the power spectral density.
The power spectral density \(P_{xx}\) by Welch's average periodogram method. The vector x is divided into NFFT length segments. Each segment is detrended by function detrend and windowed by function window. noverlap gives the length of the overlap between segments. The \(\mathrm{fft}(i)^2\) of each segment \(i\) are averaged to compute \(P_{xx}\).
If len(x) < NFFT, it will be zero padded to NFFT.
Parameters: 


Returns: 

See also
specgram
specgram
differs in the default overlap; in not returning the mean of the segment periodograms; and in returning the times of the segments.magnitude_spectrum
csd
References
Bendat & Piersol  Random Data: Analysis and Measurement Procedures, John Wiley & Sons (1986)
matplotlib.mlab.
specgram
(x, NFFT=None, Fs=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None, mode=None)[source]¶Compute a spectrogram.
Compute and plot a spectrogram of data in x. Data are split into NFFT length segments and the spectrum of each section is computed. The windowing function window is applied to each segment, and the amount of overlap of each segment is specified with noverlap.
Parameters: 


Returns: 

See also
psd
complex_spectrum
magnitude_spectrum
angle_spectrum
phase_spectrum
Notes
detrend and scale_by_freq only apply when mode is set to 'psd'.
matplotlib.mlab.
stride_repeat
(x, n, axis=0)[source]¶Repeat the values in an array in a memoryefficient manner. Array x is stacked vertically n times.
Warning
It is not safe to write to the output array. Multiple elements may point to the same piece of memory, so modifying one value may change others.
Parameters: 


References
matplotlib.mlab.
stride_windows
(x, n, noverlap=None, axis=0)[source]¶Get all windows of x with length n as a single array, using strides to avoid data duplication.
Warning
It is not safe to write to the output array. Multiple elements may point to the same piece of memory, so modifying one value may change others.
Parameters: 


References
stackoverflow: Rolling window for 1D arrays in Numpy? stackoverflow: Using strides for an efficient moving average filter
matplotlib.mlab.
window_hanning
(x)[source]¶Return x times the hanning window of len(x).
See also
window_none
matplotlib.mlab.
window_none
(x)[source]¶No window function; simply return x.
See also
window_hanning