def correlate_periodic(a, v=None):
"""Cross-correlation of two 1-dimensional periodic sequences.
a and v must be sequences with the same length. If v is not specified, it is
assumed to be the same as a (i.e. the function computes auto-correlation).
:param a: input sequence #1
:param v: input sequence #2
:returns: discrete periodic cross-correlation of a and v
"""
a_fft = _np.fft.fft(_np.asarray(a))
if v is None:
v_cfft = a_fft.conj()
else:
v_cfft = _np.fft.fft(_np.asarray(v)).conj()
x = _np.fft.ifft(a_fft * v_cfft)
if _np.isrealobj(a) and (v is None or _np.isrealobj(v)):
x = x.real
return x
评论列表
文章目录