Autocorrelation - How to implement step by step

In summary: Thanks for trying to help me though.Thanks for your help!In summary, to calculate the lag between the microphones, you need to use autocorrelation. There are succesive steps required to process the data set just acquired, including normalization. Once the lag has been calculated, you can use the speed of sound to find the distance between the microphones.
  • #1
Hola, my first time in this forum.

Two microphones at diferent distances from an audio source are receiving the same steady signal (frequency/amplitude unchanged).

A microprocessor takes succesive samples of both channels in batches of N samples. Time between samples is ts microseconds.

Once a batch is ready I want the micro to calculate the time difference (lag) between the incoming signals.

I know I have to use autocorrelation here (cross correlation of itself, right?).

In spite of reading a lot I could not conclude what is the formula to be solved thus how to program the micro to calculate the lag between both channels.

Can anyone tell:

The actual formula to be implemented?.

What are the succesive steps required to process the data set just acquired?

Normalization, is it needed? If so, how do you actually do it and when?

I am not into high level maths so bear with me. Math notation is sometimes quite hard for me to follow.

Gracias for any help.

Agustín Tomás
Physics news on
  • #2
When you say the lag between the channels, do you mean that you want to find how much longer it takes microphone 2 to get the sound microphone 1 got?

If this is the case, if you subtract the distance from microphone 2 to the sound source from the distance of microphone 1 from the sound source,

and then divide that difference by the speed of sound, you should get the lag between what time one microphone gets the sound and the other one get it.

This assumes that the computer processor? of both microphones doesn't lag - I don't know if you mean computer lag or the difference between when sound reaches the microphone.

This doesn't answer your question if you want the computer to calculate it, by only using the sound batches N. If this is the case I'm still trying to use a special diagram to solve it.

Hope this helps.
  • #3
i might suggest to the OP to post this at the USENET newsgroup comp.dsp.
  • #4
To RandomMystery and rbj

Thanks for replying.

You got my idea right, "lag" is the difference between when sound reaches the microphone.

If the audio source moves wrt microphones, in any sense it does, distances will change even if distance between microphones keeps.

I want the microprocessor to calculate it using autocorrelation.
  • #5
As soon as the first microphone picks up some noise, it should send a signal to the second microphone to record time. It then stops recording that time, when the same sound reaches it. The time recorded is the lag.

Now, do you also want an equation to also factor in the magnitude of the sound? The method above should work, but the equipment that is farther away from the sound source, will register it as having less batches of N. I'm assuming that when one microphone gets N batches, the other one won't recognize the sounds as N batches, but as N - x batches, (since it's farther away)
If that's the case, we need to find some ratio or relation ship between the batches of one microphone and the other. Which I'm still trying to do with the same diagram.
  • #6
Okay, this might work:

(Distance from the farther microphone to the sound source - the Distance from the nearer microphone to the sound source)
(Batch N from the nearer microphone - Batch N from the farther microphone)

Test and see if this ratio is true for every distance (or just enough to prove it's accuracy). If it is true, then all you have to do is:

(Batch N from the nearer microphone - Batch N from the farther microphone)(the same ratio written above)
(the speed of sound)

*This looks kind of messy, the underline indicates divide by what's under it.
You only have to find that ratio once, if my assumptions are correct. Assuming that your not moving the microphones, but only the sound source.

Edit: To calculate the distance, have a computer start recording time when sound is released, then have the microphone send a signal to stop the recording time when the signal reaches the microphone. Divide the duration of the recording by the speed of sound to get the distance. Make sure you have the right units.
Last edited:
  • #7
Hola RM,

Quoting myself:

Can anyone tell:

The actual formula to be implemented?.

What are the succesive steps required to process the data set just acquired?

Normalization, is it needed? If so, how do you actually do it and when?

As the the title says, with Autocorrelation. I want to solve it that way.

Thanks for your time, anyway.
  • #8
Hi RM,
I have been told to use cross correlation since the signal en each channel is to be considered a different one. No outocorrelation then.

Sorry for wasting your time. Thanks.

1. What is autocorrelation and why is it important in scientific research?

Autocorrelation is a statistical technique used to measure the correlation between a variable and its past values. It is important in scientific research because it helps identify patterns and relationships between variables over time, allowing researchers to make more accurate predictions and draw meaningful conclusions.

2. How is autocorrelation calculated?

To calculate autocorrelation, you must first standardize the data by subtracting the mean and dividing by the standard deviation. Then, you can use a mathematical formula to compute the autocorrelation coefficient, which ranges from -1 to 1 and indicates the strength and direction of the relationship between the variable and its past values.

3. What are some common methods for implementing autocorrelation?

The most common method for implementing autocorrelation is through the use of statistical software, such as R or SPSS. These programs have built-in functions for calculating autocorrelation coefficients and visualizing autocorrelation plots. Additionally, autocorrelation can also be implemented manually using mathematical formulas and data manipulation techniques.

4. How can autocorrelation be used in different fields of science?

Autocorrelation has applications in a variety of scientific fields, including economics, finance, ecology, meteorology, and neuroscience. In economics and finance, autocorrelation can be used to analyze trends and predict future market movements. In ecology and meteorology, it can help identify patterns in climate data. In neuroscience, it can be used to study brain activity over time.

5. What are some potential limitations of autocorrelation analysis?

One limitation of autocorrelation analysis is that it assumes a linear relationship between the variable and its past values, which may not always be the case. Additionally, it is important to consider the length of the time series data and the potential for data to be correlated due to external factors, rather than a true causal relationship. Finally, autocorrelation analysis should always be used in conjunction with other statistical techniques and should not be relied upon as the sole method for analyzing data.

Similar threads

  • STEM Academic Advising