%% pre: clean up...

clear all
close all

%% (TODO: Import data from mat files)

%% I) Wahrnehmung / Empfindung verschieden hoher Pegel

% sound level in dB
p = [50:10:80];

% import n-data from Excel
T1 = xlsread('C:\Users\T400\Desktop\Projektpraktikum Bioanaloge Informationsverarbeitung\Kalibierung_Haupttest_geteilteGruppen.xlsx','Tabelle N','B2:Z5');

% calculate mean values (mean value of each row when ignoring NaN values)
T1_m = nanmean(T1,2);

% import ci-data from Excel
T2 = xlsread('C:\Users\T400\Desktop\Projektpraktikum Bioanaloge Informationsverarbeitung\Kalibierung_Haupttest_geteilteGruppen.xlsx','Tabelle CI','B2:Z5');

% calculate mean values (mean value of each row when ignoring NaN values)
T2_m = nanmean(T2,2);

%% put in N-data and CI-data

figure;

subplot(221)
plot(p, T1, '-k')
title('Wahrnehmung Probanden [N]')
xlabel('dargebotener Pegel in dB')
axis([50 80 0 50])                  % xmin xmax ymin ymax
grid on

subplot(222)
plot(p, T1_m, '-ko')
title('Durchschnittliche Wahrnehmung [N]')
xlabel('dargebotener Pegel in dB')
axis([50 80 0 50])                  % xmin xmax ymin ymax
grid on

subplot(223)
plot(p, T2, '-k')
title('Wahrnehmung Probanden [CI]')
xlabel('dargebotener Pegel in dB')
axis([50 80 0 50])                  % xmin xmax ymin ymax
grid on

subplot(224)
plot(p, T2_m, '-.ko')
title('Durchschnittliche Wahrnehmung [CI]')
xlabel('dargebotener Pegel in dB')
axis([50 80 0 50])                  % xmin xmax ymin ymax
grid on

% main title
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Empfindung verschiedener Pegel (Details)','HorizontalAlignment','center','VerticalAlignment', 'top')

%% compare N and CI mean values

figure;

plot(p,T1_m,'-ko', p,T2_m,'-.k*')
xlabel('dargebotener Pegel in dB')
axis([50 80 0 50])                  % xmin xmax ymin ymax
grid on

hleg1 = legend('N','CI');
set(hleg1,'Location','NorthWest')

% main title
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Empfindung verschiedener Pegel (Gruppenvergleich)','HorizontalAlignment','center','VerticalAlignment', 'top')


%% II) IME-SA: Verständnis der Sätze

% import data from Excel
tab_n = xlsread('C:\Users\T400\Desktop\Projektpraktikum Bioanaloge Informationsverarbeitung\Kalibierung_Haupttest_geteilteGruppen.xlsx','Tabelle N','B25:Z64');
tab_ci = xlsread('C:\Users\T400\Desktop\Projektpraktikum Bioanaloge Informationsverarbeitung\Kalibierung_Haupttest_geteilteGruppen.xlsx','Tabelle CI','B25:Z64');

% sort data
[M,N] = size(tab_n);    % dimensions of tab_n
M_s = (M-4)/4 + 1;      % M of sorted matrices

% split into 4 sub-matrices (N + CI)
tab_n_m = tab_n(1:4:end,:); 
tab_n_w = tab_n(2:4:end,:);
tab_n_r = tab_n(3:4:end,:);
tab_n_ref = tab_n(4:4:end,:);

tab_ci_m = tab_ci(1:4:end,:); 
tab_ci_w = tab_ci(2:4:end,:);
tab_ci_r = tab_ci(3:4:end,:);
tab_ci_ref = tab_ci(4:4:end,:);

%% put data (minium, mean and maximum values) into plot

p = [-25:5:20];

figure;

