根据采样时间不同的两个数据系列创建新的数据系列

Create new data series based on two data series with different sampling time

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

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

开始时间不完全相同。

我想创建一个新版本的数据集 B,其中包含基于数据集 A 的定向数据(一种合成数据集),其中我每 10 次填写一次记录数据集 A 的分钟数,并保留数据集 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中最近可用时间的方向数据的最佳方法是什么,同时仍保持与新矩阵中A相同的数据采样B?

这很容易通过 interp1(table 查找函数)实现。


内插到较慢的采样

假设您有一些非常干净的数据 AB 用于此演示...

% 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) ].';

现在我们使用interp1A中获取最接近的数据值(根据时间列)并将其分配给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);