This is a program I am using to find the delay between two signals with different sampling frequencies. My time signal is from 1 to 10.
The actual delay in the plot is 1.382 but I am getting 109 when I calculate the cross-correlation and find the max value.
Please help me figure out how to get exact value in this case.
x = sin(2*pi*(1:.025:20));t1 = linspace(1,10,length(x));x = rand(1,t1)*x;y = sin(2*pi*(1:.0123:30));t2 = linspace(1,10,length(y));y = rand(1,t2)*y;y = [zeros(1,100) y(1:end-100)];figureplot(t1,x);hold on;plot(t2,y,'-r')s1 =x;s2 =y;c = xcorr(s2,s1); % Cross correlation
lag = mod(find(c == max(c)), length(t1)) % Find the position of the peak
Best Answer