How to divide a signal into windows using loops

3 次查看(过去 30 天)
i have a signal y which is 11439 long supposing it is y=randn(1,11439) which I want to divide into windows of lengths [16,64,256,1024,4096] where each window overlaps with 50% of the previous window
using 16 as an example I want the whole signal to be divided to windows of length 16 where each window overlaps with the previous by 50% like 1:16 then 8:24 and store each window
how can I implement that using a for loop or if statement

采纳的回答

Adam Danz
Adam Danz 2021-1-17
编辑:Adam Danz 2021-1-18
y=randi(100,1,11439); % Integers used for easy comparison
n = 16; % must be even
windowStart = [1, n/2+1:n/2:numel(y)];
windowStop = n:n/2:numel(y);
nColumns = floor(numel(y)/(n/2))-1;
ym = nan(nColumns,n);
for i = 1:nColumns
ym(i,:) = y(windowStart(i):windowStop(i));
end
View results; you can see columns 9:16 of row n match columns 1:8 for row n+1.
ym(1:4,:)
ans = 4×16
63 73 82 27 3 25 35 41 33 48 76 80 5 40 54 21 33 48 76 80 5 40 54 21 39 93 98 59 37 92 74 2 39 93 98 59 37 92 74 2 62 34 47 39 39 87 51 100 62 34 47 39 39 87 51 100 9 70 9 76 99 47 92 59
Any trailing values of y that didn't fit into the last window are ignored.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by