
function [dprime,c] = sdt_calculation(x, c, classif)

if ~classif
    % computing behavior
    ntrials = numel(x); %
    correction_param = 1/(2*ntrials);
    signal = numel(find( x == 1 )); %
    hits = numel(find(x == 1  & c == 1)); %
    phit = hits/signal;
    
    if phit == 1;
        phit = phit-correction_param;
    end
    if phit == 0;
        phit = phit+correction_param;
    end
    noise = numel(find(x == 0 )); %
    fa = numel(find(x == 0  & c == 0)); %
    pfa = fa/noise;
    
    if pfa == 1;
        pfa = pfa-correction_param;
    end
    
    if pfa == 0;
        pfa = pfa+correction_param;
    end
    
    prop_correct =  mean(c); %
    
    dprime = norminv(phit) - norminv(pfa);
    c = -0.5*(norminv(phit) + norminv(pfa));
    
else
    
    %% Recoding classifier performance in consonance with SDT
    ntrials = numel(x); %
    correction_param = 1/(2*ntrials);
    hits = c(:,:,x==1 );
    fas = c(:,:,x==0 );
    hits_mean = mean(hits, 3);
    fas_mean = mean(fas, 3);
    idxsp =  find(hits_mean == 1);
    hits_mean(idxsp) = hits_mean(idxsp)-correction_param;
    idxsp =  find(hits_mean == 0);
    hits_mean(idxsp) = hits_mean(idxsp)+correction_param;
    idxsp =  find(fas_mean == 1);
    fas_mean(idxsp) = hits_mean(idxsp)-correction_param;
    idxsp =  find(fas_mean == 0);
    fas_mean(idxsp) = fas_mean(idxsp)+correction_param;
    
    
    dprime =  norminv(hits_mean) - norminv(fas_mean);
    c =  -(norminv(hits_mean) + norminv(fas_mean))/2;
    
    
end

end