How do I find the time delay between two signals?
Show older comments
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)];
figure
plot(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
1 Comment
Randy Souza
on 24 Sep 2013
I have restored the original text of this question.
@Sainath: this question has a clear subject and an accepted answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!