Asked by Sepp
on 20 Sep 2017

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.

Answer by 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);

Then use `corrcoef` to get the correlation coefficient like this:

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`.

Sepp
on 25 Sep 2017

Thank you for your answer, Chad.

With the corrcoef I'm getting a matrix of valus. How can I aggregate it to a single value estimating the correlation?

Chad Greene
on 25 Sep 2017

In that example, a single value for the correlation is given by `R(2)`.

Sepp
on 27 Sep 2017

Log in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Log in to comment.