简体   繁体   中英

Calculating correlation of different time series

I have several time series, ie I have measured a couple of signals over 15min. Each signal is sampled several times each second but the timestamps of the different signals are not equal. Let's say we start at time 0s. For example, signal one has the following (timestamp, values):

0.1s: 954
0.2s: 1000
0.24s: 1090
0.3s: 855
0.45s: 600
... 

Signal two has the following (timestamp, values):

0.05s: 900
0.13s: 960
0.2s: 1000
0.29s: 850 
0.33s 800
...

How can I now calculate the correlation of the values of these time series in eg python or Matlab? If the values would be always at the same timestamps I could calculate just the correlation between the individual values but unfortunately the values are not at the same timestamps.

Let's say you have a signal with values in an array s1 at time points t1 , and a signal s2 evaluate at time points t2 . With NumPy in Python:

  1. Select a common set of time points for both signals t . You can pick t1 or t2 , or compute a linear space in the considered time range with np.linspace . In any case, I'd make sure that the minimum and maximum values of t are in the range of both t1 and t2 to avoid extrapolations.
  2. Compute interpolations for both signals, s1interp and s2interp . This can be done with np.interp , which computes linear interpolations. If you need more sophisticated interpolation methods, you can take a look at SciPy's interp1d .
  3. Compute the correlation between s1interp and s2interp . This is done with np.corrcoef .

You could do some simple interpolation (see interp1 for MATLAB) on one of the data sets so that they share a sampling rate, if that's your only issue...

X =[0.1   954
    0.2   1000
    0.24  1090
    0.3   855
    0.45  600];

Y =[0.05  900
    0.13  960
    0.2   1000
    0.29  850 
    0.33  800];

t = Y(:,1); % get time samples from Y
% Interpolate (linearly, with extrapolation) X2 values onto time samples t
X2 = [t, interp1(X(:,1), X(:,2), t, 'linear', 'extrap')];

>> X2 = [0.05  931
         0.13  967.8
         0.2   1000
         0.29  894.1667
         0.33  804];

Now they have the same sample points, you can do what you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM