【发布时间】:2017-10-24 00:37:43
【问题描述】:
我是菜鸟,我在 Slinding Window 的堆栈上发现了非常零散的信息。
我有一个 mXn 矩阵,其中 m 是固定的(纬度、经度、ax、y、az),n 可以从不同的日志中改变。
1) 我怎样才能只为 az 创建一个滑动窗口而不提取向量然后分析它?
2) 如果我想保存 az 标准差超过定义阈值的所有行,我该怎么做?
3) 如果日志长度不固定,我该如何处理? (例如,一个文件包含 932 行,另一个包含 953 行)
4) 我读了很多问题,我正在研究 bsxfun 在这种情况下是如何工作的,但对我来说还不清楚(in this examples 我只是不明白 根据窗口大小创建一个新矩阵,然后分析新矩阵)(最后一个问题与我的土木工程师背景密切相关)
这是我学到的,并试图汇总。
滑动窗口是一个强大的工具,可以分析信号或图像。 当我试图向我的女朋友描述我在做什么时,我解释了 “就像用放大镜看书, 放大镜有一个定义的尺寸,你分析文本”
Matlab 上的基本方法,不是最有效的,这样做是
1.定义矢量尺寸
2。定义您的窗口尺寸
3.定义步数
这是我写的一个基本示例
a= randi(100,[1,50]); %Generic Vector
win_dim=3; %Generic window size
num_stps=(length(a)-win_dim) %number of "slides", we need to subtract win_dim to avoid that the window will go over the signal
threshold= 15 %Generic number only for the example
for i= 1:num_stps
mean_win(i)=mean(a(i:i+win_dim -1); %we subtract 1 or we make an error, and the code analyzes a segment bigger than one unit
std_win(i)=std( a(i:i+win_dim -1); %example for i=2 if we don't subtract 1 our segment starts from 2 until 5, so we analyze
% 2 3 4 5, but we defined a window dimension of 3
If std_win(i)> threshold
std_anomalies=std_win(i) %here i think there is an error
end
这样代码会在整个信号上滑动,但窗口会重叠。
如何确定“重叠率”(或幻灯片增量)?
我们可以将其定义为“两个相邻窗口共享多少信息?” 我所做的以下示例是完全错误的,但我在问这里之前尝试编写一些代码,目标本来希望是 一半的片段或没有重叠
的重叠%Half segment overlap
a= randi(100,[1,20]); %Generic Vector
win_dim=4; %generic window size
%v is the increment vector in our case we desire to have 50% of overlap
l= win_dim
if l%2==0
v=l/2
else
v=(l+1)/2
end
for i= 1:num_stps
if (i==1)
mean_win(i)=mean(a(1:1+win_dim -1);
else
mean(i)= mean(a (i+v:i+win_dim+v-1);
end
【问题讨论】:
标签: matlab sliding-window bsxfun