function [FAR0,HR0]=vyhodnotROC(vst_sig,roc,zasum,p)

% Funkce pro vyhodnoceni ROC charakteristik jednotlivych detektoru
%
% Priklad spusteni: [FAR0,HR0]=vyhodnotROC('sny',0,0,0.2)
% roc - pri volbe 1, se zobrazi krivky ROC
% zasum - pri volbe 1 dojde k zasumneni signalu (SNR = 30, 20, 10, 5, 0, -5 dB)
% 
% ve stejne slozce musi byt funkce idealni.m, vst_sig.wav a soubor vst_sig.dat
%
% 2008   Michal Adamec VUT Brno (v ramci Diplomove prace - Moderni rozpoznavace reci)



[y,Fvz] = wavread(vst_sig);                     %nacteni signalu
alfa = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
%% Vytvoreni ROC %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% podminka pro pridani sumu do signalu
if zasum==1
    for i = 1:6
        snr=[30 20 10 5 0 -5];
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%% zasumneni signalu, pro snizeni SNR%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        z = awgn(y,snr(i),'measured');                 	 %pridani white Gaussian noise (bily sum), odstup sig sum je nastaven dle cisla v zavorce
        wavwrite(z,Fvz,'sum');                           %ulozeni zasumneleho signalu
        v = 0;
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%%%%%%%%% detetekce pomoci detektoru%%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        %%%%%%%% Testovany detektor odkomentujte %%%%%%%%%%    
  
        %  [v]=detektor('sum',256,30);
           [v]=vadcepstralni('sum',256,30,p,alfa(8),0,0);
        %  [v]=vadenerg('sum',256,30,p,alfa(1),0,0);
        %  [v] =vadintenz('sum',256,30,p,alfa(4),0,0);
        %  [v]=g729('sum',0.1,0.1,0.1,0.1,0);

        if i==1
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %%%% Idealni/rucni detekce%%%%%
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            lv = length(v);
            dat='.dat';
            dat = strcat(vst_sig,dat);
            ideal = idealni(dat,lv);
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        end
        a          = sum(ideal.*v);              % pocet shodnych detekci reci
        idealpauza = double(~ideal);             % inverzni vektor k vektoru ideal (obsahuje "1" na mistech recove pauzy)
        vpauza     = double(~v);                 % inverzni vektor k vektoru v (obsahuje "1" na mistech recove pauzy)
        b          = sum(idealpauza.*vpauza);    % pocet shodnych detekci pauz

        HR0(i)  = b/sum(idealpauza)*100;         % vypocet HR0[%] - relativni pocet shodnych detekci ramcu recovych pauz
        HR1(i)  = a/sum(ideal)*100;              % vypocet HR1[%] - relativni pocet shodnych detekci recovych ramcu
        FAR0(i) = 100-HR1(i);                    % plany poplach
    end

    %%% podminka pro neprimichavani sumu do signalu 
    %%% (muze se menit parametr alfa)    
elseif zasum==0
    for i = 1:11
        v = 0;
        
        %%%%%%%% Testovany detektor odkomentujte %%%%%%%%%%
        
        %[v]=detektor(vst_sig,256,10);
        [v]=vadcepstralni(vst_sig,256,30,p,alfa(i),0,0);
        %[v]=vadenerg(vst_sig,256,30,p,alfa(i),0,0);
        %[v]=vadintenz(vst_sig,256,30,p,alfa(i),0,0);
               
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%% Idealni/rucni detekce%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        lv = length(v);
        dat='.dat';
        dat = strcat(vst_sig,dat);
        ideal = idealni(dat,lv);
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        a          = sum(ideal.*v);              % pocet shodnych detekci reci
        idealpauza = double(~ideal);             % inverzni vektor k vektoru ideal (obsahuje "1" na mistech recove pauzy)
        vpauza     = double(~v);                 % inverzni vektor k vektoru v (obsahuje "1" na mistech recove pauzy)
        b          = sum(idealpauza.*vpauza);    % pocet shodnych detekci pauz

        HR0(i)  = b/sum(idealpauza)*100;         % vypocet HR0[%] - relativni pocet shodnych detekci ramcu recovych pauz
        HR1(i)  = a/sum(ideal)*100;              % vypocet HR1[%] - relativni pocet shodnych detekci recovych ramcu
        FAR0(i) = 100-HR1(i);                    % plany poplach
    end
end
HR0=HR0';
HR1=HR1';
FAR0=FAR0';


plot (FAR0,HR0,'x-'); figure(gcf);
grid on;
axis([0 max(FAR0)+5 0 100]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Grafické znázornění ROC křivek %%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if roc==1
    if zasum==1
        figure(9)
        subplot(2,1,1)
        plot(FAR0,HR0)
        title('ROC krivka');xlabel('FAR0 (%)');ylabel('HR0 (%)');
        subplot(2,1,2)
        plot(snr,HR0)
        title('Závislost HR0 na SNR ');xlabel('SNR (dB)');ylabel('HR0 (%)');
    else
        figure(9)
        plot(FAR0,HR0)
        title('ROC křivka');xlabel('FAR0 (%)');ylabel('HR0 (%)');
    end
end