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

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

问题描述

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

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)))

对打印输出的快速检查表明,具有最多power (N=1,N=2) 给出合理的估计,如果你看一下 N=3 也可以绝对值 (np.absolute),虽然我无法解释为什么会这样.

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天全站免登陆