Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:30   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 用于活动识别的滑动窗口算法

我想编写一个用于活动识别的滑动窗口算法。

训练数据为,所以我认为我只需要获取(例如window_size=3 )数据的window_size并对其进行训练。稍后我也想在矩阵上使用此算法。

我是Matlab的新手,所以我需要有关如何正确实施此方法的任何建议/指导。



回答:

简短的答案:

%# nx = length(x) %# nwind = window_size idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix(nx/nwind)-1))*nwind)-1; idx将是大小为nwind-by-K的矩阵,其中K是滑动窗口的数量(即,每一列包含一个滑动窗口的索引)。

请注意,在上面的代码中,如果最后一个窗口的长度小于所需的长度,则将其删除。滑动窗口也不重叠。

一个例子来说明:

%# lets create a sin signal t = linspace(0,1,200); x = sin(2*pi*5*t); %# compute indices nx = length(x); nwind = 8; idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix(nx/nwind)-1))*nwind)-1; %'# loop over sliding windows for k=1:size(idx,2) slidingWindow = x( idx(:,k) ); %# do something with it .. end %# or more concisely as slidingWindows = x(idx); 编辑:

对于重叠的窗口,让:

noverlap = number of overlapping elements 然后将以上内容更改为:

idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix((nx-noverlap)/(nwind-noverlap))-1))*(nwind-noverlap))-1;
显示结果的示例:

>> nx = 100; nwind = 10; noverlap = 2; >> idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix((nx-noverlap)/(nwind-noverlap))-1))*(nwind-noverlap))-1 idx = 1 9 17 25 33 41 49 57 65 73 81 89 2 10 18 26 34 42 50 58 66 74 82 90 3 11 19 27 35 43 51 59 67 75 83 91 4 12 20 28 36 44 52 60 68 76 84 92 5 13 21 29 37 45 53 61 69 77 85 93 6 14 22 30 38 46 54 62 70 78 86 94 7 15 23 31 39 47 55 63 71 79 87 95 8 16 24 32 40 48 56 64 72 80 88 96 9 17 25 33 41 49 57 65 73 81 89 97 10 18 26 34 42 50 58 66 74 82 90 98

更多&回答...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:15


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.