can someone tell how to do the cross-correlation of two speech signals (each of 40,000 samples) in MATLAB without using the built-in function xcorr
and the correlation coefficient?
Thanks in advance.
You can do cross-correlations using fft
. The cross-correlation of two vectors is simply the product of their respective Fourier transforms, with one of the transforms conjugated.
a=rand(5,1);
b=rand(5,1);
corrLength=length(a)+length(b)-1;
c=fftshift(ifft(fft(a,corrLength).*conj(fft(b,corrLength))));
Compare results:
c =
0.3311
0.5992
1.1320
1.5853
1.5848
1.1745
0.8500
0.4727
0.0915
>> xcorr(a,b)
ans =
0.3311
0.5992
1.1320
1.5853
1.5848
1.1745
0.8500
0.4727
0.0915
If there some good reason why you can't use the inbuilt, you can use a convolution instead. Cross-correlation is simply a convolution without the reversing, so to 'undo' the reversing of the correlation integral you can first apply an additional reverse to one of your signals (which will cancel out in the convolution).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With