1
votes

i have two signals. one is generated by a phone to a wave file (original signal) and the other signal is recorded to a file (a delayed copy of the first signal).

what i want to do is cross correlate these two signals using MATLAB to know the detection time of that signal and the lag duration. Xcorr inbuilt function correlates at a lag of zero which is not the case here.

i want to know especially how and on what basis i have to set the window length, i read a lot about the correlation but i couldn't really know how start implementing it.

1
Have you tried [c,lags]=xcorr(x,y,maxlags) where maxlags is the number of elements of the longer of your two vectors (i.e. max(numel(x),numel(y))? - Dan
what is the use of maxlags? i thought in cross correlation we add zeros for the shorter signal so that they both have equal lengths - hanaa
If you read the xcorr docs, you'll see that (a) it handles the zero padding for you and (b) that the optional maxlags argument makes it find the correlation for all the lags in the series -maxlag:maxlags. Read the docs: mathworks.com/help/signal/ref/xcorr.html, they should clarify things - Dan
thank you. that was helpful. but i couldnt understand the window concept here. this function does not shift the copied signal. - hanaa
I'm pretty sure that lags and shifts are the same? I don't have the signal processing toolbox to test it though, but the docs do imply that it does shift them. - Dan

1 Answers

0
votes

Lets say you have 2 signals of length N and M.The correlation of those 2 signals will have a length (N + M + 1).What windowing does is essentially just crops the signal, but the cropping is from the centre.So if I wanted a window length of K, I would just take the K samples in the middle of the (N + M + 1) length correlated signal.

If for example you cross-correlated two 100-sample long signals and wanted to implement a window length of 160, you would get the cross correlation which would yield a 201 sample long signal and would get the 160 samples in the middle of the cross correlation signal, i.e knock out 20 samples from beginning of the signal and 21 samples from the end of the signal.

Now, lets proceed to delay detection.If I understand you correct you have 2 signals, but one signal is just a delayed version of the other one and you want to estimate what that delay is, is that right?

What you want to do in this case is compute the cross correlation of the 2 signals (with maxlags = 0 ) and find where the cross correlated signal is maximum, the distance between the point where the signal is maximum and the midpoint of cross correlated signal gives you the delay of the signal ( in number of samples, the actual delay in seconds will depend on how many seconds those samples represent ).

Hope I made things clear