计算互相关函数? [英] Computing cross-correlation function?
问题描述
在R
中,我正在使用ccf
或acf
计算成对互相关函数,以便我可以找出哪个偏移使我获得了最大值.从它的外观来看,R
给我一个规范化的值序列. Python的scipy中是否有类似的东西,还是应该使用fft
模块来做到这一点?目前,我正在执行以下操作:
In R
, I am using ccf
or acf
to compute the pair-wise cross-correlation function so that I can find out which shift gives me the maximum value. From the looks of it, R
gives me a normalized sequence of values. Is there something similar in Python's scipy or am I supposed to do it using the fft
module? Currently, I am doing it as follows:
xcorr = lambda x,y : irfft(rfft(x)*rfft(y[::-1]))
x = numpy.array([0,0,1,1])
y = numpy.array([1,1,0,0])
print xcorr(x,y)
推荐答案
To cross-correlate 1d arrays use numpy.correlate.
对于2d数组,请使用 scipy.signal.correlate2d .
For 2d arrays, use scipy.signal.correlate2d.
还有 scipy .stsci.convolve.correlate2d .
还有 matplotlib.pyplot.xcorr 这是基于numpy.correlate.
There is also matplotlib.pyplot.xcorr which is based on numpy.correlate.
请参见SciPy邮件列表上的此信息一些指向不同实现的链接.
See this post on the SciPy mailing list for some links to different implementations.
@ user333700添加了指向此问题的科学票证.
@user333700 added a link to the SciPy ticket for this issue in a comment.
这篇关于计算互相关函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!