TimeSeriesSRC.xcorr¶
- TimeSeriesSRC.xcorr(a, b, maxlag=20, flag='none')¶
Compute the cross-correlation (or autocorrelation) between two sequences.
Produces a symmetric array of length
2*maxlag + 1covering lags-maxlagto+maxlag.- Parameters:
a (array-like) – First 1-D sequence (length N).
b (array-like) – Second 1-D sequence (same length as
a).maxlag (int, optional) – Maximum lag to compute; must be less than N. Default 20.
flag ({'biased', 'unbiased', 'coeff', 'none'}, optional) –
Normalization method:
'biased'— divide by N (biased estimate).'unbiased'— divide by N - |k| (unbiased estimate).'coeff'— normalize so that the zero-lag value is 1.0.'none'— no scaling (raw inner product). Default.
- Returns:
c – Cross-correlation values at lags
-maxlag, ..., 0, ..., +maxlag. The zero-lag value is at indexmaxlag.- Return type:
ndarray, shape (1, 2*maxlag+1)
Examples
>>> import numpy as np >>> from scipy.signal import lfilter >>> from TimeSeriesSRC.basefunctions.xcorr import func_xcorr >>> e = np.random.default_rng(0).standard_normal(500) >>> y = lfilter([1], [1, -0.8], e) >>> acf = func_xcorr(y, y, maxlag=20, flag='biased') >>> acf.shape (1, 41)