coherence(x, y, fs=1.0, window='hann', nperseg=None, noverlap=None, nfft=None, detrend='constant', axis=-1)
Cxy = abs(Pxy)**2/(Pxx*Pyy)
, where :None:None:`Pxx`
and :None:None:`Pyy`
are power spectral density estimates of X and Y, and :None:None:`Pxy`
is the cross spectral density estimate of X and Y.
An appropriate amount of overlap will depend on the choice of window and on your requirements. For the default Hann window an overlap of 50% is a reasonable trade off between accurately estimating the signal power, while not over counting any of the data. Narrower windows may require a larger overlap.
Time series of measurement values
Time series of measurement values
Sampling frequency of the x
and y
time series. Defaults to 1.0.
Desired window to use. If :None:None:`window`
is a string or tuple, it is passed to get_window
to generate the window values, which are DFT-even by default. See get_window
for a list of windows and required parameters. If :None:None:`window`
is array_like it will be used directly as the window and its length must be nperseg. Defaults to a Hann window.
Length of each segment. Defaults to None, but if window is str or tuple, is set to 256, and if window is array_like, is set to the length of the window.
Number of points to overlap between segments. If :None:None:`None`
, noverlap = nperseg // 2
. Defaults to :None:None:`None`
.
Length of the FFT used, if a zero padded FFT is desired. If :None:None:`None`
, the FFT length is :None:None:`nperseg`
. Defaults to :None:None:`None`
.
Specifies how to detrend each segment. If detrend
is a string, it is passed as the :None:None:`type`
argument to the detrend
function. If it is a function, it takes a segment and returns a detrended segment. If detrend
is :None:None:`False`
, no detrending is done. Defaults to 'constant'.
Axis along which the coherence is computed for both inputs; the default is over the last axis (i.e. axis=-1
).
Estimate the magnitude squared coherence estimate, Cxy, of discrete-time signals X and Y using Welch's method.
csd
Cross spectral density by Welch's method.
lombscargle
Lomb-Scargle periodogram for unevenly sampled data
periodogram
Simple, optionally modified periodogram
welch
Power spectral density by Welch's method.
>>> from scipy import signal
... import matplotlib.pyplot as plt
... rng = np.random.default_rng()
Generate two test signals with some common features.
>>> fs = 10e3
... N = 1e5
... amp = 20
... freq = 1234.0
... noise_power = 0.001 * fs / 2
... time = np.arange(N) / fs
... b, a = signal.butter(2, 0.25, 'low')
... x = rng.normal(scale=np.sqrt(noise_power), size=time.shape)
... y = signal.lfilter(b, a, x)
... x += amp*np.sin(2*np.pi*freq*time)
... y += rng.normal(scale=0.1*np.sqrt(noise_power), size=time.shape)
Compute and plot the coherence.
>>> f, Cxy = signal.coherence(x, y, fs, nperseg=1024)See :
... plt.semilogy(f, Cxy)
... plt.xlabel('frequency [Hz]')
... plt.ylabel('Coherence')
... plt.show()
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.signal._spectral_py.csd
scipy.signal._spectral_py.coherence
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them