Skip to content

Instantly share code, notes, and snippets.

@dmcdougall
Created April 11, 2013 17:20
Show Gist options
  • Save dmcdougall/5365320 to your computer and use it in GitHub Desktop.
Save dmcdougall/5365320 to your computer and use it in GitHub Desktop.
Computing autocorrelations via Fourier transform
def compute_corr(f, pad=2, normalise=True):
n = pad * len(f)
fk = np.fft.rfft(f, n=n)
acf = np.fft.irfft(fk * np.conj(fk), n=n)
acf = acf[:len(f)]
if normalise:
acf /= acf[0]
acf = np.append(acf[::-1][:len(acf) - 1], acf)
return acf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment