How to segment data using overlapping window
97 views (last 30 days)
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.
for n_start = 1:overlap_win:(N_max-n_window)
New_data(count,:) = ECG_data(n_start_1:(n_start+ n_window));
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?
Guillaume on 6 Oct 2016
Edited: Guillaume on 6 Oct 2016
Something that's really not clear is that your ECG_data has two rows, yet within your loop you're using linear indexing, which is not consistent. The end result, when n_start is 1 is that New_data(1, :) is [time(1), ECG(1), time(2), ECG(2), ...].
Assuming you only want the second row (ECG) of ECG_data in new_data, a very simple way to create it in one go, without a loop is with:
Matlab R2016b or later only:
new_data = ECG((0:64:307200)' + (1:5120));
Any version of matlab:
new_data = ECG(bsxfun(@plus, (0:64:307200)', 1:5120));
You can do the same with time if needed
More Answers (2)
LauraLee Austin on 6 Oct 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.
max_count = ceil((length(ECG_data)-n_window)/(n_window-overlap_win))+1;
new_data = zeros(max_count,n_window);
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);
new_data(count,:) = ECG(n_start:n_end);
n_start = n_end-overlap_win;
% do something..