bundles / scipy latest / scipy / signal / _signaltools / correlation_lags
function
scipy.signal._signaltools:correlation_lags
Signature
def correlation_lags ( in1_len , in2_len , mode = full ) Summary
Calculates the lag / displacement indices array for 1D cross-correlation.
Parameters
in1_len: intFirst input size.
in2_len: intSecond input size.
mode: str {'full', 'valid', 'same'}, optionalA string indicating the size of the output. See the documentation
correlatefor more information.
Returns
lags: arrayReturns an array containing cross-correlation lag/displacement indices. Indices can be indexed with the np.argmax of the correlation to return the lag/displacement.
Notes
Cross-correlation for continuous functions and is defined as:
Where is defined as the displacement, also known as the lag.
Cross correlation for discrete functions and is defined as:
Where is the lag.
Array API Standard Support
correlation_lags is not in-scope for support of Python Array API Standard compatible backends other than NumPy.
See dev-arrayapi for more information.
Examples
Cross-correlation of a signal with its time-delayed self.import numpy as np from scipy import signal rng = np.random.default_rng() x = rng.standard_normal(1000) y = np.concatenate([rng.standard_normal(100), x]) correlation = signal.correlate(x, y, mode="full") lags = signal.correlation_lags(x.size, y.size, mode="full") lag = lags[np.argmax(correlation)]✓
See also
- correlate
Compute the N-dimensional cross-correlation.
Aliases
-
scipy.signal.correlation_lags