Calculating correlation of different time series
98 views (last 30 days)
Show older comments
Hello
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.
0 Comments
Answers (1)
Chad Greene
on 20 Sep 2017
So you have two different signals, y1 and y2, each measured at their own respective times t1 and t2.
First, use interp1 to interpolate both time series to common timestamps(*). For example, you can get values of y2 at times t1 like this:
y2i = interp1(t2,y2,t1);
R = corrcoef(y1,y2);
And the correlation coefficient will be the second entry in the R matrix.
(*) Note: when choosing timestamps you have a few options. I showed the simplest option, which is to get values of y2 at times t1. You could just as easily get values of y1 at times t2. However, in these situations it can sometimes be marginally better to make up a new time vector ti and interpolate both signals to times ti. If you do this, make sure ti is sampled at more than 2 times the sampling frequency (Nyquist) of t1 or t2 to make sure you don't lose any information in either y1 or y2.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!