Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Calculating cross-correlation

by mykl (Monk)
on Nov 25, 2010 at 12:32 UTC ( [id://873632]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://873632]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found