Surely this question has been answered before in parts but I cannot find one solid answer. Ultimately I am trying to calculate the audio delay between two signals I am recording on USB microphones. With no problem I am recording the audio, reading it back into python, computing the cross correlation/convolving, and then finding the delay. When I manually create the signals (one with a delay) and feed them into my algorithm both methods find the right delay. As a test for real data I am trying to find the speed of sound between two mics (velocity = dis / time). Again, with a man-made delay of 76 frames and mic spacing of .6 meters I get a speed of sound of roughly 348.157...close enough for me.

When I try this with real recorded data no two tests have similar outputs; huge outliers, and no consistency.

  • What should I try next? filtering?
  • Add more mics for more accuracy?

The source signal is Guassian white noise. Any help you guys can give would be awesome.

  • $\begingroup$ how long is the sequence your correlating? $\endgroup$ Aug 15 '16 at 18:50
  • 1
    $\begingroup$ are you running into issues due to different signal energies? are you doing normalized cross-correlation? $\endgroup$
    – Atul Ingle
    Aug 15 '16 at 21:14
  • $\begingroup$ Multipath can really complicate time delay measurements. Is your data recorded indoors? $\endgroup$
    – user28715
    Jun 16 '17 at 3:43

I had done something like this and ran into similar problems a while ago, using Matlab. The audio to the microphones was speech or whistling in my case. I was estimating the delay between two mics to find the direction sound was arriving from.

The audio data from the mics probably has oscillations of some kind (like a sum of sinusoids plus some noise), at least at certain locations. The cross-correlation of one such waveform with a delayed version of it will be a signal with oscillations. This would look like this example, but possibly decaying slowly. I've seen something similar in this question.

The cross-correlation peak should indicate the delay, but there are multiple peaks so you may be detecting the wrong one. Since your input signal is not a pure sine-wave, the largest peak should be the delay but it would be hard to guarantee that in a hardware system. This may be why you're getting inconsistent results.

Since you know the distance between the two microphones (and the system's sampling rate), you can estimate the maximum expected delay (in a number of samples), as the time it would take for sound to travel the full distance between the mics (0.6 meters). Then you should search for the cross-correlation peak only in the first such number samples, rather than in the full waveform.

Low-pass filtering may also be helpful if you're just interested in the delay. The higher frequency components can create peaks in the cross-correlation sooner (oscillations with a smaller period). In my case, I had found that a low-pass cut-off of about 1.0-1.5 kHz was adequate since my signal (speech) was wide-band and contained enough information at low frequencies for the delay estimation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.