Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
385 B
4
Indexable
Never
def corrfft(x):
    N = len(x)
    x = np.pad(x, ((0, N)))
    fft = np.fft.fft(x)
    iff = np.fft.ifft(fft*np.conjugate(fft))
    iff = np.concatenate([iff[N+1:], iff[:N]])
    return iff.real
import numpy as np
from scipy import signal
t = np.linspace(0, 10, 100)
s = np.cos(t)
ac = signal.correlate(s,s)
ac_by_fft = corrfft(s)
np.allclose(ac, ac_by_fft)
Out[99]: True