Effacer les filtres
Effacer les filtres

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

43 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 9 Mar 2020
Modifié(e) : Ameer Hamza le 9 Mar 2020
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 commentaires
SOPAE YI
SOPAE YI le 16 Mar 2020
Mr. Hamza,
You've been such a great help!!
I am very much appreciative of your sharing your expertise, sir.
Stay healthy and happy!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by