obspy.signal.cross_correlation.xcorr

xcorr(tr1, tr2, shift_len, full_xcorr=False)[source]

Cross correlation of tr1 and tr2 in the time domain using window_len.

Note

Please use the correlate() function for new code.

                            Mid Sample
                                |
|AAAAAAAAAAAAAAA|AAAAAAAAAAAAAAA|AAAAAAAAAAAAAAA|AAAAAAAAAAAAAAA|
|BBBBBBBBBBBBBBB|BBBBBBBBBBBBBBB|BBBBBBBBBBBBBBB|BBBBBBBBBBBBBBB|
|<-shift_len/2->|   <- region of support ->     |<-shift_len/2->|
Parameters:
  • tr1 (ndarray, Trace) Trace 1
  • tr2 (ndarray, Trace) Trace 2 to correlate with trace 1
  • shift_len (int) Total length of samples to shift for cross correlation.
  • full_xcorr (bool) If True, the complete xcorr function will be returned as ndarray
Returns:

index, value[, fct] - Index of maximum xcorr value and the value itself. The complete xcorr function is returned only if full_xcorr=True.

Note

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.