function [QRS etime] = QRSdetektor_combi(vstup)
%%%Veverka Vojtìch, 2015
stime=tic;
fvz=500;
svodu = size(vstup,1);
sig=vstup(2,:);
QRSpom = cell(1,4);

QRSp = QRSdetektor_global(vstup,'n');
QRSpom(1,1) = {QRSp};
QRSp = QRSdetektor_local(sig,'n');
QRSpom(1,2) = {QRSp};
QRSp = banka_filtru(sig);
QRSpom(1,3) = {QRSp};
QRSp = banka_filtru_global(vstup);
QRSpom(1,4) = {QRSp};
QRSp = umocneni_multi(vstup);
QRSpom(1,5) = {QRSp};
QRSp = obalka_multi(vstup);
QRSpom(1,6) = {QRSp};

QRS=[];
    shluky = shlukovka(QRSpom);
    for i = 1:length(shluky)
        if length(shluky{1,i})>3
           QRS = [QRS median(shluky{1,i})];
        end
    end
  etime=toc(stime);  
end

function shluky = shlukovka(polohy)
mezery=50;
polohy2 = sort(cell2mat(polohy));
if length(polohy2)>=2
    vzdalenosti = pdist(polohy2'); 
    shlukovani = linkage(vzdalenosti); 
    shluk = cluster(shlukovani,'cutoff', mezery,'criterion','distance')'; % nastaveni shlukove analyzy
    [poradi,hodnota] = unique(shluk,'first'); 
    [~,poradi2] = sort(hodnota); 
    shluky = cell(1,length(poradi)); % ulozeni shluku
    for i = poradi
        shluky{i} = sort(polohy2(shluk==poradi2(i)));
    end
else
    shluky = {polohy2};
end
end