How can I measure similarity between two signals with different lengths (and with different time points)?

조회 수: 19 (최근 30일)
Hi all,
I want to measure similarity between two signals with different lengths.
Following is my code.
A = [1.2,1.5;
2.4,0.5;
3.2,1.5;
4.1,1]
B = [1,1;
2,0;
3,1;
4,0.5;
5,1.5]
BB = [1,1;
2,0;
3,1;
4,0.5;
5,1.5]
C = [1.1,1.2;
2.2,1.3;
3.3,1.5;
4.2,1.7]
%%%%% B and BB are the same signal
plot(A(:,1), A(:,2)) % first column is the x-values
hold on;
plot(B(:,1), B(:,2))
figure(2)
plot(C(:,1), C(:,2)) % first column is the x-values
hold on;
plot(BB(:,1), BB(:,2))
%%% Similarity between B and A
B=imresize(B, size(A))
r_BA = corr2(B,A) % Correlation between B and A
maxB = max(B)
maxA = max(A)
nor_B = bsxfun(@rdivide,B,max(B))
nor_A = bsxfun(@rdivide,A,max(A))
nor_r_BA = corr2(nor_A, nor_B) % Normalized Correlation
%%% Similarity between B and C
BB=imresize(BB, size(C))
r_BBC = corr2(BB,C) % Correlation between BB and C
maxBB = max(BB)
maxC = max(C)
nor_BB = bsxfun(@rdivide,BB,max(BB))
nor_C = bsxfun(@rdivide,C,max(C))
nor_r_BBC = corr2(nor_A, nor_BB) % Normalized Correlation
%plot between B and A
Plot between B and C
It looks like B and A have higher similarity than B and C.
However, the correlation (corr2) value between B and C is greater than B and A.
Normalized correlation values are the same for both.
Please let me know how I can measure similarity of the 2 signals above?
I can accommodate R, SPSS or any other tool to solve this problem.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 9일
편집: Ameer Hamza 2020년 3월 9일
If you plot the signals after applying imresize you will see that A and B are not very similar to each other. It appears from the discussion on different forums, there is no universal way to address the issue of correlation between vectors of unequal length. The most appropriate strategy seems to be getting rid of extra data from signals to make them of equal length.
  댓글 수: 15
SOPAE YI
SOPAE YI 2020년 3월 16일
Mr. Hamza,
You've been such a great help!!
I am very much appreciative of your sharing your expertise, sir.
Stay healthy and happy!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by