Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating correlation of different time series

I have several time series, i.e. 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 e.g. 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.

like image 935
machinery Avatar asked Dec 02 '25 23:12

machinery


1 Answers

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.
like image 106
jdehesa Avatar answered Dec 05 '25 12:12

jdehesa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!