Comparing Time Series data using correlation

6 visualizaciones (últimos 30 días)
samson p
samson p el 2 de Mzo. de 2013
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.

Respuesta aceptada

ChristianW
ChristianW el 2 de Mzo. de 2013
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 comentarios
samson p
samson p el 2 de Mzo. de 2013
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 el 2 de Mzo. de 2013
Change interp1 method to perform extrapolation for out of range values.
b1 = interp1(t2,b,t1,'pchip');
doc interp1

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by