两种大小不同的两个信号之间的相关性 [英] Correlation between two signals with two different sizes

查看:881
本文介绍了两种大小不同的两个信号之间的相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算两个信号之间的相关性,如果两个信号相同,则返回1,否则返回0到1.两个信号的大小不同,因此需要重采样的问题.我已经做到了,但是输出不正确.谁能帮助我有效地实施它.

我的代码:

MaxRow = max(size(A,1),size(B,1));
MaxCol = max(size(A,2),size(B,2));
NewA = resample(A,MaxRow,size(A,1));
NewB = resample(B,MaxRow,size(B,1));
NewA = resample(NewA',MaxCol,size(A,2))';
NewB = resample(NewB',MaxCol,size(B,2))';
for s = 1:MaxRow
    a = NewA(s,:);
    b = NewB(s,:);
    c(s)=real(corr(a',b'));
end
c(isnan(c)) = 0 ;
score = mean(c);

解决方案

这是一个玩具示例.

% Example Data
x = 0:9;
y = 1:0.1:10;

% Check if y is longer
if length(x) < length(y)
    x = interp1( x, linspace( 1, length(x), length(y) ) );   % Resample x
else
    y = interp1( y, linspace( 1, length(y), length(x) ) );   % Resample y
end

% Get corrcoeff
c = abs( corrcoef( x, y ) );   % Corrcoeff solution here
c = c(2,1);

% Get MSE
m = mse( x - y );   % MSE solution here

linespace将在1length(x)之间生成带有length(y)格数的索引.

基本上interp1会将变量重新采样为另一个变量的长度. if语句将检查哪个需要重新采样.函数corrcoef将获得2个信号的系数的相关系数.由于corrcoef在0到1之间,因此我们需要一个绝对值.如果您不关心缩放和偏差,则corrcoef将为您工作.

如果您打算改用MSE,则可以对错误(x-y)使用MSE函数,但是它不会在0到1之间.任何比较方法都适用于此重采样代码.

I am trying to calculate the correlation between two signals, where it returns 1 if both are the same and it will return between 0 and 1 otherwise. The problem that the two signals have different sizes so resampling is needed. I already did it but the output is not correct. Can anyone help me to implement it in an efficient way.

My code:

MaxRow = max(size(A,1),size(B,1));
MaxCol = max(size(A,2),size(B,2));
NewA = resample(A,MaxRow,size(A,1));
NewB = resample(B,MaxRow,size(B,1));
NewA = resample(NewA',MaxCol,size(A,2))';
NewB = resample(NewB',MaxCol,size(B,2))';
for s = 1:MaxRow
    a = NewA(s,:);
    b = NewB(s,:);
    c(s)=real(corr(a',b'));
end
c(isnan(c)) = 0 ;
score = mean(c);

解决方案

Here is a toy example.

% Example Data
x = 0:9;
y = 1:0.1:10;

% Check if y is longer
if length(x) < length(y)
    x = interp1( x, linspace( 1, length(x), length(y) ) );   % Resample x
else
    y = interp1( y, linspace( 1, length(y), length(x) ) );   % Resample y
end

% Get corrcoeff
c = abs( corrcoef( x, y ) );   % Corrcoeff solution here
c = c(2,1);

% Get MSE
m = mse( x - y );   % MSE solution here

linespace will generate indicies between 1 and length(x) with length(y) number of divisions.

Essentially interp1 will resample the variable to the length of the other one. The if statement will check which one needs resampling. The function corrcoef will get the correlation coefficient of the coefficient of the 2 signals. Since corrcoef is between 0 and 1, we need an absolute value. If you don't care about scaling and bias corrcoef will work for you.

If you plan to use MSE instead, then you can use the MSE function on the error (x-y) but it will not be between 0 and 1. Any comparison method will work with this resampling code.

这篇关于两种大小不同的两个信号之间的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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