【问题标题】:Need help aligning time series data in MATLAB需要帮助在 MATLAB 中对齐时间序列数据
【发布时间】:2014-07-24 15:03:26
【问题描述】:

因此,我和我的朋友在 2 周前进行了一项实验,我们遇到了一些奇怪的事情。我应该先说,如果这是一个愚蠢的问题并且似乎是在浪费时间,我真的不会编程,所以很抱歉。

假设我们有数据集 A 和数据集 B(实验本身并不重要)。所有时间都以小数天数给出。数据的格式应该全部匹配,但是为每组记录数据点的时间不一定对齐(它们都有自己的时间向量)。例如,数据集 A 的测量值每 100 毫秒记录一次。但是,数据集 B 的仪器正在对数据进行平均,并且每分钟左右只记录一个点。我的问题是调整收集不同类型数据的时间。对于数据集 A,数据和时间向量的长度为 25042(25042x1 双倍)。数据集 B 及其时间向量的长度为 828 (828x1 double)。

归结为我需要查看数据集 B,并找到与数据中的峰值相对应的时间。这些时间是我在数据集 A 中唯一感兴趣的时间。这就是为什么我需要一种对齐时间向量/序列以及数据的方法。如果一个精确的解决方案是不可能的,即使是一个近似值也会有很大的帮助。有人有什么想法吗?

【问题讨论】:

  • 求B中连续点之间的差值。C = B(2,end) - B(1,end-1) 当C中符号由正变为负时,你有一个峰值.

标签: algorithm matlab time linear-algebra


【解决方案1】:

因此,您有两个时间向量:tAtB,以及一个包含已知峰值的时间索引向量 bIndices。这对应于时间tB(bIndices(:))。您需要遍历整个向量 bIndices 再次搜索整个向量 tA(:) FULLY 直到时间大于或等于 tB(b)

bIndices = [101, 403,...];  %Vector containing the indices of the peaks in 'tB'
aIndices = [];              %Allocate an empty vector
A = [];                     %Allocate an empty vector
B = [];                     %Allocate an empty vector
for b = bIndices            %This will cycle through all peak indices one at a time setting 'b' to the current single index
    B = [B tB(b)];          %Retrieve the actual time using the index, concatenate it
    for a = 1:length(tA)    %Loop through the entire time vector tA
        if (tA(a) >= tB(b)) %Time is greater than or equal
             %Concatenate the newly found index 'a' from tA to the vector aIndex:
             aIndices = [aIndices a];
             %Concatenate the newly found time 'tA(a)' to the time vector A:
             A = [A tA(a)]; %Or if you want the actual time
             break;         %Exit the inner loop, search for the next index `b`
        end
    end
end

最后,A 存储了一组与B 中所有时间相匹配的峰值时间(大约,可能稍晚一点)。 A-B 是两个时间之间的差异(两个向量应该是相同的长度),但它应该非常小,任何零都意味着 2 在这些情况下完全对齐。 aIndicestA 在所需时间的对应索引。我实际上并没有测试这段代码,希望我的逻辑是正确的。

【讨论】:

  • 为什么是循环?为什么不find(tA>B,1,'first')
  • 这是一个很好的速记建议,但对于教育解释来说并不是很好。授人以鱼还是授人以渔?
  • 这对我来说很困难,因为我有一个已知峰值出现位置的向量。这不仅仅是一个数字。有什么建议吗?我尝试使用 2 个 for 循环,但无法正常工作。
  • 查看新的编辑。我没有测试它,但它应该可以工作。
猜你喜欢
  • 2014-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-25
  • 2015-01-07
  • 2019-12-25
  • 2013-06-14
相关资源
最近更新 更多