How to divide a signal into windows using loops
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Adam Danz
on 17 Jan 2021
Edited: Adam Danz
on 18 Jan 2021
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,:)
Any trailing values of y that didn't fit into the last window are ignored.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!