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.2.2). 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.18)"><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.4.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>
<dt><aclass="reference internal" href="#matplotlib.mlab.stride_repeat" title="matplotlib.mlab.stride_repeat"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">stride_repeat</span></code></a></dt><dd>Repeat an array in a memory-efficient manner</dd>
<dt><aclass="reference internal" href="#matplotlib.mlab.apply_window" title="matplotlib.mlab.apply_window"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">apply_window</span></code></a></dt><dd>Apply a window along a given axis</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 2-D 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><strong>values</strong><spanclass="classifier">(# of points,)-array</span></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="reference internal" href="../_modules/matplotlib/mlab.html#angle_spectrum"><spanclass="viewcode-link">[source]</span></a><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
<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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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 values for the angle spectrum in radians (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>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.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>This function returns the angle value of <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.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 magnitudes of the corresponding frequencies.</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 corresponding frequencies.</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.apply_window">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">apply_window</code><spanclass="sig-paren">(</span><em><spanclass="n">x</span></em>, <em><spanclass="n">window</span></em>, <em><spanclass="n">axis</span><spanclass="o">=</span><spanclass="default_value">0</span></em>, <em><spanclass="n">return_window</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/mlab.html#apply_window"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.apply_window" title="Permalink to this definition">¶</a></dt>
<dd><p>[<em>Deprecated</em>] Apply the given window to the given 1D or 2D array along the given axis.</p>
<dt><strong>x, y</strong></dt><dd><p>Array or sequence containing the data</p>
</dd>
<dt><strong>Fs</strong><spanclass="classifier">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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</span></dt><dd><p>The number of data points used in each block for the FFT.
A power 2 is most efficient. The default value is 256.
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.
<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>, and <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>, but you can use a custom
function as well. You can also use a string to choose one of the
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, optional</span></dt><dd><p>Specifies 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">integer</span></dt><dd><p>The number of points of overlap between blocks. The default value
is 0 (no overlap).</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt>The return value is the tuple (<em>Cxy</em>, <em>f</em>), where <em>f</em> are the</dt><dd></dd>
<dt>frequencies of the coherence vector. For cohere, scaling the</dt><dd></dd>
<dt>individual densities by the sampling frequency has no effect,</dt><dd></dd>
<dt>since the factors cancel out.</dt><dd></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="reference internal" href="../_modules/matplotlib/mlab.html#complex_spectrum"><spanclass="viewcode-link">[source]</span></a><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 applied to the
<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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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 values for the complex spectrum (complex valued)</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.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 this function.</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 this function.</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 this function.</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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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</span></dt><dd><p>The number of data points used in each block for the FFT.
A power 2 is most efficient. The default value is 256.
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.
<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>, and <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>, but you can use a custom
function as well. You can also use a string to choose one of the
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, optional</span></dt><dd><p>Specifies 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">integer</span></dt><dd><p>The number of points of overlap between segments.
The default value is 0 (no overlap).</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 <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">P_{xy}</span></code> 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.demean">
<codeclass="descclassname">matplotlib.mlab.</code><codeclass="descname">demean</code><spanclass="sig-paren">(</span><em><spanclass="n">x</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#demean"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.demean" title="Permalink to this definition">¶</a></dt>
<dd><p>[<em>Deprecated</em>] Return x minus its mean along the specified axis.</p>
<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
Can have any dimensionality</p>
</dd>
<dt><strong>axis</strong><spanclass="classifier">integer</span></dt><dd><p>The axis along which to take the mean. See numpy.mean for a
description of this argument.</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>Same as <aclass="reference internal" href="#matplotlib.mlab.demean" title="matplotlib.mlab.demean"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">demean</span></code></a> except for the default <em>axis</em>.</dd>
</dl>
</div>
<pclass="rubric">Notes</p>
<divclass="deprecated">
<p><spanclass="versionmodified deprecated">Deprecated since version 3.1.</span></p>
</div>
</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>Specifies the detrend algorithm to use. 'default' is 'mean', which is
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>. 'constant' is the same. '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">integer</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="reference internal" href="../_modules/matplotlib/mlab.html#magnitude_spectrum"><spanclass="viewcode-link">[source]</span></a><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
<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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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 values for the magnitude spectrum (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>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>This function returns the absolute value of <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 angles of the corresponding frequencies.</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 corresponding frequencies.</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="reference internal" href="../_modules/matplotlib/mlab.html#phase_spectrum"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.mlab.phase_spectrum" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the phase of the frequency spectrum (unwrapped angle spectrum) of
<em>x</em>. Data is padded to a length of <em>pad_to</em> and the windowing function
<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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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 values for the phase spectrum in radians (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>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.complex_spectrum" title="matplotlib.mlab.complex_spectrum"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">complex_spectrum</span></code></a></dt><dd>This function returns the phase value of <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.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 magnitudes of the corresponding frequencies.</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 (wrapped phase) of the corresponding frequencies.</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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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</span></dt><dd><p>The number of data points used in each block for the FFT.
A power 2 is most efficient. The default value is 256.
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.
<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>, and <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>, but you can use a custom
function as well. You can also use a string to choose one of the
<dt><strong>scale_by_freq</strong><spanclass="classifier">bool, optional</span></dt><dd><p>Specifies 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">integer</span></dt><dd><p>The number of points of overlap between segments.
The default value is 0 (no overlap).</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 <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">P_{xx}</span></code> (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">scalar</span></dt><dd><p>The sampling frequency (samples per time unit). It is used
to calculate the Fourier frequencies, freqs, in cycles per time
unit. The default value is 2.</p>
</dd>
<dt><strong>window</strong><spanclass="classifier">callable or ndarray</span></dt><dd><p>A function or a vector of length <em>NFFT</em>. To create window vectors see
default is <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>. If a 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'}</span></dt><dd><p>Specifies which sides of the spectrum to return. Default gives the
default behavior, which returns one-sided for real data and both
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</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</span></dt><dd><p>The number of data points used in each block for the FFT.