function [F] = Pitch_ACF_final(y, Fs, delka_okna, znelost_handle, znelost_delka_okna) %handle volej jako @STE

    [~, znelost] = znelost_handle(y, Fs, znelost_delka_okna);
    [b,a] = butter(9,400/Fs);
    y = filter(b,a,y);

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

    for i = 1:pocet_oken
        if znelost(i) == 0
            Y(:,i) = 0;
        else
            Y(:,i) = Y(:,i);
        end
    end

    y = reshape(Y,1,[]);
    y = y(1:end - (pocet_vzorku_okna-remainder));
    

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


    for i = 1:1:pocet_oken
    
        R = autocorr(Y(:,i),pocet_vzorku_okna-1);
        [~, locs] = findpeaks(R);
    
        if isempty(locs)        
            dist(i) = NaN;
        else
            dist(i) = locs(2)-locs(1);
        end
    
        F(i) = Fs/dist(i);
    
    end

    y = reshape(Y,1,[]);
    y = y(1:end - (pocet_vzorku_okna-remainder));
    
end