I want to calculate delay between an input and an output audio signal of my audio processing system. The input and output signals are available as signed 16 bit integers. To try out, I tried the autocorrelation of the input signal with the following numpy commands:
import numpy as np import wave wfp = wave.open('test.wav', 'rb') samples = wfp.readframes(wfp.getnframes()) signal = np.frombuffer(samples, np.int16) corr = np.correlate(signal, signal, "full")
I assumed that the peak of the autocorrelation is always at lag 0, which is at the index corr.size / 2 in the corr array. However I get different values for the index, when I calculate np.argmax(corr).
When I normalize the signal first to get values between -1.0 and +1.0, the peak is always at corr.size / 2 as expected, at least in my tests with different signals.
For normalization, I used the following steps:
signal = signal / float(0xFFFF)
Can someone please explain to me, why I have to normalize the signal.