【问题标题】:Create new data series based on two data series with different sampling time基于具有不同采样时间的两个数据系列创建新的数据系列
【发布时间】:2018-04-28 15:55:03
【问题描述】:

我有两个数据集,分别是速度和方向数据,以不同的时间步长记录。

一个数据集 (A) 每 10 分钟记录一次,另一个 (B) 每小时记录一次。

开始时间并不完全相同。

  • A(速度和方向数据)每 10 分钟采样一次,例如00.00, 00.10, 00.20, ...

  • B(方向数据)每小时采样一次,例如23.54, 00.54, 01.54, ...

我想基于数据集A 创建一个新版本的数据集B,其中包含方向数据(一种合成数据集),我从数据集@987654327 中每10 分钟填写一次记录@并保留数据集B每小时的原始记录。

示例数据:

% columns: timestamp, direction, speed
A = [732381.006944445  22.70  2.23 
     732381.013888889  18.20  3.41 
     732381.020833333  31.00  6.97 
     732381.027777778  36.90  5.63]; 


% columns: timestamp, direction
B = [732381.038078704   3.01 
     732381.079745370   5.63 
     732381.121412037   0.68 
     732381.163078704 359.56]; 

..我想要这样的东西..

% columns: timestamp, direction
B_new = [732381.038078704 'some value based on value in A at that time' 
         732381.079745370 'some value based on value in A at that time'  
         732381.121412037 'some value based on value in A at that time'  
         732381.163078704 'some value based on value in A at that time']; 

所以B_new 矩阵中的第一列是 10 分钟的时间戳,而不是一小时的原始时间戳。 IE。我们创建一个新的时间序列(B_new),采样时间为 10 分钟。所以像你这样的东西已经展示了@Wolfie,但时间步长为矩阵A。

将B 中的方向数据分配为A 中最近可用时间的方向数据,同时仍保持与新矩阵B 中的A 相同的数据采样的最佳方法是什么?

【问题讨论】:

    标签: matlab time-series sampling


    【解决方案1】:

    这很容易通过interp1(一个表格查找功能)实现。


    内插到较慢的采样

    假设您有一些不错的干净数据 A 和 B 用于此演示...

    % Columns: time (0.1s timestep), data (just the row number)
    A = [ (1:0.1:2); (1:11) ].';
    % Columns: time (1.0s timestep), data (doesn't even matter, to be removed)
    B = [ (1:1:2); rand(1,2) ].';
    

    现在我们使用interp1 从A 获取最接近的数据值(就时间列而言)并将其分配给B_new。

    B_new = zeros(size(B)); % Initialise 
    B_new(:,1) = B(:,1);    % Get time data from B
    % Get nearest neighbour by specifying the 'nearest' method.
    % Using 'extrap' means we extrapolate if B's times aren't contained by A's
    B_new(:,2) = interp1(A(:,1), A(:,2), B_new(:,1), 'nearest', 'extrap');
    
    % Output
    disp(B_new)
    % >> [ 1   1
    %      2  11 ]
    % This is as expected, because 1 and 11 are the values at t = 1 and 2 
    % in the A data, where t = 1 and 2 are the time values in the B data.
    

    内插到更高的采样率

    我们也可以反其道而行之。您建议您获取一些基本数据A,并填写您对B(或最接近的匹配项)的点数。

    B_new = A;    % Initialise to fast sample data
    % Get row indices of nearest neighbour (in time) by using interp1 and mapping
    % onto a list of integers 1 to number of rows in A 
    idx = interp1(A(:,1), 1:size(A,1), B(:,1), 'nearest', 'extrap');
    % Overwrite those values (which were originally from A) with values from B
    B_new(idx,2) = B(:,2);
    

    【讨论】:

    • 所以你想从B_new = A开始,然后覆盖所有最接近B的点,所以在你的例子中,每个第6个方向的值都来自B,所有其他的来自A?
    • 如果您在 B_new 的第一列上使用 datestr 函数,则应显示时间戳。
    • 两者兼而有之?我不知道“基于 A 中的值的某个值”应该是什么......您已经说过最后一个示例具有矩阵 A 的时间步长,但事实并非如此,它与 B 匹配。请考虑将此答案标记为已接受,并根据您的意愿调整结果,或澄清问题以便回答和关闭。
    猜你喜欢
    • 2022-11-30
    • 2020-11-18
    • 2014-06-19
    • 2012-02-26
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    相关资源
    最近更新 更多