Calculating correlation of different time series

조회 수: 84 (최근 30일)
Sepp
Sepp 2017년 9월 20일
댓글: Pawan Sharma 2020년 8월 7일
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.

답변 (1개)

Chad Greene
Chad Greene 2017년 9월 20일
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.
  댓글 수: 4
Sepp
Sepp 2017년 9월 27일
Thank you. Let's say both signals correlate but they are shifted in y-direction (one signal has lower amplitude). How can I compensate for this if I don't know the value of the shift? I don't want to incorporate this shift into the correlation value.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by