计算不同时间序列的相关性

Calculating correlation of different time series

我有几个时间序列,即我在 15 分钟内测量了几个信号。每个信号每秒被采样几次,但不同信号的时间戳不相等。假设我们从时间 0 开始。例如,信号一具有以下(时间戳,值):

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

信号二具有以下(时间戳,值):

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

我现在如何计算这些时间序列值的相关性,例如python 还是 Matlab?如果这些值始终处于相同的时间戳,我可以只计算各个值之间的相关性,但不幸的是,这些值不在相同的时间戳。

您可以对其中一个数据集进行一些简单的插值(请参阅 interp1 for MATLAB),以便它们共享采样率,如果这是您唯一的问题...

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];

现在他们有相同的样本点,你可以做你喜欢的。

假设您有一个信号,其值在时间点 t1 的数组 s1 中,信号 s2 在时间点 t2 处求值。在 Python 中使用 NumPy

  1. Select 两个信号的一组通用时间点 t。您可以选择 t1t2,或使用 np.linspace 在考虑的时间范围内计算线性 space。在任何情况下,我都会确保 t 的最小值和最大值在 t1t2 的范围内以避免外推。
  2. 计算两个信号 s1interps2interp 的插值。这可以通过 np.interp, which computes linear interpolations. If you need more sophisticated interpolation methods, you can take a look at SciPy's interp1d.
  3. 来完成
  4. 计算 s1interps2interp 之间的相关性。这是通过 np.corrcoef.
  5. 完成的