1

I need to find the timedelay between two signals. I guess MSE is the best approach. How to find that MSE? I am writing the code and I have access to the autocorrelation matrix of one signal and the crosscorrelation of both signals plus the power of the signal. Is this enough information to calculate the MSE? Any tips on how that would be done?

Thanks.

user1876942
  • 161
  • 3

3 Answers3

2

As long as the two signals are simply delayed versions of each other the delay is simply given by the point in time where maximum of the cross correlation occurs.

If the signals are uncorrelated, then the question is meaningless.

The tricky part is when the two signals are partially correlated or are filtered versions of the same original signal. In this case you will first need to define what exactly you mean by "delay". One possible way to approach this would be to time shift the signals against each other, subtract them and sum the squares. The shift that results in the minimum energy in the difference would be considered the delay. Something like $d = min[sum((x(n)-y(n-d))^{2})]$

Hilmar
  • 44,604
  • 1
  • 32
  • 63
2

Hilmar's answer is perfectly correct though incomplete in some sense.

For any two finite-energy signals both having the same energy, one criterion for measurement of how similar they are is the energy in the difference signal which energy is given by

$$\sum_{n=-\infty}^\infty |x[n]-y[n]|^2 \qquad\text{or} \qquad \int_{-\infty}^\infty |x(t)-y(t)|^2 \textrm{d}t$$

depending on whether discrete-time or continuous-time signals are under consideration. For periodic signals, the sum or integration should be carried out over the common period.

But note that upon expanding $|x-y|^2 = (x-y)(x-y)^* = |x|^2 + |y|^2 -2\operatorname{Re}\left(xy^*\right)$ and noting that the first two terms, upon summation or integration, will give us just the energy of the two signals, and so the criterion for similarity is essentially the inner product of the two signals; the larger the inner product, the more similar the two signals.

A more general question would be not how similar $x$ and $y$ are, but rather,

Which delayed version (or time-advanced version) of $y$ is most similar to $x$?

We can construct measures of similarity

$$\sum_{n=-\infty}^\infty |x[n]-y[n-m]|^2 \qquad\text{or} \qquad \int_{-\infty}^\infty |x(t)-y(t-\tau)|^2 \textrm{d}t$$ regarded as functions of $m$ or $\tau$, and find the value of $m$ or $\tau$ for which the two signals are the most similar. Using the same arguments as before, we arrive at the conclusion that

The delay ($m$ or $\tau$) for which the cross-correlation function $R_{x,y}[m]$ or $R_{x,y}(\tau)$ achieves its maximum value is the delay for which $y[n-m]$ (or $y(t-\tau)$) is the most similar to $x[n]$ (or $x(t)$).

In short, the OP is perfectly correct in trying to use mean-square error as the criterion for determining the similarity of signals. However, upon further development of the idea, we arrive at the solution provided by Hilmar: look at the peak of the cross-correlation function

Bob
  • 2,348
  • 4
  • 11
Dilip Sarwate
  • 20,349
  • 4
  • 48
  • 94
0

You can use cross correlation between two signals to fing thw dealy between two signals,

import numpy as np

correlation = np.correlate(signal_1 ,signal_2 ,mode="same")

delay= np.argmax(correlation)-int(len(correlation)/2)

for more details please check the numpy library for detailed explanation about the function correlate and argmax.

lennon310
  • 3,590
  • 19
  • 24
  • 27