FFT cross-correlation lag (samples) that best aligns b onto a.
(a, b)
| 78 | |
| 79 | |
| 80 | def _best_lag(a, b): |
| 81 | """FFT cross-correlation lag (samples) that best aligns b onto a.""" |
| 82 | n = 1 << int(np.ceil(np.log2(a.size + b.size))) |
| 83 | fa = np.fft.rfft(a, n) |
| 84 | fb = np.fft.rfft(b, n) |
| 85 | corr = np.fft.irfft(fa * np.conj(fb), n) |
| 86 | corr = np.concatenate((corr[-(b.size - 1) :], corr[: a.size])) |
| 87 | return int(np.argmax(corr)) - (b.size - 1) |
| 88 | |
| 89 | |
| 90 | def align_and_score(reference, test): |