function [y2, znelost, Y] = HNR_final(y, Fs, delka_okna)    


    [Y, pocet_oken, pocet_vzorku_okna, remainder] = SEG_A_DOPLN(y, Fs, delka_okna);



    for i = 1:pocet_oken
        a = xcorr(Y(:,i),Y(:,i),pocet_vzorku_okna,'coeff');
        n = ceil(length(a)/2);
        a = a(n:end);

        max0 = a(1);
    
            for lag = 2:length(a)
                sample = a(lag);
                if(( max0 > 0 ) && ( sample < 0 )) 
                    zero_position = lag; 
                    break; 
                elseif(( max0 == 0 ) || ( sample == 0)) 
                    zero_position = lag; 
                    break; 
                else 
                    max0 = sample; 
                end
            end
        
        
        max1 = max(a(zero_position:end));
        r(i) = max1;
        HNR1(i)= 10*log10(r(i)/(1-r(i))); 
    
        threshold = 0.5;
        if  (HNR1(i) > 0.5) znelost(i)=1;
        else znelost(i)=0;
        end
    
    end
    
    
    
    for n = 1:pocet_oken
    
        if znelost(n) == 0
            Y(:,n) = 0;            
        else
            Y(:,n) = Y(:,n);
        end
        
    end
        
        
     y2 = reshape(Y,1,[]);
     y2 = y2(1:end - (pocet_vzorku_okna-remainder));
    
     
     
end