Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Cross correlation: What am I seeing?

Subject: Cross correlation: What am I seeing?

From: Sebastian Gatzka

Date: 8 Aug, 2011 18:05:28

Message: 1 of 2

Hello World.

This litte code

t = 0:1:100;

figure(1)
x1 = 0*t;
x2 = 0*t;

subplot(2,1,1)
x1(4) = 1;
x2(50) = 1;
plot(t,x1,t,x2)

subplot(2,1,2)
xx = xcorr(x1,x2);
plot(xx);

[c,i] = max(xx);
i

results in a cross correlation having a peak at the 55th entry.
What use is this information? I'm to sure how to handle this ...

Thanks! Sebastian

Subject: Cross correlation: What am I seeing?

From: Greg Heath

Date: 9 Aug, 2011 04:21:13

Message: 2 of 2

"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote in message <j1p8h8$nq2$1@newscl01ah.mathworks.com>...
> Hello World.
>
> This litte code
>
> t = 0:1:100;
>
> figure(1)
> x1 = 0*t;
> x2 = 0*t;
>
> subplot(2,1,1)
> x1(4) = 1;
> x2(50) = 1;
> plot(t,x1,t,x2)
>
> subplot(2,1,2)
> xx = xcorr(x1,x2);
> plot(xx);
>
> [c,i] = max(xx);
> i
>
> results in a cross correlation having a peak at the 55th entry.
> What use is this information? I'm to sure how to handle this ...
>
> Thanks! Sebastian

clear all, close all, clc

t = 0:1:100;
N = length(t) % 101
figure(1)
x1 = 0*t;
x2 = 0*t;

subplot(2,1,1)
x1(4) = 1;
x2(50) = 1;
plot(t,x1,t,x2)

[xx lags] = xcorr(x1,x2);
M = length(lags) % 201
minmaxllags = minmax(lags) % [ -100 100 ]

subplot(2,1,2)
plot(lags,xx);
[c,i] = max(xx); % [ 1 55 ]
delay = lags(i) % -46

Answer: 55 is the index in a 201 dim lags array that starts at -100.
Conclusion: x1 is delayed 46 seconds behind x2.

Hope this helps.

Greg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us