MATLAB: Time delay between two signals from the same source

time delay

Hi
Could someone help me to find the time delay between two signals coming from the same source by using the concepts of correlation and autocorrelation. I am new to matlab, so could you please explain from the basic concepts?
Thanks in advance

Best Answer

You can use xcorr to determine the delay in samples and then use sampling frequency to find out the exact delay in time.
fs = 100;
t = 0:1/fs:1;
x = sin(2*pi*t);
y = sin(2*pi*t+pi/10);
[c, lags] = xcorr(x,y)
If you examine c, the maximum is at index 106, which corresponds t a lag of (see lags) 5. This means the two signals match at a delay of 5 samples. You can translate that to time by dividing the number of samples with the sampling frequency. You can also use findpeaks to automate the peak search.
HTH
Related Question