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.
coherecsddetrendpsdspecgramcomplex_spectrummagnitude_spectrumangle_spectrumphase_spectrumdetrend_meandetrend_lineardetrend_nonestride_windowsstride_repeatapply_windowmatplotlib.mlab.GaussianKDE(dataset, bw_method=None)[source]¶Bases: object
Representation of a kernel-density 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_spectrumcomplex_spectrum.magnitude_spectrumphase_spectrumspecgrammatplotlib.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 complex-valued 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_spectrumangle_spectrumphase_spectrumspecgrammatplotlib.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 cross-spectral 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
psdy = 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_meandemean 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_meandetrend_lineardetrend_nonematplotlib.mlab.detrend_linear(y)[source]¶Return x minus best fit line; 'linear' detrending.
| Parameters: |
|
|---|
See also
detrend_meandetrend_nonedetrendmatplotlib.mlab.detrend_mean(x, axis=None)[source]¶Return x minus the mean(x).
| Parameters: |
|
|---|
See also
detrend_lineardetrend_nonedetrendmatplotlib.mlab.detrend_none(x, axis=None)[source]¶Return x: no detrending.
| Parameters: |
|
|---|
See also
detrend_meandetrend_lineardetrendmatplotlib.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
psdcomplex_spectrumcomplex_spectrum.angle_spectrumphase_spectrumspecgrammatplotlib.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_spectrumcomplex_spectrum.magnitude_spectrumangle_spectrumspecgrammatplotlib.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
specgramspecgram differs in the default overlap; in not returning the mean of the segment periodograms; and in returning the times of the segments.magnitude_spectrumcsdReferences
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
psdcomplex_spectrummagnitude_spectrumangle_spectrumphase_spectrumNotes
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 memory-efficient 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_nonematplotlib.mlab.window_none(x)[source]¶No window function; simply return x.
See also
window_hanning