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.
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.
Well yoda gave a good answer but I thought I mention this anyway just in case. Coming back to the definition of the discrete cross correlation you can compute it without using (too much) builtin Matlab functions (which should be what Matlab do with
xcorr
). Of course there is still room for improvment as I did not try to vectorize this:Which match the result of the
xcorr
function.UPDATE: forgot to mention that in my opinion Matlab is not the appropriate tool for doing real time cross correlation of large data sets, I would rather try it in C or other compiled languages.
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.Example:
Compare results:
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).