%83764
%Tomáš Heitel

function [Y,R,S]=segmentaced(x_waterm,wind,prekryv)

% delka vstupniho signalu
N=length(x_waterm);


if length(wind)>1  
    winlen=length(wind);
else  
    winlen=wind;
end

overlen=ceil((prekryv/100)*winlen);

if overlen~=0
Sn= ceil((N-overlen)/(winlen-overlen));
indf= (winlen-overlen)*(0:(Sn-1))';
else
Sn  = ceil((N)/winlen);
indf= winlen*(0:(Sn-1))';
end


% priprava vstupni matice
Y=zeros(winlen,Sn);
inds = (1:winlen);
x_waterm([end+1:((winlen*Sn)-((Sn-1)*overlen))])=0;
Y(:) = x_waterm(indf(:,ones(1,winlen))'+inds(ones(Sn,1),:)');

% vynasobeni vahovacim oknem
if (length(wind) > 1)
     Y = Y.*repmat(wind,1,Sn);
end
%R pocet vzorku v jednom segmentu
%S pocet segmentu
[R S] = size(Y);


