【问题标题】:Timestamp Processing Brain Teaser时间戳处理脑筋急转弯
【发布时间】:2013-07-24 18:01:18
【问题描述】:

我正在处理来自记录器的 1Hz 时间戳(变量“timestamp_1hz”),该记录器并非每秒都在同一时间记录(差异从 0.984 到 1.094 不等,但有时如果记录器打嗝,则为 0.5 或几秒)。 1Hz数据集用于构建10分钟平均数据集,每10分钟间隔必须有600条记录。因为记录器并不是每秒都在同一时间记录,所以时间戳会慢慢地漂移到 1 秒标记。当时间戳超过 0 标记以及 0.5 标记时会出现问题。

我尝试了各种方法来预处理时间戳。它们之间大约 1 秒的时间戳应该被认为是有效的。一些例子包括:

% simple
% this screws up around half second and full second values    
rawseconds = raw_1hz_new(:,6)+(raw_1hz_new(:,7)./1000);
rawsecondstest = rawseconds;
    rawsecondstest(:,1) = floor(rawseconds(:,1))+ rawseconds(1,1);

% more complicated
% this screws up if there is missing data, then the issue compounds because k+1 timestamp is dependent on k timestamp
rawseconds = raw_1hz_new(:,6)+(raw_1hz_new(:,7)./1000);
 A = diff(rawseconds);
    numcheck = rawseconds(1,1);
    integ = floor(numcheck);
    fract = numcheck-integ;
    if fract>0.5
        rawseconds(1,1) = rawseconds(1,1)-0.5;
    end
 for k=2:length(rawseconds)
        rawsecondstest(k,1) =  rawsecondstest(k-1,1)+round(A(k-1,1)); 
end

我想对时间戳进行预处理,然后使用“相交”将其与连续的 1Hz 时间戳进行比较,以便找到丢失的、重复的等数据,例如:

 % pull out the time stamp (round to 1hz and convert to serial number)
timestamp_1hz=round((datenum(raw_1hz_new(:,[1:6])))*86400)/86400;

% calculate new start time and end time to find contig time
starttime=min(timestamp_1hz);
endtime=max(timestamp_1hz);

% determine the contig time
contigtime=round([floor(mean([starttime endtime])):1/86400:ceil(mean([starttime endtime]))-1/86400]'*86400)/86400;
% find indices where logger time stamp matches real time and puts
% the indices of a and b
clear Ia Ib Ic Id
[~,Ia,Ib]=intersect(timestamp_1hz,contigtime);
% find indices where there is a value in real time that is not in
% logger time
[~,Ic] = setdiff(contigtime,timestamp_1hz);
% finds the indices that are unique
[~,Id] = unique(timestamp_1hz);

您可以下载 10 天的 raw_1hz_new 时间戳here。任何帮助或提示将不胜感激!

【问题讨论】:

  • 如果你的记录器不能产生 600 条记录,你不觉得捏造丢失的数据有点虚伪吗?如果您不介意虚假数据,则可以预处理您拥有的数据(
  • 我不是在假装它,我只是在间隔之间大约 1 秒左右颠簸有效数据,以便它与 intersect 函数一起使用。我对填补漏洞不感兴趣。
  • 我无法查看带有时间戳的链接;它说“抱歉,我们目前无法生成文档视图。请稍后再试。”
  • 抱歉,应该提到它 - 您必须下载 xls 文件,因为它对于 Google 文档来说太大了 - DL 链接位于该屏幕的左上角。可以使用 10 天 x ~86400 个时间戳。由于漂移有时很慢,你需要很多行才能看到我在说什么。

标签: matlab timestamp intersect


【解决方案1】:

您遇到的问题是您不能简单地将这些标记与时间列表相匹配,因为您可能期望在秒 = 1000、1001、1002 处有一组数据点,但如果有更早的 blip 你可以在 1000.5、1001.5、1002.5 处拥有完全合法的数据。

如果您想要的只是一个有效时间列表/它们在您的系列中的位置,为什么不只是类似(以秒为单位的时间):

A = diff(times); % difference between times
n = find(abs(A-1)<0.1) % change 0.1 to whatever your tolerance is
times2 = times(n+1); 

times2 应该是所有时间戳的列表,其中上一个时间戳大约是 1 秒前 - 适用于我构建的一小部分假数据,没有在你的上尝试过。 (供将来参考:提供一小部分数据会更有帮助,例如,只有几分钟的价值,您知道其中包含一个信号)。

然后,我将获取有效时间戳列表并将其分成 10 分钟的部分进行平均,计算在每个部分中获得了多少有效时间戳。如果它正常工作,您最终应该不会超过 600 - 但如果偶尔出现问题,则不会更少。

【讨论】:

    猜你喜欢
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 2017-05-30
    • 2014-08-03
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多