Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Measuring Time Delay Between Two Signals, Xcorr
Replies: 4   Last Post: May 11, 2013 3:46 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Zac Kelton

Posts: 28
Registered: 10/4/08
Measuring Time Delay Between Two Signals, Xcorr
Posted: Oct 9, 2008 9:53 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hey everyone. So I've created two simple sine wave signals, with the same frequency, just one is the delayed version of the other by 4s (Yes I know 4s is an unrealistically high amount for my application, but for now I'm just trying to get concepts down...).

THE EXPERIMENT I'M SIMULATING: Pretend you are sending out a simple sine wave from a transmitter and receiving the signal through two different microphones, one close, and one far away and recording the data from both microphones for 10 seconds. Now, figure out the time delay between the first signal recieved by the close microphone and the signal recieved by the far microphone.

THE PROBLEM: Anyway, so I'm trying to use cross correlation to determine how much time delay there is in my second signal by finding the peak correlation point, which should (I think) occur when the two signals align. For some reason my code is giving me a weird result, so this is where you all come in :-)

-------------------------------------------------
THE CODE:
-------------------------------------------------

clc;
clear all;

f = 1; % 1 Hz frequency
t = 0:.01:10; % Creates a 10 second time span for samples to be taken in

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CREATE & PLOT SIGNAL 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
signal1 = sin(2*pi*f*t); % Create signal 1
figure(1);
plot(t, signal1);
title('Signal From Close Receiver/Transmitter Pair');
xlabel('Time (s)');
ylabel('Amplitude');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CREATE & PLOT SIGNAL 2, SAME AS SIGNAL 1
% JUST TIME DELAYED 4s.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
signal2=[zeros(1,400), signal1(1,1:length(signal1)-400)]; % Create a signal2 with 4 second delay

figure(2);
plot(t, signal2);
title('Signal From Far Receiver/Transmitter Pair');
xlabel('Time (s)');
ylabel('Amplitude');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CORRELATE SIGNAL 1 TO SIGNAL 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
signal1 = signal1';
signal2 = signal2';
xcorrValues = xcorr(signal2,signal1)
xCorrMax = max(abs(xcorrValues));


----------------------------------------------------

Thanks in advance for your help/support.

--Zac



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.