【发布时间】: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