# Function for Autocorrelation

Is there a built in function to compute the autocorrelation of a signal ?

• You can get ListCorrelate to do this. Feb 23, 2012 at 14:17

From the help file for ListConvolve, to find the autocorrelation of a list:

data = Table[Mod[i^2, 17], {i, 100}];
autocorrelation = ListConvolve[data, data, {1, 1}];
ListLinePlot[autocorrelation ] • This only works because the list in the example is circularly even. (# == Reverse[#]) &@Rest@Table[Mod[i^2, 17], {i, 100}] gives True
– Rojo
Feb 23, 2012 at 14:22

Yes, in version 9 you have CorrelationFunction built in.

data = Table[Mod[i^2, 17], {i, 100}];
autocorrelation = CorrelationFunction[data, {0, Length[data] - 1}];

ListLinePlot[autocorrelation] • @OleksandrR Thanks, I missed this in the documentation! (It's also ~100 faster :) Feb 21, 2013 at 14:16
• This does not seem to match the output of the ListConvolve method (just look at the y-scale). Using some test functions like a square pulse and a triangular pulse, I also don't get the expected output using CorrelationFunction. Any idea what the discrepancy is? I'm working with some applications of autocorrelation functions and I'm struggling to find the discrepancy between the two methods. Jun 4, 2013 at 17:09
• @skratch Nope. Look under the help to see exactly what is calculated using CorrelationFunction. Jun 4, 2013 at 17:13
• In response to myself and anyone else who may be interested: The "CorrelationFunction" approach seems to indeed be the "correct" one if you're looking for an autocorrelation function (ACF). I'm not so sure about ListConvolve and ListCorrelate... In v9, CorrelationFunction is scaled to vary between 1 and -1 and takes its maximum value at the first data point, which is a property of autocorrelation functions. Jun 5, 2013 at 19:18

Perhaps this satisfies you?

autocorrelate[exp_, varFrom_, varTo_]:=Convolve[exp, exp/.varFrom->-varFrom, varFrom, varTo]

If your signal is discrete but symbolic, change Convolve to DiscreteConvolve. If they are lists, check out ListCorrelate

If you search the docs for "autocorrelation", ListConvolve turns up. There's also ListCorrelate. Does this work for you?

• @Rojo the point I was sort of making is that typing "autocorrelate" in the help viewer takes you to ListConvolve which has an example.
– acl
Feb 23, 2012 at 14:21