我正在处理来自记录器的1 1Hz时间戳(变量'timestamp_1hz'),该记录器每秒记录的时间并不完全相同(差值从0.984到1.094不等,但如果记录器打鼓,有时会有0.5秒或几秒钟的差异)。1 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我想要对时间戳进行预处理,然后使用'intersect‘将其与连续的1 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。任何帮助或提示都将不胜感激!
发布于 2013-07-25 18:51:54
您遇到的问题是,您不能简单地将这些标记匹配到一个时间列表,因为您可能期望在秒数= 1000.5、1001、1002处获得一组数据点,但是如果出现较早的点数,您可能会得到完全合法的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秒前的-工作在我构建的一小部分假数据上,而不是在你的上。(供将来参考:提供您的数据的一小部分会更有帮助,例如,只有几分钟的价值,您知道其中包含一个blip)。
然后,我会将有效时间戳列表拆分成10分钟的部分进行平均,计算每个部分中获得了多少有效时间戳。如果它是有效的,你最终应该不会超过600个-但如果偶尔出现小插曲,也不会少很多。
https://stackoverflow.com/questions/17841496
复制相似问题