如何将两个时间序列与差距和不同的时基相关联? [英] How to correlate two time series with gaps and different time bases?

查看:21
本文介绍了如何将两个时间序列与差距和不同的时基相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个时间序列的 3D 加速度计数据,它们具有不同的时基(时钟在不同的时间开始,在采样时间内有一些非常轻微的蠕变),并且包含许多不同大小的间隙(由于与写入单独的闪存设备).

I have two time series of 3D accelerometer data that have different time bases (clocks started at different times, with some very slight creep during the sampling time), as well as containing many gaps of different size (due to delays associated with writing to separate flash devices).

我使用的加速度计是便宜的 GCDC X250-2.我正在以最高增益运行加速度计,因此数据具有明显的本底噪声.

The accelerometers I'm using are the inexpensive GCDC X250-2. I'm running the accelerometers at their highest gain, so the data has a significant noise floor.

每个时间序列有大约 200 万个数据点(超过一个小时,512 个样本/秒),并包含大约 500 个感兴趣的事件,其中一个典型的事件跨越 100-150 个样本(每个 200-300 毫秒).其中许多事件都受到闪存写入期间数据中断的影响.

The time series each have about 2 million data points (over an hour at 512 samples/sec), and contain about 500 events of interest, where a typical event spans 100-150 samples (200-300 ms each). Many of these events are affected by data outages during flash writes.

因此,数据不是原始的,甚至不是很漂亮.但是我的眼球检查显示它清楚地包含了我感兴趣的信息.(如果需要,我可以发布图表.)

So, the data isn't pristine, and isn't even very pretty. But my eyeball inspection shows it clearly contains the information I'm interested in. (I can post plots, if needed.)

加速度计处于相似的环境中,但只是适度耦合,这意味着我可以通过肉眼判断每个加速度计匹配的事件,但到目前为止我在软件中这样做没有成功.由于物理限制,这些设备也安装在不同的方向,其中轴不匹配,但它们尽可能接近正交.因此,例如,对于 3 轴加速度计 A &B,+Ax 映射到-By(上下),+Az 映射到-Bx(左右),+Ay 映射到-Bz(前后).

The accelerometers are in similar environments but are only moderately coupled, meaning that I can tell by eye which events match from each accelerometer, but I have been unsuccessful so far doing so in software. Due to physical limitations, the devices are also mounted in different orientations, where the axes don't match, but they are as close to orthogonal as I could make them. So, for example, for 3-axis accelerometers A & B, +Ax maps to -By (up-down), +Az maps to -Bx (left-right), and +Ay maps to -Bz (front-back).

我最初的目标是在垂直轴上关联冲击事件,尽管我最终希望 a) 自动发现轴映射,b) 关联映射 ace 上的活动,以及 c) 提取两个加速度计之间的行为差​​异(例如扭曲或弯曲).

My initial goal is to correlate shock events on the vertical axis, though I would eventually like to a) automatically discover the axis mapping, b) correlate activity on the mapped aces, and c) extract behavior differences between the two accelerometers (such as twisting or flexing).

时间序列数据的性质使得 Python 的 numpy.correlate() 无法使用.我也看过 R 的 Zoo 包,但没有取得任何进展.我向信号分析的不同领域寻求帮助,但没有取得任何进展.

The nature of the times series data makes Python's numpy.correlate() unusable. I've also looked at R's Zoo package, but have made no headway with it. I've looked to different fields of signal analysis for help, but I've made no progress.

有人知道我可以做什么或我应该研究的方法吗?

Anyone have any clues for what I can do, or approaches I should research?

2011 年 2 月 28 日更新:在此处 显示数据示例.

Update 28 Feb 2011: Added some plots here showing examples of the data.

推荐答案

我对您问题的解释:给定两个非常长、嘈杂的时间序列,找到一个与一个信号中的大颠簸"相匹配的转换另一个信号.

My interpretation of your question: Given two very long, noisy time series, find a shift of one that matches large 'bumps' in one signal to large bumps in the other signal.

我的建议:对数据进行插值,使其间隔均匀,校正和平滑数据(假设快速振荡的相位无趣),并进行一次一点的互相关(假设有一个小的偏移)将排列数据).

My suggestion: interpolate the data so it's uniformly spaced, rectify and smooth the data (assuming the phase of the fast oscillations is uninteresting), and do a one-point-at-a-time cross correlation (assuming a small shift will line up the data).

import numpy
from scipy.ndimage import gaussian_filter
"""
sig1 and sig 2 are assumed to be large, 1D numpy arrays
sig1 is sampled at times t1, sig2 is sampled at times t2
t_start, t_end, is your desired sampling interval
t_len is your desired number of measurements
"""

t = numpy.linspace(t_start, t_end, t_len)
sig1 = numpy.interp(t, t1, sig1)
sig2 = numpy.interp(t, t2, sig2)
#Now sig1 and sig2 are sampled at the same points.

"""
Rectify and smooth, so 'peaks' will stand out.
This makes big assumptions about your data;
these assumptions seem true-ish based on your plots.
"""
sigma = 10 #Tune this parameter to get the right smoothing
sig1, sig2 = abs(sig1), abs(sig2)
sig1, sig2 = gaussian_filter(sig1, sigma), gaussian_filter(sig2, sigma)

"""
Now sig1 and sig2 should look smoothly varying, with humps at each 'event'.
Hopefully we can search a small range of shifts to find the maximum of the 
cross-correlation. This assumes your data are *nearly* lined up already.
"""
max_xc = 0
best_shift = 0
for shift in range(-10, 10): #Tune this search range
    xc = (numpy.roll(sig1, shift) * sig2).sum()
    if xc > max_xc:
        max_xc = xc
        best_shift = shift
print 'Best shift:', best_shift
"""
If best_shift is at the edges of your search range,
you should expand the search range.
"""

这篇关于如何将两个时间序列与差距和不同的时基相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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