Python中的规范化互相关 [英] Normalized Cross-Correlation in Python

查看:178
本文介绍了Python中的规范化互相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的日子里,我一直在努力尝试根据Chelton(1983)的参考来计算两对向量(x和y)的自由度:

I have been struggling the last days trying to compute the degrees of freedom of two pair of vectors (x and y) following reference of Chelton (1983) which is:

根据Chelton(1983)的自由度

,我找不到使用np.correlate计算归一化互相关函数的正确方法, 我总是得到不在-1、1之间的输出.

and I can't find a proper way to calculate the normalized cross correlation function using np.correlate, I always get an output that it isn't in between -1, 1.

有没有一种简便的方法可以对互相关函数进行归一化以便计算两个向量的自由度?

Is there any easy way to get the cross correlation function normalized in order to compute the degrees of freedom of two vectors?

推荐答案

很好的问题.没有直接的方法,但是您可以像这样在使用np.correlate之前标准化"输入向量,并且将在[-1,1]范围内返回合理的值:

Nice Question. There is no direct way but you can "normalize" the input vectors before using np.correlate like this and reasonable values will be returned within a range of [-1,1]:

在这里,我定义了信号处理教科书中通常定义的相关性.

Here i define the correlation as generally defined in signal processing textbooks.

c'_{ab}[k] = sum_n a[n] conj(b[n+k])

代码:如果a和b是向量:

CODE: If a and b are the vectors:

a = (a - np.mean(a)) / (np.std(a) * len(a))
b = (b - np.mean(b)) / (np.std(b))
c = np.correlate(a, b, 'full')

参考文献:

https://docs.scipy.org/doc/numpy/reference/generation/numpy.correlate.html

https://en.wikipedia.org/wiki/Cross-correlation

这篇关于Python中的规范化互相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