估计两个时间序列之间的小时移 [英] Estimating small time shift between two time series

查看:109
本文介绍了估计两个时间序列之间的小时移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个时间序列,我怀疑它们之间存在时间偏移,我想估计这个时间偏移。



已经问了这个问题之前版本:
找出两个(非谐波)波之间的相位差找到两个相似波形之间的时移,但在我的情况下,时移小于数据的分辨率。例如,可以每小时的分辨率获得数据,并且时间偏移只有几分钟(参见图片)。



原因是数据记录器曾经测量一个



有什么算法可以估算出这种变化,最好不用插值法吗?



解决方案

这是一个非常有趣的问题。这是尝试使用傅立叶变换的部分解决方案。这依赖于适度周期性的数据。我不确定它是否适用于您的数据(端点上的导数似乎不匹配)。

 将numpy导入为np 

X = np.linspace(0,2 * np.pi,30)#一些X值

def yvals(x):
返回np.sin(x)+ np.sin(2 * x)+ np.sin(3 * x)

Y1 = yvals(X)
Y2 = yvals(X- 0.1)#移位y值

#对两个序列进行傅立叶变换
FT1 = np.fft.fft(Y1)
FT2 = np.fft.fft(Y2)

#从分析上可以看出,系数的相移会导致
#exp(-1.j * N * T_d)的乘法因子

#无法采用第0个元素,因为那是除以0的结果。
#由L'hopital的< sp?>将0除以是可以的规则,但计算机不知道演算:)
print np.log(FT2 [1:] / FT1 [1:])/(-1.j * np.arange(1,len(X)) )

对打印输出的快速检查显示,具有
功率的频率最大( N = 1,N = 2)给出合理的估计值,如果您查看
的绝对值(np.absolute),N = 3也可以,尽管我不知道要解释为什么会这样。 / p>

也许对数学更熟悉的人可以从这里得到更好的答案...


I have two time series, and i suspect that there is a time shift between them, and i want to estimate this time shift.

This question has been asked before in: Find phase difference between two (inharmonic) waves and find time shift between two similar waveforms but in my case, the time shift is smaller than the resolution of the data. for example the data is available at hourly resolution, and the time shift is only few minutes(see image).

The cause of this is that the datalogger used to measure one of the series has few minutes shift in its time.

Any algorithms out there that can estimate this shift, preferably without using interpolation?

解决方案

This is quite an interesting problem. Here's an attempt at a partial solution using fourier transforms. This relies on the data being moderately periodic. I'm not sure if it will work with your data (where the derivatives at the endpoints don't seem to match).

import numpy as np

X = np.linspace(0,2*np.pi,30)  #some X values

def yvals(x):
    return np.sin(x)+np.sin(2*x)+np.sin(3*x)

Y1 = yvals(X)
Y2 = yvals(X-0.1)  #shifted y values

#fourier transform both series
FT1 = np.fft.fft(Y1)
FT2 = np.fft.fft(Y2)

#You can show that analyically, a phase shift in the coefficients leads to a 
#multiplicative factor of `exp(-1.j * N * T_d)`

#can't take the 0'th element because that's a division by 0.  Analytically, 
#the division by 0 is OK by L'hopital's<sp?> rule, but computers don't know calculus :)
print np.log(FT2[1:]/FT1[1:])/(-1.j*np.arange(1,len(X)))

A quick inspection of the printed output shows that the frequencies with the most power (N=1,N=2) give reasonable estimates, N=3 does OK too if you look at the absolute value (np.absolute), although I'm at a loss to explain why that would be.

Maybe someone more familiar with the math can take it from here to give a better answer...

这篇关于估计两个时间序列之间的小时移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