How to segment data using overlapping window
Mostrar comentarios más antiguos
Hello, I have an ECG data of 20mins length (2x307200). I want to apply a 20 sec window(5120) with an overlap of 64samples. I want 20 sec segments so i can extract features from it. I tried to write a loop for window but it doesn't give me right answer. Can somebody help me.
ECG_data=[time; ECG];
N_max=length(ECG_data);
n_window=5120;
overlap_win=64;
count=1;
for n_start = 1:overlap_win:(N_max-n_window)
New_data(count,:) = ECG_data(n_start_1:(n_start+ n_window));
do something..
mean(count,:)=mean(new_data);
count=count+1;
end
The number of samples in each window is limited to 4720 sample(thats 18 sec) even though i need 20sec(5120). What am I doing wrong here? it something to do with the termination of window?? Also how can i retain the time information after applying window?
Respuesta aceptada
Más respuestas (2)
LauraLee Austin
el 6 de Oct. de 2016
It was not clear to me how/where you wanted the overlap. Below is my quick stab at what I think you might be looking for. It is not efficient.
ECG_data=[time; ECG];
N_max=length(ECG_data);
n_window=5120;
overlap_win=64;
max_count = ceil((length(ECG_data)-n_window)/(n_window-overlap_win))+1;
new_data = zeros(max_count,n_window);
n_start=1;
for count = 1:max_count
n_end = n_start + n_window - 1;
if n_end > N_max
new_data(count,1:N_max-n_start+1) = ECG(n_start:N_max);
else
new_data(count,:) = ECG(n_start:n_end);
end
n_start = n_end-overlap_win;
% do something..
end
ECG_mean=mean(new_data');
Fars Samann
el 26 de Jun. de 2022
1 voto
Simply use buffer.m and define the length of the window and the overlapped part
with regards
Fars
1 comentario
Alistair Steyn-Ross
el 21 de Jun. de 2023
Great suggestion. The 'buffer' function handles overlap, underlap, and no overlap. It's a compiled function (in Signal Processing toolbox) so should run very fast. The built-in documentation illustrates with an informative example:
x = 1:18; % Example input data to be buffered
y = buffer(x, 8, 4); % Create overlapping buffer matrix
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!