从不规则的数据时间每0.01秒创建一次常规数据

时间:2014-07-18 14:06:03

标签: matlab interpolation

我怀疑我的程序给了我错误的结果。

我有一个不规则的时间序列数据:(时间(h:m:s:ms),X加速度,Y加速度,Z加速度)十六进制

我的日志文件的部分

7:43:08.437 > ATT_HandleValueNotification: status=0 h=45 n=3 07 C7 17
17:43:08.477 > ATT_HandleValueNotification: status=0 h=45 n=3 07 C7 17
17:43:08.437 > ATT_HandleValueNotification: status=0 h=45 n=3 07 C7 17
17:43:08.477 > ATT_HandleValueNotification: status=0 h=45 n=3 07 C7 17
17:43:08.497 > ATT_HandleValueNotification: status=0 h=45 n=3 07 C7 17
17:43:08.516 > ATT_HandleValueNotification: status=0 h=45 n=3 07 C7 17
17:43:08.537 > ATT_HandleValueNotification: status=0 h=45 n=3 09 C7 17

第一列用于时间,最后三列用于加速度数据(x,y,z)。

我的目标是将不规则的时间序列插入到常规时间序列中,我希望每0.01秒获得一次加速度数据。

我的代码matlab:

s=data(:,3)+data(:,4)/1000; % convert to seconds+fractions



t = datenum(2014,07,18,data(:,1),data(:,2),s)*86400;

t = t - t(1);

sample = interp1(t,res(:,1:3), 0:0.01:t(end)); % i fixed a time to 100ms to obtain estimated data in this time

将加速度数据从十六进制转换为加速度g后,我获得此表

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,140625000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

这是应用interp1函数后的一部分表格样本:

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

0,110866306584362   -0,890625000000000  0,359375000000000

0,125746056832695   -0,890625000000000  0,359375000000000

0,140624576267240   -0,890625000000000  0,359375000000000

0,132812426778048   -0,890625000000000  0,359375000000000

0,125000277288855   -0,890625000000000  0,359375000000000

0,117188127799663   -0,890625000000000  0,359375000000000

0,109375978310470   -0,890625000000000  0,359375000000000

0,109375000000000   -0,890625000000000  0,359375000000000

端 我认为我有重复的值

1 个答案:

答案 0 :(得分:0)

我猜你的查询点也涵盖了你的样本点。如果您想避免产生重复项,只需从查询点集中删除样本点,例如:

% prepare your data:
t = datenum(2014,07,18,data(:,1),data(:,2),s)*86400;
samplepoints = t - t(1);
querypoints = 0:0.01:t(end);

% remove sample points from query points:
newQuerypoints = setdiff(querypoints,samplepoints);

% obtain values as usual:
queryvalues = interp1(samplepoints, samplevalues, newQuerypoints);