- xcorr(tr1, tr2, shift_len, full_xcorr=False)¶
Cross correlation of tr1 and tr2 in the time domain using window_len.
Mid Sample | |AAAAAAAAAAAAAAA|AAAAAAAAAAAAAAA|AAAAAAAAAAAAAAA|AAAAAAAAAAAAAAA| |BBBBBBBBBBBBBBB|BBBBBBBBBBBBBBB|BBBBBBBBBBBBBBB|BBBBBBBBBBBBBBB| |<-shift_len/2->| <- region of support -> |<-shift_len/2->|
index, value[, fct] - Index of maximum xcorr value and the value itself. The complete xcorr function is returned only if full_xcorr=True.
As shift_len gets higher the window supporting the cross correlation actually gets smaller. So with shift_len=0 you get the correlation coefficient of both traces as a whole without any shift applied. As the xcorr function works in time domain and does not zero pad at all, with higher shifts allowed the window of support gets smaller so that the moving windows shifted against each other do not run out of the timeseries bounds at high time shifts. Of course there are other possibilities to do cross correlations e.g. in frequency domain.
>>> tr1 = np.random.randn(10000).astype(np.float32) >>> tr2 = tr1.copy() >>> a, b = xcorr(tr1, tr2, 1000) >>> a 0 >>> round(b, 7) 1.0