# Correlating signals in real-time when the time-delay is larger than frame-time What are some possible approaches to address the challenge of correlating two signals when the time delay ($$T_d$$) from the source to the microphone is greater than the microphone's frame time ($$T_f$$)? Given that the samples from source $$s_1$$ arrive significantly later than the samples from source $$s_2$$, making correlation difficult, are there any potential solutions to overcome this issue?

• What do you mean by "frame-time"? Normally, like in the STFT, the frame is a window of samples that is treated as a single object and advanced by a hop. There is a frame width or frame length and there is the hop length also. Sometimes, if there is 50% overlap, the frame length is twice as big as the hop length. Jun 13 at 19:09
• Now it appears to me that your question is what to do if $s_2$ is much smaller than $s_1$. If that's the case, then use semiconductor memory (a buffer) on the $s_2$ signal to bring it to the approximate equal delay as with $s_1$. Jun 13 at 19:11

Since $$s_2$$ is arriving later, the signal $$s_1$$ must be delayed to match this time prior to computing a correlation. Repeated correlations are done to align waveforms in time for this reason-- when the delays are matched, the correlation will be maximum.

The frame time only effects the frequency resolution of the correlation (a shorter frame time will result in a wider resolution bandwidth). As far as the effect of delay, regardless of frame time, the start of s1 must be time aligned with the start of s2 (within the coherence time of the signal) to get a meaningful correlation result. The more low-pass filtered a signal is, the wider the coherence time will be.

The "Cross-correlation Function" is used to determine such time alignment by successively delaying by time $$\tau$$ one vs the other, and for each time offset (delay) of $$\tau$$ a new correlation is computed. When the waveforms are the same, the result would be the "auto-correlation function" for that waveform. Waveforms that have "nice auto-correlation properties" have an auto-correlation that approximates an impulse response (only provides a strong correlation when the waveforms are aligned and close to zero everywhere else) are ideal for timing and synchronization. White noise is an example of such a waveform, and pseudo-random noise sources approximate this well for practical purposes. GPS is one example where psuedo-random noise is used as the waveform and correlation is used in the receiver to determine time and position.

As an example, below is the autocorrelation of simulated samples of Additive White Gaussian Noise (AWGN) using Python's random number generators, and below that for comparison is the autocorrelation of a GPS C/A Code. The point with both related to the OP's question is to see how the correlation is maximum when the time delay between the waveform (and itself here) is zero, and then very low elsewhere, so in order to find the correlation the delay between the waveforms must be removed prior to computing a correlation. Once the delays are close enough (within this observation window), a cross-correlation function computation can be used to find the correlation.

The sharp correlation peak as done here would occur when the waveform is "white" meaning has energy evenly distributed across all frequency. If we were to low-pass filter these waveforms the correlation would begin to spread over a wider time range, but still be maximum at zero time delay. If the waveform repeats in time, additional correlation peaks will occur versus delay. If a smaller portion repeats, then smaller peaks will appear. This can lead to "false acquistions" in what the best delay alignment is if we were to focus on a smaller peak without seeing the birds-eye view first of all possible delays (and miss the actual largest correlation peak). An autocorrelation function computation of the OP's source would be helpful in determining the expected correlation result and how it varies versus offset.  I'm assuming that what's happening is more like this. So that the delay in the path from Signal Source to speaker to microphone to corr(S1,S2) to produce $$s_2$$ is much longer than the delay in translating $$s_1$$ to the corr(S1,S2) box.

I'm also assuming, by your description of the problem, that the data coming from the microphone is coming in frames or batches of many samples instead of sample-by-sample.

If what I describe is the case, then your best bet is to store several frames worth of data --- enough to cover the range of delays in the longer signal path. Then you can cross-correlate the incoming $$s_1$$ signal with all of the data in the stored frames.

Even if the data from $$s_2$$ is coming sample-by-sample, just store as much data as you can before doing the correlation with $$s_1$$.