难以理解滑动 Window 矩阵的一列,Matlab 中的一般情况和特定情况
Trouble Understanding Sliding Window for a column of a matrix, general and specific case in Matlab
我是菜鸟,我在 Slinding 的堆栈上发现了非常零散的信息 Window。
我有一个 mXn 矩阵,其中 m 是固定的(纬度、经度、ax、ay、az),n 可以根据不同的日志进行更改。
1) 如何在不提取矢量然后分析的情况下只为 az 创建滑动 window?
2) 如果我想保存 az 标准偏差超过定义阈值的所有行,我该怎么做?
3) 如果日志长度不固定,我该如何处理? (例如,一个文件包含 932 行,另一个文件包含 953 行)
4) 我读了很多问题,我正在研究 bsxfun 在这种情况下是如何工作的,但我不太清楚 (in this examples 我只是不明白
根据 window 大小创建一个新矩阵,然后分析新矩阵)(最后一个问题与我的土木工程师背景密切相关)
这是我学到的,并尝试汇总的。
滑动 Window 是一个强大的工具,可以分析信号或图像。
当我试图向我的女朋友描述我在做什么时,我解释了
“就像拿着放大镜看书,
放大镜有一个定义的尺寸,你可以分析文本”
Matlab 上的基本方法(不是最有效的方法)是
1.定义向量维度
2。定义你window维度
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
这样代码会在整个信号上滑动,但是windows会重叠。
如何决定"overlap ratio"(或滑动增量)?
我们可以这样定义 "how much informations two adjacent windows share?"
下面的例子我做的是完全错误的,但我试着在问这里之前编写一些代码,目标是重叠 一半的片段或没有重叠
%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
我喜欢这个问题的创造性方法! :) 这就是您要找的吗?
a = rand(100, 5); % the data
window_size = 5; % size of the window
overlap = 2; % desired overlap
step = window_size - overlap; % compute the step
threshold = 0.3; % large std threshold
std_vals = NaN(size(a, 1), 1);
for i=1:step:(size(a, 1) - window_size)
std_vals(i) = std(a(i:(i+window_size-1),5)); % calculate std of 5th col
end
% finding the rows with standard deviation larger than threshold
large_indexes = find(std_vals>threshold);
large_indexes
将为您提供标准偏差大于阈值的 windows 的起始行。 std_vals
将为您存储所有标准差,以备日后需要。
如果你想要window中所有行的索引都满足你的阈值,你可以在最后添加这个
large_windows = zeros(numel(large_indexes), window_size);
for i=1:window_size
large_windows(:,i) = large_indexes + i - 1;
end
其中 large_windows
的每一行给出 window 中行的索引。
我是菜鸟,我在 Slinding 的堆栈上发现了非常零散的信息 Window。
我有一个 mXn 矩阵,其中 m 是固定的(纬度、经度、ax、ay、az),n 可以根据不同的日志进行更改。
1) 如何在不提取矢量然后分析的情况下只为 az 创建滑动 window?
2) 如果我想保存 az 标准偏差超过定义阈值的所有行,我该怎么做?
3) 如果日志长度不固定,我该如何处理? (例如,一个文件包含 932 行,另一个文件包含 953 行)
4) 我读了很多问题,我正在研究 bsxfun 在这种情况下是如何工作的,但我不太清楚 (in this examples 我只是不明白 根据 window 大小创建一个新矩阵,然后分析新矩阵)(最后一个问题与我的土木工程师背景密切相关)
这是我学到的,并尝试汇总的。
滑动 Window 是一个强大的工具,可以分析信号或图像。 当我试图向我的女朋友描述我在做什么时,我解释了 “就像拿着放大镜看书, 放大镜有一个定义的尺寸,你可以分析文本”
Matlab 上的基本方法(不是最有效的方法)是
1.定义向量维度
2。定义你window维度
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
这样代码会在整个信号上滑动,但是windows会重叠。
如何决定"overlap ratio"(或滑动增量)?
我们可以这样定义 "how much informations two adjacent windows share?"
%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
我喜欢这个问题的创造性方法! :) 这就是您要找的吗?
a = rand(100, 5); % the data
window_size = 5; % size of the window
overlap = 2; % desired overlap
step = window_size - overlap; % compute the step
threshold = 0.3; % large std threshold
std_vals = NaN(size(a, 1), 1);
for i=1:step:(size(a, 1) - window_size)
std_vals(i) = std(a(i:(i+window_size-1),5)); % calculate std of 5th col
end
% finding the rows with standard deviation larger than threshold
large_indexes = find(std_vals>threshold);
large_indexes
将为您提供标准偏差大于阈值的 windows 的起始行。 std_vals
将为您存储所有标准差,以备日后需要。
如果你想要window中所有行的索引都满足你的阈值,你可以在最后添加这个
large_windows = zeros(numel(large_indexes), window_size);
for i=1:window_size
large_windows(:,i) = large_indexes + i - 1;
end
其中 large_windows
的每一行给出 window 中行的索引。