Electronic – phase shift detection between 2 non-periodic signals

fftsound

I would like to find the phase shift between two non-periodic signals read from an electret microphone. So what I did so far is the following:

  1. read the signals from the mics using an arduino uno micro controller.
  2. finished writing an fft code based on cooley_tukey algorithm.
  3. tested the fft with the help of matlab.

My plan is:

  1. search for the maximum value in each signal and store its index
  2. find the phase corresponding to the index found in the previous step from fft using:
    phase = atan(imaginary/real)
  3. assume phase1 and phase2 corresponding to phases calculated in step(2) for signals 1 and 2 respectively.
  4. difference = phase1 – phase2
    if (difference < 0) → phase1 < phase2 → signal 1 came first and vice versa.

So, is this procedure correct? Am I going to get the phase shift using this technique? I would to do a sound localization using 4 microphones.
Thanks in advance. Your help is appreciated.

Best Answer

You have two functions. One is \$f(t)\$ and the other is the time shift of \$f\$, \$g(t) = f(t+\Delta)\$. You would like to find \$\Delta\$.

We can take the Laplace/Fourier transform (say via Cooley-Tukey FFT algorithm) and denote the transformed signals by \$\hat{f}(s)\$ and \$\hat{g}(s)\$.

Now \$\hat{g}(s) = e^{\Delta s} \hat{f}(s)\$ so the quantity you seek is $$\Delta = \frac{ln(\hat{g}(s))-ln(\hat{f}(s))}{s}.$$

In other words, the natural log of the quotient \$\frac{\hat{g}}{\hat{f}}\$ will be linear in \$s\$ and the slope of this line will be \$\Delta\$.