subplot(121)
plot(p,nanmean(tab_n_m,2),'-ko', p,nanmean(tab_n_w,2)','-k*', p,nanmean(tab_n_r,2),'-kd', p,nanmean(tab_n_ref,2),'-.ks')
title('\bf Durchschnitt N')
xlabel('dargebotener Pegel in dB')
axis([-25 25 0 1])                  % xmin xmax ymin ymax
grid on

% add legend
hleg1 = legend('m','w','r','ref');
set(hleg1,'Location','NorthWest')

% convert values on y-axis to percent
set(gca, 'YTickMode','manual')
set(gca, 'YTickLabel',num2str(100.*get(gca,'YTick')','%g%%'))

subplot(122)
plot(p,nanmean(tab_ci_m,2),'-ko', p,nanmean(tab_ci_w,2),'-k*', p,nanmean(tab_ci_r,2),'-kd', p,nanmean(tab_ci_ref,2),'-.ks')
title('\bf Durchschnitt CI')
xlabel('dargebotener Pegel in dB')
axis([-25 25 0 1])                  % xmin xmax ymin ymax
grid on

% add legend
hleg1 = legend('m','w','r','ref');
set(hleg1,'Location','NorthWest')

% convert values on y-axis to percent
set(gca, 'YTickMode','manual')
set(gca, 'YTickLabel',num2str(100.*get(gca,'YTick')','%g%%'))

% main title
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf IME-SA: Satzverständnis (nach Gruppe)','HorizontalAlignment','center','VerticalAlignment', 'top')

%% compare N and CI at different conditions / interfering signals

figure;

subplot(221)
plot(p,nanmean(tab_n_m,2),'-ko', p,nanmean(tab_ci_m,2)','-k*')
title('\bf männlicher Sprecher (m)')
xlabel('dargebotener Pegel in dB')
axis([-25 25 0 1])                  % xmin xmax ymin ymax
grid on

% add legend
hleg1 = legend('N','CI');
set(hleg1,'Location','NorthWest')

% convert values on y-axis to percent
set(gca, 'YTickMode','manual')
set(gca, 'YTickLabel',num2str(100.*get(gca,'YTick')','%g%%'))

subplot(222)
plot(p,nanmean(tab_n_w,2),'-ko', p,nanmean(tab_ci_w,2),'-k*')
title('\bf weiblicher Specher (w)')
xlabel('dargebotener Pegel in dB')
axis([-25 25 0 1])                  % xmin xmax ymin ymax
grid on

% add legend
hleg1 = legend('N','CI');
set(hleg1,'Location','NorthWest')

% convert values on y-axis to percent
set(gca, 'YTickMode','manual')
set(gca, 'YTickLabel',num2str(100.*get(gca,'YTick')','%g%%'))

subplot(223)
plot(p,nanmean(tab_n_r,2),'-ko', p,nanmean(tab_ci_r,2)','-k*')
title('\bf Fastl-Rauschen (r)')
xlabel('dargebotener Pegel in dB')
axis([-25 25 0 1])                  % xmin xmax ymin ymax
grid on

% add legend
hleg1 = legend('N','CI');
set(hleg1,'Location','NorthWest')

% convert values on y-axis to percent
set(gca, 'YTickMode','manual')
set(gca, 'YTickLabel',num2str(100.*get(gca,'YTick')','%g%%'))

subplot(224)
plot(p,nanmean(tab_n_ref,2),'-ko', p,nanmean(tab_ci_ref,2),'-k*')
title('\bf Referenzkondition (ref)')
xlabel('dargebotener Pegel in dB')
axis([-25 25 0 1])                  % xmin xmax ymin ymax
grid on

% add legend
hleg1 = legend('N','CI');
set(hleg1,'Location','NorthWest')

% convert values on y-axis to percent
set(gca, 'YTickMode','manual')
set(gca, 'YTickLabel',num2str(100.*get(gca,'YTick')','%g%%'))

% main title
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf IME-SA: Satzverständnis (nach Störgeräusch)','HorizontalAlignment','center','VerticalAlignment', 'top')