0

I'm looking to compute the autocorrelation of a large vector. I've seen a few implementations, and the following, from https://stackoverflow.com/a/51168178/7470093 gives me the results I want, however, it is too slow:

corr = [1. if l == 0 else numpy.corrcoef(x[l:], x[:-l])[0][1] for l in lags]

I have found FFT based solutions, which are much quicker, and do work (it seems "circular" or "periodic" implementations are what I'm looking for), however they do not give exactly the same results. For example:

np.fft.ifft(np.fft.fft(x) * np.fft.fft(x).conj()).real

gives a slightly different result. I believe this is due to what the linked answer refers to as "partial", where the mean/variance is calculated for the full input, vs for each overlap. (Is this the same as biased vs unbiased?)

Is there a way I can calculate the auto correlation using an FFT that uses the mean/variance of the overlap (referred to as "partial" in the linked answer), or is there a way to speed up the np.corrcoef based method such that is equivalent in speed?

Daniel Whettam
  • 345
  • 1
  • 2
  • 9

0 Answers0