How get cross-correlation peak and based on it calculate correlation score for similarity of two audio samples. SO far I've
- FFT two samples
- complex conjugate second
- multiply results
- IFFT
- cross-correlate with itself(autocorrelate)
Thanks for any advice
Answer
As Matt stated, you should use the correlation coefficient!.
Points 1 to 4 calculate the crosscorrelation. From that you have to find the highest peak (or lowest, if it has a higher absolute value). This value is the value of the nominator.
The denominator consists of the two autocorrelation values. Those are obtained by using the same algorithm where both signals are the equal. Here the peak should be in the middle (t=0) as already stated by welcomedungeon. Taking the square root of both autocorrelation values and multiplying them, gives the denominator.
Edit: Maybe this description is more clear:
$\frac{max(abs(ifft(fft(x_1)*fft(x_2)')))}{sqrt(max(abs(ifft(fft(x_1)*fft(x_1)'))))*sqrt(max(abs(ifft(fft(x_2)*fft(x_2)'))))}$
The apostroph means conjugate complex.
Edit: Two examples with Matlab code:
Using the same signal:
x = rand(1000,1)-0.5;
max(abs(ifft(fft(x).*fft(x)')))/(sqrt(max(abs(ifft(fft(x).*fft(x)')))).*sqrt(max(abs(ifft(fft(x).*fft(x)')))));
gives 1
;
Using a sine and a cosine, should also give 1
because they are delayed versions of each other:
x = sin([0:pi/100:10*pi]);
y = cos([0:pi/100:10*pi]);
max(abs(ifft(fft(x).*fft(y)')))/(sqrt(max(abs(ifft(fft(x).*fft(x)')))).*sqrt(max(abs(ifft(fft(y).*fft(y)')))))
gives approximately 1
Using windowing before transformation to frequency domain should improve results.
No comments:
Post a Comment