maximize crosscorrelation

*To*: mathgroup at smc.vnet.net*Subject*: [mg125374] maximize crosscorrelation*From*: alexxx <alexxx.magni at gmail.com>*Date*: Sat, 10 Mar 2012 06:16:55 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

Hi guys, I hope somebody can help me with this. 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. Typical datafile, containing both signals: # time V1 V2 6.25e-011 0.787938 0.845207 ................................................................ 4.25e-010 0.886294 0.883048 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]; then I defined the crosscorrelation thus: cc[\[Tau]_] := Integrate[f1[t] * f2[t + \[Tau]], {t, a,b}] with the time limits a and b where my functions are well defined. Last, I believed that the plot of my cc[\[Tau]_] as a function of varying offset would show a clear peak at the correct offset value, but it isnt so. So, understanding that I didnt understand a thing, I setup a mokeup problem: f1[t_] := Cos[t]*Exp[-t^2/20]; f2[t_] := Cos[t - 2]*Exp[-(t - 2)^2/20]; Print[Plot[{f1[t], f2[t]}, {t, -10, 10}, PlotRange -> All]]; cc[\[Tau]_] := Integrate[f1[t]*f2[t + \[Tau]], {t, -Infinity, Infinity}] Plot[cc[\[Tau]], {\[Tau], -3, 3}, Mesh -> All, PlotPoints -> 5, MaxRecursion -> 1, PlotRange -> All] and it clearly works (e.g. maximum at 2), so I guess that my problem lies 1) in the discrete nature of my data, and 2) in the fact that my data is defined in a finite, not infinite interval. Any ideas about how to define this problem? Thanks! alessandro