|
"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
|