Question regarding comparing shape of two graphs using correlation coefficient (xcorr function)
조회 수: 8 (최근 30일)
이전 댓글 표시
Dear All,
I am attempting to compare graphs of 2 signals as seen below using the correlation coefficient. My objective is to find portions of the signal which are bad (i.e below square waves in the blue signal) using the correlation coefficient between the two signals as their shapes are somewhat similar. I was under the impression that the correlation coefficient would be high when both cycles are in sync and would be low in areas where the graph does not follow the pattern (i.e the square wave). I am an amateur when it comes to mathematical terms so bear with me.
I initially tried using the code below, I divided the graph into groups, each 1 cycle from peak to peak, found the correlation coefficient between signal 1 and 2 at lags = 0.
[p,ind]=findpeaks(signal2,'MinPeakHeight',0.4,'MinPeakDistance',150);
b=[];
for i = 1:length(ind)-1
q = ind(i):ind(i+1);
a = xcorr(signal1(q),signal2(q),'coeff');
b = [b a((end+1)/2)];
end
Giving a total of 3709 cycles without any indication of where the bad quality signal data might lie as the correlation coefficient values seem random. Also, the correlation coefficient from the cycles shown above, cycles 47 to 54 where cycles 51,52, and 53, I expected different results from gave values which remained within a reasonable range,c = [-0.1028 , -0.1081 , -0.0785 , -0.0340 , -0.1266, -0.1651 -0.1835, -0.0830]
I am sorry if this question is dragging on but I would like to ask if I should pursue attempting to find abnormalities in signal 1 using the shape of signal 2 using correlation coefficient. Or is there another statistical method I am not aware which might prove more useful. Any input is much appreciated.
Kind Regards,
Blixan
댓글 수: 0
답변 (1개)
Brandon Eidson
2017년 3월 16일
편집: Brandon Eidson
2017년 3월 16일
Hey Nabil, the problem you present is an interesting one. Unfortunately, I do not think a correlation calculation between signal1 and signal2 is going to help you. Although oversimplified, one way to think about what is a correlation coefficient is to see it as a measure of "how well the two signals move together". But if you look at your two signals, especially between the peaks, signal1 gradually declines while signal2 goes up, then down, then flat-lines. The measurements you are getting are somewhat reasonable: on average there is not much correlation between the signals (a normalized correlation coefficient of -0.1 is effectively no correlation).
If you know what a section of signal1 should look like given the look of a section of signal2, you could have two baselines: signal1Baseline and signal2Baseline. You then could calculation the normalized correlation coefficient for signal1Baseline and the subsequent signal1 sections. If you get an abnormally low correlation, you can then check signal2Baseline against the corresponding signal2 section. If it has a normally high correlation, then you know something is up with that section of signal1.
The above algorithm has several assumptions to it (e.g., the patterns are very consistent in length), so you may have to make some creative adjustments to make it work in your case.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!