You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
<divid="unreleased-message"> You are reading an old version of the documentation (v3.4.1). For the latest version see <ahref="https://matplotlib.org/stable/api/mlab_api.html">https://matplotlib.org/stable/api/mlab_api.html</a></div>
<spanid="matplotlib-mlab"></span><h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.mlab</span></code><aclass="headerlink" href="#module-matplotlib.mlab" title="Permalink to this headline">¶</a></h1>
<p>Numerical python functions written for compatibility with MATLAB
commands with the same names. Most numerical python functions can be found in
the <aclass="reference external" href="https://numpy.org/doc/stable/reference/index.html#module-numpy" title="(in NumPy v1.20)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">numpy</span></code></a> and <aclass="reference external" href="https://docs.scipy.org/doc/scipy/reference/index.html#module-scipy" title="(in SciPy v1.6.1)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">scipy</span></code></a> libraries. What remains here is code for performing
spectral computations.</p>
<divclass="section" id="spectral-functions">
<h2>Spectral functions<aclass="headerlink" href="#spectral-functions" title="Permalink to this headline">¶</a></h2>
<dt><aclass="reference internal" href="#matplotlib.mlab.csd" title="matplotlib.mlab.csd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">csd</span></code></a></dt><dd>Cross spectral density using Welch's average periodogram</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend" title="matplotlib.mlab.detrend"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend</span></code></a></dt><dd>Remove the mean or best fit line from an array</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">psd</span></code></a></dt><dd>Power spectral density using Welch's average periodogram</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a></dt><dd>Spectrogram (spectrum over segments of time)</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>Return the complex-valued frequency spectrum of a signal</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.magnitude_spectrum" title="matplotlib.mlab.magnitude_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">magnitude_spectrum</span></code></a></dt><dd>Return the magnitude of the frequency spectrum of a signal</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.angle_spectrum" title="matplotlib.mlab.angle_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">angle_spectrum</span></code></a></dt><dd>Return the angle (wrapped phase) of the frequency spectrum of a signal</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.phase_spectrum" title="matplotlib.mlab.phase_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">phase_spectrum</span></code></a></dt><dd>Return the phase (unwrapped angle) of the frequency spectrum of a signal</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend_mean" title="matplotlib.mlab.detrend_mean"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_mean</span></code></a></dt><dd>Remove the mean from a line.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend_linear" title="matplotlib.mlab.detrend_linear"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_linear</span></code></a></dt><dd>Remove the best fit line from a line.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend_none" title="matplotlib.mlab.detrend_none"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_none</span></code></a></dt><dd>Return the original line.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.stride_windows" title="matplotlib.mlab.stride_windows"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">stride_windows</span></code></a></dt><dd>Get all windows in an array in a memory-efficient manner</dd>
</dl>
<dlclass="py class">
<dtid="matplotlib.mlab.GaussianKDE">
<emclass="property">class </em><codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">GaussianKDE</code><spanclass="sig-paren">(</span><em><spanclass="n">dataset</span></em>, <em><spanclass="n">bw_method</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#GaussianKDE"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.GaussianKDE" title="Permalink to this definition">¶</a></dt>
<dt><strong>dataset</strong><spanclass="classifier">array-like</span></dt><dd><p>Datapoints to estimate from. In case of univariate data this is a 1-D
array, otherwise a 2D array with shape (# of dims, # of data).</p>
</dd>
<dt><strong>bw_method</strong><spanclass="classifier">str, scalar or callable, optional</span></dt><dd><p>The method used to calculate the estimator bandwidth. This can be
'scott', 'silverman', a scalar constant or a callable. If a
scalar, this will be used directly as <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">kde.factor</span></code>. If a
callable, it should take a <aclass="reference internal" href="#matplotlib.mlab.GaussianKDE" title="matplotlib.mlab.GaussianKDE"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">GaussianKDE</span></code></a> instance as only
parameter and return a scalar. If None (default), 'scott' is used.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Attributes:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>dataset</strong><spanclass="classifier">ndarray</span></dt><dd><p>The dataset with which <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">gaussian_kde</span></code> was initialized.</p>
</dd>
<dt><strong>dim</strong><spanclass="classifier">int</span></dt><dd><p>Number of dimensions.</p>
</dd>
<dt><strong>num_dp</strong><spanclass="classifier">int</span></dt><dd><p>Number of datapoints.</p>
</dd>
<dt><strong>factor</strong><spanclass="classifier">float</span></dt><dd><p>The bandwidth factor, obtained from <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">kde.covariance_factor</span></code>, with which
the covariance matrix is multiplied.</p>
</dd>
<dt><strong>covariance</strong><spanclass="classifier">ndarray</span></dt><dd><p>The covariance matrix of <em>dataset</em>, scaled by the calculated bandwidth
<codeclass="descname">covariance_factor</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.mlab.GaussianKDE.covariance_factor" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py method">
<dtid="matplotlib.mlab.GaussianKDE.evaluate">
<codeclass="descname">evaluate</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">points</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#GaussianKDE.evaluate"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.GaussianKDE.evaluate" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate the estimated pdf on a set of points.</p>
<dt><strong>points</strong><spanclass="classifier">(# of dimensions, # of points)-array</span></dt><dd><p>Alternatively, a (# of dimensions,) vector can be passed in and
<dt>(# of points,)-array</dt><dd><p>The values at each point.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-odd field"><thclass="field-name">Raises:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>ValueError</strong><spanclass="classifier">if the dimensionality of the input points is different</span></dt><dd><p>than the dimensionality of the KDE.</p>
<codeclass="descname">scotts_factor</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#GaussianKDE.scotts_factor"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.GaussianKDE.scotts_factor" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">silverman_factor</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#GaussianKDE.silverman_factor"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.GaussianKDE.silverman_factor" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.angle_spectrum">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">angle_spectrum</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.mlab.angle_spectrum" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the angle of the frequency spectrum (wrapped phase spectrum) of <em>x</em>.
Data is padded to a length of <em>pad_to</em> and the windowing function <em>window</em> is
<dt><strong>x</strong><spanclass="classifier">1-D array or sequence</span></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. While not increasing the actual resolution of the spectrum (the
minimum distance between resolvable peaks), this can give more points in
the plot, allowing for more detail. This corresponds to the <em>n</em> parameter
in the call to fft(). The default is None, which sets <em>pad_to</em> equal to
the length of the input signal (i.e. no padding).</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>spectrum</strong><spanclass="classifier">1-D array</span></dt><dd><p>The angle of the frequency spectrum (wrapped phase spectrum).</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies corresponding to the elements in <em>spectrum</em>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">psd</span></code></a></dt><dd>Returns the power spectral density.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>Returns the complex-valued frequency spectrum.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.magnitude_spectrum" title="matplotlib.mlab.magnitude_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">magnitude_spectrum</span></code></a></dt><dd>Returns the absolute value of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.angle_spectrum" title="matplotlib.mlab.angle_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">angle_spectrum</span></code></a></dt><dd>Returns the angle of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.phase_spectrum" title="matplotlib.mlab.phase_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">phase_spectrum</span></code></a></dt><dd>Returns the phase (unwrapped angle) of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a></dt><dd>Can return the complex spectrum of segments within the signal.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.cohere">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">cohere</code><spanclass="sig-paren">(</span><em>x</em>, <em>y</em>, <em>NFFT=256</em>, <em>Fs=2</em>, <em>detrend=<function detrend_none at 0x7f5f32ce50d0></em>, <em>window=<function window_hanning at 0x7f5f32cdfca0></em>, <em>noverlap=0</em>, <em>pad_to=None</em>, <em>sides='default'</em>, <em>scale_by_freq=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#cohere"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.cohere" title="Permalink to this definition">¶</a></dt>
<dd><p>The coherence between <em>x</em> and <em>y</em>. Coherence is the normalized
<dt><strong>x, y</strong></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. This can be different from <em>NFFT</em>, which specifies the number
of data points used. While not increasing the actual resolution of the
spectrum (the minimum distance between resolvable peaks), this can give
more points in the plot, allowing for more detail. This corresponds to
the <em>n</em> parameter in the call to fft(). The default is None, which sets
<em>pad_to</em> equal to <em>NFFT</em></p>
</dd>
<dt><strong>NFFT</strong><spanclass="classifier">int, default: 256</span></dt><dd><p>The number of data points used in each block for the FFT. A power 2 is
most efficient. This should <em>NOT</em> be used to get zero padding, or the
scaling of the result will be incorrect; use <em>pad_to</em> for this instead.</p>
</dd>
<dt><strong>detrend</strong><spanclass="classifier">{'none', 'mean', 'linear'} or callable, default: 'none'</span></dt><dd><p>The function applied to each segment before fft-ing, designed to remove
the mean or linear trend. Unlike in MATLAB, where the <em>detrend</em> parameter
is a vector, in Matplotlib is it a function. The <aclass="reference internal" href="#module-matplotlib.mlab" title="matplotlib.mlab"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">mlab</span></code></a>
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, default: True</span></dt><dd><p>Whether the resulting density values should be scaled by the scaling
frequency, which gives density in units of Hz^-1. This allows for
integration over the returned frequency values. The default is True for
MATLAB compatibility.</p>
</dd>
<dt><strong>noverlap</strong><spanclass="classifier">int, default: 0 (no overlap)</span></dt><dd><p>The number of points of overlap between segments.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies for the elements in <em>Cxy</em>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">psd()</span></code></a>, <aclass="reference internal" href="#matplotlib.mlab.csd" title="matplotlib.mlab.csd"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">csd()</span></code></a></dt><dd>For information about the methods used to compute <spanclass="math notranslate nohighlight">\(P_{xy}\)</span>, <spanclass="math notranslate nohighlight">\(P_{xx}\)</span> and <spanclass="math notranslate nohighlight">\(P_{yy}\)</span>.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.complex_spectrum">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">complex_spectrum</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.mlab.complex_spectrum" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the complex-valued frequency spectrum of <em>x</em>.
Data is padded to a length of <em>pad_to</em> and the windowing function <em>window</em> is
<dt><strong>x</strong><spanclass="classifier">1-D array or sequence</span></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. While not increasing the actual resolution of the spectrum (the
minimum distance between resolvable peaks), this can give more points in
the plot, allowing for more detail. This corresponds to the <em>n</em> parameter
in the call to fft(). The default is None, which sets <em>pad_to</em> equal to
the length of the input signal (i.e. no padding).</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>spectrum</strong><spanclass="classifier">1-D array</span></dt><dd><p>The complex-valued frequency spectrum.</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies corresponding to the elements in <em>spectrum</em>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">psd</span></code></a></dt><dd>Returns the power spectral density.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>Returns the complex-valued frequency spectrum.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.magnitude_spectrum" title="matplotlib.mlab.magnitude_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">magnitude_spectrum</span></code></a></dt><dd>Returns the absolute value of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.angle_spectrum" title="matplotlib.mlab.angle_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">angle_spectrum</span></code></a></dt><dd>Returns the angle of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.phase_spectrum" title="matplotlib.mlab.phase_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">phase_spectrum</span></code></a></dt><dd>Returns the phase (unwrapped angle) of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a></dt><dd>Can return the complex spectrum of segments within the signal.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.csd">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">csd</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">y</span></em>, <em><spanclass="n">NFFT</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">detrend</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">noverlap</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">scale_by_freq</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#csd"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.csd" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the cross-spectral density.</p>
<p>The cross spectral density <spanclass="math notranslate nohighlight">\(P_{xy}\)</span> by Welch's average
periodogram method. The vectors <em>x</em> and <em>y</em> are divided into
<em>NFFT</em> length segments. Each segment is detrended by function
<em>detrend</em> and windowed by function <em>window</em>. <em>noverlap</em> gives
the length of the overlap between segments. The product of
the direct FFTs of <em>x</em> and <em>y</em> are averaged over each segment
to compute <spanclass="math notranslate nohighlight">\(P_{xy}\)</span>, with a scaling to correct for power
loss due to windowing.</p>
<p>If len(<em>x</em>) < <em>NFFT</em> or len(<em>y</em>) < <em>NFFT</em>, they will be zero
<dt><strong>x, y</strong><spanclass="classifier">1-D arrays or sequences</span></dt><dd><p>Arrays or sequences containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. This can be different from <em>NFFT</em>, which specifies the number
of data points used. While not increasing the actual resolution of the
spectrum (the minimum distance between resolvable peaks), this can give
more points in the plot, allowing for more detail. This corresponds to
the <em>n</em> parameter in the call to fft(). The default is None, which sets
<em>pad_to</em> equal to <em>NFFT</em></p>
</dd>
<dt><strong>NFFT</strong><spanclass="classifier">int, default: 256</span></dt><dd><p>The number of data points used in each block for the FFT. A power 2 is
most efficient. This should <em>NOT</em> be used to get zero padding, or the
scaling of the result will be incorrect; use <em>pad_to</em> for this instead.</p>
</dd>
<dt><strong>detrend</strong><spanclass="classifier">{'none', 'mean', 'linear'} or callable, default: 'none'</span></dt><dd><p>The function applied to each segment before fft-ing, designed to remove
the mean or linear trend. Unlike in MATLAB, where the <em>detrend</em> parameter
is a vector, in Matplotlib is it a function. The <aclass="reference internal" href="#module-matplotlib.mlab" title="matplotlib.mlab"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">mlab</span></code></a>
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, default: True</span></dt><dd><p>Whether the resulting density values should be scaled by the scaling
frequency, which gives density in units of Hz^-1. This allows for
integration over the returned frequency values. The default is True for
MATLAB compatibility.</p>
</dd>
<dt><strong>noverlap</strong><spanclass="classifier">int, default: 0 (no overlap)</span></dt><dd><p>The number of points of overlap between segments.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>Pxy</strong><spanclass="classifier">1-D array</span></dt><dd><p>The values for the cross spectrum <spanclass="math notranslate nohighlight">\(P_{xy}\)</span> before scaling (real
valued)</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies corresponding to the elements in <em>Pxy</em></p>
<p>Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John
Wiley & Sons (1986)</p>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.detrend">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">detrend</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">key</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">axis</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#detrend"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.detrend" title="Permalink to this definition">¶</a></dt>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>x</strong><spanclass="classifier">array or sequence</span></dt><dd><p>Array or sequence containing the data.</p>
</dd>
<dt><strong>key</strong><spanclass="classifier">{'default', 'constant', 'mean', 'linear', 'none'} or function</span></dt><dd><p>The detrending algorithm to use. 'default', 'mean', and 'constant' are
the same as <aclass="reference internal" href="#matplotlib.mlab.detrend_mean" title="matplotlib.mlab.detrend_mean"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_mean</span></code></a>. 'linear' is the same as <aclass="reference internal" href="#matplotlib.mlab.detrend_linear" title="matplotlib.mlab.detrend_linear"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_linear</span></code></a>.
'none' is the same as <aclass="reference internal" href="#matplotlib.mlab.detrend_none" title="matplotlib.mlab.detrend_none"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_none</span></code></a>. The default is 'mean'. See the
corresponding functions for more details regarding the algorithms. Can
also be a function that carries out the detrend operation.</p>
</dd>
<dt><strong>axis</strong><spanclass="classifier">int</span></dt><dd><p>The axis along which to do the detrending.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend_mean" title="matplotlib.mlab.detrend_mean"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_mean</span></code></a></dt><dd>Implementation of the 'mean' algorithm.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend_linear" title="matplotlib.mlab.detrend_linear"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_linear</span></code></a></dt><dd>Implementation of the 'linear' algorithm.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend_none" title="matplotlib.mlab.detrend_none"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend_none</span></code></a></dt><dd>Implementation of the 'none' algorithm.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.detrend_linear">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">detrend_linear</code><spanclass="sig-paren">(</span><em><spanclass="n">y</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#detrend_linear"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.detrend_linear" title="Permalink to this definition">¶</a></dt>
<dd><p>Return x minus best fit line; 'linear' detrending.</p>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend" title="matplotlib.mlab.detrend"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend</span></code></a></dt><dd>A wrapper around all the detrend algorithms.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.detrend_mean">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">detrend_mean</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">axis</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#detrend_mean"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.detrend_mean" title="Permalink to this definition">¶</a></dt>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend" title="matplotlib.mlab.detrend"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend</span></code></a></dt><dd>A wrapper around all the detrend algorithms.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.detrend_none">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">detrend_none</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">axis</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#detrend_none"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.detrend_none" title="Permalink to this definition">¶</a></dt>
<dt><aclass="reference internal" href="#matplotlib.mlab.detrend" title="matplotlib.mlab.detrend"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">detrend</span></code></a></dt><dd>A wrapper around all the detrend algorithms.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.magnitude_spectrum">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">magnitude_spectrum</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.mlab.magnitude_spectrum" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the magnitude (absolute value) of the frequency spectrum of <em>x</em>.
Data is padded to a length of <em>pad_to</em> and the windowing function <em>window</em> is
<dt><strong>x</strong><spanclass="classifier">1-D array or sequence</span></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. While not increasing the actual resolution of the spectrum (the
minimum distance between resolvable peaks), this can give more points in
the plot, allowing for more detail. This corresponds to the <em>n</em> parameter
in the call to fft(). The default is None, which sets <em>pad_to</em> equal to
the length of the input signal (i.e. no padding).</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>spectrum</strong><spanclass="classifier">1-D array</span></dt><dd><p>The magnitude (absolute value) of the frequency spectrum.</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies corresponding to the elements in <em>spectrum</em>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">psd</span></code></a></dt><dd>Returns the power spectral density.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>Returns the complex-valued frequency spectrum.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.magnitude_spectrum" title="matplotlib.mlab.magnitude_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">magnitude_spectrum</span></code></a></dt><dd>Returns the absolute value of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.angle_spectrum" title="matplotlib.mlab.angle_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">angle_spectrum</span></code></a></dt><dd>Returns the angle of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.phase_spectrum" title="matplotlib.mlab.phase_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">phase_spectrum</span></code></a></dt><dd>Returns the phase (unwrapped angle) of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a></dt><dd>Can return the complex spectrum of segments within the signal.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.phase_spectrum">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">phase_spectrum</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.mlab.phase_spectrum" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the phase of the frequency spectrum (unwrapped phase spectrum) of <em>x</em>.
Data is padded to a length of <em>pad_to</em> and the windowing function <em>window</em> is
<dt><strong>x</strong><spanclass="classifier">1-D array or sequence</span></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. While not increasing the actual resolution of the spectrum (the
minimum distance between resolvable peaks), this can give more points in
the plot, allowing for more detail. This corresponds to the <em>n</em> parameter
in the call to fft(). The default is None, which sets <em>pad_to</em> equal to
the length of the input signal (i.e. no padding).</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>spectrum</strong><spanclass="classifier">1-D array</span></dt><dd><p>The phase of the frequency spectrum (unwrapped phase spectrum).</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies corresponding to the elements in <em>spectrum</em>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">psd</span></code></a></dt><dd>Returns the power spectral density.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>Returns the complex-valued frequency spectrum.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.magnitude_spectrum" title="matplotlib.mlab.magnitude_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">magnitude_spectrum</span></code></a></dt><dd>Returns the absolute value of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.angle_spectrum" title="matplotlib.mlab.angle_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">angle_spectrum</span></code></a></dt><dd>Returns the angle of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.phase_spectrum" title="matplotlib.mlab.phase_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">phase_spectrum</span></code></a></dt><dd>Returns the phase (unwrapped angle) of the <aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a>.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a></dt><dd>Can return the complex spectrum of segments within the signal.</dd>
</dl>
</div>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.psd">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">psd</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">NFFT</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">detrend</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">noverlap</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">scale_by_freq</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#psd"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.psd" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the power spectral density.</p>
<p>The power spectral density <spanclass="math notranslate nohighlight">\(P_{xx}\)</span> by Welch's average
periodogram method. The vector <em>x</em> is divided into <em>NFFT</em> length
segments. Each segment is detrended by function <em>detrend</em> and
windowed by function <em>window</em>. <em>noverlap</em> gives the length of
the overlap between segments. The <spanclass="math notranslate nohighlight">\(|\mathrm{fft}(i)|^2\)</span>
of each segment <spanclass="math notranslate nohighlight">\(i\)</span> are averaged to compute <spanclass="math notranslate nohighlight">\(P_{xx}\)</span>.</p>
<p>If len(<em>x</em>) < <em>NFFT</em>, it will be zero padded to <em>NFFT</em>.</p>
<dt><strong>x</strong><spanclass="classifier">1-D array or sequence</span></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. This can be different from <em>NFFT</em>, which specifies the number
of data points used. While not increasing the actual resolution of the
spectrum (the minimum distance between resolvable peaks), this can give
more points in the plot, allowing for more detail. This corresponds to
the <em>n</em> parameter in the call to fft(). The default is None, which sets
<em>pad_to</em> equal to <em>NFFT</em></p>
</dd>
<dt><strong>NFFT</strong><spanclass="classifier">int, default: 256</span></dt><dd><p>The number of data points used in each block for the FFT. A power 2 is
most efficient. This should <em>NOT</em> be used to get zero padding, or the
scaling of the result will be incorrect; use <em>pad_to</em> for this instead.</p>
</dd>
<dt><strong>detrend</strong><spanclass="classifier">{'none', 'mean', 'linear'} or callable, default: 'none'</span></dt><dd><p>The function applied to each segment before fft-ing, designed to remove
the mean or linear trend. Unlike in MATLAB, where the <em>detrend</em> parameter
is a vector, in Matplotlib is it a function. The <aclass="reference internal" href="#module-matplotlib.mlab" title="matplotlib.mlab"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">mlab</span></code></a>
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, default: True</span></dt><dd><p>Whether the resulting density values should be scaled by the scaling
frequency, which gives density in units of Hz^-1. This allows for
integration over the returned frequency values. The default is True for
MATLAB compatibility.</p>
</dd>
<dt><strong>noverlap</strong><spanclass="classifier">int, default: 0 (no overlap)</span></dt><dd><p>The number of points of overlap between segments.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>Pxx</strong><spanclass="classifier">1-D array</span></dt><dd><p>The values for the power spectrum <spanclass="math notranslate nohighlight">\(P_{xx}\)</span> (real valued)</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">1-D array</span></dt><dd><p>The frequencies corresponding to the elements in <em>Pxx</em></p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a></dt><dd><aclass="reference internal" href="#matplotlib.mlab.specgram" title="matplotlib.mlab.specgram"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">specgram</span></code></a> differs in the default overlap; in not returning the mean of the segment periodograms; and in returning the times of the segments.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.csd" title="matplotlib.mlab.csd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">csd</span></code></a></dt><dd>returns the spectral density between two signals.</dd>
</dl>
</div>
<pclass="rubric">References</p>
<p>Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John
Wiley & Sons (1986)</p>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.specgram">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">specgram</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">NFFT</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">Fs</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">detrend</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">window</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">noverlap</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pad_to</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">sides</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">scale_by_freq</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">mode</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#specgram"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.specgram" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute a spectrogram.</p>
<p>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
<dt><strong>x</strong><spanclass="classifier">array-like</span></dt><dd><p>1-D array or sequence.</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">float, default: 2</span></dt><dd><p>The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, <em>freqs</em>, in cycles per time unit.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray, default: <aclass="reference internal" href="#matplotlib.mlab.window_hanning" title="matplotlib.mlab.window_hanning"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">window_hanning</span></code></a></span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
function is passed as the argument, it must take a data segment as an
argument and return the windowed version of the segment.</p>
</dd>
<dt><strong>sides</strong><spanclass="classifier">{'default', 'onesided', 'twosided'}, optional</span></dt><dd><p>Which sides of the spectrum to return. 'default' is one-sided for real
data and two-sided for complex data. 'onesided' forces the return of a
one-sided spectrum, while 'twosided' forces two-sided.</p>
</dd>
<dt><strong>pad_to</strong><spanclass="classifier">int, optional</span></dt><dd><p>The number of points to which the data segment is padded when performing
the FFT. This can be different from <em>NFFT</em>, which specifies the number
of data points used. While not increasing the actual resolution of the
spectrum (the minimum distance between resolvable peaks), this can give
more points in the plot, allowing for more detail. This corresponds to
the <em>n</em> parameter in the call to fft(). The default is None, which sets
<em>pad_to</em> equal to <em>NFFT</em></p>
</dd>
<dt><strong>NFFT</strong><spanclass="classifier">int, default: 256</span></dt><dd><p>The number of data points used in each block for the FFT. A power 2 is
most efficient. This should <em>NOT</em> be used to get zero padding, or the
scaling of the result will be incorrect; use <em>pad_to</em> for this instead.</p>
</dd>
<dt><strong>detrend</strong><spanclass="classifier">{'none', 'mean', 'linear'} or callable, default: 'none'</span></dt><dd><p>The function applied to each segment before fft-ing, designed to remove
the mean or linear trend. Unlike in MATLAB, where the <em>detrend</em> parameter
is a vector, in Matplotlib is it a function. The <aclass="reference internal" href="#module-matplotlib.mlab" title="matplotlib.mlab"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">mlab</span></code></a>
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, default: True</span></dt><dd><p>Whether the resulting density values should be scaled by the scaling
frequency, which gives density in units of Hz^-1. This allows for
integration over the returned frequency values. The default is True for
MATLAB compatibility.</p>
</dd>
<dt><strong>noverlap</strong><spanclass="classifier">int, default: 128</span></dt><dd><p>The number of points of overlap between blocks.</p>
<dt>What sort of spectrum to use:</dt><dd><dlclass="docutils">
<dt>'psd'</dt><dd><p>Returns the power spectral density.</p>
</dd>
<dt>'complex'</dt><dd><p>Returns the complex-valued frequency spectrum.</p>
</dd>
<dt>'magnitude'</dt><dd><p>Returns the magnitude spectrum.</p>
</dd>
<dt>'angle'</dt><dd><p>Returns the phase spectrum without unwrapping.</p>
</dd>
<dt>'phase'</dt><dd><p>Returns the phase spectrum with unwrapping.</p>
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>spectrum</strong><spanclass="classifier">array-like</span></dt><dd><p>2D array, columns are the periodograms of successive segments.</p>
</dd>
<dt><strong>freqs</strong><spanclass="classifier">array-like</span></dt><dd><p>1-D array, frequencies corresponding to the rows in <em>spectrum</em>.</p>
</dd>
<dt><strong>t</strong><spanclass="classifier">array-like</span></dt><dd><p>1-D array, the times corresponding to midpoints of segments
(i.e the columns in <em>spectrum</em>).</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<dlclass="last docutils">
<dt><aclass="reference internal" href="#matplotlib.mlab.psd" title="matplotlib.mlab.psd"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">psd</span></code></a></dt><dd>differs in the overlap and in the return values.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>similar, but with complex valued frequencies.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.magnitude_spectrum" title="matplotlib.mlab.magnitude_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">magnitude_spectrum</span></code></a></dt><dd>similar single segment when mode is 'magnitude'.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.angle_spectrum" title="matplotlib.mlab.angle_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">angle_spectrum</span></code></a></dt><dd>similar to single segment when mode is 'angle'.</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.phase_spectrum" title="matplotlib.mlab.phase_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">phase_spectrum</span></code></a></dt><dd>similar to single segment when mode is 'phase'.</dd>
</dl>
</div>
<pclass="rubric">Notes</p>
<p>detrend and scale_by_freq only apply when <em>mode</em> is set to 'psd'.</p>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.stride_windows">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">stride_windows</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">n</span></em>, <em><spanclass="n">noverlap</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">axis</span><spanclass="o">=</span><spanclass="default_value">0</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#stride_windows"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.stride_windows" title="Permalink to this definition">¶</a></dt>
<dd><p>Get all windows of x with length n as a single array,
using strides to avoid data duplication.</p>
<divclass="admonition warning">
<pclass="first admonition-title">Warning</p>
<pclass="last">It is not safe to write to the output array. Multiple
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>x</strong><spanclass="classifier">1D array or sequence</span></dt><dd><p>Array or sequence containing the data.</p>
</dd>
<dt><strong>n</strong><spanclass="classifier">int</span></dt><dd><p>The number of data points in each window.</p>
</dd>
<dt><strong>noverlap</strong><spanclass="classifier">int, default: 0 (no overlap)</span></dt><dd><p>The overlap between adjacent windows.</p>
</dd>
<dt><strong>axis</strong><spanclass="classifier">int</span></dt><dd><p>The axis along which the windows will run.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<pclass="rubric">References</p>
<p><aclass="reference external" href="http://stackoverflow.com/a/6811241">stackoverflow: Rolling window for 1D arrays in Numpy?</a>
<aclass="reference external" href="http://stackoverflow.com/a/4947453">stackoverflow: Using strides for an efficient moving average filter</a></p>
</dd></dl>
<dlclass="py function">
<dtid="matplotlib.mlab.window_hanning">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">window_hanning</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#window_hanning"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.window_hanning" title="Permalink to this definition">¶</a></dt>
<dd><p>Return x times the hanning window of len(x).</p>