0
$\begingroup$

I work with two signals, the second being perfectly delayed and attenuated, with no reverberation. I implemented cross-correlation algorithm, which yields me these results:

enter image description here enter image description here

Here is my code for these results:

res1_fft = np.fft.fft(res1_red)
res2_fft = np.fft.fft(res2_red)
prod = np.conjugate(res1_fft) * res2_fft
CC = np.fft.ifft(prod)

abs = [i for i in range(-int(len(CC)/2),int(len(CC)/2))]
plt.plot(abs,np.fft.fftshift(np.real(CC)))
plt.grid()
plt.show()

Please note that I both tried with my data being zero-padded or not. In both case I get a pike at the right delay of 137 samples I imposed.

However as soon as I add the PHAT filtering with this code:

res1_fft = np.fft.fft(res1_red)
res2_fft = np.fft.fft(res2_red)
prod = np.conjugate(res1_fft) * res2_fft
CC = np.fft.ifft(prod)
sign = 1/(np.abs(prod)) * prod
GCC_vrai = np.fft.ifft(sign)

and then plot GCC_vrai, I get weird results, with a pike always in 0: enter image description here enter image description here

I also tried this piece of code I found there (with a similar problem seen there too), with a very similar result.

N = len(res1_red)
Ncorr = 2*N-1;  # N size of the signal
NFFT = 2**nextpow2(Ncorr)
R12 = np.fft.fft(res2_red,NFFT)*np.conjugate(np.fft.fft(res1_red,NFFT))
r12_temp = np.fft.fftshift(np.fft.ifft(np.exp(1j*np.angle(R12))))
r12 = r12_temp[int(NFFT/2+1-(N-1)/2):int(NFFT/2+1+(N-1)/2)];

abs = [i for i in range(-int(len(r12)/2),int(len(r12)/2))]
plt.plot(abs,np.real(r12))
plt.grid()
plt.show()

What am I doing wrong?

$\endgroup$
6
  • $\begingroup$ Cross correlation benefits from averaging but can give a reasonable answer. The normalized estimators need to be averaged. MSC will need around a hundred averages to start being useful. $\endgroup$
    – user28715
    Commented Jun 7, 2018 at 6:18
  • $\begingroup$ Cross correlation indeed gives me a reasonable result. Yet I am there (in the pictures) working with a perfectly delayed and attenuated SINGLE source, while in my real experiment I also work in a zone where I have one source but also some little noise. As cross correlation gives a large pike, I wanted to use this PHAT filtering which is said to narrow pikes to have better results. What is MSC? I actually didn't really understand your answer... $\endgroup$
    – fxmarty
    Commented Jun 7, 2018 at 6:25
  • $\begingroup$ You also need to time align the 2 channels. The alignment delay with the greatest response is your delay estimate $\endgroup$
    – user28715
    Commented Jun 7, 2018 at 6:27
  • $\begingroup$ Magnitude squared coherence $\endgroup$
    – user28715
    Commented Jun 7, 2018 at 6:29
  • $\begingroup$ Well I indeed want to find the alignment delay thanks to GCC-PHAT. $\endgroup$
    – fxmarty
    Commented Jun 7, 2018 at 6:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.