互相关系数
我在时域中有两个波形,我需要测量其中的互相关 MATLAB 中的系数。我已经尝试过 max(abs(xcorr(m,n,'coeff'))) 但它似乎无法正常工作。
另外我需要测量波形不同部分的互相关系数,例如以1分钟的间隔测量互相关系数。如果可能的话,将这些值输出到矩阵或其他东西。
我知道这是一个很多问题,但我是 MATLAB 新手,发现这项任务令人畏惧!
如果您能就这个问题的任何部分向我提供任何帮助,我将不胜感激。
编辑: 这是我用来测试相关代码的代码:
x = rand(1,14400);
y = rand(1,14400);
r = max( abs(xcorr(x,y,'coeff')) )
I have two waveforms in the time domain, of which I need to measure the cross-correlation coefficient in MATLAB. I have tried max(abs(xcorr(m,n,'coeff')))
but it doesn't seem to be working properly.
Also I need to measure the cross correlation coefficient for different sections of the waveform, e.g. measure the cross correlation coefficient at 1 minute intervals. And if possible output these values to a matrix or something.
I know this is a lot to ask but I'm a MATLAB novice and find this task daunting!
Any help you could give me on any section of this question would be gratefully received.
EDIT:
This is the code I used to test the correlation code:
x = rand(1,14400);
y = rand(1,14400);
r = max( abs(xcorr(x,y,'coeff')) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据本文中的方程,您可以计算互相关系数这样:如果您只想计算信号某些部分的系数,只需使用:
您是否也尝试过 corrcoef 功能?
编辑
好的,我检查了 corrcoef 函数,它似乎工作正常,看一下:
所以相关系数等于 -0.0543 - 相似度很小(如预期)。
为了检查这一点,让我们计算相同信号的系数:
正如预期的那样,它等于 1。
编辑。
正如您所看到的, corrcoef 的结果是这两个信号之间所有可能的相关系数的矩阵:
因此,对于互相关,您需要选择主对角线之外的元素之一(存在自相关系数,在此大小写始终等于 1)。
如果您选择 ans(2,1) 或 ans(1,2),则没有区别 - 如果您计算 x 和 y 的相关性,或者 y 和 x 的相关性,则没有区别。
所以最终的代码应该类似于:
According to equations in this article you can count the cross-correlation coefficient in this way:if you want to compute the coefficient only for some part of the signals, just use:
Have you also tried the
corrcoef
function?Edit
Ok, I have checked the corrcoef function and it seems to be working properly, take a look:
So the correlation coefficient is equal -0.0543 - small similarity (as expected).
To check that, let's compute the coefficient for identical signals:
As expected, it's equal 1.
Edit.
As you can see, the result of corrcoef is a matrix of all possible correlation coefficients between these two signals:
So for cross-correlation you need to select one of the elements outside the main diagonal (there are located self-correlation coefficients, in this case always equal 1).
There is no difference if you would select ans(2,1) or ans(1,2) - there is no difference, if you compute the correlation of x and y, or correlation of y and x.
So the final code should look similar to this:
尝试使用交叉协方差代替
交叉协方差序列是均值去除的互相关
序列。就像 Joonas 提到的那样,rand 的 DC 偏移为 0.5,并且会给您一个“不正确”的结果。
Try using Cross-Covariance instead
cross-covariance sequence is the cross-correlation of mean-removed
sequences. Like Joonas mentioned,
rand
has a DC offset at 0.5 and will give you an "incorrect" results.你这是什么意思?它输出什么,您期望什么?
互相关中的一个可能的问题是波形中的直流偏置会破坏结果。据我所知,没有通用的方法可以解决这个问题。您必须以某种方式确保您的波形不包含任何直流偏置。
What do you mean by that? What does it output, and what do you expect?
One possible gotcha in cross correlation is that a DC bias in the waveform will corrupt the result. And as far as I know, there's no universal way to do anything about it. You have to somehow ensure that your waveforms do not contain any DC bias.
问题是
rand
返回的数字均匀分布在区间 (0,1) 中。换句话说,您的 DC 偏置(平均值)为 0.5!这就是为什么看似随机的信号会获得高相关系数的原因:它们并不完全随机,因为每个信号都有一个类似的常数分量,显示在相关系数中。因此,尝试使用
randn
来代替:它返回随机数,其元素均值 0 呈正态分布,这正是您想要的。The problem is that
rand
returns numbers that are are uniformly distributed in the interval (0,1). In other words, you have a DC bias (mean) of 0.5! That's why you get high correlation coefficient for seemingly random signals: they are not quite random, since each has a similar constant component that shows up in the correlation coefficient.So, try using
randn
instead: it returns random numbers whose elements are normally distributed with mean 0, which is what you want here.