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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by