%% Skript pro vypocet vsech parametru
% Pro spravnou funkcnost musi byt ve slozce s timto skriptem i slozka wav\
% se slozkami jednotlivych pacientu, ve kterych jsou prislusne nahravky
% Cistka
close all;
clear all;
clc;

%%
% projed vsechny pacienty

patientname = 'K'; % Nastaveni pocatecni skupiny kontrolnich recniku
MAXPARAMETERS = 119; % Pocet pocitanych parametru
vystup = cell(1000); % priprava cell pro vlozeni hodnot
%% pojmenovani parametru
for wavnr = 1:10
if wavnr >= 6
    middleL = '-l-';
    wavnr2 = wavnr-5;
else
    middleL = '-';
    wavnr2 = wavnr;
end

filename = strcat('9.2' , num2str(middleL) , num2str(wavnr2) , '_1_');
    
i = wavnr;
vystup(1,1) = cellstr('X');
vystup(2+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'mean_E'));
vystup(3+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'var_E'));
vystup(4+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'std_E'));
vystup(5+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'max_E'));
vystup(6+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'min_E'));
vystup(7+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'median_E'));
vystup(8+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'1p_E'));
vystup(9+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'99p_E'));
vystup(10+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'ir_E'));

vystup(11+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_median'));
vystup(12+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_mean'));
vystup(13+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_std'));
vystup(14+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_min'));
vystup(15+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_max'));

vystup(16+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_frac'));
vystup(17+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_nbreaks'));
vystup(18+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_degree'));

vystup(19+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_local'));
vystup(20+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_localabs'));
vystup(21+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_rap'));
vystup(22+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_ppq5'));
vystup(23+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_ddp'));

vystup(24+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_local'));
vystup(25+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_localdb'));
vystup(26+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq3'));
vystup(27+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq5'));
vystup(28+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq11'));
vystup(29+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_dda'));

vystup(30+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_aut'));
vystup(31+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_nh'));
vystup(32+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_hn'));

vystup(33+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_mean'));
vystup(34+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_var'));
vystup(35+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_std'));
vystup(36+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_max'));
vystup(37+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_min'));
vystup(38+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_median'));
vystup(39+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_1p'));
vystup(40+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_99p'));
vystup(41+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_ir'));
vystup(42+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_mean'));
vystup(43+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_var'));
vystup(44+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_std'));
vystup(45+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_max'));
vystup(46+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_min'));
vystup(47+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_median'));
vystup(48+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_1p'));
vystup(49+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_99p'));
vystup(50+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_ir'));

vystup(51+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_mean'));
vystup(52+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_var'));
vystup(53+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_std'));
vystup(54+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_max'));
vystup(55+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_min'));
vystup(56+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_median'));
vystup(57+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_1p'));
vystup(58+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_99p'));
vystup(59+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_ir'));
vystup(60+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_mean'));
vystup(61+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_var'));
vystup(62+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_std'));
vystup(63+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_max'));
vystup(64+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_min'));
vystup(65+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_median'));
vystup(66+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_1p'));
vystup(67+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_99p'));
vystup(68+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_ir'));

vystup(69+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_mean'));
vystup(70+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_var'));
vystup(71+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_std'));
vystup(72+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_max'));
vystup(73+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_min'));
vystup(74+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_median'));
vystup(75+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_1p'));
vystup(76+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_99p'));
vystup(77+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_ir'));
vystup(78+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_mean'));
vystup(79+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_var'));
vystup(80+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_std'));
vystup(81+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_max'));
vystup(82+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_min'));
vystup(83+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_median'));
vystup(84+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_1p'));
vystup(85+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_99p'));
vystup(86+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_ir'));

vystup(87+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TST'));
vystup(88+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TPT'));
vystup(89+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NST'));
vystup(90+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TSR'));
vystup(91+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NSR'));
vystup(92+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'PPR'));
vystup(93+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TPT50'));
vystup(94+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NST50'));
vystup(95+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'AR'));

vystup(96+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'LSTER'));

vystup(97+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'MPSD'));

vystup(98+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_1'));
vystup(99+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_2'));
vystup(100+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_3'));
vystup(101+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_4'));
vystup(102+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_5'));

vystup(103+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_1'));
vystup(104+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_2'));
vystup(105+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_3'));
vystup(106+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_4'));
vystup(107+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_5'));

vystup(108+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'mean_tko'));
vystup(109+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'var_tko'));
vystup(110+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'std_tko'));
vystup(111+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'max_tko'));
vystup(112+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'min_tko'));
vystup(113+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'median_tko'));
vystup(114+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'1p_tko'));
vystup(115+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'99p_tko'));
vystup(116+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'ir_tko'));

vystup(117+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_VR'));
vystup(118+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'relF0SD'));
vystup(119+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'relF0VR'));

vystup(120+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'SPIR'));


end
%%  pro vsechny pacienty
coll = 1;
patientnr = 1002;
while patientnr <=2114

%while patientnr <=1015
    
    patientnr = patientnr+1;
     
    % Po skupine kontrolnich recniku prejdi na recniky s PN
    if patientnr == 2114 && patientname == 'K'
        patientname = 'P';
        patientnr = 1006;
    end;
    
    patientnamefull = strcat(num2str(patientname),num2str(patientnr));
    wav_pth2 = strcat('wav/', patientnamefull);
    
    % Pokud existuje slozka recnika, tak proved  
     if exist(wav_pth2,'dir') == 7 
    coll = coll + 1;
    
    %zapis na vystup kod pacienta
    vystup(1,coll) = cellstr(patientnamefull);

%% pro vsechny soubory
for wavnr = 1:10
if wavnr >= 6
    middleL = '-l-';
    wavnr2 = wavnr-5;
else
    middleL = '-';
    wavnr2 = wavnr;
end

    row = wavnr;
    filename = strcat(patientnamefull, '_9.2' , num2str(middleL) , num2str(wavnr2) , '_1.wav'); 
    wav_pth3 = strcat(wav_pth2, '/', filename);
   
    %% kontrola existence souboru
    if exist(wav_pth3,'file') == 2
        %disp('existuje'); 
        disp('Pocitam: '); 
        disp(filename); 
        
%% nasleduje vypocet parametru
[x, fs] = wavread( fullfile( wav_pth2, filename));

%% Promenne
winlen = hamming(256);
winover = 128;

wav_pth = strcat(wav_pth2,'/', filename);
time_step = 0;
max_frm = 5500;
win_len = 0.020;
preem = 50;

dir_pth = [pwd '\'];
%dir_pth = 'C:/Škola/Diplomka/Matlab_jaa/prace/';
time_lo = 0.0;
time_up = 0.0;
pitch_lo = 75;
pitch_up = 400;
max_per = 1.3;
max_ampl = 1.6;
silence_th = 0.03;
voicing_th = 0.45;

delka_ramce = 110;
init = 10;


%% Vypocet kratkodobe Energie
E = energie(x, winlen, winover);

%% Vypocet Teageruv Kaiserova energetickeho operatoru
tko = teager_kaiser(x);

%% Vypocet Formantu za pomoci praatcon.exe
[frm_out, F1, F2, F3] = praat_formants(wav_pth, dir_pth, time_step, max_frm, win_len, preem);

%% Vypocet ostatnich parametru za pomoci praatcon.exe
praat_str = praat_info(wav_pth, dir_pth, time_lo, time_up, pitch_lo, pitch_up, max_per, max_ampl, silence_th, voicing_th);

%% Vypocty Tempa řeči
[TST, TPT, NST, TSR, NSR, PPR] = tempo(x, fs, delka_ramce, init, filename);
[TPT50, NST50, AR] = arate(x, fs, delka_ramce, init, filename);
SPIR = praat_str.voicing_nbreaks/(TST/60);

%% Vypocet LSTER (Low Short-Time Energy Ratio)
LSTER = LEF(x, fs, win_len);

%% Vypocet MPSD (Median of Power Spectral Density)
MPSD = mpsd(x);

%% Vypocet RASTA energie formantu

% Pro prvni formant
E_rasta_F1 = rastaenergie(F1, x, fs);

% Pro druhy formant
E_rasta_F2 = rastaenergie(F2, x, fs);

%% zapis vysledku do cellu

% Zapis kratkodobe energie
vystup(2+MAXPARAMETERS*(row-1),coll) = num2cell(mean(E)); 
vystup(3+MAXPARAMETERS*(row-1),coll) = num2cell(var(E));
vystup(4+MAXPARAMETERS*(row-1),coll) = num2cell(std(E));
vystup(5+MAXPARAMETERS*(row-1),coll) = num2cell(max(E));
vystup(6+MAXPARAMETERS*(row-1),coll) = num2cell(min(E));
vystup(7+MAXPARAMETERS*(row-1),coll) = num2cell(median(E));
vystup(8+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,1));
vystup(9+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,99));
vystup(10+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,99)-prctile(E,1));

% Zapis kmitoctu zakladniho tonu F0
vystup(11+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_median(1,1));
vystup(12+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_mean(1,1));
vystup(13+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_std(1,1));
vystup(14+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_min(1,1));
vystup(15+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_max(1,1));

% Zapis pauzovacich parametru praat
vystup(16+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_frac(1,1));
vystup(17+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_nbreaks(1,1));
vystup(18+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_degree(1,1));

% Zapis jitter
vystup(19+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_local(1,1));
vystup(20+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_localabs(1,1));
vystup(21+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_rap(1,1));
vystup(22+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_ppq5(1,1));
vystup(23+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_ddp(1,1));

% Zapis shimmer
vystup(24+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_local(1,1));
vystup(25+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_localdb(1,1));
vystup(26+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq3(1,1));
vystup(27+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq5(1,1));
vystup(28+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq11(1,1));
vystup(29+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_dda(1,1));

% Zapis harmonics-to-noise ratio
vystup(30+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_aut(1,1));
vystup(31+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_nh(1,1));
vystup(32+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_hn(1,1));

% Zapis prvniho formantu F1 a odpovidajiciho pasma B1
vystup(33+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_mean(1,1));
vystup(34+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_var(1,1));
vystup(35+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_std(1,1));
vystup(36+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_max(1,1));
vystup(37+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_min(1,1));
vystup(38+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_med(1,1));
vystup(39+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_1p(1,1));
vystup(40+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_99p(1,1));
vystup(41+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_ir(1,1));
vystup(42+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_mean(1,1));
vystup(43+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_var(1,1));
vystup(44+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_std(1,1));
vystup(45+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_max(1,1));
vystup(46+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_min(1,1));
vystup(47+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_med(1,1));
vystup(48+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_1p(1,1));
vystup(49+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_99p(1,1));
vystup(50+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_ir(1,1));

% Zapis druheho formantu F2 a odpovidajiciho pasma B2
vystup(51+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_mean(1,1));
vystup(52+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_var(1,1));
vystup(53+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_std(1,1));
vystup(54+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_max(1,1));
vystup(55+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_min(1,1));
vystup(56+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_med(1,1));
vystup(57+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_1p(1,1));
vystup(58+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_99p(1,1));
vystup(59+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_ir(1,1));
vystup(60+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_mean(1,1));
vystup(61+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_var(1,1));
vystup(62+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_std(1,1));
vystup(63+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_max(1,1));
vystup(64+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_min(1,1));
vystup(65+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_med(1,1));
vystup(66+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_1p(1,1));
vystup(67+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_99p(1,1));
vystup(68+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_ir(1,1));

% Zapis tretiho formantu F3 a odpovidajiciho pasma B3
vystup(69+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_mean(1,1));
vystup(70+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_var(1,1));
vystup(71+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_std(1,1));
vystup(72+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_max(1,1));
vystup(73+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_min(1,1));
vystup(74+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_med(1,1));
vystup(75+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_1p(1,1));
vystup(76+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_99p(1,1));
vystup(77+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_ir(1,1));
vystup(78+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_mean(1,1));
vystup(79+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_var(1,1));
vystup(80+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_std(1,1));
vystup(81+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_max(1,1));
vystup(82+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_min(1,1));
vystup(83+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_med(1,1));
vystup(84+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_1p(1,1));
vystup(85+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_99p(1,1));
vystup(86+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_ir(1,1));

% Zapis Tempa řeči
vystup(87+MAXPARAMETERS*(row-1),coll) = num2cell(TST);
vystup(88+MAXPARAMETERS*(row-1),coll) = num2cell(TPT);
vystup(89+MAXPARAMETERS*(row-1),coll) = num2cell(NST);
vystup(90+MAXPARAMETERS*(row-1),coll) = num2cell(TSR);
vystup(91+MAXPARAMETERS*(row-1),coll) = num2cell(NSR);
vystup(92+MAXPARAMETERS*(row-1),coll) = num2cell(PPR);
vystup(93+MAXPARAMETERS*(row-1),coll) = num2cell(TPT50);
vystup(94+MAXPARAMETERS*(row-1),coll) = num2cell(NST50);
vystup(95+MAXPARAMETERS*(row-1),coll) = num2cell(AR);

% Zapis LSTER (Low Short-Time Energy Ratio)
vystup(96+MAXPARAMETERS*(row-1),coll) = num2cell(LSTER);

% Zapis MPSD (Median of Power Spectral Density)
vystup(97+MAXPARAMETERS*(row-1),coll) = num2cell(MPSD);

% Zapis RASTA energie formantu pro prvni formant
vystup(98+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(1,1));
vystup(99+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(2,1));
vystup(100+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(3,1));
vystup(101+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(4,1));
vystup(102+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(5,1));

% Zapis RASTA energie formantu pro druhy formant
vystup(103+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(1,1));
vystup(104+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(2,1));
vystup(105+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(3,1));
if length(E_rasta_F2) > 3
vystup(106+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(4,1));
vystup(107+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(5,1));
else
vystup(106+MAXPARAMETERS*(row-1),coll) = num2cell(NaN);
vystup(107+MAXPARAMETERS*(row-1),coll) = num2cell(NaN);
end
% Zapis Teageruv Kaiserova energetickeho operatoru
vystup(108+MAXPARAMETERS*(row-1),coll) = num2cell(mean(tko)); 
vystup(109+MAXPARAMETERS*(row-1),coll) = num2cell(var(tko));
vystup(110+MAXPARAMETERS*(row-1),coll) = num2cell(std(tko));
vystup(111+MAXPARAMETERS*(row-1),coll) = num2cell(max(tko));
vystup(112+MAXPARAMETERS*(row-1),coll) = num2cell(min(tko));
vystup(113+MAXPARAMETERS*(row-1),coll) = num2cell(median(tko));
vystup(114+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,1));
vystup(115+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,99));
vystup(116+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,99)-prctile(tko,1));  

% Zapis zbyvajicich parametru F0
vystup(117+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_max(1,1) - praat_str.F0_min(1,1));
vystup(118+MAXPARAMETERS*(row-1),coll) = num2cell((praat_str.F0_std(1,1)/praat_str.F0_mean(1,1))*100);
vystup(119+MAXPARAMETERS*(row-1),coll) = num2cell(((praat_str.F0_max(1,1) - praat_str.F0_min(1,1))/praat_str.F0_mean(1,1))*100);

% Zapis SPIR
vystup(120+MAXPARAMETERS*(row-1),coll) = num2cell(SPIR);

    else
       %%wav nenalezen 
       disp('wav nenalezen')
        
    end


end %end foru

     else
         % pokud slozka neexistuje
         disp('Slozka neexistuje');        
     end
end

for i=1:10*MAXPARAMETERS+1
    for j=1:1000
        kontrola = isempty(vystup{i,j});
        if kontrola == 1
        vystup{i,j} = NaN;
        end   
    end
end
disp('Vsechny pohlavi - vypocitano');
[outputmat,label_train] = ClasificationTable(vystup,coll-1);
[outputmat2] = ComputeParameters(outputmat,label_train,vystup);
disp('Vsechny pohlavi - Parametry - vypocitano');

%% MEN
vystupW = cell(1151);
patientname = 'K';
%% pojmenovani parametru
for wavnr = 1:10
if wavnr >= 6
    middleL = '-l-';
    wavnr2 = wavnr-5;
else
    middleL = '-';
    wavnr2 = wavnr;
end

filename = strcat('9.2' , num2str(middleL) , num2str(wavnr2) , '_1_');
    
i = wavnr;
vystupW(1,1) = cellstr('X');
vystupW(2+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'mean_E'));
vystupW(3+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'var_E'));
vystupW(4+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'std_E'));
vystupW(5+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'max_E'));
vystupW(6+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'min_E'));
vystupW(7+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'median_E'));
vystupW(8+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'1p_E'));
vystupW(9+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'99p_E'));
vystupW(10+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'ir_E'));

vystupW(11+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_median'));
vystupW(12+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_mean'));
vystupW(13+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_std'));
vystupW(14+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_min'));
vystupW(15+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_max'));

vystupW(16+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_frac'));
vystupW(17+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_nbreaks'));
vystupW(18+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_degree'));

vystupW(19+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_local'));
vystupW(20+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_localabs'));
vystupW(21+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_rap'));
vystupW(22+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_ppq5'));
vystupW(23+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_ddp'));

vystupW(24+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_local'));
vystupW(25+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_localdb'));
vystupW(26+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq3'));
vystupW(27+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq5'));
vystupW(28+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq11'));
vystupW(29+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_dda'));

vystupW(30+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_aut'));
vystupW(31+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_nh'));
vystupW(32+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_hn'));

vystupW(33+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_mean'));
vystupW(34+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_var'));
vystupW(35+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_std'));
vystupW(36+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_max'));
vystupW(37+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_min'));
vystupW(38+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_median'));
vystupW(39+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_1p'));
vystupW(40+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_99p'));
vystupW(41+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_ir'));
vystupW(42+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_mean'));
vystupW(43+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_var'));
vystupW(44+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_std'));
vystupW(45+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_max'));
vystupW(46+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_min'));
vystupW(47+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_median'));
vystupW(48+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_1p'));
vystupW(49+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_99p'));
vystupW(50+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_ir'));

vystupW(51+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_mean'));
vystupW(52+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_var'));
vystupW(53+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_std'));
vystupW(54+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_max'));
vystupW(55+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_min'));
vystupW(56+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_median'));
vystupW(57+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_1p'));
vystupW(58+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_99p'));
vystupW(59+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_ir'));
vystupW(60+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_mean'));
vystupW(61+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_var'));
vystupW(62+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_std'));
vystupW(63+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_max'));
vystupW(64+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_min'));
vystupW(65+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_median'));
vystupW(66+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_1p'));
vystupW(67+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_99p'));
vystupW(68+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_ir'));

vystupW(69+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_mean'));
vystupW(70+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_var'));
vystupW(71+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_std'));
vystupW(72+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_max'));
vystupW(73+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_min'));
vystupW(74+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_median'));
vystupW(75+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_1p'));
vystupW(76+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_99p'));
vystupW(77+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_ir'));
vystupW(78+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_mean'));
vystupW(79+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_var'));
vystupW(80+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_std'));
vystupW(81+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_max'));
vystupW(82+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_min'));
vystupW(83+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_median'));
vystupW(84+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_1p'));
vystupW(85+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_99p'));
vystupW(86+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_ir'));

vystupW(87+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TST'));
vystupW(88+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TPT'));
vystupW(89+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NST'));
vystupW(90+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TSR'));
vystupW(91+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NSR'));
vystupW(92+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'PPR'));
vystupW(93+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TPT50'));
vystupW(94+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NST50'));
vystupW(95+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'AR'));

vystupW(96+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'LSTER'));

vystupW(97+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'MPSD'));

vystupW(98+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_1'));
vystupW(99+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_2'));
vystupW(100+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_3'));
vystupW(101+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_4'));
vystupW(102+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_5'));

vystupW(103+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_1'));
vystupW(104+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_2'));
vystupW(105+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_3'));
vystupW(106+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_4'));
vystupW(107+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_5'));

vystupW(108+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'mean_tko'));
vystupW(109+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'var_tko'));
vystupW(110+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'std_tko'));
vystupW(111+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'max_tko'));
vystupW(112+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'min_tko'));
vystupW(113+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'median_tko'));
vystupW(114+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'1p_tko'));
vystupW(115+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'99p_tko'));
vystupW(116+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'ir_tko'));

vystupW(117+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_VR'));
vystupW(118+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'relF0SD'));
vystupW(119+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'relF0VR'));

vystupW(120+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'SPIR'));

end

coll = 1;
patientnr = 2000;
while patientnr <=2114

%while patientnr <=1015
    
    patientnr = patientnr+1;
     
    % Po skupine kontrolnich recniku prejdi na recniky s PN
    if patientnr == 2114 && patientname == 'K'
        patientname = 'P';
        patientnr = 2000;
    end;
    
    patientnamefull = strcat(num2str(patientname),num2str(patientnr));
    wav_pth2 = strcat('wav/', patientnamefull);
    
    % Pokud existuje slozka recnika, tak proved  
     if exist(wav_pth2,'dir') == 7 
    coll = coll + 1;
    
    %zapis na vystup kod pacienta
    vystupW(1,coll) = cellstr(patientnamefull);

%% pro vsechny soubory
for wavnr = 1:10
if wavnr >= 6
    middleL = '-l-';
    wavnr2 = wavnr-5;
else
    middleL = '-';
    wavnr2 = wavnr;
end

    row = wavnr;
    filename = strcat(patientnamefull, '_9.2' , num2str(middleL) , num2str(wavnr2) , '_1.wav'); 
    wav_pth3 = strcat(wav_pth2, '/', filename);
   
    %% kontrola existence souboru
    if exist(wav_pth3,'file') == 2
        %disp('existuje'); 
        disp('Pocitam: '); 
        disp(filename); 
    
%% nasleduje vypocet parametru
[x, fs] = wavread( fullfile( wav_pth2, filename));

%% Promenne
winlen = hamming(256);
winover = 128;

wav_pth = strcat(wav_pth2,'/', filename);
time_step = 0;
max_frm = 5500;
win_len = 0.020;
preem = 50;

dir_pth = [pwd '\'];
%dir_pth = 'C:/Škola/Diplomka/Matlab_jaa/prace/';
time_lo = 0.0;
time_up = 0.0;
pitch_lo = 75;
pitch_up = 400;
max_per = 1.3;
max_ampl = 1.6;
silence_th = 0.03;
voicing_th = 0.45;

delka_ramce = 110;
init = 10;


%% Vypocet kratkodobe Energie
E = energie(x, winlen, winover);

%% Vypocet Teageruv Kaiserova energetickeho operatoru
tko = teager_kaiser(x);

%% Vypocet Formantu za pomoci praatcon.exe
[frm_out, F1, F2, F3] = praat_formants(wav_pth, dir_pth, time_step, max_frm, win_len, preem);

%% Vypocet ostatnich parametru za pomoci praatcon.exe
praat_str = praat_info(wav_pth, dir_pth, time_lo, time_up, pitch_lo, pitch_up, max_per, max_ampl, silence_th, voicing_th);

%% Vypocty Tempa řeči
[TST, TPT, NST, TSR, NSR, PPR] = tempo(x, fs, delka_ramce, init, filename);
[TPT50, NST50, AR] = arate(x, fs, delka_ramce, init, filename);
SPIR = praat_str.voicing_nbreaks/(TST/60);

%% Vypocet LSTER (Low Short-Time Energy Ratio)
LSTER = LEF(x, fs, win_len);

%% Vypocet MPSD (Median of Power Spectral Density)
MPSD = mpsd(x);

%% Vypocet RASTA energie formantu

% Pro prvni formant
E_rasta_F1 = rastaenergie(F1, x, fs);

% Pro druhy formant
E_rasta_F2 = rastaenergie(F2, x, fs);

%% zapis vysledku do cellu

% Zapis kratkodobe energie
vystupW(2+MAXPARAMETERS*(row-1),coll) = num2cell(mean(E)); 
vystupW(3+MAXPARAMETERS*(row-1),coll) = num2cell(var(E));
vystupW(4+MAXPARAMETERS*(row-1),coll) = num2cell(std(E));
vystupW(5+MAXPARAMETERS*(row-1),coll) = num2cell(max(E));
vystupW(6+MAXPARAMETERS*(row-1),coll) = num2cell(min(E));
vystupW(7+MAXPARAMETERS*(row-1),coll) = num2cell(median(E));
vystupW(8+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,1));
vystupW(9+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,99));
vystupW(10+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,99)-prctile(E,1));


% Zapis kmitoctu zakladniho tonu F0
vystupW(11+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_median(1,1));
vystupW(12+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_mean(1,1));
vystupW(13+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_std(1,1));
vystupW(14+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_min(1,1));
vystupW(15+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_max(1,1));

% Zapis pauzovacich parametru praat
vystupW(16+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_frac(1,1));
vystupW(17+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_nbreaks(1,1));
vystupW(18+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_degree(1,1));

% Zapis jitter
vystupW(19+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_local(1,1));
vystupW(20+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_localabs(1,1));
vystupW(21+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_rap(1,1));
vystupW(22+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_ppq5(1,1));
vystupW(23+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_ddp(1,1));

% Zapis shimmer
vystupW(24+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_local(1,1));
vystupW(25+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_localdb(1,1));
vystupW(26+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq3(1,1));
vystupW(27+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq5(1,1));
vystupW(28+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq11(1,1));
vystupW(29+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_dda(1,1));

% Zapis harmonics-to-noise ratio
vystupW(30+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_aut(1,1));
vystupW(31+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_nh(1,1));
vystupW(32+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_hn(1,1));

% Zapis prvniho formantu F1 a odpovidajiciho pasma B1
vystupW(33+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_mean(1,1));
vystupW(34+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_var(1,1));
vystupW(35+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_std(1,1));
vystupW(36+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_max(1,1));
vystupW(37+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_min(1,1));
vystupW(38+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_med(1,1));
vystupW(39+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_1p(1,1));
vystupW(40+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_99p(1,1));
vystupW(41+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_ir(1,1));
vystupW(42+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_mean(1,1));
vystupW(43+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_var(1,1));
vystupW(44+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_std(1,1));
vystupW(45+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_max(1,1));
vystupW(46+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_min(1,1));
vystupW(47+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_med(1,1));
vystupW(48+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_1p(1,1));
vystupW(49+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_99p(1,1));
vystupW(50+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_ir(1,1));

% Zapis druheho formantu F2 a odpovidajiciho pasma B2
vystupW(51+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_mean(1,1));
vystupW(52+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_var(1,1));
vystupW(53+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_std(1,1));
vystupW(54+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_max(1,1));
vystupW(55+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_min(1,1));
vystupW(56+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_med(1,1));
vystupW(57+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_1p(1,1));
vystupW(58+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_99p(1,1));
vystupW(59+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_ir(1,1));
vystupW(60+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_mean(1,1));
vystupW(61+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_var(1,1));
vystupW(62+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_std(1,1));
vystupW(63+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_max(1,1));
vystupW(64+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_min(1,1));
vystupW(65+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_med(1,1));
vystupW(66+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_1p(1,1));
vystupW(67+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_99p(1,1));
vystupW(68+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_ir(1,1));

% Zapis tretiho formantu F3 a odpovidajiciho pasma B3
vystupW(69+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_mean(1,1));
vystupW(70+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_var(1,1));
vystupW(71+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_std(1,1));
vystupW(72+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_max(1,1));
vystupW(73+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_min(1,1));
vystupW(74+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_med(1,1));
vystupW(75+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_1p(1,1));
vystupW(76+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_99p(1,1));
vystupW(77+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_ir(1,1));
vystupW(78+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_mean(1,1));
vystupW(79+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_var(1,1));
vystupW(80+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_std(1,1));
vystupW(81+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_max(1,1));
vystupW(82+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_min(1,1));
vystupW(83+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_med(1,1));
vystupW(84+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_1p(1,1));
vystupW(85+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_99p(1,1));
vystupW(86+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_ir(1,1));

% Zapis Tempa řeči
vystupW(87+MAXPARAMETERS*(row-1),coll) = num2cell(TST);
vystupW(88+MAXPARAMETERS*(row-1),coll) = num2cell(TPT);
vystupW(89+MAXPARAMETERS*(row-1),coll) = num2cell(NST);
vystupW(90+MAXPARAMETERS*(row-1),coll) = num2cell(TSR);
vystupW(91+MAXPARAMETERS*(row-1),coll) = num2cell(NSR);
vystupW(92+MAXPARAMETERS*(row-1),coll) = num2cell(PPR);
vystupW(93+MAXPARAMETERS*(row-1),coll) = num2cell(TPT50);
vystupW(94+MAXPARAMETERS*(row-1),coll) = num2cell(NST50);
vystupW(95+MAXPARAMETERS*(row-1),coll) = num2cell(AR);

% Zapis LSTER (Low Short-Time Energy Ratio)
vystupW(96+MAXPARAMETERS*(row-1),coll) = num2cell(LSTER);

% Zapis MPSD (Median of Power Spectral Density)
vystupW(97+MAXPARAMETERS*(row-1),coll) = num2cell(MPSD);

% Zapis RASTA energie formantu pro prvni formant
vystupW(98+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(1,1));
vystupW(99+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(2,1));
vystupW(100+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(3,1));
vystupW(101+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(4,1));
vystupW(102+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(5,1));

% Zapis RASTA energie formantu pro druhy formant
vystupW(103+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(1,1));
vystupW(104+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(2,1));
vystupW(105+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(3,1));
if length(E_rasta_F2) > 3
vystupW(106+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(4,1));
vystupW(107+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(5,1));
else
vystupW(106+MAXPARAMETERS*(row-1),coll) = num2cell(NaN);
vystupW(107+MAXPARAMETERS*(row-1),coll) = num2cell(NaN);
end
% Zapis Teageruv Kaiserova energetickeho operatoru
vystupW(108+MAXPARAMETERS*(row-1),coll) = num2cell(mean(tko)); 
vystupW(109+MAXPARAMETERS*(row-1),coll) = num2cell(var(tko));
vystupW(110+MAXPARAMETERS*(row-1),coll) = num2cell(std(tko));
vystupW(111+MAXPARAMETERS*(row-1),coll) = num2cell(max(tko));
vystupW(112+MAXPARAMETERS*(row-1),coll) = num2cell(min(tko));
vystupW(113+MAXPARAMETERS*(row-1),coll) = num2cell(median(tko));
vystupW(114+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,1));
vystupW(115+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,99));
vystupW(116+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,99)-prctile(tko,1));

% Zapis zbyvajicich parametru F0
vystupW(117+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_max(1,1) - praat_str.F0_min(1,1));
vystupW(118+MAXPARAMETERS*(row-1),coll) = num2cell((praat_str.F0_std(1,1)/praat_str.F0_mean(1,1))*100);
vystupW(119+MAXPARAMETERS*(row-1),coll) = num2cell(((praat_str.F0_max(1,1) - praat_str.F0_min(1,1))/praat_str.F0_mean(1,1))*100);

% Zapis SPIR
vystupW(120+MAXPARAMETERS*(row-1),coll) = num2cell(SPIR);

    else
       %%wav nenalezen 
       disp('wav nenalezen')
        
    end


end %end foru

     else
         % pokud slozka neexistuje
         disp('Slozka neexistuje');        
     end
end
for i=1:10*MAXPARAMETERS+1
    for j=1:1000
        kontrola = isempty(vystupW{i,j});
        if kontrola == 1
        vystupW{i,j} = NaN;
        end   
    end
end

disp('Muzi - vypocitano');
[outputmatW,label_trainW] = ClasificationTable(vystupW,coll-1);
[outputmat2W] = ComputeParameters(outputmatW,label_trainW,vystupW);
disp('Muzi -Parametry- vypocitano');

%% WOMEN

vystupM = cell(1151); % priprava cell pro vlozeni hodnot
patientname = 'K';
%% pojmenovani parametru
for wavnr = 1:10
if wavnr >= 6
    middleL = '-l-';
    wavnr2 = wavnr-5;
else
    middleL = '-';
    wavnr2 = wavnr;
end

filename = strcat('9.2' , num2str(middleL) , num2str(wavnr2) , '_1_');
    
i = wavnr;
vystupM(1,1) = cellstr('X');
vystupM(2+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'mean_E'));
vystupM(3+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'var_E'));
vystupM(4+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'std_E'));
vystupM(5+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'max_E'));
vystupM(6+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'min_E'));
vystupM(7+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'median_E'));
vystupM(8+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'1p_E'));
vystupM(9+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'99p_E'));
vystupM(10+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'ir_E'));

vystupM(11+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_median'));
vystupM(12+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_mean'));
vystupM(13+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_std'));
vystupM(14+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_min'));
vystupM(15+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_max'));

vystupM(16+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_frac'));
vystupM(17+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_nbreaks'));
vystupM(18+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'voicing_degree'));

vystupM(19+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_local'));
vystupM(20+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_localabs'));
vystupM(21+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_rap'));
vystupM(22+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_ppq5'));
vystupM(23+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'jitter_ddp'));

vystupM(24+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_local'));
vystupM(25+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_localdb'));
vystupM(26+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq3'));
vystupM(27+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq5'));
vystupM(28+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_apq11'));
vystupM(29+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'shimm_dda'));

vystupM(30+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_aut'));
vystupM(31+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_nh'));
vystupM(32+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'hnr_hn'));

vystupM(33+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_mean'));
vystupM(34+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_var'));
vystupM(35+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_std'));
vystupM(36+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_max'));
vystupM(37+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_min'));
vystupM(38+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_median'));
vystupM(39+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_1p'));
vystupM(40+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_99p'));
vystupM(41+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1_ir'));
vystupM(42+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_mean'));
vystupM(43+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_var'));
vystupM(44+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_std'));
vystupM(45+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_max'));
vystupM(46+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_min'));
vystupM(47+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_median'));
vystupM(48+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_1p'));
vystupM(49+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_99p'));
vystupM(50+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F1b_ir'));

vystupM(51+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_mean'));
vystupM(52+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_var'));
vystupM(53+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_std'));
vystupM(54+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_max'));
vystupM(55+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_min'));
vystupM(56+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_median'));
vystupM(57+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_1p'));
vystupM(58+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_99p'));
vystupM(59+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2_ir'));
vystupM(60+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_mean'));
vystupM(61+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_var'));
vystupM(62+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_std'));
vystupM(63+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_max'));
vystupM(64+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_min'));
vystupM(65+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_median'));
vystupM(66+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_1p'));
vystupM(67+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_99p'));
vystupM(68+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F2b_ir'));

vystupM(69+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_mean'));
vystupM(70+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_var'));
vystupM(71+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_std'));
vystupM(72+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_max'));
vystupM(73+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_min'));
vystupM(74+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_median'));
vystupM(75+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_1p'));
vystupM(76+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_99p'));
vystupM(77+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3_ir'));
vystupM(78+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_mean'));
vystupM(79+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_var'));
vystupM(80+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_std'));
vystupM(81+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_max'));
vystupM(82+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_min'));
vystupM(83+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_median'));
vystupM(84+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_1p'));
vystupM(85+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_99p'));
vystupM(86+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F3b_ir'));

vystupM(87+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TST'));
vystupM(88+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TPT'));
vystupM(89+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NST'));
vystupM(90+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TSR'));
vystupM(91+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NSR'));
vystupM(92+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'PPR'));
vystupM(93+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'TPT50'));
vystupM(94+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'NST50'));
vystupM(95+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'AR'));

vystupM(96+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'LSTER'));

vystupM(97+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'MPSD'));

vystupM(98+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_1'));
vystupM(99+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_2'));
vystupM(100+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_3'));
vystupM(101+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_4'));
vystupM(102+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F1_5'));

vystupM(103+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_1'));
vystupM(104+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_2'));
vystupM(105+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_3'));
vystupM(106+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_4'));
vystupM(107+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'E_rasta_F2_5'));

vystupM(108+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'mean_tko'));
vystupM(109+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'var_tko'));
vystupM(110+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'std_tko'));
vystupM(111+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'max_tko'));
vystupM(112+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'min_tko'));
vystupM(113+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'median_tko'));
vystupM(114+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'1p_tko'));
vystupM(115+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'99p_tko'));
vystupM(116+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'ir_tko'));

vystupM(117+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'F0_VR'));
vystupM(118+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'relF0SD'));
vystupM(119+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'relF0VR'));

vystupM(120+MAXPARAMETERS*(i-1),1) = cellstr(strcat(filename,'SPIR'));

end

coll = 1;
patientnr = 1002;
while patientnr <=1999

%while patientnr <=1015
    
    patientnr = patientnr+1;
     
    % Po skupine kontrolnich recniku prejdi na recniky s PN
    if patientnr == 1999 && patientname == 'K'
        patientname = 'P';
        patientnr = 1006;
    end;
    
    patientnamefull = strcat(num2str(patientname),num2str(patientnr));
    wav_pth2 = strcat('wav/', patientnamefull);
    
    % Pokud existuje slozka recnika, tak proved  
     if exist(wav_pth2,'dir') == 7 
    coll = coll + 1;
    
    %zapis na vystupM kod pacienta
    vystupM(1,coll) = cellstr(patientnamefull);

%% pro vsechny soubory
for wavnr = 1:10
if wavnr >= 6
    middleL = '-l-';
    wavnr2 = wavnr-5;
else
    middleL = '-';
    wavnr2 = wavnr;
end

    row = wavnr;
    filename = strcat(patientnamefull, '_9.2' , num2str(middleL) , num2str(wavnr2) , '_1.wav'); 
    wav_pth3 = strcat(wav_pth2, '/', filename);
   
    %% kontrola existence souboru
    if exist(wav_pth3,'file') == 2
        %disp('existuje'); 
        disp('Pocitam: '); 
        disp(filename); 
    
%% nasleduje vypocet parametru
[x, fs] = wavread( fullfile( wav_pth2, filename));

%% Promenne
winlen = hamming(256);
winover = 128;

wav_pth = strcat(wav_pth2,'/', filename);
time_step = 0;
max_frm = 5500;
win_len = 0.020;
preem = 50;

dir_pth = [pwd '\'];
%dir_pth = 'C:/Škola/Diplomka/Matlab_jaa/prace/';
time_lo = 0.0;
time_up = 0.0;
pitch_lo = 75;
pitch_up = 400;
max_per = 1.3;
max_ampl = 1.6;
silence_th = 0.03;
voicing_th = 0.45;

delka_ramce = 110;
init = 10;

%% Vypocet kratkodobe Energie
E = energie(x, winlen, winover);

%% Vypocet Teageruv Kaiserova energetickeho operatoru
tko = teager_kaiser(x);

%% Vypocet Formantu za pomoci praatcon.exe
[frm_out, F1, F2, F3] = praat_formants(wav_pth, dir_pth, time_step, max_frm, win_len, preem);

%% Vypocet ostatnich parametru za pomoci praatcon.exe
praat_str = praat_info(wav_pth, dir_pth, time_lo, time_up, pitch_lo, pitch_up, max_per, max_ampl, silence_th, voicing_th);

%% Vypocty Tempa řeči
[TST, TPT, NST, TSR, NSR, PPR] = tempo(x, fs, delka_ramce, init, filename);
[TPT50, NST50, AR] = arate(x, fs, delka_ramce, init, filename);
SPIR = praat_str.voicing_nbreaks/(TST/60);

%% Vypocet LSTER (Low Short-Time Energy Ratio)
LSTER = LEF(x, fs, win_len);

%% Vypocet MPSD (Median of Power Spectral Density)
MPSD = mpsd(x);

%% Vypocet RASTA energie formantu

% Pro prvni formant
E_rasta_F1 = rastaenergie(F1, x, fs);

% Pro druhy formant
E_rasta_F2 = rastaenergie(F2, x, fs);

%% zapis vysledku do cellu

% Zapis kratkodobe energie
vystupM(2+MAXPARAMETERS*(row-1),coll) = num2cell(mean(E)); 
vystupM(3+MAXPARAMETERS*(row-1),coll) = num2cell(var(E));
vystupM(4+MAXPARAMETERS*(row-1),coll) = num2cell(std(E));
vystupM(5+MAXPARAMETERS*(row-1),coll) = num2cell(max(E));
vystupM(6+MAXPARAMETERS*(row-1),coll) = num2cell(min(E));
vystupM(7+MAXPARAMETERS*(row-1),coll) = num2cell(median(E));
vystupM(8+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,1));
vystupM(9+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,99));
vystupM(10+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(E,99)-prctile(E,1));

% Zapis kmitoctu zakladniho tonu F0
vystupM(11+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_median(1,1));
vystupM(12+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_mean(1,1));
vystupM(13+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_std(1,1));
vystupM(14+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_min(1,1));
vystupM(15+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_max(1,1));

% Zapis pauzovacich parametru praat
vystupM(16+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_frac(1,1));
vystupM(17+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_nbreaks(1,1));
vystupM(18+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.voicing_degree(1,1));

% Zapis jitter
vystupM(19+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_local(1,1));
vystupM(20+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_localabs(1,1));
vystupM(21+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_rap(1,1));
vystupM(22+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_ppq5(1,1));
vystupM(23+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.jitter_ddp(1,1));

% Zapis shimmer
vystupM(24+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_local(1,1));
vystupM(25+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_localdb(1,1));
vystupM(26+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq3(1,1));
vystupM(27+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq5(1,1));
vystupM(28+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_apq11(1,1));
vystupM(29+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.shimm_dda(1,1));

% Zapis harmonics-to-noise ratio
vystupM(30+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_aut(1,1));
vystupM(31+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_nh(1,1));
vystupM(32+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.hnr_hn(1,1));

% Zapis prvniho formantu F1 a odpovidajiciho pasma B1
vystupM(33+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_mean(1,1));
vystupM(34+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_var(1,1));
vystupM(35+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_std(1,1));
vystupM(36+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_max(1,1));
vystupM(37+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_min(1,1));
vystupM(38+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_med(1,1));
vystupM(39+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_1p(1,1));
vystupM(40+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_99p(1,1));
vystupM(41+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1_ir(1,1));
vystupM(42+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_mean(1,1));
vystupM(43+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_var(1,1));
vystupM(44+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_std(1,1));
vystupM(45+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_max(1,1));
vystupM(46+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_min(1,1));
vystupM(47+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_med(1,1));
vystupM(48+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_1p(1,1));
vystupM(49+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_99p(1,1));
vystupM(50+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F1b_ir(1,1));

% Zapis druheho formantu F2 a odpovidajiciho pasma B2
vystupM(51+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_mean(1,1));
vystupM(52+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_var(1,1));
vystupM(53+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_std(1,1));
vystupM(54+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_max(1,1));
vystupM(55+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_min(1,1));
vystupM(56+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_med(1,1));
vystupM(57+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_1p(1,1));
vystupM(58+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_99p(1,1));
vystupM(59+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2_ir(1,1));
vystupM(60+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_mean(1,1));
vystupM(61+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_var(1,1));
vystupM(62+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_std(1,1));
vystupM(63+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_max(1,1));
vystupM(64+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_min(1,1));
vystupM(65+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_med(1,1));
vystupM(66+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_1p(1,1));
vystupM(67+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_99p(1,1));
vystupM(68+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F2b_ir(1,1));

% Zapis tretiho formantu F3 a odpovidajiciho pasma B3
vystupM(69+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_mean(1,1));
vystupM(70+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_var(1,1));
vystupM(71+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_std(1,1));
vystupM(72+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_max(1,1));
vystupM(73+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_min(1,1));
vystupM(74+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_med(1,1));
vystupM(75+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_1p(1,1));
vystupM(76+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_99p(1,1));
vystupM(77+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3_ir(1,1));
vystupM(78+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_mean(1,1));
vystupM(79+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_var(1,1));
vystupM(80+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_std(1,1));
vystupM(81+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_max(1,1));
vystupM(82+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_min(1,1));
vystupM(83+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_med(1,1));
vystupM(84+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_1p(1,1));
vystupM(85+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_99p(1,1));
vystupM(86+MAXPARAMETERS*(row-1),coll) = num2cell(frm_out.F3b_ir(1,1));

% Zapis Tempa řeči
vystupM(87+MAXPARAMETERS*(row-1),coll) = num2cell(TST);
vystupM(88+MAXPARAMETERS*(row-1),coll) = num2cell(TPT);
vystupM(89+MAXPARAMETERS*(row-1),coll) = num2cell(NST);
vystupM(90+MAXPARAMETERS*(row-1),coll) = num2cell(TSR);
vystupM(91+MAXPARAMETERS*(row-1),coll) = num2cell(NSR);
vystupM(92+MAXPARAMETERS*(row-1),coll) = num2cell(PPR);
vystupM(93+MAXPARAMETERS*(row-1),coll) = num2cell(TPT50);
vystupM(94+MAXPARAMETERS*(row-1),coll) = num2cell(NST50);
vystupM(95+MAXPARAMETERS*(row-1),coll) = num2cell(AR);

% Zapis LSTER (Low Short-Time Energy Ratio)
vystupM(96+MAXPARAMETERS*(row-1),coll) = num2cell(LSTER);

% Zapis MPSD (Median of Power Spectral Density)
vystupM(97+MAXPARAMETERS*(row-1),coll) = num2cell(MPSD);

% Zapis RASTA energie formantu pro prvni formant
vystupM(98+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(1,1));
vystupM(99+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(2,1));
vystupM(100+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(3,1));
vystupM(101+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(4,1));
vystupM(102+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F1(5,1));

% Zapis RASTA energie formantu pro druhy formant
vystupM(103+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(1,1));
vystupM(104+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(2,1));
vystupM(105+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(3,1));
if length(E_rasta_F2) > 3
vystupM(106+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(4,1));
vystupM(107+MAXPARAMETERS*(row-1),coll) = num2cell(E_rasta_F2(5,1));
else
vystupM(106+MAXPARAMETERS*(row-1),coll) = num2cell(NaN);
vystupM(107+MAXPARAMETERS*(row-1),coll) = num2cell(NaN);
end
% Zapis Teageruv Kaiserova energetickeho operatoru
vystupM(108+MAXPARAMETERS*(row-1),coll) = num2cell(mean(tko)); 
vystupM(109+MAXPARAMETERS*(row-1),coll) = num2cell(var(tko));
vystupM(110+MAXPARAMETERS*(row-1),coll) = num2cell(std(tko));
vystupM(111+MAXPARAMETERS*(row-1),coll) = num2cell(max(tko));
vystupM(112+MAXPARAMETERS*(row-1),coll) = num2cell(min(tko));
vystupM(113+MAXPARAMETERS*(row-1),coll) = num2cell(median(tko));
vystupM(114+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,1));
vystupM(115+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,99));
vystupM(116+MAXPARAMETERS*(row-1),coll) = num2cell(prctile(tko,99)-prctile(tko,1));

% Zapis zbyvajicich parametru F0
vystupM(117+MAXPARAMETERS*(row-1),coll) = num2cell(praat_str.F0_max(1,1) - praat_str.F0_min(1,1));
vystupM(118+MAXPARAMETERS*(row-1),coll) = num2cell((praat_str.F0_std(1,1)/praat_str.F0_mean(1,1))*100);
vystupM(119+MAXPARAMETERS*(row-1),coll) = num2cell(((praat_str.F0_max(1,1) - praat_str.F0_min(1,1))/praat_str.F0_mean(1,1))*100);

% Zapis SPIR
vystupM(120+MAXPARAMETERS*(row-1),coll) = num2cell(SPIR);
    else
       %%wav nenalezen 
       disp('wav nenalezen')
        
    end


end %end foru

     else
         % pokud slozka neexistuje
         disp('Slozka neexistuje');        
     end
end

for i=1:10*MAXPARAMETERS+1
    for j=1:1000
        kontrola = isempty(vystupM{i,j});
        if kontrola == 1
        vystupM{i,j} = NaN;
        end   
    end
end
disp('Zeny - vypocitano');
[outputmatM,label_trainM] = ClasificationTable(vystupM,coll-1);
[outputmat2M] = ComputeParameters(outputmatM,label_trainM,vystupM);
disp('Zeny - Parametry - vypocitano');



