Files
intellecton/venv/lib/python3.12/site-packages/matplotlib/__pycache__/mlab.cpython-312.pyc
T

555 lines
32 KiB
Plaintext
Raw Normal View History

Ë
†Rjvã ó„dZddlZddlmZddlZddlmZmZm Z dZ
dZ d$dZ d%dZ
d%d „Zd
Z d&d Z d'd Zej$j'd
dd¬«ej$ d(d«Zej$ d(d«ZdZej.ed«Zej2d)ddiej$j4¤Že_ej.ed«Zej2d)ddiej$j4¤Že_ej.ed«Zej2d)ddiej$j4¤Že_ej.ed«Zej2d)ddiej$j4¤Že_ej$ d*d«Zej$ddee
ddd dfd!„«ZGd"„d#«Z y)+a¶
Numerical Python functions written for compatibility with MATLAB
commands with the same names. Most numerical Python functions can be found in
the `NumPy`_ and `SciPy`_ libraries. What remains here is code for performing
spectral computations and kernel density estimations.
.. _NumPy: https://numpy.org
.. _SciPy: https://www.scipy.org
Spectral functions
------------------
`cohere`
Coherence (normalized cross spectral density)
`csd`
Cross spectral density using Welch's average periodogram
`detrend`
Remove the mean or best fit line from an array
`psd`
Power spectral density using Welch's average periodogram
`specgram`
Spectrogram (spectrum over segments of time)
`complex_spectrum`
Return the complex-valued frequency spectrum of a signal
`magnitude_spectrum`
Return the magnitude of the frequency spectrum of a signal
`angle_spectrum`
Return the angle (wrapped phase) of the frequency spectrum of a signal
`phase_spectrum`
Return the phase (unwrapped angle) of the frequency spectrum of a signal
`detrend_mean`
Remove the mean from a line.
`detrend_linear`
Remove the best fit line from a line.
`detrend_none`
Return the original line.
éN)ÚNumber)Ú_apiÚ
_docstringÚcbookcóDtjt|««|zS)z
Return *x* times the Hanning (or Hann) window of len(*x*).
See Also
--------
window_none : Another window algorithm.
)ÚnpÚhanningÚlen©Úxs úR/home/antigravity/intellecton/venv/lib/python3.12/site-packages/matplotlib/mlab.pyÚwindow_hanningr:sô :‰:”c˜!“fÓ ˜aÑ Ðócó|S)zz
No window function; simply return *x*.
See Also
--------
window_hanning : Another window algorithm.
©r s r
Ú window_nonerEs ð
€Hrcóê||dvrt|t|¬«S|dk(rt|t|¬«S|dk(rt|t|¬«St |«rmt j |«}|!|dz|jkDrtd|d«||jdk(s|s|jdk(r||«S |||¬ «Std |d «#t$rt j|||¬
«cYSwxYw)
al
Return *x* with its trend removed.
Parameters
----------
x : array or sequence
Array or sequence containing the data.
key : {'default', 'constant', 'mean', 'linear', 'none'} or function
The detrending algorithm to use. 'default', 'mean', and 'constant' are
the same as `detrend_mean`. 'linear' is the same as `detrend_linear`.
'none' is the same as `detrend_none`. 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.
axis : int
The axis along which to do the detrending.
See Also
--------
detrend_mean : Implementation of the 'mean' algorithm.
detrend_linear : Implementation of the 'linear' algorithm.
detrend_none : Implementation of the 'none' algorithm.
)ÚconstantÚmeanÚdefault)ÚkeyÚaxisÚlinearÚnoneézaxis(=z) out of boundsr©r)rÚarrzUnknown value for key: zH, must be one of: 'default', 'constant', 'mean', 'linear', or a function) ÚdetrendÚ detrend_meanÚdetrend_linearÚ detrend_noneÚcallablerÚasarrayÚndimÚ
ValueErrorÚ TypeErrorÚapply_along_axis)r rrs r
rrPsð2 €{qœl°Ô ŠÜqœn°4Ô ŠÜqœl°ÔÜ J‰Jq‹MˆØ Ð   q¡¨1¯6©6Ò 1ܘv d V¨?Ð ˆL˜QŸV™V qš[±$¸1¿6¹6ÀQº;Ùq“6ˆq˜ Ø% c -:ð
 <øôò×& ¸  >úsÂ5 CÃ!C2Ã1C2cóœtj|«}| |dz|jkDrtd|z«||j |d¬«z
S)
Return *x* minus the mean(*x*).
Parameters
----------
x : array or sequence
Array or sequence containing the data
Can have any dimensionality
axis : int
The axis along which to take the mean. See `numpy.mean` for a
description of this argument.
See Also
--------
detrend_linear : Another detrend algorithm.
detrend_none : Another detrend algorithm.
detrend : A wrapper around all the detrend algorithms.
rzaxis(=%s) out of boundsT)Úkeepdims)rr#r$r%r©r rs r
rrsNô(
1
€Aà ИD ™F Q§V¡VšOÜÐ2°TÑ ˆqv‰vd Tˆ *rcó|S)
Return *x*: no detrending.
Parameters
----------
x : any object
An object containing the data
axis : int
This parameter is ignored.
It is included for compatibility with detrend_mean
See Also
--------
detrend_mean : Another detrend algorithm.
detrend_linear : Another detrend algorithm.
detrend : A wrapper around all the detrend algorithms.
rr*s r
r!r!s ð&
€Hrcó¨tj|«}|jdkDr td«|js!tjd|j
¬«Stj |jt¬«}tj||d¬«}|d|dz }|j«||j«zz
}|||z|zz
S)ab
Return *x* minus best fit line; 'linear' detrending.
Parameters
----------
y : 0-D or 1-D array or sequence
Array or sequence containing the data
See Also
--------
detrend_mean : Another detrend algorithm.
detrend_none : Another detrend algorithm.
detrend : A wrapper around all the detrend algorithms.
rzy cannot have ndim > 1g)Údtype)Úbias)rr)rr) rr#r$r%Úarrayr-ÚarangeÚsizeÚfloatÚcovr)Úyr Úas r
r r ³ô
1
€Aà‡vv‚zÜÐ
6Š6Üx‰x˜ !§'¡'Ô
!—&Ô&€Aä
ˆq!˜!Ô€AØ ˆ$‰$‘€Aà 1Q—V‘V“X‘:Ñ€AØ !‘a‘‰=Ðrc ór |d} n||u} |d}|d}|t}|t}|d}||k\r td«|
|
dk(rd}
tjgd ¢|
¬
«| s|
dk7r td «t j |«}| st j |«}||dk(rt j|«rd }nd
}tjgd¢|¬«t|«|kr&t|«} t j||«}d|| d| s4t|«|kr&t|«} t j||«}d|| d||}|
dk7rd} n| €d} |d k(r|}
|dzr |dz
dzdz}n|dz}d}n|d
k(r|dzr |dzdz}
n|dzdz}
d}t j|«s&|t j||j««}t|«|k7r td«t
jjj||d¬«dd||z
j }t#||d¬«}||j%d«z}t
j&j'||d¬«d
ddf}t
j&j)|d|z «d|
}| s¥t
jjj||d¬«dd||z
j }t#||d¬«}||j%d«z}t
j&j'||d¬«d|
ddf}t j*|«|z}n|
dk(rt j*|«|z}nd|
dk(r't j,|«|j/«z }n8|
dk(s|
dk(rt j0|«}n|
dk(r||j/«z}|
dk(ra|dzst3ddd«}n
t3ddd«}||xxzcc<| r||z}||dzj/«z}n||j/«dzz}t j4|dz t|«|dz z
dz||z
«|z }|d k(r3t j6| d¬«}t j6|| d¬«}n|dzs
|dxxdzcc<|
dk(rt j8|d¬«}|||fS)z
Private helper implementing the common parts between the psd, csd,
spectrogram and complex, magnitude, angle, and phase spectrums.
NTéréznoverlap must be less than NFFTrÚpsd)rr;ÚcomplexÚ magnitudeÚangleÚphase©Úmodez*x and y must be equal if mode is not 'psd'ÚtwosidedÚonesided)rrCrB)ÚsidesFrgð?ç@z7The window length must match the data's first dimensionr)éÿÿÿÿr)Únrr=r>r?r<rF)r!rr%rÚ
check_in_listrr#Ú iscomplexobjr
ÚresizeÚiterableÚonesr-ÚlibÚ
stride_tricksÚsliding_window_viewÚTrÚreshapeÚfftÚfftfreqÚconjÚabsÚsumr>Úslicer0ÚrollÚunwrap)r r4ÚNFFTÚFsÚ detrend_funcÚwindowÚnoverlapÚpad_torDÚ
scale_by_freqrAÚ same_datarGÚnumFreqsÚ
freqcenterÚscaling_factorÚresultÚfreqsÚresultYÚslcÚts r
Ú_spectral_helperrjÕð €yà‰ ð
˜Fˆ à €zØ
ˆØÐ؈ØÐÜ Ø
€~܈ð €|؈àÜÐ €|t˜yÒˆÜ×ÑÚ
õñ ˜ šÜÐ
1
€AÙ Ü J‰Jq‹Mˆà €}˜ Ò
?‰?˜1Ô Ø‰EàˆEÜ×ÑÒ:À%Õ ˆ1ƒv‚}Ü ‹FˆÜ I‰IÓ ˆØˆˆ!ˆ"ˆá œ˜Q› $šÜ ‹FˆÜ I‰IÓ ˆØˆˆ!ˆ"ˆà
€~Øˆà ˆu
Ø Ð Øˆ
ð
ÒØˆØ AŠ:Ø  1™* q™¨1Ñ,‰Jà ˆJØØ Ø AŠ:Ø 
 Q‘‰Hà˜q‘y 1‘}ˆH؈ä
