Correlation coefficeint as a similarity index

7 次查看(过去 30 天)
Hello everyone,
I am trying to find similarity among let's say 1000 signals via correlation coefficient. Each signal will be compared against the other signal so a weights matrix of size 1000x1000 will be created. I am using two for loops to find this value via MATLAB command corrcoef(signals(:,i),signals(:,j)). This command returns a 4x4 matrix (let's call it R), where the correlation coefficent value is R(1,2)=R(2,1) which I am storing as the weight.
My questions is how to avoid for loops (because it literally took over 2 hours for signal size of 9) and compute the weights matrix efficiently. Also, a value close to +1 means more similarity and a value close to 0 means less similarity. What would we say about a value in negative range (since the value can range from -1 to +1), will a value of -1 be still more similar or it will be considered as least similar? What about a value of let's say -0.2? Kindly guide.
Thanks.

采纳的回答

Image Analyst
Image Analyst 2016-4-28
编辑:Image Analyst 2016-4-28
Well are you sure you're not calculating all 1000 by 1000? Because with 1000 signals, to compute something with each of the other 999 signals, you would have 1000*999/2 computations. Because correlating signal 13 with signal 73 is the same as correlating signal 73 with 13, so you don't need to do it twice.
And 499500 cross correlations of signals only 9 elements long doesn't seem like it should take 2 hours, so let's see your loops. You forgot to attach your code.
A correlation coefficient of -0.2 means a weak negative correlation, so that when one signal increases, the other decreases (roughly). A correlation of 0 means that what one signal does has no relation whatsoever to what the other signal is doing.
  3 个评论
Image Analyst
Image Analyst 2016-4-28
This only takes 39 seconds on my computer:
total_signals = 1000;
signals = rand(9, total_signals)
fprintf('Computing weighting matrix...\n');
tic
for i = 1:total_signals
fprintf('Iteration %d...\n',i);
for j = i : total_signals
% fprintf('Iteration %i, %i...\n',i,j);
temp = corrcoef(signals(:, i),signals(:, j));
w(i, j) = temp(1, 2);
% Copy upper triangle to lower triangle
w(j, i) = w(i, j);
end
end
toc
To sort values in decreasing order of similarity, take the absolute value and use sort():
[decr, indexes] = sort(abs(yourArray(:)), 'decend');
You take the absolute value because 0 is no similarity while a correlation of -1 is like the negative of the array, like it's a negative/inverted intensity of the original image. So even if the image is just a negative, it has all the same structures and looks pretty similar.
Muzammil Behzad
Muzammil Behzad 2016-4-28
Oh okay I get it so no matter what's the sign is as long as it's absolute value is near 1 , the signals are structurally similar. Thanks a lot for your help :)

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by