Filter löschen
Filter löschen

How to divide a signal into windows using loops

2 Ansichten (letzte 30 Tage)
Mohamed Medhat
Mohamed Medhat am 17 Jan. 2021
Bearbeitet: Adam Danz am 18 Jan. 2021
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

Akzeptierte Antwort

Adam Danz
Adam Danz am 17 Jan. 2021
Bearbeitet: Adam Danz am 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,:)
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by