     clear 
close all

addpath('G:\Fixations\DurationDistribution\toolboxdistrib_exgauss\distribV2.3')

%--------------------------FE-----------------------------------
[num,txt,raw] = xlsread('EFED1_durations_0_5000ms.xls', 'G1'); 
AllFixation = num(:); 
val = ~isnan(AllFixation); 
pos = find(val==1); 

AllFixation = AllFixation(pos); %'FE'
nbSujet  = size(num, 1); 
tabNbFixParSujet = zeros(nbSujet); 

%fit pdf Ex_Gauss
nbPts = 1000; 
x = linspace(0, 1.2*max(AllFixation), nbPts); 
nbBin = 50;

ParamsExGaussAllFix     = egfit(AllFixation); 
yExGaussAllFix          = exgausspdf(ParamsExGaussAllFix(1),ParamsExGaussAllFix(2),ParamsExGaussAllFix(3),x); % gets ex-Gaussian density
[eff, bin]              = hist(AllFixation, nbBin); %get empirical density

figure; 
bar(bin, eff)
hold on
plot(x, yExGaussAllFix*sum(eff)*(bin(2)-bin(1)), 'r-', 'linewidth', 2)
legend('G1')
xlabel('Fixation duration')
ylabel('Effectif') 

empiricalPdf = eff/sum(eff)/(bin(2)-bin(1)); %Normalisation 

figure; 
bar(bin, empiricalPdf)
hold on
plot(x, yExGaussAllFix, 'r-', 'linewidth', 2)
legend('G1')
xlabel('Fixation duration [ms]', 'fontsize', 16)
ylabel('pdf', 'fontsize', 16) %Probability density function
title(['\mu= ' num2str(ParamsExGaussAllFix(1)) ', \sigma = ' num2str(ParamsExGaussAllFix(2)) ...
       ', \tau = ' num2str(ParamsExGaussAllFix(3))])
   
fprintf('parameter mu : %5.2f\n', ParamsExGaussAllFix(1));
fprintf('parameter sigma : %5.2f\n', ParamsExGaussAllFix(2));
fprintf('parameter tau : %5.2f\n', ParamsExGaussAllFix(3));
