function [startseg,durseg,nseg]=retrieveSegDur(data,dur,srate)

dur_npts=dur*srate;
data = cell2mat(data);

wv = zeros(size(data,1),size(data,2));
ind_w_s = zeros(size(data,1),size(data,2));

for i=1: size(data,1)
    w = diff([0 data(i,:) 0] == 1);
    t1 = find(w == -1) - find(w == 1);
    t2 = find(w==1);
    wv(i,1:size(t1,2))=t1;
    ind_w_s(i,1:size(t2,2))=t2;
    ind_w_s(i,wv(i,:)<=dur_npts)=0;
    wv(i,wv(i,:)<=dur_npts)=0;
end

data_seg=zeros(size(data,1),size(data,2));

for i=1: size(data,1)
    data_seg(i,ind_w_s(i,:):ind_w_s(i,:)+wv(i,:)-1)=1;
end

startseg = cell(size(ind_w_s,1),1);
durseg = cell(size(wv,1),1);

for i=1: size(ind_w_s,1)
    startseg{i}= ind_w_s(i,ind_w_s(i,:)~=0);
    durseg{i}= wv(i,wv(i,:)~=0);
end

nseg = 0;
for i=1:size(data,1)
    nseg = nseg + size(startseg{i,1},2);
end

end