关于互相关和互相关的问题相关系数

发布于 2024-11-14 10:14:09 字数 340 浏览 4 评论 0原文

可能的重复:
Matlab互相关与相关系数问题

当我互相关2个数据集时ab(各 73 点长)在 MATLAB 中绘制并绘制,它看起来像一个有 145 点的三角形。当我绘制范围为 +/- 1 的互相关输出时,我对相关系数和类似三角形的图感到困惑。

Possible Duplicate:
Matlab Cross correlation vs Correlation Coefficient question

When I cross correlate 2 data sets a and b (each 73 points long) in MATLAB and graph it, it appears like a triangle with 145 points. I'm confused between the correlation coefficient and the triangle-like graph when I plot the cross correlation output which ranges from +/- 1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

待天淡蓝洁白时 2024-11-21 10:14:10

我认真地认为您需要阅读更多有关互相关函数和互相关函数的内容。统计书籍中的相关系数,因为您在这里的困惑比与 MATLAB 相关的更为根本。除非您知道自己正在处理什么,否则即使您编写了正确的程序,您也无法理解 MATLAB 为您提供的内容。

交叉相关:

这是您在交叉相关中执行的操作。考虑数据AB如下,

    A                   B

    x                   
x   |       x           x   
|   |       |       x   |   
|   |   x   |       |   |   x
|   |   |   |       |   |   |
---------------     -----------
0   1   2   3       0   1   2 

然后将B一直滑动到末尾,这样的最后一个点>BA 的第一个点对齐:

                x                   
            x   |       x 
            |   |       |   
            |   |   x   |       
            |   |   |   |
----x---x------------------
   -2  -1   0   1   2   3

        x   
    x   |   
    |   |   x
    |   |   |
----------------x---x---x--
   -2  -1   0   1   2   3

在数据不存在的地方填充零,即在这种情况下,B 超出 0 且A 在 0 之前。然后将它们逐点相乘并相加,将 0 + 0 + 3 + 0 + 0 + 0 = 3 作为互相关中的第一个点。

然后将 B 向右滑动一步,并重复

            x                   
        x   |       x 
        |   |       |   
        |   |   x   |       
        |   |   |   |
----x------------------
   -1   0   1   2   3

        x   
    x   |   
    |   |   x
    |   |   |
----------------x---x--
   -1   0   1   2   3

0 + 9 + 4 + 0 + 0 = 13 作为互相关中的第二个点。继续这样做,直到将 B 一直滑动到 A 的另一端。

得到的向量是 length(A)+length(B)-1,-1 是因为我们从 0 处开始重叠,所以少了一个点。因此,在这里,您应该在互相关中获得 3 + 4 - 1=6 点,在您的情况下,您应该获得 73 + 73 -1 = 145 点。

正如您所看到的,任意点处的互相关向量的值不需要在±1之内。当两个数据向量“最相似”时,互相关性达到最大值。峰值相对于零的“偏移”指示了两个数据集之间的“滞后”。

相关系数

相关系数(我假设是 Pearson 的)只是一个数字,定义为

            Covariance(A,B)
r = --------------------------------
    ________________________________
  \|Covariance(A,A)*Covariance(B,B)

协方差(A,A) 更广为人知的名称是方差(A)。这是一个范围从 -11 的数量(至于为什么它必须在 ±1 之间,请查找 Cauchy-Schwartz 不等式)

注意:

虽然您可以肯定地计算具有不相等数据的两个数据向量的互相关性点,您无法计算它们的相关系数。协方差的概念是对两个变量/数据集如何一起变化的度量,并且不是为不相等的数据集定义的。

I seriously think you need to read up more on cross-correlation functions & correlation coefficient from a statistics book, because your confusion here is more fundamental than related to MATLAB. Unless you know what you're dealing with, you cannot make sense of what MATLAB gives you, even if you get the program right.

CROSS-CORRELATION:

Here is what you do in a cross correlation. Consider data A and B as follows

    A                   B

    x                   
x   |       x           x   
|   |       |       x   |   
|   |   x   |       |   |   x
|   |   |   |       |   |   |
---------------     -----------
0   1   2   3       0   1   2 

You then take B and slide it all the way to the end, so that the last point of B and the first point of A are aligned:

                x                   
            x   |       x 
            |   |       |   
            |   |   x   |       
            |   |   |   |
----x---x------------------
   -2  -1   0   1   2   3

        x   
    x   |   
    |   |   x
    |   |   |
----------------x---x---x--
   -2  -1   0   1   2   3

You fill in zeros where ever the data does not exist i.e., in this case, B beyond 0 and A before 0. Then you multiply them point wise and add, giving 0 + 0 + 3 + 0 + 0 + 0 = 3 as your first point in the cross-correlation.

Then you slide B one step to the right and repeat

            x                   
        x   |       x 
        |   |       |   
        |   |   x   |       
        |   |   |   |
----x------------------
   -1   0   1   2   3

        x   
    x   |   
    |   |   x
    |   |   |
----------------x---x--
   -1   0   1   2   3

giving 0 + 9 + 4 + 0 + 0 = 13 as the second point in the cross-correlation. You keep doing this till you slide B all the way to the other end of A.

The resulting vector is length(A)+length(B)-1, the -1 being because we started with an overlap at 0, so it's one point less. So here you should get 3 + 4 - 1=6 points in the cross-correlation and in your case, you should get 73 + 73 -1 = 145 points.

As you can see, the value of the cross-correlation vector at any point, need not be within ±1. The cross-correlation has a maximum when the two data vectors are "most alike". The "offset" of the peak from zero gives an indication of the "lag" between the two datasets.

CORRELATION COEFFICIENT

The correlation coefficient (I'm assuming Pearson's) is a mere number defined as

            Covariance(A,B)
r = --------------------------------
    ________________________________
  \|Covariance(A,A)*Covariance(B,B)

where Covariance(A,A) is better known as Variance(A). This is a quantity that can range from -1 to 1 (as for why it has to be between ±1, look up Cauchy-Schwartz inequality)

NOTE:

While you can most certainly calculate the cross-correlation of two data vectors with unequal data points, you cannot compute their correlation coefficient. The notion of covariance is a measure of how two variables/datasets change together and is not defined for unequal datasets.

好菇凉咱不稀罕他 2024-11-21 10:14:10

您读过该函数返回的内容吗?
http://www.mathworks.com/help/toolbox/signal/xcorr.html

c = xcorr(x,y) 返回长度2*N-1向量中的互相关序列,其中< code>x 和 y 是长度为 N 的向量 (N>1)

2*73-1=145 这样就可以检查出来。下面的公式解释了原因。

Have you read what that function returns?
http://www.mathworks.com/help/toolbox/signal/xcorr.html

c = xcorr(x,y) returns the cross-correlation sequence in a length 2*N-1 vector, where x and y are length N vectors (N>1).

2*73-1=145 so that checks out. And the formula right below it explains why.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文