def xcorr(x1,x2,Nlags):
K = <NUM_LIT:2>*(int(np.floor(len(x1)/<NUM_LIT:2>)))<EOL>X1 = fft.fft(x1[:K])<EOL>X2 = fft.fft(x2[:K])<EOL>E1 = sum(abs(x1[:K])**<NUM_LIT:2>)<EOL>E2 = sum(abs(x2[:K])**<NUM_LIT:2>)<EOL>r12 = np.fft.ifft(X1*np.conj(X2))/np.sqrt(E1*E2)<EOL>k = np.arange(K) - int(np.floor(K/<NUM_LIT:2>))<EOL>r12 = np.fft.fftshift(r12)<EOL>idx = np.nonzero(np.ravel(abs(k) <= Nlags))<EOL>return r12[idx], k[idx]<EOL>
r12, k = xcorr(x1,x2,Nlags), r12 and k are ndarray's
Compute the energy normalized cross correlation between the sequences
x1 and x2. If x1 = x2 the cross correlation is the autocorrelation.
The number of lags sets how many lags to return centered about zero