in reply to Calculating cross-correlation

If you can't find a module that does cross-correlation, you can always use one of the many FFT implementations - in pseudo-code:

# input arrays are @f and @g, this calculates @cc which is the cross-c +orrelation of these. @Ff = fft(@f); @Fg = fft(@g); @Fcc = complex_conjugate(@Ff) * @Fg; @cc = inverse_fft(@Fcc);

This makes use of the fourth of the properties listed here. If your input arrays are purely real, I think it may be possible to optimise this further by performing their FFTs in a single FFT calculation, with a bit of clever maths.

I did calculation of a cross-correlation using this method some years ago, but it wasn't in Perl, unfortunately.

--

"Any sufficiently analyzed magic is indistinguishable from science" - Agatha Heterodyne

Replies are listed 'Best First'.
Re^2: Calculating cross-correlation
by mykl (Monk) on Nov 25, 2010 at 14:46 UTC

    Found one!

    In Math::FFT the author has provided an easy way to use FFTs to calculate cross-correlation:

    $fft1 = new Math::FFT($data1); $fft2 = new Math::FFT($data2); $corr = $fft1->correl($fft2);

    Look under Applications - Correlation in the documention of Math::FFT.

    --

    "Any sufficiently analyzed magic is indistinguishable from science" - Agatha Heterodyne