Re: maximize crosscorrelation
- To: mathgroup at smc.vnet.net
- Subject: [mg125389] Re: maximize crosscorrelation
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sun, 11 Mar 2012 04:08:09 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
On 3/10/12 at 6:16 AM, alexxx.magni at gmail.com (alexxx) wrote:
>I have two similar signals s1 and s2, where one is shifted with
>respect to the other by an unknown amount. These signals are
>captured by an oscilloscope, so you can represent them as arrays of
>{t,v} time and voltage values.
>I always knew that the theory says in such cases you have to
>maximize the selfcorrelation between the two signals, but I never
>used it until now.
>(BTW I was surprised to find that Mathematica had it as a standalone
>function, but doesnt provide it anymore)
>Anyway, 1st thing since crosscorr requires integration I defined the
>interpolation functions f1= Interpolation[v1]; f2=
>Interpolation[v2];
For discrete data the function you want is ListCorrelate. For example,
First generate a "signal" and the same signal with an offset:
x = RandomReal[1, {20}];
y = RotateLeft[x, 5];
Now find the offset by:
In[12]:= Ordering[
Flatten@Table[ListCorrelate[RotateLeft[x, n], y], {n, 20}], -1]
Out[12]= {5}