Comparing Time Series data using correlation

조회 수: 7 (최근 30일)
samson p
samson p 2013년 3월 2일
I have 2 matrices. Each matrix has a column of time and sensor output at that time. So matrix A has time and sensor output A, and matrix B has time and sensor output B. I want to do a correlation between the two sensors. Unfortunatley, the length of the matrices are slightly different. I try to interpolate the data so that they have a common time vector. However, the correlation of that comes out to be 0. I've read of correlation between two vectors of different lengths. One gets padded with zeros to make them the same size. However, I don't think that will work in my case because it would change the shape of one of the plots. I hope this makes sense. i feel like this would be a common thing but can't seem to find the solution.
Any help would be appreciated.

채택된 답변

ChristianW
ChristianW 2013년 3월 2일
Both, interpolation and adding zeros will work. But xcorr doesn't need same vector length. For not constant signal sample time the interpolation is needed.
This xcorr example might be usefull for you.
t = 0:0.01:10-0.01;
x = cos(2*pi*0.5*t) + randn(size(t))*0.1;
z = sin(2*pi*0.5*t) + randn(size(t))*0.1;
z([1:350 550:end]) = 0;
[c,lags] = xcorr(x,z,'coeff');
% z = x; z([1:350 550:end]) = [];
% [c,lags] = xcorr(x,z,'none');
subplot(211), plot(t,x,'k',(0:length(z)-1)*0.01,z,'r'), legend('A','B')
subplot(212), plot(lags,c,'k'), xlabel('lags [steps]'), ylabel('corr')
  댓글 수: 3
samson p
samson p 2013년 3월 2일
Ahhh! When you interpolate, there may exist some NaNs. If those get carried through to the xcorr function, then everything becomes NaN.
Thank you for all your help!
ChristianW
ChristianW 2013년 3월 2일
Change interp1 method to perform extrapolation for out of range values.
b1 = interp1(t2,b,t1,'pchip');
doc interp1

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

추가 답변 (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