function [hranice]=speech_segmentation(signal, Fvz)

load speech_segmentation_seting


 signal = signal - mean(signal); %ustredneni
 
 signal = filter([1 -0.97], 1, signal); %preemfaze
 
 signal = signal / max(abs(signal));%normovani vstup. sig.


[mel_koef1, mel_banka, ramce] = melcepst(signal, Fvz, 'eMtaz', 8, 8, okno, prekryv, 0, 0.5); %mfcc

[m0,n0] =  size(signal);
[m1,n1] = size(mel_banka); % zjistim pocet radku(koef.) a sloupcu(ramce)

%normovani 
%  for j = 1:n1
%      mel_banka(:,j) = (mel_banka(:,j))./(max(abs(mel_banka(:,j))));
%  end  

Euklid_mel_banka = zeros(m1,n1-1);

for j = 1:n1
    if j<n1
        Euklid_mel_banka(:,j) = (mel_banka(:,j) - mel_banka(:,j+1)).^2;
    end
end

Euklid_mel_banka = sqrt(sum(Euklid_mel_banka));

[m2,n2] = size(Euklid_mel_banka);
pocet = floor(m0/n2);
Euklid_mel_banka1 = zeros(1,m0);
for k = 1:n2
    for l = 1:pocet
        nkoef(1,l) = Euklid_mel_banka(1,k);
    end
        Euklid_mel_banka1(1,(((k+1)*pocet)-pocet)+1:pocet*(k+1)) = nkoef(1,:);
end


%normování křivky rozdílnosti
Euklid_mel_banka=Euklid_mel_banka/max(Euklid_mel_banka);

% Vypocet maxim (hranic)
D_Euklid_mel_banka=diff(Euklid_mel_banka);  %zderivuje
for n=1:length(Euklid_mel_banka)-1-1     %po derivaci ubude vzorek
    PN(n)=(sign(D_Euklid_mel_banka(n))-sign(D_Euklid_mel_banka(n+1)))/2; %urci Max a min
end   
for n=1:length(Euklid_mel_banka)-1-1
    if PN(n) <0;
        PN(n)=0; % Vybere jen Maxima
    end
end

M=[0 PN 0]; % doplni na pocet segmentu

%prahovani maxim
prah=find(Euklid_mel_banka < 0.2);%3.4 pokud se nenormuje
M(prah)=0;

%roztazeni maxim (doplneni nulami) na delku signalu
M2=zeros(1,length(signal)); 
    for n=1:length(Euklid_mel_banka)                          
        M2(round(n*(length(signal)/length(Euklid_mel_banka))))=M(n); 
    end

%nalezene hranice
 hranice=find(M2);
