import numpy as np from matplotlib.pylab import * def cross_corr(A, B): N = max(len(A), len(B)) Ahat = np.fft.rfft(A, N) Bhat = np.fft.rfft(B, N) prod = Ahat.conj()*Bhat corr = 1.0/N * np.fft.irfft(prod) return corr t, signal1, ref1, signal2, ref2 = np.load('radar.npy') figure() subplot(411) plot(t, signal1) title('Signal') subplot(412) plt.plot(t, ref1, '.') title('Reflected signal') shifted_signal = np.zeros_like(signal1) shifted_signal[2048:] = signal1[:-2048] autocorr = cross_corr(signal1, shifted_signal) subplot(413) plot(t, autocorr) title('Autocorrelation') cross = cross_corr(signal1, ref1) subplot(414) plot(t, cross) title('Cross-correlation') figure() subplot(411) plot(t, signal2) title('Signal') subplot(412) plot(t, ref2, '.') title('Reflected signal') shifted_signal = np.zeros_like(signal2) shifted_signal[2048:] = signal2[:-2048] autocorr = cross_corr(signal2, shifted_signal) subplot(413) plot(t, autocorr) title('Autocorrelation') cross = cross_corr(signal2, ref2) subplot(414) plot(t, cross) title('Cross-correlation') plt.show()