;‰; ÙœŸ  a§g¡gÓÜ
ˆ6ƒ{ÜØ Gð GôV‰V×
!×
 ˆ4Ù*˜4 (™?Ð,ß,-©Að ä
V˜Ô
2€FØ
f—nn 
-€FÜ
V‰VZ‰Z˜ &¨qˆ
1°)°8°)ºQ°,Ñ
?€FÜ F‰FN‰N˜6 1 R¡4Ó ¨(Ð 3€Eá ä—&&×&×
ˆt˜!ðÙ.˜t h™Ð0ß01±ð ä˜' <°aÔ8ˆØ˜FŸN™N¨7Ó3ˆÜ—&&—**˜°Q7¸ ¸¸ Â1¸ Ñܘ 7Ñ*‰Ø
ŠÜ˜ 6Ñ)‰Ø
Ò Ü˜ &§*¡*£,Ñ.‰Ø
Š˜D GšOä˜!‰Ø
Ò Ø&—*‘*“,Ñˆà ˆu‚}ðaŠxܘ˜2˜tÓ$‰Cô˜˜4 Ó&ˆCàˆs % ñ
Ø b‰Lˆ
v˜qy—o '‰Fð
f—jj“l A %ˆ
$q&œ#˜a& ¡6™/¨AÑ-¨t°h©ÓÑB€Aà
Ò䘠
˜{°Ôܘ * °1Ô5‰Ø
aŠZà
ˆb‹ R‰‹ ð ˆw‚ܘ6¨Ôà 5˜!Ð Ðrc
ótjgd¢|¬«| t|«}t|dt|«|t|d||d|¬« \}}}|dk7r |j
}|j dk(r|jd d k(r |dddf}||fS)
zu
Private helper implementing the commonality between the complex, magnitude,
angle, and phase spectrums.
)r<r=r>r?r@Nr r r4rZr[r\r]r^r_rDr`rAr<r9r)rrHr
rjr!Úrealr$Úshape) rAr r[r]r_rDÚspecrfÚ_s r
Ú_single_spectrum_helperrqxsô  ×ÑÒÕ
€~ÜQ“ˆä¨T¼¸A»À2Ü3?ÈØ/0¸Ø,1Ø49Ø+/ô 1N€Dˆ%ð  ˆyÒØy‰yˆà ‡yyA‚~˜$Ÿ*™* Q™-¨1Ò’AqD‰zˆà ˆraLFs : float, default: 2
The sampling frequency (samples per time unit). It is used to calculate
the Fourier frequencies, *freqs*, in cycles per time unit.
window : callable or ndarray, default: `.window_hanning`
A function or a vector of length *NFFT*. To create window vectors see
`.window_hanning`, `.window_none`, `numpy.blackman`, `numpy.hamming`,
`numpy.bartlett`, `scipy.signal`, `scipy.signal.get_window`, etc. 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.
sides : {'default', 'onesided', 'twosided'}, optional
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.aÚpad_to : int, optional
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 *n* parameter
in the call to `~numpy.fft.fft`. The default is None, which sets *pad_to*
equal to the length of the input signal (i.e. no padding).afpad_to : int, optional
The number of points to which the data segment is padded when performing
the FFT. This can be different from *NFFT*, 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 *n* parameter in the call to `~numpy.fft.fft`. The default is None,
which sets *pad_to* equal to *NFFT*
NFFT : int, default: 256
The number of data points used in each block for the FFT. A power 2 is
most efficient. This should *NOT* be used to get zero padding, or the
scaling of the result will be incorrect; use *pad_to* for this instead.
detrend : {'none', 'mean', 'linear'} or callable, default: 'none'
The function applied to each segment before fft-ing, designed to remove
the mean or linear trend. Unlike in MATLAB, where the *detrend* parameter
is a vector, in Matplotlib it is a function. The :mod:`~matplotlib.mlab`
module defines `.detrend_none`, `.detrend_mean`, and `.detrend_linear`,
but you can use a custom function as well. You can also use a string to
choose one of the functions: 'none' calls `.detrend_none`. 'mean' calls
`.detrend_mean`. 'linear' calls `.detrend_linear`.
scale_by_freq : bool, default: True
Whether the resulting density values should be scaled by the scaling
frequency, which gives density in units of 1/Hz. This allows for
integration over the returned frequency values. The default is True for
MATLAB compatibility.)ÚSpectralÚSingle_SpectrumÚPSDc óNt|d||||||||¬«
\} }
| j|
fS)a
Compute the power spectral density.
The power spectral density :math:`P_{xx}` by Welch's average
periodogram method. The vector *x* is divided into *NFFT* length
segments. Each segment is detrended by function *detrend* and
windowed by function *window*. *noverlap* gives the length of
the overlap between segments. The :math:`|\mathrm{fft}(i)|^2`
of each segment :math:`i` are averaged to compute :math:`P_{xx}`.
If len(*x*) < *NFFT*, it will be zero padded to *NFFT*.
Parameters
----------
x : 1-D array or sequence
Array or sequence containing the data
%(Spectral)s
%(PSD)s
noverlap : int, default: 0 (no overlap)
The number of points of overlap between segments.
Returns
-------
Pxx : 1-D array
The values for the power spectrum :math:`P_{xx}` (real valued)
freqs : 1-D array
The frequencies corresponding to the elements in *Pxx*
References
----------
Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John
Wiley & Sons (1986)
See Also
--------
specgram
`specgram` differs in the default overlap; in not returning the mean of
the segment periodograms; and in returning the times of the segments.
magnitude_spectrum : returns the magnitude spectrum.
csd : returns the spectral density between two signals.
N)
r r4rZr[rr]r^r_rDr`)Úcsdrm) r rZr[rr]r^r_rDr`ÚPxxrfs r
r;r;Ís9ôdq˜D ¸"¨X¸ °
ô?J€Cˆð 8‰8Uˆrc
óÆ|d}t|||||||||| d¬« \}
} } |
jdk(r1|
jddkDr|
jd¬«}
|
| fS|
dddf}
|
| fS) a
Compute the cross-spectral density.
The cross spectral density :math:`P_{xy}` by Welch's average
periodogram method. The vectors *x* and *y* are divided into
*NFFT* length segments. Each segment is detrended by function
*detrend* and windowed by function *window*. *noverlap* gives
the length of the overlap between segments. The product of
the direct FFTs of *x* and *y* are averaged over each segment
to compute :math:`P_{xy}`, with a scaling to correct for power
loss due to windowing.
If len(*x*) < *NFFT* or len(*y*) < *NFFT*, they will be zero
padded to *NFFT*.
Parameters
----------
x, y : 1-D arrays or sequences
Arrays or sequences containing the data
%(Spectral)s
%(PSD)s
noverlap : int, default: 0 (no overlap)
The number of points of overlap between segments.
Returns
-------
Pxy : 1-D array
The values for the cross spectrum :math:`P_{xy}` before scaling (real
valued)
freqs : 1-D array
The frequencies corresponding to the elements in *Pxy*
References
----------
Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John
Wiley & Sons (1986)
See Also
--------
psd : equivalent to setting ``y = x``.
Nr:r;rlr9rrr)rjr$rnr)
r r4rZr[rr]r^r_rDr`ÚPxyrfrps
r
rvrvs‹ð` €|؈Ü$ q¨A°D¸RØ29À&Ø.6¸vØ+0À
Ø*/ô 1M€Cˆð  ‡xx1 9‰9Q‰<˜ Ø—(( "ˆCð ˆð’a˜d‘)ˆCØ ˆra9Compute the {quantity} of *x*.
Data is padded to a length of *pad_to* and the windowing function *window* is
applied to the signal.
Parameters
----------
x : 1-D array or sequence
Array or sequence containing the data
{Spectral}
{Single_Spectrum}
Returns
-------
spectrum : 1-D array
The {quantity}.
freqs : 1-D array
The frequencies corresponding to the elements in *spectrum*.
See Also
--------
psd
Returns the power spectral density.
complex_spectrum
Returns the complex-valued frequency spectrum.
magnitude_spectrum
Returns the absolute value of the `complex_spectrum`.
angle_spectrum
Returns the angle of the `complex_spectrum`.
phase_spectrum
Returns the phase (unwrapped angle) of the `complex_spectrum`.
specgram
Can return the complex spectrum of segments within the signal.
r<Úquantityz!complex-valued frequency spectrumr=z4magnitude (absolute value) of the frequency spectrumr>z8angle of the frequency spectrum (wrapped phase spectrum)r?z:phase of the frequency spectrum (unwrapped phase spectrum)c
óØ|d}|d}t|«|kr%tjd|dt|«d«t|d||||||||| ¬« \}
} } | dk7r |
j}
|
| | fS) a
Compute a spectrogram.
Compute and plot a spectrogram of data in *x*. Data are split into
*NFFT* length segments and the spectrum of each section is
computed. The windowing function *window* is applied to each
segment, and the amount of overlap of each segment is
specified with *noverlap*.
Parameters
----------
x : array-like
1-D array or sequence.
%(Spectral)s
%(PSD)s
noverlap : int, default: 128
The number of points of overlap between blocks.
mode : str, default: 'psd'
What sort of spectrum to use:
'psd'
Returns the power spectral density.
'complex'
Returns the complex-valued frequency spectrum.
'magnitude'
Returns the magnitude spectrum.
'angle'
Returns the phase spectrum without unwrapping.
'phase'
Returns the phase spectrum with unwrapping.
Returns
-------
spectrum : array-like
2D array, columns are the periodograms of successive segments.
freqs : array-like
1-D array, frequencies corresponding to the rows in *spectrum*.
t : array-like
1-D array, the times corresponding to midpoints of segments
(i.e the columns in *spectrum*).
See Also
--------
psd : differs in the overlap and in the return values.
complex_spectrum : similar, but with complex valued frequencies.
magnitude_spectrum : similar single segment when *mode* is 'magnitude'.
angle_spectrum : similar to single segment when *mode* is 'angle'.
phase_spectrum : similar to single segment when *mode* is 'phase'.
Notes
-----
*detrend* and *scale_by_freq* only apply when *mode* is set to 'psd'.
Né€r:z6Only one segment is calculated since parameter NFFT (=z) >= signal length (=z).rlr<)r
rÚ
warn_externalrjrm)
r rZr[rr]r^r_rDr`rArorfris
r
Úspecgramr~}sð|ÐØˆØ €|؈Ü
ˆ1ƒv‚~Ü ×Ñð%Ø%) FÐ*?ÄÀAøxÀrðKô Lô¨T¸ÀØ3:À6Ø/7ÀØ,1Ø4AØ+/ô 1N€Dˆ%ð ˆyÒØy‰yˆà ˜ˆrr:r9rc
ót|«d|zkr td«t||||||||| « \}
} t||||||||| « \} } t|||||||||| «
\}
} t j
|
«dz|
| zz }|| fS)
The coherence between *x* and *y*. Coherence is the normalized
cross spectral density:
.. math::
C_{xy} = \frac{|P_{xy}|^2}{P_{xx}P_{yy}}
Parameters
----------
x, y
Array or sequence containing the data
%(Spectral)s
%(PSD)s
noverlap : int, default: 0 (no overlap)
The number of points of overlap between segments.
Returns
-------
Cxy : 1-D array
The coherence vector.
freqs : 1-D array
The frequencies for the elements in *Cxy*.
See Also
--------
:func:`psd`, :func:`csd` :
For information about the methods used to compute :math:`P_{xy}`,
:math:`P_{xx}` and :math:`P_{yy}`.
r9zvCoherence is calculated by averaging over *NFFT* length segments. Your signal is too short for your choice of *NFFT*.)r
r%r;rvrrU)r r4rZr[rr]r^r_rDr`rwÚPyyryÚCxys r