# [SciPy-user] Autocorrelation

David Huard david.huard at gmail.com
Wed Aug 16 08:50:12 CDT 2006

```Thanks Stefan for the tip,
Fortunately, I got a pretty simple case so I don't need to rely on anything
fancy.

David

2006/8/15, Stefan van der Walt <stefan at sun.ac.za>:
>
> On Tue, Aug 15, 2006 at 05:18:43PM +0100, Pierre Barbier de Reuille wrote:
> > David Huard wrote:
> > > Hi,
> > > I haven't seen in Scipy a function to compute the autocorrelation of a
> > > time series. Is there one I missed ?
> > >
> > Isn't numpy.correlate enough ? For autocorrelation you can do something
> > like:
> >
> > r = numpy.correlate(x, x)
>
> These functions are useful when working with short 1-dimensional
> signals, but for larger images they are agonisingly slow.  A way
> around the problem is to calculate the correlation using the FFT, i.e.
>
> def fft_correlate(A,B,*args,**kwargs):
>     return S.signal.fftconvolve(A,B[::-1,::-1,...],*args,**kwargs)
>
> On my computer, I benchmarked these methods with different length
> signals.  See the attached graph and script.  You'll notice that the
> FFT execution time jumps around bit -- I know that it can be
> calculated especially quickly for lengths that are powers of two,
> maybe this has something to do with that.  Can someone on the list
> enlighten me?
>
> Either way, your mileage may vary.  Some say that this method is
> somewhat less accurate, and that it uses more memory.  All I know is
> that it finishes calculating before the end of time.
>
> Regards
> Stéfan
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20060816/b1622abd/attachment.html
```