MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _best_lag

Function _best_lag

tests/utils/audio_tools.py:80–87  ·  view source on GitHub ↗

FFT cross-correlation lag (samples) that best aligns b onto a.

(a, b)

Source from the content-addressed store, hash-verified

78
79
80def _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
90def align_and_score(reference, test):

Callers 1

align_and_scoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected