% Se placer dans le dossier contenant les dossiers de tous les participants
% (le nom de chaque dossier doit se terminer par le nom du
% participant)

clear all
close all

%% Creating structure cfg_cmp and loading data from all subjects

fprintf('\n** Creating structure cfg_cmp **\n');
clear cfg_cmp reprisetrial n_stim RSB n_signal responsetime n_reponse is_correct

% Paramètres de calcul
cfg_cmp.Subject = {'6','11','14','16','17','18','19','21','22','23','25','26','27','28','29','30','31','32'}; % Liste des sujets à inclure dans le calcul
cfg_cmp.fenetre_calcul = 500; % Fenetre (en nombre d'essais) pour effectuer les moyennes. Si vide, utiliser les pauses.

cfg_cmp = set_default_cfg(cfg_cmp, 'N_Subject', length(cfg_cmp.Subject));
liste_folder = dir;
cd_root = cd;
fprintf('\n** Loading data for all subjects **\n');
for i_subject = 1:cfg_cmp.N_Subject
    fprintf(['Loading subject ' cfg_cmp.Subject{i_subject} '\n']);
    cd(cd_root)
    idx_folder = 0;
    for i_dir=1:length(liste_folder)
        if length(liste_folder(i_dir).name) > length(cfg_cmp.Subject{i_subject}) && strcmp(liste_folder(i_dir).name(end-length(cfg_cmp.Subject{i_subject}):end),['S' cfg_cmp.Subject{i_subject}])
            idx_folder=i_dir;
        end
    end
    if idx_folder==0
        error(['dossier S' num2str(cfg_cmp.Subject{i_subject}) ' introuvable']);
    end
    cd(liste_folder(idx_folder).name);
    load('savegame_final.mat');
    
    if exist('cfg_pass')
        cfg_cmp.cfg_pass{i_subject}         = cfg_pass;
    else
        fprintf(['importation warning : structure cfg_pass does not exist for subject ' cfg_cmp.Subject{i_subject} '\n'])
    end
    
    reprisetrial{i_subject} = data_passation.reprisetrial;
    n_stim(i_subject,:) = data_passation.n_stim;
    RSB(i_subject,:) = data_passation.RSB;
    n_signal(i_subject,:) = data_passation.n_signal;
    responsetime(i_subject,:) = data_passation.responsetime;
    n_reponse(i_subject,:) = data_passation.n_reponse;
    is_correct(i_subject,:) = data_passation.is_correct;
end
cd(cd_root);

for i_subject = 1:cfg_cmp.N_Subject
   compare_cfg(cfg_cmp.cfg_pass{1},cfg_cmp.cfg_pass{i_subject}, 'FolderInBruit', 'FolderInSignal', 'N', 'N_signal', 'N_response', 'NameSignal', 'NameResponse', 'CorrectResponses');
end
cfg_cmp = import_cfg(cfg_cmp.cfg_pass{1}, cfg_cmp, 'FolderInBruit', 'FolderInSignal', 'N', 'N_signal', 'N_response', 'NameSignal', 'NameResponse', 'CorrectResponses');

cfg_cmp = set_default_cfg(cfg_cmp, 'FolderInBruit', 'ListeBruit', 'FolderInSignal', 'ListeSignal', 'N', length(ListStim), 'N_signal', max(data_passation.n_signal),...
    'N_response', max(data_passation.n_reponse), 'NameSignal', {'signal#1', 'signal#2'}, 'NameResponse', {'signal#1', 'signal#2'});
cfg_cmp = set_default_cfg(cfg_cmp, 'CorrectResponses', 1:cfg_cmp.N_signal);

if isempty(cfg_cmp.fenetre_calcul)
    if isfield(data_passation,'reprisetrial')
        cfg_cmp.fenetre_calcul = data_passation.reprisetrial(2)-1;
    else
        cfg_cmp.fenetre_calcul = 500;
    end
end

fprintf(['\n=> Loading complete, N = ' num2str(cfg_cmp.N_Subject) '\n']);
clear cd_root cfg_pass i_dir i i_subject idx_folder liste_folder symbol color data_passation ListStim

%% SNR values for each participant
% utilise la fonction plotspread (http://www.mathworks.com/matlabcentral/fileexchange/37105-plot-spread-points--beeswarm-plot-/content/plotSpread/plotSpread.m)

pas_affichage = 0.5;
RSB_affiche = [-22 0];

figure; plotspread(RSB','xNames',cfg_cmp.Subject, 'showMM', 2, 'spreadFcn', {'lin',200}, 'binWidth', 0.01); title('SNR values for each participant');ylabel('SNR (dB)');xlabel('participant number');
RSB_level=RSB_affiche(1):pas_affichage:RSB_affiche(2);
H=histc(RSB',RSB_level);
figure;bar(RSB_level,H);xlim(RSB_affiche)

%% Participants' scores

fprintf('\n** Participants'' scores **\n')
for i_subject = 1:cfg_cmp.N_Subject
    for i=1:cfg_cmp.N_signal
        correct_rate_signal(i_subject,i) = mean(double(is_correct(i_subject,find(n_signal(i_subject,:)==i))));
    end
    H(i_subject)=mean(correct_rate_signal(i_subject,find(cfg_cmp.CorrectResponses==2)));
    M=1-H;
    FA(i_subject)=mean(1-correct_rate_signal(i_subject,find(cfg_cmp.CorrectResponses==1)));
    CR=1-FA;
    dprime(i_subject)=norminv(H(i_subject),0,1)-norminv(FA(i_subject),0,1);
    decisionc(i_subject)=-0.5*(norminv(H(i_subject),0,1)+norminv(FA(i_subject),0,1));
    decisionca(i_subject)=-norminv(FA(i_subject),0,1);
end

figure
boxplot([mean(correct_rate_signal,2) correct_rate_signal(:,1) correct_rate_signal(:,2) correct_rate_signal(:,3) correct_rate_signal(:,4) mean(correct_rate_signal(:,[1 2]),2) mean(correct_rate_signal(:,[3 4]),2)], 'labels', {'global', 'Alda', 'Alga', 'Arda', 'Arga', 'Al-', 'Ar-'});
ylabel(['Participants'' mean score']);ylim([0 1]);title('Participants'' scores for each condition');
figure
plot_multichar(0.5:6.5,[mean(correct_rate_signal,2) correct_rate_signal(:,1) correct_rate_signal(:,2) correct_rate_signal(:,3) correct_rate_signal(:,4) mean(correct_rate_signal(:,[1 2]),2) mean(correct_rate_signal(:,[3 4]),2)], generate_symbol_list(cfg_cmp.N_Subject,'noline'));
ylabel(['Participants'' mean score']);ylim([0 1]);xlim([0 7]);set(gca,'XTick',0.5:6.5);set(gca,'XTickLabel',{'global', 'Alda', 'Alga', 'Arda', 'Arga', 'Al-', 'Ar-'});legend(cfg_cmp.Subject,'Location','NorthEastOutside');title('Participants'' scores for each condition');

[~,p] = ttest(correct_rate_signal(1,:),correct_rate_signal(2,:));
fprintf(['Paired ttest on participants'' scores, ' cfg_cmp.NameSignal{31} ' vs ' cfg_cmp.NameSignal{2} ' : p=' num2str(p) '\n'])
[~,p] = ttest(correct_rate_signal(3,:),correct_rate_signal(4,:));
fprintf(['Paired ttest on participants'' scores, ' cfg_cmp.NameSignal{3} ' vs ' cfg_cmp.NameSignal{4} ' : p=' num2str(p) '\n'])

clear i  

%% Response time, SNR
% utilise la fonction boundedline (http://www.mathworks.com/matlabcentral/fileexchange/27485-boundedline-m)

fprintf('\n** Response time, SNR **\n')
clear RTmedian_session RSBmean_session

Nfenetre = floor(cfg_cmp.N/cfg_cmp.fenetre_calcul);
RSB_session = reshape(RSB, [cfg_cmp.N_Subject, cfg_cmp.fenetre_calcul, Nfenetre]);
RSBmean_session = squeeze(mean(RSB_session,2));
for i_subject = 1:cfg_cmp.N_Subject
    RSBmean_session(i_subject,:) = squeeze(mean(RSB_session(i_subject,:,:),2));
end
RT_session = reshape(responsetime, [cfg_cmp.N_Subject, cfg_cmp.fenetre_calcul, Nfenetre]);
for i_subject = 1:cfg_cmp.N_Subject
    RTmedian_session(i_subject,:) = squeeze(mean(RT_session(i_subject,:,:),2));
end

figure;plot_multichar((1:Nfenetre)*cfg_cmp.fenetre_calcul,RSBmean_session,generate_symbol_list(cfg_cmp.N_Subject,'alternlineonly'));xlim([500 10000]);title(['SNR (mean over ' num2str(cfg_cmp.fenetre_calcul) ' stimuli)']);ylabel('SNR(dB)');xlabel('trial number');legend(cfg_cmp.Subject,'Location','NorthEastOutside')
figure;plot_multichar((1:Nfenetre)*cfg_cmp.fenetre_calcul,RTmedian_session,generate_symbol_list(cfg_cmp.N_Subject,'alternlineonly'));xlim([500 10000]);title(['RT (mean over ' num2str(cfg_cmp.fenetre_calcul) ' stimuli)']);ylabel('response time (s)');xlabel('trial number');legend(cfg_cmp.Subject,'Location','NorthEastOutside')
figure;boundedline((1:Nfenetre)*cfg_cmp.fenetre_calcul,mean(RSBmean_session,1),sem(RSBmean_session,0,1),'b','alpha');set(gca,'YGrid','on');xlim([500 10000]);title(['SNR (mean over ' num2str(cfg_cmp.fenetre_calcul) ' stimuli)']);ylabel('SNR(dB)');xlabel('trial number')
figure;boundedline((1:Nfenetre)*cfg_cmp.fenetre_calcul,mean(RTmedian_session,1),sem(RTmedian_session,0,1),'k','alpha');set(gca,'YGrid','on');xlim([500 10000]);title(['RT (mean over ' num2str(cfg_cmp.fenetre_calcul) ' stimuli)']);ylabel('response time (s)');xlabel('trial number')

clear i_subject Nfenetre

%% Response time analysis

fprintf('\n** Response time analysis **\n')

for i_subject = 1:cfg_cmp.N_Subject
    for i=1:cfg_cmp.N_signal
        RTcond=responsetime(i_subject,find(n_signal(i_subject,:)==i));
        RT_signal(i_subject,i)=mean(RTcond);
    end
end

figure
boxplot([mean(RT_signal,2) RT_signal(:,1) RT_signal(:,2) RT_signal(:,3) RT_signal(:,4) mean(RT_signal(:,[1 2]),2) mean(RT_signal(:,[3 4]),2)], 'labels', {'global', 'Alda', 'Alga', 'Arda', 'Arga', 'Al-', 'Ar-'});
ylabel(['Participants'' mean RT']);title('Participants'' mean RT for each condition');%ylim([0 1]);
figure
plot_multichar(0.5:6.5,[mean(RT_signal,2) RT_signal(:,1) RT_signal(:,2) RT_signal(:,3) RT_signal(:,4) mean(RT_signal(:,[1 2]),2) mean(RT_signal(:,[3 4]),2)], generate_symbol_list(cfg_cmp.N_Subject,'noline'));
ylabel(['Participants'' mean RT']);xlim([0 7]);set(gca,'XTick',0.5:6.5);set(gca,'XTickLabel',{'global', 'Alda', 'Alga', 'Arda', 'Arga', 'Al-', 'Ar-'});legend(cfg_cmp.Subject,'Location','NorthEastOutside');title('Participants'' mean RT for each condition');

%% Psychometric functions (parameters)
% utilise la toolbox Palamedes (http://www.palamedestoolbox.org/) 
% et la fonction mtit (http://www.mathworks.com/matlabcentral/fileexchange/3218-mtit-a-pedestrian-major-title-creator/content/mtit.m)

% Parametres 
pas_affichage = 2; % pas de RSB pour le calcul des fonctions psychometriques
RSB_affiche = [-30 0]; % intervalle de RSB pour le calcul
Ntrialsmin = 10000/(length(RSB_level)); % nombre d'essais en dessous duquel on n'affiche pas un point
% Parametres de calcul de Palamedes, voir la notice
PF=@PAL_CumulativeNormal;
searchGrid.alpha = -18:1:-6;
searchGrid.beta = power(10,(-2:.1:2));
searchGrid.gamma = 0.5;
searchGrid.lambda = 0;
paramsFree = [1 1 1 1];
lapseLimits = [0 1];
guessLimits = [.4 .5];

clear Fit paramsValues LL exitfl ag 
RSB_level=RSB_affiche(1):pas_affichage:RSB_affiche(2);
options = PAL_minimize('options');
options.Display = 'on';
options.MaxIter = '400*numberOfVariables';
options.MaxFunEvals = '400*numberOfVariables';
options.TolX = 1e-4;
options.TolFun = 1e-4;

fprintf('\n** Psychometric functions (global) **\n')

% Ajustement
for i_subject = 1:cfg_cmp.N_Subject
    [paramsValues(i_subject,:) LL(i_subject,:) exitfl(i_subject,:) ag(i_subject,:)] = PAL_PFML_Fit(RSB(i_subject,:), is_correct(i_subject,:), ones(1,10000), searchGrid, paramsFree, PF,'lapseLimits',lapseLimits,'guessLimits',guessLimits, 'searchOptions',options);    
    Fit(i_subject,:) = PF(paramsValues(i_subject,:),RSB_level);
end

% Affichage
figure
for i_subject = 1:cfg_cmp.N_Subject
    for i=1:length(RSB_level)
        numpos(i,i_subject) = mean(is_correct(i_subject,find(RSB(i_subject,:)>=RSB_level(i)-pas_affichage/2 & RSB(i_subject,:)<=RSB_level(i)+pas_affichage/2)));
    end
        subplot(4,5,i_subject)
    plot(RSB(i_subject,:),is_correct(i_subject,:),'.'); hold on
    
    plot(RSB_level, Fit(i_subject,:), 'k-')

    plot(RSB_level, numpos(:,i_subject), 'r.')
    title(['Subject ' num2str(cfg_cmp.Subject{i_subject})]);
    xlim(RSB_affiche);
    ylabel(['Rate of correct answers']);
end
mtit('Psychometric functions for all subjects','xoff', 0, 'yoff',.03,'fontsize',14,'FontWeight', 'bold')

figure
plot_multichar(RSB_level, Fit(:,:),generate_symbol_list(cfg_cmp.N_Subject,'alternlineonly'),'LineWidth',2)
    xlim(RSB_affiche);
ylabel(['Rate of correct answers']); xlabel('SNR(dB)');legend(cfg_cmp.Subject,'Location','NorthEastOutside')
title('Psychometric functions for all subjects')

clear i_subject i 

%% Bias and context effect analysis

fprintf('\n** Bias analysis **\n')

response_bias = 2; % En fonction de quelle réponse afficher le biais

for i_subject = 1:cfg_cmp.N_Subject
    for i=1:cfg_cmp.N_signal
        N_response_bias(i_subject,i)=sum(n_reponse(i_subject,find(n_signal(i_subject,:)==i))==response_bias);
    end
end

figure
boxplot([sum(N_response_bias,2), cfg_cmp.N_signal*N_response_bias(:,1), cfg_cmp.N_signal*N_response_bias(:,2), cfg_cmp.N_signal*N_response_bias(:,3), cfg_cmp.N_signal*N_response_bias(:,4), cfg_cmp.N_response*sum(N_response_bias(:,[1 2]),2), cfg_cmp.N_response*sum(N_response_bias(:,[3 4]),2)]/cfg_cmp.N, 'labels', {'global', 'Alda', 'Alga', 'Arda', 'Arga', 'Al-', 'Ar-'});
ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses']); ylim([0 1]);title('Participants'' bias in each condition');
figure
plot_multichar(0.5:6.5,[sum(N_response_bias,2), cfg_cmp.N_signal*N_response_bias(:,1), cfg_cmp.N_signal*N_response_bias(:,2), cfg_cmp.N_signal*N_response_bias(:,3), cfg_cmp.N_signal*N_response_bias(:,4), cfg_cmp.N_response*sum(N_response_bias(:,[1 2]),2), cfg_cmp.N_response*sum(N_response_bias(:,[3 4]),2)]/cfg_cmp.N, generate_symbol_list(cfg_cmp.N_Subject,'noline'));
ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses']); ylim([0 1]);xlim([0 7]);set(gca,'XTick',0.5:6.5);set(gca,'XTickLabel',{'global', 'Alda', 'Alga', 'Arda', 'Arga', 'Al-', 'Ar-'});legend(cfg_cmp.Subject,'Location','NorthEastOutside');title('Participants'' bias in each condition');

[~,p]=ttest(sum(N_response_bias(:,[1 2 3 4]),2), 5000);
fprintf(['ttest on participants'' percentage of ' cfg_cmp.NameResponse{response_bias} ' responses : p=' num2str(p) '\n'])
[~,p]=ttest(sum(N_response_bias(:,[1 2]),2), 2500);
fprintf(['ttest on participants'' percentage of ' cfg_cmp.NameResponse{response_bias} ' responses, context Al : p=' num2str(p) '\n'])
[~,p]=ttest(sum(N_response_bias(:,[3 4]),2), 2500);
fprintf(['ttest on participants'' percentage of ' cfg_cmp.NameResponse{response_bias} ' responses, context Ar : p=' num2str(p) '\n'])
[~,p]=ttest(sum(N_response_bias(:,[1 2]),2), sum(N_response_bias(:,[3 4]),2));
fprintf(['Paired ttest on participants'' percentage of ' cfg_cmp.NameResponse{response_bias} ' responses, context Al vs context Ar : p=' num2str(p) '\n'])

clear i_subject i

figure
boxplot([cfg_cmp.N_response*sum(N_response_bias(:,[1 2]),2)-cfg_cmp.N_response*sum(N_response_bias(:,[3 4]),2), cfg_cmp.N_signal*N_response_bias(:,1)-cfg_cmp.N_signal*N_response_bias(:,3), cfg_cmp.N_signal*N_response_bias(:,2)-cfg_cmp.N_signal*N_response_bias(:,4)]/cfg_cmp.N, 'labels', {'global', '-da', '-ga'});
ylabel(['Differential rate of ' cfg_cmp.NameResponse{response_bias} ' responses']); ylim([-0.5 0.5]);title('Participants'' context effect in each condition');
figure
plot_multichar(0.5:2.5,[cfg_cmp.N_response*sum(N_response_bias(:,[1 2]),2)-cfg_cmp.N_response*sum(N_response_bias(:,[3 4]),2), cfg_cmp.N_signal*N_response_bias(:,1)-cfg_cmp.N_signal*N_response_bias(:,3), cfg_cmp.N_signal*N_response_bias(:,2)-cfg_cmp.N_signal*N_response_bias(:,4)]/cfg_cmp.N, generate_symbol_list(cfg_cmp.N_Subject,'noline'));
ylabel(['Differential rate of ' cfg_cmp.NameResponse{response_bias} ' responses']); ylim([-0.5 0.5]);xlim([0 4]);set(gca,'XTick',0.5:2.5);set(gca,'XTickLabel',{'global', '-da', '-ga'});legend(cfg_cmp.Subject,'Location','NorthEastOutside');title('Participants'' context effect in each condition');

%% Bias and context effect as a function of SNR

fprintf('\n** Bias as a function of SNR **\n')

response_bias = 2;
pas_affichage = 1;
RSB_affiche = [-22 0];
RSB_level=RSB_affiche(1):pas_affichage:RSB_affiche(2);
Ntrialsmin = 0;

figure
clear numpos numtrial
nsubplot=ceil(sqrt(cfg_cmp.N_Subject));
if nsubplot*(nsubplot-2)>=cfg_cmp.N_Subject
    msubplot=nsubplot-2;
elseif nsubplot*(nsubplot-1)>=cfg_cmp.N_Subject
    msubplot=nsubplot-1;
else
    msubplot=nsubplot;
end    
for i_subject = 1:cfg_cmp.N_Subject
    subplot(nsubplot,msubplot,i_subject)
    is_biased(i_subject,:)=(n_reponse(i_subject,:)==response_bias);

    for i=1:length(RSB_level)
        for j=1:cfg_cmp.N_signal
            numtrial(i_subject,i,j) = sum(RSB(i_subject,:)>=RSB_level(i)-pas_affichage/2 & RSB(i_subject,:)<=RSB_level(i)+pas_affichage/2 & n_signal(i_subject,:)==j);
            numpos(i_subject,i,j) = mean(is_biased(i_subject,find(RSB(i_subject,:)>=RSB_level(i)-pas_affichage/2 & RSB(i_subject,:)<=RSB_level(i)+pas_affichage/2 & n_signal(i_subject,:)==j)));
            numpos(find(numtrial<=Ntrialsmin)) = NaN;
        end
    end
    plot(RSB_level, [mean(numpos(i_subject,:,[1 2]),3); mean(numpos(i_subject,:,[3 4]),3)], '.', RSB_affiche, [0.5 0.5],'r--')
    title(['Subject ' num2str(cfg_cmp.Subject{i_subject})]);
    ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses'])
    xlim(RSB_affiche);
    ylim([0 1]);
end
legend('prec. with Al', 'prec. with Ar')
mtit('Bias as a function of SNR','xoff', 0, 'yoff',.03,'fontsize',14,'FontWeight', 'bold')
figure
for i_subject = 1:cfg_cmp.N_Subject
    subplot(nsubplot,msubplot,i_subject)
    plot(RSB_level, [mean(numpos(i_subject,:,[1 2]),3)-mean(numpos(i_subject,:,[3 4]),3)], '.', RSB_affiche, [0 0],'r--')
    title(['Subject ' num2str(cfg_cmp.Subject{i_subject})]);
    ylabel(['Differential rate of ' cfg_cmp.NameResponse{response_bias} ' responses'])
    xlim(RSB_affiche);
    ylim([-0.5 0.5]);
end
mtit('Contect effect as a function of SNR','xoff', 0, 'yoff',.03,'fontsize',14,'FontWeight', 'bold')

figure
plot(RSB_level, [mean(mean(numpos(:,:,[1 2]),3),1); mean(mean(numpos(:,:,[3 4]),3),1)], '.', RSB_affiche, [0.5 0.5],'r--')
title('Bias as a function of SNR, mean over subjects');
ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses'])
xlim(RSB_affiche);
ylim([0 1]);
legend('prec. with Al', 'prec. with Ar')

figure
plot(RSB_level, [mean(mean(numpos(:,:,[1 2]),3),1)-mean(mean(numpos(:,:,[3 4]),3),1)], '.', RSB_affiche, [0 0],'r--')
title('Context effect as a function of SNR, mean over subjects');
ylabel(['Differential rate of ' cfg_cmp.NameResponse{response_bias} ' responses'])
xlim(RSB_affiche);
ylim([-0.5 0.5]);

%% Bias as a function of session and trial number

fprintf('\n** Bias as a function of session and trial number**\n')

response_bias = 2;
Nfenetre = floor(cfg_cmp.N/cfg_cmp.fenetre_calcul);
n_reponse_session = reshape(n_reponse, [cfg_cmp.N_Subject, cfg_cmp.fenetre_calcul, Nfenetre]);
bias_session = squeeze(mean(n_reponse_session==response_bias,2));

figure;plot_multichar((1:Nfenetre)*cfg_cmp.fenetre_calcul,bias_session,generate_symbol_list(cfg_cmp.N_Subject,'alternlineonly'));xlim([500 10000]);title(['Bias as a function of session (mean over ' num2str(cfg_cmp.fenetre_calcul) ' stimuli)']);ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses']);ylim([0 1]);xlabel('trial number');legend(cfg_cmp.Subject,'Location','NorthEastOutside');
figure;boundedline((1:Nfenetre)*cfg_cmp.fenetre_calcul,mean(bias_session,1),sem(bias_session,0,1));xlim([500 10000]);title(['Bias as a function of session (mean over ' num2str(cfg_cmp.fenetre_calcul) ' stimuli)']);ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses']);ylim([0 1]);xlabel('trial number');

bias_trial = squeeze(mean(n_reponse_session==response_bias,3));

figure;plot_multichar((1:cfg_cmp.fenetre_calcul),bias_trial,generate_symbol_list(cfg_cmp.N_Subject,'alternlineonly'));title(['Bias as a function of trial number (mean over ' num2str(Nfenetre) ' stimuli)']);ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses']);ylim([0 1]);xlabel('trial number');legend(cfg_cmp.Subject,'Location','NorthEastOutside');
figure;boundedline((1:cfg_cmp.fenetre_calcul),mean(bias_trial,1),sem(bias_trial,0,1));title(['Bias as a function of trial number (mean over ' num2str(Nfenetre) ' stimuli)']);ylabel(['Rate of ' cfg_cmp.NameResponse{response_bias} ' responses']);ylim([0 1]);xlabel('trial number');