clc
clear all;
close all;

%  Načítání dat a parametrů
% EEG
% pro 1 pacienta
eeg1=load('eeg1.mat'); % nasteni signalu
eeg1=eeg1.eeg1;
emg1=load('emg1.mat');
emg1=emg1.emg1;
eog1=load('eog1.mat');
eog1=eog1.eog1;

faze=load('faze.mat'); % nacteni matice fazi
faze=faze.faze;

% pro všech 10 pacientů
% eeg1=load('EEGpro10.mat'); % nasteni signalu
% eeg1=eeg1.EEGpro10;
% emg1=load('EMGpro10.mat');
% emg1=EMGpro10;
% eog=load('EOGpro10.mat');
% eog1=EOGpro10;
% 
% faze=load('fazenove.mat'); % nacteni matice fazi
% faze=faze.fazenove;

fs=256; % frekvence vzorkovací
usek=fs*30; % pocet vzorku na 30 s

alfa_min=8; % Hz
alfa_max=12;
beta_min=18;
beta_max=30;
delta_min=0.5;
delta_max=4;
theta_min=4;
theta_max=7; % Hz

%%  Rozdělení na epochy -> matice epoch

maticeeeg=vec2mat(eeg1,usek);

maticeemg=vec2mat(emg1,usek);

maticeeog=vec2mat(eog1,usek);


%% EEG -> Hypnogram -> Přiřazení fází k epochám, výpočet spektra, výpočet výkonů jednotlivých parametrů u jednotlivých fází, vykreslení

WAKEeeg=3.5;REMeeg=3;N1eeg=2.5;N2eeg=2;N3eeg=1.5;unscored=0;

cast_WAKEeeg=[];cast_REMeeg=[];cast_N3eeg=[];cast_N2eeg=[];cast_N1eeg=[]; % iniciovani promennych

hypno=zeros(1,length(faze));

j=1;n1=1;n2=1;n3=1;n4=1;n5=1;

for h=1:length(faze)

        eegsp(h,:)=fft(maticeeeg(h,:));      % vypocet spektrum eeg
        eegsp2=(abs(eegsp./(length(maticeeeg(h,:))))).^2;
        spektrumeeg=eegsp2(:,1:length(eegsp2)/2);
        sp=spektrumeeg(delta_min*length(spektrumeeg)/(fs/2):theta_max*length(spektrumeeg)/(fs/2));
        sp1=spektrumeeg(alfa_min*length(spektrumeeg)/(fs/2):alfa_max*length(spektrumeeg)/(fs/2));
        sp2=spektrumeeg(beta_min*length(spektrumeeg)/(fs/2):beta_max*length(spektrumeeg)/(fs/2));
        spektrumeeg2=[sp sp1 sp2];
        c_f=(sum(spektrumeeg2));

    if faze(h)==0
        hypno(j)=WAKEeeg;
        cast_WAKEeeg=[cast_WAKEeeg; maticeeeg(h,:)];
        
        vykon_delta_w(n1,:)=100*((sum(spektrumeeg(delta_min*length(spektrumeeg)/(fs/2):delta_max*length(spektrumeeg)/(fs/2))))./c_f); % vypocet vykonu
        vykon_theta_w(n1,:)=100*((sum(spektrumeeg(theta_min*length(spektrumeeg)/(fs/2):theta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_alfa_w(n1,:)=100*((sum(spektrumeeg(alfa_min*length(spektrumeeg)/(fs/2):alfa_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_beta_w(n1,:)=100*((sum(spektrumeeg(beta_min*length(spektrumeeg)/(fs/2):beta_max*length(spektrumeeg)/(fs/2))))./c_f);

        n1=n1+1;
    elseif faze(h)==1
        hypno(j)=N1eeg;
        cast_N1eeg=[cast_N1eeg; maticeeeg(h,:)];

        vykon_delta_n1(n2,:)=100*((sum(spektrumeeg(delta_min*length(spektrumeeg)/(fs/2):delta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_theta_n1(n2,:)=100*((sum(spektrumeeg(theta_min*length(spektrumeeg)/(fs/2):theta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_alfa_n1(n2,:)=100*((sum(spektrumeeg(alfa_min*length(spektrumeeg)/(fs/2):alfa_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_beta_n1(n2,:)=100*((sum(spektrumeeg(beta_min*length(spektrumeeg)/(fs/2):beta_max*length(spektrumeeg)/(fs/2))))./c_f);
        
        n2=n2+1;
    elseif faze(h)==2
        hypno(j)=N2eeg;
        cast_N2eeg=[cast_N2eeg; maticeeeg(h,:)];
        
        vykon_delta_n2(n3,:)=100*((sum(spektrumeeg(delta_min*length(spektrumeeg)/(fs/2):delta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_theta_n2(n3,:)=100*((sum(spektrumeeg(theta_min*length(spektrumeeg)/(fs/2):theta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_alfa_n2(n3,:)=100*((sum(spektrumeeg(alfa_min*length(spektrumeeg)/(fs/2):alfa_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_beta_n2(n3,:)=100*((sum(spektrumeeg(beta_min*length(spektrumeeg)/(fs/2):beta_max*length(spektrumeeg)/(fs/2))))./c_f);
        
        n3=n3+1;
    elseif faze(h)==3
        hypno(j)=N3eeg;
        cast_N3eeg=[cast_N3eeg; maticeeeg(h,:)];

        vykon_delta_n3(n4,:)=100*((sum(spektrumeeg(delta_min*length(spektrumeeg)/(fs/2):delta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_theta_n3(n4,:)=100*((sum(spektrumeeg(theta_min*length(spektrumeeg)/(fs/2):theta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_alfa_n3(n4,:)=100*((sum(spektrumeeg(alfa_min*length(spektrumeeg)/(fs/2):alfa_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_beta_n3(n4,:)=100*((sum(spektrumeeg(beta_min*length(spektrumeeg)/(fs/2):beta_max*length(spektrumeeg)/(fs/2))))./c_f);
        
        n4=n4+1;
    elseif faze(h)==5
        hypno(j)=REMeeg;
        cast_REMeeg=[cast_REMeeg; maticeeeg(h,:)];

        vykon_delta_r(n5,:)=100*((sum(spektrumeeg(delta_min*length(spektrumeeg)/(fs/2):delta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_theta_r(n5,:)=100*((sum(spektrumeeg(theta_min*length(spektrumeeg)/(fs/2):theta_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_alfa_r(n5,:)=100*((sum(spektrumeeg(alfa_min*length(spektrumeeg)/(fs/2):alfa_max*length(spektrumeeg)/(fs/2))))./c_f);
        vykon_beta_r(n5,:)=100*((sum(spektrumeeg(beta_min*length(spektrumeeg)/(fs/2):beta_max*length(spektrumeeg)/(fs/2))))./c_f);

        n5=n5+1;
    else
        hypno(j)=unscored;
    end
    j=j+1;

end

figure(1)
group_d=[zeros(1,length(vykon_delta_w)),ones(1,length(vykon_delta_n1)),2*ones(1,length(vykon_delta_n2)), 3*ones(1,length(vykon_delta_n3)), 4*ones(1,length(vykon_delta_r))];
boxplot([vykon_delta_w', vykon_delta_n1', vykon_delta_n2', vykon_delta_n3', vykon_delta_r'],group_d,'labels',{'wake','N1','N2','N3','REM'})
title('Výkon pásma delta'),xlabel('Spánkové fáze'), ylabel(' Relativní výkonové spektrum frekvencního pásma [%]')
set(findall(gcf,'type','text'),'FontSize',10)
% 
figure(2)
group_t=[zeros(1,length(vykon_theta_w)),ones(1,length(vykon_theta_n1)),2*ones(1,length(vykon_theta_n2)), 3*ones(1,length(vykon_theta_n3)), 4*ones(1,length(vykon_theta_r))];
boxplot([vykon_theta_w', vykon_theta_n1', vykon_theta_n2', vykon_theta_n3', vykon_theta_r'],group_t,'labels',{'wake','N1','N2','N3','REM'})
title('Výkon pásma theta'), xlabel('Spánkové fáze'), ylabel(' Relativní výkonové spektrum frekven?ního pásma [%]')
% 
figure(3)
group_a=[zeros(1,length(vykon_alfa_w)),ones(1,length(vykon_alfa_n1)),2*ones(1,length(vykon_alfa_n2)), 3*ones(1,length(vykon_alfa_n3)), 4*ones(1,length(vykon_alfa_r))];
boxplot([vykon_alfa_w', vykon_alfa_n1', vykon_alfa_n2', vykon_alfa_n3', vykon_alfa_r'],group_a,'labels',{'wake','N1','N2','N3','REM'})
title('Výkon pásma alfa'),xlabel('Spánkové fáze'), ylabel(' Relativní výkonové spektrum frekvencního pásma [%]')
xlim([0 6]), ylim([-50 50])
% 
figure(4)
group_b=[zeros(1,length(vykon_beta_w)),ones(1,length(vykon_beta_n1)),2*ones(1,length(vykon_beta_n2)), 3*ones(1,length(vykon_beta_n3)), 4*ones(1,length(vykon_beta_r))];
boxplot([vykon_beta_w', vykon_beta_n1', vykon_beta_n2', vykon_beta_n3', vykon_beta_r'],group_b,'labels',{'wake','N1','N2','N3','REM'})
title('Výkon pásma beta'),xlabel('Spánkové fáze'), ylabel(' Relativní výkonové spektrum frekvencního pásma [%]')

%% EOG a EMG -> Hypnogram a rozdělení na fáze

WAKEeeg=3.5;REMeeg=3;N1eeg=2.5;N2eeg=2;N3eeg=1.5;unscored=0;

cast_WAKEemg=[];cast_REMemg=[];cast_N3emg=[];cast_N2emg=[];cast_N1emg=[];
cast_WAKEeog=[];cast_REMeog=[];cast_N3eog=[];cast_N2eog=[];cast_N1eog=[];

hypno=zeros(1,length(faze));

j=1;n1=1;n2=1;n3=1;n4=1;n5=1;

for h=1:length(faze)

    if faze(h)==0
        hypno(j)=WAKEeeg;
        cast_WAKEeog=[cast_WAKEeog; maticeeog(h,:)];
        cast_WAKEemg=[cast_WAKEemg; maticeemg(h,:)];

        n1=n1+1;
    elseif faze(h)==1
        hypno(j)=N1eeg;
        cast_N1eog=[cast_N1eog; maticeeog(h,:)];
        cast_N1emg=[cast_N1emg; maticeemg(h,:)];

        n2=n2+1;
    elseif faze(h)==2
        hypno(j)=N2eeg;
        cast_N2eog=[cast_N2eog; maticeeog(h,:)];
        cast_N2emg=[cast_N2emg; maticeemg(h,:)];   

        n3=n3+1;
    elseif faze(h)==3
        hypno(j)=N3eeg;
        cast_N3eog=[cast_N3eog; maticeeog(h,:)]; 
        cast_N3emg=[cast_N3emg; maticeemg(h,:)]; 

        n4=n4+1;
    elseif faze(h)==5
        hypno(j)=REMeeg;
        cast_REMeog=[cast_REMeog; maticeeog(h,:)];
        cast_REMemg=[cast_REMemg; maticeemg(h,:)];

        n5=n5+1;
    else
        hypno(j)=unscored;
    end
    j=j+1;

end

j=1;

%%  Časová analýza, výpočet statistických parametrů

aktivitaREMeeg=[];aktivitaN1eeg=[];aktivitaN2eeg=[];aktivitaN3eeg=[];aktivitaWAKEeeg=[];

aktivitaREMeog=[];aktivitaN1eog=[];aktivitaN2eog=[];aktivitaN3eog=[];aktivitaWAKEeog=[];

aktivitaREMemg=[];aktivitaN1emg=[];aktivitaN2emg=[];aktivitaN3emg=[];aktivitaWAKEemg=[];

sikmostREMeeg=[];sikmostN1eeg=[];sikmostN2eeg=[];sikmostN3eeg=[];sikmostWAKEeeg=[];

sikmostREMeog=[];sikmostN1eog=[];sikmostN2eog=[];sikmostN3eog=[];sikmostWAKEeog=[];

sikmostREMemg=[];sikmostN1emg=[];sikmostN2emg=[];sikmostN3emg=[];sikmostWAKEemg=[];

spicatostREMeeg=[];spicatostN1eeg=[];spicatostN2eeg=[];spicatostN3eeg=[];spicatostWAKEeeg=[];

spicatostREMeog=[];spicatostN1eog=[];spicatostN2eog=[];spicatostN3eog=[];spicatostWAKEeog=[];

spicatostREMemg=[];spicatostN1emg=[];spicatostN2emg=[];spicatostN3emg=[];spicatostWAKEemg=[];

entropieREMeeg=[];entropieN1eeg=[];entropieN2eeg=[];entropieN3eeg=[];entropieWAKEeeg=[];

entropieREMeog=[];entropieN1eog=[];entropieN2eog=[];entropieN3eog=[];entropieWAKEeog=[];

entropieREMemg=[];entropieN1emg=[];entropieN2emg=[];entropieN3emg=[];entropieWAKEemg=[];

percentilREMeeg=[];percentilN1eeg=[];percentilN2eeg=[];percentilN3eeg=[];percentilWAKEeeg=[];

percentilREMeog=[];percentilN1eog=[];percentilN2eog=[];percentilN3eog=[];percentilWAKEeog=[];

percentilREMemg=[];percentilN1emg=[];percentilN2emg=[];percentilN3emg=[];percentilWAKEemg=[];

smerodatodREMeeg=[];smerodatodN1eeg=[];smerodatodN2eeg=[];smerodatodN3eeg=[];smerodatodWAKEeeg=[];

smerodatodREMeog=[];smerodatodN1eog=[];smerodatodN2eog=[];smerodatodN3eog=[];smerodatodWAKEeog=[];

smerodatodREMemg=[];smerodatodN1emg=[];smerodatodN2emg=[];smerodatodN3emg=[];smerodatodWAKEemg=[];

stredhodREMeeg=[];stredhodN1eeg=[];stredhodN2eeg=[];stredhodN3eeg=[];stredhodWAKEeeg=[];

stredhodREMeog=[];stredhodN1eog=[];stredhodN2eog=[];stredhodN3eog=[];stredhodWAKEeog=[];

stredhodREMemg=[];stredhodN1emg=[];stredhodN2emg=[];stredhodN3emg=[];stredhodWAKEemg=[];

mobilitaREMeeg=[];mobilitaN1eeg=[];mobilitaN2eeg=[];mobilitaN3eeg=[];mobilitaWAKEeeg=[];

mobilitaREMeog=[];mobilitaN1eog=[];mobilitaN2eog=[];mobilitaN3eog=[];mobilitaWAKEeog=[];

mobilitaREMemg=[];mobilitaN1emg=[];mobilitaN2emg=[];mobilitaN3emg=[];mobilitaWAKEemg=[];

slozitostREMeeg=[];slozitostN1eeg=[];slozitostN2eeg=[];slozitostN3eeg=[];slozitostWAKEeeg=[];

slozitostREMeog=[];slozitostN1eog=[];slozitostN2eog=[];slozitostN3eog=[];slozitostWAKEeog=[];

slozitostREMemg=[];slozitostN1emg=[];slozitostN2emg=[];slozitostN3emg=[];slozitostWAKEemg=[];


for  b=1:size(cast_REMeeg,1)

aktivitaREMeeg= [aktivitaREMeeg; var(cast_REMeeg(b,:))];
sikmostREMeeg=[sikmostREMeeg; skewness(cast_REMeeg(b,:))];
spicatostREMeeg=[spicatostREMeeg; kurtosis(cast_REMeeg(b,:))];
entropieREMeeg=[entropieREMeeg; entropy(cast_REMeeg(b,:))];
percentilREMeeg=[percentilREMeeg; quantile(cast_REMeeg(b,:), 0.75)];
smerodatodREMeeg=[smerodatodREMeeg; std(cast_REMeeg(b,:))];
stredhodREMeeg=[stredhodREMeeg; mean(cast_REMeeg(b,:))];
mobilitaREMeeg=[mobilitaREMeeg; sqrt(var(diff(cast_REMeeg(b,:),1))/var(cast_REMeeg(b,:)))];
slozitostREMeeg=[slozitostREMeeg; sqrt(var(diff(cast_REMeeg(b,:),2))*var(cast_REMeeg(b,:))/var(diff(cast_REMeeg(b,:),1))^2)];

aktivitaREMeog= [aktivitaREMeog; var(cast_REMeog(b,:))];
sikmostREMeog=[sikmostREMeog; skewness(cast_REMeog(b,:))];
spicatostREMeog=[spicatostREMeog; kurtosis(cast_REMeog(b,:))];
entropieREMeog=[entropieREMeog; entropy(cast_REMeog(b,:))];
percentilREMeog=[percentilREMeog; quantile(cast_REMeog(b,:), 0.75)];
smerodatodREMeog=[smerodatodREMeog; std(cast_REMeog(b,:))];
stredhodREMeog=[stredhodREMeog; mean(cast_REMeog(b,:))];
mobilitaREMeog=[mobilitaREMeog; sqrt(var(diff(cast_REMeog(b,:),1))/var(cast_REMeog(b,:)))];
slozitostREMeog=[slozitostREMeog; sqrt(var(diff(cast_REMeog(b,:),2))*var(cast_REMeog(b,:))/var(diff(cast_REMeog(b,:),1))^2)];

aktivitaREMemg= [aktivitaREMemg; var(cast_REMemg(b,:))];
sikmostREMemg=[sikmostREMemg; skewness(cast_REMemg(b,:))];
spicatostREMemg=[spicatostREMemg; kurtosis(cast_REMemg(b,:))];
entropieREMemg=[entropieREMemg; entropy(cast_REMemg(b,:))];
percentilREMemg=[percentilREMemg; quantile(cast_REMemg(b,:), 0.75)];
smerodatodREMemg=[smerodatodREMemg; std(cast_REMemg(b,:))];
stredhodREMemg=[stredhodREMemg; mean(cast_REMemg(b,:))];
mobilitaREMemg=[mobilitaREMemg; sqrt(var(diff(cast_REMemg(b,:),1))/var(cast_REMemg(b,:)))];
slozitostREMemg=[slozitostREMemg; sqrt(var(diff(cast_REMemg(b,:),2))*var(cast_REMemg(b,:))/var(diff(cast_REMemg(b,:),1))^2)];

b=b+1;
  end

for  b=1:size(cast_N1eeg,1)
    
aktivitaN1eeg= [aktivitaN1eeg; var(cast_N1eeg(b,:))];
sikmostN1eeg=[sikmostN1eeg; skewness(cast_N1eeg(b,:))];
spicatostN1eeg=[spicatostN1eeg; kurtosis(cast_N1eeg(b,:))];
entropieN1eeg=[entropieN1eeg; entropy(cast_N1eeg(b,:))];
percentilN1eeg=[percentilN1eeg; quantile(cast_N1eeg(b,:), 0.75)];
smerodatodN1eeg=[smerodatodN1eeg; std(cast_N1eeg(b,:))];
stredhodN1eeg=[stredhodN1eeg; mean(cast_N1eeg(b,:))];
mobilitaN1eeg=[mobilitaN1eeg; sqrt(var(diff(cast_N1eeg(b,:),1))/var(cast_N1eeg(b,:)))];
slozitostN1eeg=[slozitostN1eeg; sqrt(var(diff(cast_N1eeg(b,:),2))*var(cast_N1eeg(b,:))/var(diff(cast_N1eeg(b,:),1))^2)];

aktivitaN1eog= [aktivitaN1eog; var(cast_N1eog(b,:))];
sikmostN1eog=[sikmostN1eog; skewness(cast_N1eog(b,:))];
spicatostN1eog=[spicatostN1eog; kurtosis(cast_N1eog(b,:))];
entropieN1eog=[entropieN1eog; entropy(cast_N1eog(b,:))];
percentilN1eog=[percentilN1eog; quantile(cast_N1eog(b,:), 0.75)];
smerodatodN1eog=[smerodatodN1eog; std(cast_N1eog(b,:))];
stredhodN1eog=[stredhodN1eog; mean(cast_N1eog(b,:))];
mobilitaN1eog=[mobilitaN1eog; sqrt(var(diff(cast_N1eog(b,:),1))/var(cast_N1eog(b,:)))];
slozitostN1eog=[slozitostN1eog; sqrt(var(diff(cast_N1eog(b,:),2))*var(cast_N1eog(b,:))/var(diff(cast_N1eog(b,:),1))^2)];

aktivitaN1emg= [aktivitaN1emg; var(cast_N1emg(b,:))];
sikmostN1emg=[sikmostN1emg; skewness(cast_N1emg(b,:))];
spicatostN1emg=[spicatostN1emg; kurtosis(cast_N1emg(b,:))];
entropieN1emg=[entropieN1emg; entropy(cast_N1emg(b,:))];
percentilN1emg=[percentilN1emg; quantile(cast_N1emg(b,:), 0.75)];
smerodatodN1emg=[smerodatodN1emg; std(cast_N1emg(b,:))];
stredhodN1emg=[stredhodN1emg; mean(cast_N1emg(b,:))];
mobilitaN1emg=[mobilitaN1emg; sqrt(var(diff(cast_N1emg(b,:),1))/var(cast_N1emg(b,:)))];
slozitostN1emg=[slozitostN1emg; sqrt(var(diff(cast_N1emg(b,:),2))*var(cast_N1emg(b,:))/var(diff(cast_N1emg(b,:),1))^2)];

b=b+1;
end

 for  b=1:size(cast_N2eeg,1)
      
aktivitaN2eeg= [aktivitaN2eeg; var(cast_N2eeg(b,:))];
sikmostN2eeg=[sikmostN2eeg; skewness(cast_N2eeg(b,:))];
spicatostN2eeg=[spicatostN2eeg; kurtosis(cast_N2eeg(b,:))];
entropieN2eeg=[entropieN2eeg; entropy(cast_N2eeg(b,:))];
percentilN2eeg=[percentilN2eeg; quantile(cast_N2eeg(b,:), 0.75)];
smerodatodN2eeg=[smerodatodN2eeg; std(cast_N2eeg(b,:))];
stredhodN2eeg=[stredhodN2eeg; mean(cast_N2eeg(b,:))];
mobilitaN2eeg=[mobilitaN2eeg; sqrt(var(diff(cast_N2eeg(b,:),1))/var(cast_N2eeg(b,:)))];
slozitostN2eeg=[slozitostN2eeg; sqrt(var(diff(cast_N2eeg(b,:),2))*var(cast_N2eeg(b,:))/var(diff(cast_N2eeg(b,:),1))^2)];

aktivitaN2eog= [aktivitaN2eog; var(cast_N2eog(b,:))];
sikmostN2eog=[sikmostN2eog; skewness(cast_N2eog(b,:))];
spicatostN2eog=[spicatostN2eog; kurtosis(cast_N2eog(b,:))];
entropieN2eog=[entropieN2eog; entropy(cast_N2eog(b,:))];
percentilN2eog=[percentilN2eog; quantile(cast_N2eog(b,:), 0.75)];
smerodatodN2eog=[smerodatodN2eog; std(cast_N2eog(b,:))];
stredhodN2eog=[stredhodN2eog; mean(cast_N2eog(b,:))];
mobilitaN2eog=[mobilitaN2eog; sqrt(var(diff(cast_N2eog(b,:),1))/var(cast_N2eog(b,:)))];
slozitostN2eog=[slozitostN2eog; sqrt(var(diff(cast_N2eog(b,:),2))*var(cast_N2eog(b,:))/var(diff(cast_N2eog(b,:),1))^2)];

aktivitaN2emg= [aktivitaN2emg; var(cast_N2emg(b,:))];
sikmostN2emg=[sikmostN2emg; skewness(cast_N2emg(b,:))];
spicatostN2emg=[spicatostN2emg; kurtosis(cast_N2emg(b,:))];
entropieN2emg=[entropieN2emg; entropy(cast_N2emg(b,:))];
percentilN2emg=[percentilN2emg; quantile(cast_N2emg(b,:), 0.75)];
smerodatodN2emg=[smerodatodN2emg; std(cast_N2emg(b,:))];
stredhodN2emg=[stredhodN2emg; mean(cast_N2emg(b,:))];
mobilitaN2emg=[mobilitaN2emg; sqrt(var(diff(cast_N2emg(b,:),1))/var(cast_N2emg(b,:)))];
slozitostN2emg=[slozitostN2emg; sqrt(var(diff(cast_N2emg(b,:),2))*var(cast_N2emg(b,:))/var(diff(cast_N2emg(b,:),1))^2)];

b=b+1;
end

for  b=1:size(cast_N3eeg,1)
      
aktivitaN3eeg= [aktivitaN3eeg; var(cast_N3eeg(b,:))];
sikmostN3eeg=[sikmostN3eeg; skewness(cast_N3eeg(b,:))];
spicatostN3eeg=[spicatostN3eeg; kurtosis(cast_N3eeg(b,:))];
entropieN3eeg=[entropieN3eeg; entropy(cast_N3eeg(b,:))];
percentilN3eeg=[percentilN3eeg; quantile(cast_N3eeg(b,:), 0.75)];
smerodatodN3eeg=[smerodatodN3eeg; std(cast_N3eeg(b,:))];
stredhodN3eeg=[stredhodN3eeg; mean(cast_N3eeg(b,:))];
mobilitaN3eeg=[mobilitaN3eeg; sqrt(var(diff(cast_N3eeg(b,:),1))/var(cast_N3eeg(b,:)))];
slozitostN3eeg=[slozitostN3eeg; sqrt(var(diff(cast_N3eeg(b,:),2))*var(cast_N3eeg(b,:))/var(diff(cast_N3eeg(b,:),1))^2)];

aktivitaN3eog= [aktivitaN3eog; var(cast_N3eog(b,:))];
sikmostN3eog=[sikmostN3eog; skewness(cast_N3eog(b,:))];
spicatostN3eog=[spicatostN3eog; kurtosis(cast_N3eog(b,:))];
entropieN3eog=[entropieN3eog; entropy(cast_N3eog(b,:))];
percentilN3eog=[percentilN3eog; quantile(cast_N3eog(b,:), 0.75)];
smerodatodN3eog=[smerodatodN3eog; std(cast_N3eog(b,:))];
stredhodN3eog=[stredhodN3eog; mean(cast_N3eog(b,:))];
mobilitaN3eog=[mobilitaN3eog; sqrt(var(diff(cast_N3eog(b,:),1))/var(cast_N3eog(b,:)))];
slozitostN3eog=[slozitostN3eog; sqrt(var(diff(cast_N3eog(b,:),2))*var(cast_N3eog(b,:))/var(diff(cast_N3eog(b,:),1))^2)];

aktivitaN3emg= [aktivitaN3emg; var(cast_N3emg(b,:))];
sikmostN3emg=[sikmostN3emg; skewness(cast_N3emg(b,:))];
spicatostN3emg=[spicatostN3emg; kurtosis(cast_N3emg(b,:))];
entropieN3emg=[entropieN3emg; entropy(cast_N3emg(b,:))];
percentilN3emg=[percentilN3emg; quantile(cast_N3emg(b,:), 0.75)];
smerodatodN3emg=[smerodatodN3emg; std(cast_N3emg(b,:))];
stredhodN3emg=[stredhodN3emg; mean(cast_N3emg(b,:))];
mobilitaN3emg=[mobilitaN3emg; sqrt(var(diff(cast_N3emg(b,:),1))/var(cast_N3emg(b,:)))];
slozitostN3emg=[slozitostN3emg; sqrt(var(diff(cast_N3emg(b,:),2))*var(cast_N3emg(b,:))/var(diff(cast_N3emg(b,:),1))^2)];

b=b+1;
end

for  b=1:size(cast_WAKEeeg,1)

aktivitaWAKEeeg= [aktivitaWAKEeeg; var(cast_WAKEeeg(b,:))];
sikmostWAKEeeg=[sikmostWAKEeeg; skewness(cast_WAKEeeg(b,:))];
spicatostWAKEeeg=[spicatostWAKEeeg; kurtosis(cast_WAKEeeg(b,:))];
entropieWAKEeeg=[entropieWAKEeeg; entropy(cast_WAKEeeg(b,:))];
percentilWAKEeeg=[percentilWAKEeeg; quantile(cast_WAKEeeg(b,:), 0.75)];
smerodatodWAKEeeg=[smerodatodWAKEeeg; std(cast_WAKEeeg(b,:))];
stredhodWAKEeeg=[stredhodWAKEeeg; mean(cast_WAKEeeg(b,:))];
mobilitaWAKEeeg=[mobilitaWAKEeeg; sqrt(var(diff(cast_WAKEeeg(b,:),1))/var(cast_WAKEeeg(b,:)))];
slozitostWAKEeeg=[slozitostWAKEeeg; sqrt(var(diff(cast_WAKEeeg(b,:),2))*var(cast_WAKEeeg(b,:))/var(diff(cast_WAKEeeg(b,:),1))^2)];

aktivitaWAKEeog= [aktivitaWAKEeog; var(cast_WAKEeog(b,:))];
sikmostWAKEeog=[sikmostWAKEeog; skewness(cast_WAKEeog(b,:))];
spicatostWAKEeog=[spicatostWAKEeog; kurtosis(cast_WAKEeog(b,:))];
entropieWAKEeog=[entropieWAKEeog; entropy(cast_WAKEeog(b,:))];
percentilWAKEeog=[percentilWAKEeog; quantile(cast_WAKEeog(b,:), 0.75)];
smerodatodWAKEeog=[smerodatodWAKEeog; std(cast_WAKEeog(b,:))];
stredhodWAKEeog=[stredhodWAKEeog; mean(cast_WAKEeog(b,:))];
mobilitaWAKEeog=[mobilitaWAKEeog; sqrt(var(diff(cast_WAKEeog(b,:),1))/var(cast_WAKEeog(b,:)))];
slozitostWAKEeog=[slozitostWAKEeog; sqrt(var(diff(cast_WAKEeog(b,:),2))*var(cast_WAKEeog(b,:))/var(diff(cast_WAKEeog(b,:),1))^2)];

aktivitaWAKEemg= [aktivitaWAKEemg; var(cast_WAKEemg(b,:))];
sikmostWAKEemg=[sikmostWAKEemg; skewness(cast_WAKEemg(b,:))];
spicatostWAKEemg=[spicatostWAKEemg; kurtosis(cast_WAKEemg(b,:))];
entropieWAKEemg=[entropieWAKEemg; entropy(cast_WAKEemg(b,:))];
percentilWAKEemg=[percentilWAKEemg; quantile(cast_WAKEemg(b,:), 0.75)];
smerodatodWAKEemg=[smerodatodWAKEemg; std(cast_WAKEemg(b,:))];
stredhodWAKEemg=[stredhodWAKEemg; mean(cast_WAKEemg(b,:))];
mobilitaWAKEemg=[mobilitaWAKEemg; sqrt(var(diff(cast_WAKEemg(b,:),1))/var(cast_WAKEemg(b,:)))];
slozitostWAKEemg=[slozitostWAKEemg; sqrt(var(diff(cast_WAKEemg(b,:),2))*var(cast_WAKEemg(b,:))/var(diff(cast_WAKEemg(b,:),1))^2)];

b=b+1;
end

%%  Boxploty pro vykreslení statistických parametrů

figure('name','Boxploty aktivity EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(aktivitaREMeeg)),ones(1,length(aktivitaN1eeg)),2*ones(1,length(aktivitaN2eeg)), 3*ones(1,length(aktivitaN3eeg)), 4*ones(1,length(aktivitaWAKEeeg))];
boxplot([aktivitaREMeeg', aktivitaN1eeg', aktivitaN2eeg', aktivitaN3eeg', aktivitaWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('AKTIVITA EEG'),xlabel('Spánkové fáze'), ylabel('Aktivita [µV]')
% ylim([0 30000])
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(aktivitaREMeog)),ones(1,length(aktivitaN1eog)),2*ones(1,length(aktivitaN2eog)), 3*ones(1,length(aktivitaN3eog)), 4*ones(1,length(aktivitaWAKEeog))];
boxplot([aktivitaREMeog', aktivitaN1eog', aktivitaN2eog', aktivitaN3eog', aktivitaWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('AKTIVITA EOG'),xlabel('Spánkové fáze'), ylabel('Aktivita [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(aktivitaREMemg)),ones(1,length(aktivitaN1emg)),2*ones(1,length(aktivitaN2emg)), 3*ones(1,length(aktivitaN3emg)), 4*ones(1,length(aktivitaWAKEemg))];
boxplot([aktivitaREMemg', aktivitaN1emg', aktivitaN2emg', aktivitaN3emg', aktivitaWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('AKTIVITA EMG'),xlabel('Spánkové fáze'), ylabel('Aktivita [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty sikmosti EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(sikmostREMeeg)),ones(1,length(sikmostN1eeg)),2*ones(1,length(sikmostN2eeg)), 3*ones(1,length(sikmostN3eeg)), 4*ones(1,length(sikmostWAKEeeg))];
boxplot([sikmostREMeeg', sikmostN1eeg', sikmostN2eeg', sikmostN3eeg', sikmostWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SIKMOST EEG'),xlabel('Spánkové fáze'), ylabel('Sikmost')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(sikmostREMeog)),ones(1,length(sikmostN1eog)),2*ones(1,length(sikmostN2eog)), 3*ones(1,length(sikmostN3eog)), 4*ones(1,length(sikmostWAKEeog))];
boxplot([sikmostREMeog', sikmostN1eog', sikmostN2eog', sikmostN3eog', sikmostWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SIKMOST EOG'),xlabel('Spánkové fáze'), ylabel('Sikmost')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(sikmostREMemg)),ones(1,length(sikmostN1emg)),2*ones(1,length(sikmostN2emg)), 3*ones(1,length(sikmostN3emg)), 4*ones(1,length(sikmostWAKEemg))];
boxplot([sikmostREMemg', sikmostN1emg', sikmostN2emg', sikmostN3emg', sikmostWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SIKMOST EMG'),xlabel('Spánkové fáze'), ylabel('Sikmost')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty spicatosti EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(spicatostREMeeg)),ones(1,length(spicatostN1eeg)),2*ones(1,length(spicatostN2eeg)), 3*ones(1,length(spicatostN3eeg)), 4*ones(1,length(spicatostWAKEeeg))];
boxplot([spicatostREMeeg', spicatostN1eeg', spicatostN2eeg', spicatostN3eeg', spicatostWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SPICATOST EEG'),xlabel('Spánkové fáze'), ylabel('Spicatost')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(spicatostREMeog)),ones(1,length(spicatostN1eog)),2*ones(1,length(spicatostN2eog)), 3*ones(1,length(spicatostN3eog)), 4*ones(1,length(spicatostWAKEeog))];
boxplot([spicatostREMeog', spicatostN1eog', spicatostN2eog', spicatostN3eog', spicatostWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SPICATOST EOG'),xlabel('Spánkové fáze'), ylabel('Spicatost')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(spicatostREMemg)),ones(1,length(spicatostN1emg)),2*ones(1,length(spicatostN2emg)), 3*ones(1,length(spicatostN3emg)), 4*ones(1,length(spicatostWAKEemg))];
boxplot([spicatostREMemg', spicatostN1emg', spicatostN2emg', spicatostN3emg', spicatostWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SPICATOST EMG'),xlabel('Spánkové fáze'), ylabel('Spicatost')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty entropii EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(entropieREMeeg)),ones(1,length(entropieN1eeg)),2*ones(1,length(entropieN2eeg)), 3*ones(1,length(entropieN3eeg)), 4*ones(1,length(entropieWAKEeeg))];
boxplot([entropieREMeeg', entropieN1eeg', entropieN2eeg', entropieN3eeg', entropieWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('ENTROPIE EEG'),xlabel('Spánkové fáze'), ylabel('Entropie [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(entropieREMeog)),ones(1,length(entropieN1eog)),2*ones(1,length(entropieN2eog)), 3*ones(1,length(entropieN3eog)), 4*ones(1,length(entropieWAKEeog))];
boxplot([entropieREMeog', entropieN1eog',entropieN2eog', entropieN3eog', entropieWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('ENTROPIE EOG'),xlabel('Spánkové fáze'), ylabel('Entropie [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(entropieREMemg)),ones(1,length(entropieN1emg)),2*ones(1,length(entropieN2emg)), 3*ones(1,length(entropieN3emg)), 4*ones(1,length(entropieWAKEemg))];
boxplot([entropieREMemg', entropieN1emg', entropieN2emg', entropieN3emg', entropieWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('ENTROPIE EMG'),xlabel('Spánkové fáze'), ylabel('Entropie [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
hold off


figure('name','Boxploty 75. percentilu EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(percentilREMeeg)),ones(1,length(percentilN1eeg)),2*ones(1,length(percentilN2eeg)), 3*ones(1,length(percentilN3eeg)), 4*ones(1,length(percentilWAKEeeg))];
boxplot([percentilREMeeg', percentilN1eeg', percentilN2eeg', percentilN3eeg', percentilWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('75. PERCENTIL EEG'),xlabel('Spánkové fáze'), ylabel('Percentil')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(percentilREMeog)),ones(1,length(percentilN1eog)),2*ones(1,length(percentilN2eog)), 3*ones(1,length(percentilN3eog)), 4*ones(1,length(percentilWAKEeog))];
boxplot([percentilREMeog', percentilN1eog', percentilN2eog', percentilN3eog', percentilWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('75. PERCENTIL EOG'),xlabel('Spánkové fáze'), ylabel('Percentil')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(percentilREMemg)),ones(1,length(percentilN1emg)),2*ones(1,length(percentilN2emg)), 3*ones(1,length(percentilN3emg)), 4*ones(1,length(percentilWAKEemg))];
boxplot([percentilREMemg',percentilN1emg', percentilN2emg', percentilN3emg', percentilWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('75. PERCENTIL EMG'),xlabel('Spánkové fáze'), ylabel('Percentil')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty smerodatne odchylky EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(smerodatodREMeeg)),ones(1,length(smerodatodN1eeg)),2*ones(1,length(smerodatodN2eeg)), 3*ones(1,length(smerodatodN3eeg)), 4*ones(1,length(smerodatodWAKEeeg))];
boxplot([smerodatodREMeeg', smerodatodN1eeg',smerodatodN2eeg', smerodatodN3eeg', smerodatodWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SMERODATNA ODCHYLKA EEG'),xlabel('Spánkové fáze'), ylabel('Smerodatna odchylka')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(smerodatodREMeog)),ones(1,length(smerodatodN1eog)),2*ones(1,length(smerodatodN2eog)), 3*ones(1,length(smerodatodN3eog)), 4*ones(1,length(smerodatodWAKEeog))];
boxplot([smerodatodREMeog', smerodatodN1eog',smerodatodN2eog', smerodatodN3eog', smerodatodWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SMERODATNA ODCHYLKA EOG'),xlabel('Spánkové fáze'), ylabel('Smerodatna odchylka')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(smerodatodREMemg)),ones(1,length(smerodatodN1emg)),2*ones(1,length(smerodatodN2emg)), 3*ones(1,length(smerodatodN3emg)), 4*ones(1,length(smerodatodWAKEemg))];
boxplot([smerodatodREMemg', smerodatodN1emg', smerodatodN2emg', smerodatodN3emg', smerodatodWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SMERODATNA ODCHYLKA EMG'),xlabel('Spánkové fáze'), ylabel('Smerodatna odchylka')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty stredni hodnoty EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(stredhodREMeeg)),ones(1,length(stredhodN1eeg)),2*ones(1,length(stredhodN2eeg)), 3*ones(1,length(stredhodN3eeg)), 4*ones(1,length(stredhodWAKEeeg))];
boxplot([stredhodREMeeg', stredhodN1eeg',stredhodN2eeg', stredhodN3eeg', stredhodWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('STREDNI HODNOTA EEG'),xlabel('Spánkové fáze'), ylabel('Stredni hodnota')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(stredhodREMeog)),ones(1,length(stredhodN1eog)),2*ones(1,length(stredhodN2eog)), 3*ones(1,length(stredhodN3eog)), 4*ones(1,length(stredhodWAKEeog))];
boxplot([stredhodREMeog', stredhodN1eog',stredhodN2eog', stredhodN3eog', stredhodWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('STREDNI HODNOTA EOG'),xlabel('Spánkové fáze'), ylabel('Stredni hodnota')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(stredhodREMemg)),ones(1,length(stredhodN1emg)),2*ones(1,length(stredhodN2emg)), 3*ones(1,length(stredhodN3emg)), 4*ones(1,length(stredhodWAKEemg))];
boxplot([stredhodREMemg', stredhodN1emg', stredhodN2emg', smerodatodN3emg',stredhodWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('STREDNI HODNOTA EMG'),xlabel('Spánkové fáze'), ylabel('Stredni hodnota')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty mobility EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(mobilitaREMeeg)),ones(1,length(mobilitaN1eeg)),2*ones(1,length(mobilitaN2eeg)), 3*ones(1,length(mobilitaN3eeg)), 4*ones(1,length(mobilitaWAKEeeg))];
boxplot([mobilitaREMeeg',mobilitaN1eeg',mobilitaN2eeg', mobilitaN3eeg', mobilitaWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('MOBILITA EEG'),xlabel('Spánkové fáze'), ylabel('Mobilita [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(mobilitaREMeog)),ones(1,length(mobilitaN1eog)),2*ones(1,length(mobilitaN2eog)), 3*ones(1,length(mobilitaN3eog)), 4*ones(1,length(mobilitaWAKEeog))];
boxplot([mobilitaREMeog', mobilitaN1eog',mobilitaN2eog', mobilitaN3eog', mobilitaWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('MOBILITA EOG'),xlabel('Spánkové fáze'), ylabel('Mobilita [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(mobilitaREMemg)),ones(1,length(mobilitaN1emg)),2*ones(1,length(mobilitaN2emg)), 3*ones(1,length(mobilitaN3emg)), 4*ones(1,length(mobilitaWAKEemg))];
boxplot([mobilitaREMemg', mobilitaN1emg', mobilitaN2emg', mobilitaN3emg',mobilitaWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('MOBILITA EMG'),xlabel('Spánkové fáze'), ylabel('Mobilita [µV]')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

figure('name','Boxploty slozitosti EEG, EOG, EMG')
hold on
subplot(3,1,1)
group_d=[zeros(1,length(slozitostREMeeg)),ones(1,length(slozitostN1eeg)),2*ones(1,length(slozitostN2eeg)), 3*ones(1,length(slozitostN3eeg)), 4*ones(1,length(slozitostWAKEeeg))];
boxplot([slozitostREMeeg',slozitostN1eeg',slozitostN2eeg',slozitostN3eeg', slozitostWAKEeeg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SLOZITOST EEG'),xlabel('Spánkové fáze'), ylabel('Slozitost')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,2)
group_d=[zeros(1,length(slozitostREMeog)),ones(1,length(slozitostN1eog)),2*ones(1,length(slozitostN2eog)), 3*ones(1,length(slozitostN3eog)), 4*ones(1,length(slozitostWAKEeog))];
boxplot([slozitostREMeog', slozitostN1eog',slozitostN2eog', slozitostN3eog', slozitostWAKEeog'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SLOZITOST EOG'),xlabel('Spánkové fáze'), ylabel('Slozitost')
set(findall(gcf,'type','text'),'FontSize',10)
subplot(3,1,3)
group_d=[zeros(1,length(slozitostREMemg)),ones(1,length(slozitostN1emg)),2*ones(1,length(slozitostN2emg)), 3*ones(1,length(slozitostN3emg)), 4*ones(1,length(slozitostWAKEemg))];
boxplot([slozitostREMemg',slozitostN1emg', slozitostN2emg', slozitostN3emg',slozitostWAKEemg'],group_d,'labels',{'REM','N1','N2','N3','WAKE'})
title('SLOZITOST EMG'),xlabel('Spánkové fáze'), ylabel('Slozitost')
set(findall(gcf,'type','text'),'FontSize',10)
hold off

%% Rozdělení  všech 10ti EOG a EMG na fáze

% cast_WAKEemg1=[];cast_REMemg1=[];cast_N3emg1=[];cast_N2emg1=[];cast_N1emg1=[];
% cast_WAKEeog1=[];cast_REMeog1=[];cast_N3eog1=[];cast_N2eog1=[];cast_N1eog1=[];
% cast_WAKEemg2=[];cast_REMemg2=[];cast_N3emg2=[];cast_N2emg2=[];cast_N1emg2=[];
% cast_WAKEeog2=[];cast_REMeog2=[];cast_N3eog2=[];cast_N2eog2=[];cast_N1eog2=[];
% cast_WAKEemg3=[];cast_REMemg3=[];cast_N3emg3=[];cast_N2emg3=[];cast_N1emg3=[];
% cast_WAKEeog3=[];cast_REMeog3=[];cast_N3eog3=[];cast_N2eog3=[];cast_N1eog3=[];
% cast_WAKEemg4=[];cast_REMemg4=[];cast_N3emg4=[];cast_N2emg4=[];cast_N1emg4=[];
% cast_WAKEeog4=[];cast_REMeog4=[];cast_N3eog4=[];cast_N2eog4=[];cast_N1eog4=[];
% cast_WAKEemg5=[];cast_REMemg5=[];cast_N3emg5=[];cast_N2emg5=[];cast_N1emg5=[];
% cast_WAKEeog5=[];cast_REMeog5=[];cast_N3eog5=[];cast_N2eog5=[];cast_N1eog5=[];
% cast_WAKEemg6=[];cast_REMemg6=[];cast_N3emg6=[];cast_N2emg6=[];cast_N1emg6=[];
% cast_WAKEeog6=[];cast_REMeog6=[];cast_N3eog6=[];cast_N2eog6=[];cast_N1eog6=[];
% cast_WAKEemg7=[];cast_REMemg7=[];cast_N3emg7=[];cast_N2emg7=[];cast_N1emg7=[];
% cast_WAKEeog7=[];cast_REMeog7=[];cast_N3eog7=[];cast_N2eog7=[];cast_N1eog7=[];
% cast_WAKEemg8=[];cast_REMemg8=[];cast_N3emg8=[];cast_N2emg8=[];cast_N1emg8=[];
% cast_WAKEeog8=[];cast_REMeog8=[];cast_N3eog8=[];cast_N2eog8=[];cast_N1eog8=[];
% cast_WAKEemg9=[];cast_REMemg9=[];cast_N3emg9=[];cast_N2emg9=[];cast_N1emg9=[];
% cast_WAKEeog9=[];cast_REMeog9=[];cast_N3eog9=[];cast_N2eog9=[];cast_N1eog9=[];
% cast_WAKEemg10=[];cast_REMemg10=[];cast_N3emg10=[];cast_N2emg10=[];cast_N1emg10=[];
% cast_WAKEeog10=[];cast_REMeog10=[];cast_N3eog10=[];cast_N2eog10=[];cast_N1eog10=[];
% 
% maticeemg1=vec2mat(emg1,usek);
% maticeeog1=vec2mat(eog1,usek);
% maticeemg2=vec2mat(emg2,usek);
% maticeeog2=vec2mat(eog2,usek);
% maticeemg3=vec2mat(emg3,usek);
% maticeeog3=vec2mat(eog3,usek);
% maticeemg4=vec2mat(emg4,usek);
% maticeeog4=vec2mat(eog4,usek);
% maticeemg5=vec2mat(emg5,usek);
% maticeeog5=vec2mat(eog5,usek);
% maticeemg6=vec2mat(sesteEMG{1,1},usek);
% maticeeog6=vec2mat(eog6,usek);
% maticeemg7=vec2mat(sedmeEMG{1,1},usek);
% maticeeog7=vec2mat(eog7,usek);
% maticeemg8=vec2mat(osmeEMG{1,1},usek);
% maticeeog8=vec2mat(eog8,usek);
% maticeemg9=vec2mat(devateEMG{1,1},usek);
% maticeeog9=vec2mat(eog9,usek);
% maticeemg10=vec2mat(desateEMG{1,1},usek);
% maticeeog10=vec2mat(eog10,usek);
% 
% hypno1=zeros(1,length(faze));
% hypno2=zeros(1,length(faze2));
% hypno3=zeros(1,length(faze3));
% hypno4=zeros(1,length(faze4));
% hypno5=zeros(1,length(faze5));
% hypno6=zeros(1,length(faze6));
% hypno7=zeros(1,length(faze7));
% hypno8=zeros(1,length(faze8));
% hypno9=zeros(1,length(faze9));
% hypno10=zeros(1,length(faze10));
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze)
%     if faze(h)==0
%         hypno1(j)=WAKEeeg;
%         cast_WAKEeog1=[cast_WAKEeog1; maticeeog1(h,:)];
%         cast_WAKEemg1=[cast_WAKEemg1; maticeemg1(h,:)]; 
%         n1=n1+1;
%     elseif faze(h)==1
%         hypno1(j)=N1eeg;
%         cast_N1eog1=[cast_N1eog1; maticeeog1(h,:)];
%         cast_N1emg1=[cast_N1emg1; maticeemg1(h,:)];
%         n2=n2+1;
%     elseif faze(h)==2
%         hypno1(j)=N2eeg;
%         cast_N2eog1=[cast_N2eog1; maticeeog1(h,:)];
%         cast_N2emg1=[cast_N2emg1; maticeemg1(h,:)];   
%         n3=n3+1;
%     elseif faze(h)==3
%         hypno1(j)=N3eeg;
%         cast_N3eog1=[cast_N3eog1; maticeeog1(h,:)]; 
%         cast_N3emg1=[cast_N3emg1; maticeemg1(h,:)]; 
%         n4=n4+1;
%     elseif faze(h)==5
%         hypno1(j)=REMeeg;
%         cast_REMeog1=[cast_REMeog1; maticeeog1(h,:)];
%         cast_REMemg1=[cast_REMemg1; maticeemg1(h,:)];
%         n5=n5+1;
%     else
%         hypno1(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze2)
%     if faze2(h)==0
%         hypno2(j)=WAKEeeg;
%         cast_WAKEeog2=[cast_WAKEeog2; maticeeog2(h,:)];
%         cast_WAKEemg2=[cast_WAKEemg2; maticeemg2(h,:)];
%         n1=n1+1;
%     elseif faze2(h)==1
%         hypno2(j)=N1eeg;
%         cast_N1eog2=[cast_N1eog2; maticeeog2(h,:)];
%         cast_N1emg2=[cast_N1emg2; maticeemg2(h,:)];
%         n2=n2+1;
%     elseif faze2(h)==2
%         hypno2(j)=N2eeg;
%         cast_N2eog2=[cast_N2eog2; maticeeog2(h,:)];
%         cast_N2emg2=[cast_N2emg2; maticeemg2(h,:)];   
%         n3=n3+1;
%     elseif faze2(h)==3
%         hypno2(j)=N3eeg;
%         cast_N3eog2=[cast_N3eog2; maticeeog2(h,:)]; 
%         cast_N3emg2=[cast_N3emg2; maticeemg2(h,:)]; 
%         n4=n4+1;
%     elseif faze2(h)==5
%         hypno2(j)=REMeeg;
%         cast_REMeog2=[cast_REMeog2; maticeeog2(h,:)];
%         cast_REMemg2=[cast_REMemg2; maticeemg2(h,:)];
%         n5=n5+1;
%     else
%         hypno2(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze3)
%     if faze3(h)==0
%         hypno3(j)=WAKEeeg;
%         cast_WAKEeog3=[cast_WAKEeog3; maticeeog3(h,:)];
%         cast_WAKEemg3=[cast_WAKEemg3; maticeemg3(h,:)];
%         n1=n1+1;
%     elseif faze3(h)==1
%         hypno3(j)=N1eeg;
%         cast_N1eog3=[cast_N1eog3; maticeeog3(h,:)];
%         cast_N1emg3=[cast_N1emg3; maticeemg3(h,:)];
%         n2=n2+1;
%     elseif faze3(h)==2
%         hypno3(j)=N2eeg;
%         cast_N2eog3=[cast_N2eog3; maticeeog3(h,:)];
%         cast_N2emg3=[cast_N2emg3; maticeemg3(h,:)];   
%         n3=n3+1;
%     elseif faze3(h)==3
%         hypno3(j)=N3eeg;
%         cast_N3eog3=[cast_N3eog3; maticeeog3(h,:)]; 
%         cast_N3emg3=[cast_N3emg3; maticeemg3(h,:)]; 
%         n4=n4+1;
%     elseif faze3(h)==5
%         hypno3(j)=REMeeg;
%         cast_REMeog3=[cast_REMeog3; maticeeog3(h,:)];
%         cast_REMemg3=[cast_REMemg3; maticeemg3(h,:)];
%         n5=n5+1;
%     else
%         hypno3(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze4)
%     if faze4(h)==0
%         hypno4(j)=WAKEeeg;
%         cast_WAKEeog4=[cast_WAKEeog3; maticeeog4(h,:)];
%         cast_WAKEemg4=[cast_WAKEemg4; maticeemg4(h,:)];
%         n1=n1+1;
%     elseif faze4(h)==1
%         hypno4(j)=N1eeg;
%         cast_N1eog4=[cast_N1eog4; maticeeog4(h,:)];
%         cast_N1emg4=[cast_N1emg4; maticeemg4(h,:)];
%         n2=n2+1;
%     elseif faze4(h)==2
%         hypno4(j)=N2eeg;
%         cast_N2eog4=[cast_N2eog4; maticeeog4(h,:)];
%         cast_N2emg4=[cast_N2emg4; maticeemg4(h,:)];   
%         n3=n3+1;
%     elseif faze4(h)==3
%         hypno4(j)=N3eeg;
%         cast_N3eog4=[cast_N3eog4; maticeeog4(h,:)]; 
%         cast_N3emg4=[cast_N3emg4; maticeemg4(h,:)]; 
%         n4=n4+1;
%     elseif faze4(h)==5
%         hypno4(j)=REMeeg;
%         cast_REMeog4=[cast_REMeog4; maticeeog4(h,:)];
%         cast_REMemg4=[cast_REMemg4; maticeemg4(h,:)];
%         n5=n5+1;
%     else
%         hypno4(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze5)
%     if faze5(h)==0
%         hypno5(j)=WAKEeeg;
%         cast_WAKEeog5=[cast_WAKEeog5; maticeeog5(h,:)];
%         cast_WAKEemg5=[cast_WAKEemg5; maticeemg5(h,:)];
%         n1=n1+1;
%     elseif faze5(h)==1
%         hypno5(j)=N1eeg;
%         cast_N1eog5=[cast_N1eog5; maticeeog5(h,:)];
%         cast_N1emg5=[cast_N1emg5; maticeemg5(h,:)];
%         n2=n2+1;
%     elseif faze5(h)==2
%         hypno5(j)=N2eeg;
%         cast_N2eog5=[cast_N2eog5; maticeeog5(h,:)];
%         cast_N2emg5=[cast_N2emg5; maticeemg5(h,:)];   
%         n3=n3+1;
%     elseif faze5(h)==3
%         hypno5(j)=N3eeg;
%         cast_N3eog5=[cast_N3eog5; maticeeog5(h,:)]; 
%         cast_N3emg5=[cast_N3emg5; maticeemg5(h,:)]; 
%         n4=n4+1;
%     elseif faze5(h)==5
%         hypno5(j)=REMeeg;
%         cast_REMeog5=[cast_REMeog5; maticeeog5(h,:)];
%         cast_REMemg5=[cast_REMemg5; maticeemg5(h,:)];
%         n5=n5+1;
%     else
%         hypno5(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze6)
%     if faze6(h)==0
%         hypno6(j)=WAKEeeg;
%         cast_WAKEeog6=[cast_WAKEeog6; maticeeog6(h,:)];
%         cast_WAKEemg6=[cast_WAKEemg6; maticeemg6(h,:)];
%         n1=n1+1;
%     elseif faze6(h)==1
%         hypno6(j)=N1eeg;
%         cast_N1eog6=[cast_N1eog6; maticeeog6(h,:)];
%         cast_N1emg6=[cast_N1emg6; maticeemg6(h,:)];
%         n2=n2+1;
%     elseif faze6(h)==2
%         hypno6(j)=N2eeg;
%         cast_N2eog6=[cast_N2eog6; maticeeog6(h,:)];
%         cast_N2emg6=[cast_N2emg6; maticeemg6(h,:)];   
%         n3=n3+1;
%     elseif faze6(h)==3
%         hypno6(j)=N3eeg;
%         cast_N3eog6=[cast_N3eog6; maticeeog6(h,:)]; 
%         cast_N3emg6=[cast_N3emg6; maticeemg6(h,:)]; 
%         n4=n4+1;
%     elseif faze6(h)==5
%         hypno6(j)=REMeeg;
%         cast_REMeog6=[cast_REMeog6; maticeeog6(h,:)];
%         cast_REMemg6=[cast_REMemg6; maticeemg6(h,:)];
%         n5=n5+1;
%     else
%         hypno6(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze7)
%     if faze7(h)==0
%         hypno7(j)=WAKEeeg;
%         cast_WAKEeog7=[cast_WAKEeog7; maticeeog7(h,:)];
%         cast_WAKEemg7=[cast_WAKEemg7; maticeemg7(h,:)];
%         n1=n1+1;
%     elseif faze7(h)==1
%         hypno7(j)=N1eeg;
%         cast_N1eog7=[cast_N1eog7; maticeeog7(h,:)];
%         cast_N1emg7=[cast_N1emg7; maticeemg7(h,:)];
%         n2=n2+1;
%     elseif faze7(h)==2
%         hypno7(j)=N2eeg;
%         cast_N2eog7=[cast_N2eog7; maticeeog7(h,:)];
%         cast_N2emg7=[cast_N2emg7; maticeemg7(h,:)];   
%         n3=n3+1;
%     elseif faze7(h)==3
%         hypno7(j)=N3eeg;
%         cast_N3eog7=[cast_N3eog7; maticeeog7(h,:)]; 
%         cast_N3emg7=[cast_N3emg7; maticeemg7(h,:)]; 
%         n4=n4+1;
%     elseif faze7(h)==5
%         hypno7(j)=REMeeg;
%         cast_REMeog7=[cast_REMeog7; maticeeog7(h,:)];
%         cast_REMemg7=[cast_REMemg7; maticeemg7(h,:)];
%         n5=n5+1;
%     else
%         hypno7(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze8)
%     if faze8(h)==0
%         hypno8(j)=WAKEeeg;
%         cast_WAKEeog8=[cast_WAKEeog8; maticeeog8(h,:)];
%         cast_WAKEemg8=[cast_WAKEemg8; maticeemg8(h,:)];
%         n1=n1+1;
%     elseif faze8(h)==1
%         hypno8(j)=N1eeg;
%         cast_N1eog8=[cast_N1eog8; maticeeog8(h,:)];
%         cast_N1emg8=[cast_N1emg8; maticeemg8(h,:)];
%         n2=n2+1;
%     elseif faze8(h)==2
%         hypno8(j)=N2eeg;
%         cast_N2eog8=[cast_N2eog8; maticeeog8(h,:)];
%         cast_N2emg8=[cast_N2emg8; maticeemg8(h,:)];   
%         n3=n3+1;
%     elseif faze8(h)==3
%         hypno8(j)=N3eeg;
%         cast_N3eog8=[cast_N3eog8; maticeeog8(h,:)]; 
%         cast_N3emg8=[cast_N3emg8; maticeemg8(h,:)]; 
%         n4=n4+1;
%     elseif faze8(h)==5
%         hypno8(j)=REMeeg;
%         cast_REMeog8=[cast_REMeog8; maticeeog8(h,:)];
%         cast_REMemg8=[cast_REMemg8; maticeemg8(h,:)];
%         n5=n5+1;
%     else
%         hypno8(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze9)
%     if faze9(h)==0
%         hypno9(j)=WAKEeeg;
%         cast_WAKEeog9=[cast_WAKEeog9; maticeeog9(h,:)];
%         cast_WAKEemg9=[cast_WAKEemg9; maticeemg9(h,:)];
%         n1=n1+1;
%     elseif faze9(h)==1
%         hypno9(j)=N1eeg;
%         cast_N1eog9=[cast_N1eog9; maticeeog9(h,:)];
%         cast_N1emg9=[cast_N1emg9; maticeemg9(h,:)];
%         n2=n2+1;
%     elseif faze9(h)==2
%         hypno9(j)=N2eeg;
%         cast_N2eog9=[cast_N2eog9; maticeeog9(h,:)];
%         cast_N2emg9=[cast_N2emg9; maticeemg9(h,:)];   
%         n3=n3+1;
%     elseif faze9(h)==3
%         hypno9(j)=N3eeg;
%         cast_N3eog9=[cast_N3eog9; maticeeog9(h,:)]; 
%         cast_N3emg9=[cast_N3emg9; maticeemg9(h,:)]; 
%         n4=n4+1;
%     elseif faze9(h)==5
%         hypno9(j)=REMeeg;
%         cast_REMeog9=[cast_REMeog9; maticeeog9(h,:)];
%         cast_REMemg9=[cast_REMemg9; maticeemg9(h,:)];
%         n5=n5+1;
%     else
%         hypno9(j)=unscored;
%     end
%     j=j+1;
% end
% 
% j=1;n1=1;n2=1;n3=1;n4=1;n5=1;
% 
% for h=1:length(faze10)
%     if faze10(h)==0
%         hypno10(j)=WAKEeeg;
%         cast_WAKEeog10=[cast_WAKEeog10; maticeeog10(h,:)];
%         cast_WAKEemg10=[cast_WAKEemg10; maticeemg10(h,:)];
%         n1=n1+1;
%     elseif faze10(h)==1
%         hypno10(j)=N1eeg;
%         cast_N1eog10=[cast_N1eog10; maticeeog10(h,:)];
%         cast_N1emg10=[cast_N1emg10; maticeemg10(h,:)];
%         n2=n2+1;
%     elseif faze10(h)==2
%         hypno10(j)=N2eeg;
%         cast_N2eog10=[cast_N2eog10; maticeeog10(h,:)];
%         cast_N2emg10=[cast_N2emg10; maticeemg10(h,:)];   
%         n3=n3+1;
%     elseif faze10(h)==3
%         hypno10(j)=N3eeg;
%         cast_N3eog10=[cast_N3eog10; maticeeog10(h,:)]; 
%         cast_N3emg10=[cast_N3emg10; maticeemg10(h,:)]; 
%         n4=n4+1;
%     elseif faze10(h)==5
%         hypno10(j)=REMeeg;
%         cast_REMeog10=[cast_REMeog10; maticeeog10(h,:)];
%         cast_REMemg10=[cast_REMemg10; maticeemg10(h,:)];
%         n5=n5+1;
%     else
%         hypno10(j)=unscored;
%     end
%     j=j+1;
% end
% 
% %% Spektra 2 epoch každého pacienta z každé fáze
% 
% % WAKE
% eogsp1=(abs(fft(cast_WAKEeog1)./(length(cast_WAKEeog1)))).^2;      % spektrum eog
% spektrumeog1WAKE=eogsp1(:,1:length(eogsp1)/2);
% 
% eogsp2=(abs(fft(cast_WAKEeog2)./(length(cast_WAKEeog2)))).^2;      % spektrum eog
% spektrumeog2WAKE=eogsp2(:,1:length(eogsp2)/2);
% 
% eogsp3=(abs(fft(cast_WAKEeog3)./(length(cast_WAKEeog3)))).^2;      % spektrum eog
% spektrumeog3WAKE=eogsp3(:,1:length(eogsp3)/2);
% 
% eogsp4=(abs(fft(cast_WAKEeog4)./(length(cast_WAKEeog4)))).^2;      % spektrum eog
% spektrumeog4WAKE=eogsp4(:,1:length(eogsp4)/2);
% 
% eogsp5=(abs(fft(cast_WAKEeog5)./(length(cast_WAKEeog5)))).^2;      % spektrum eog
% spektrumeog5WAKE=eogsp5(:,1:length(eogsp5)/2);
% 
% eogsp6=(abs(fft(cast_WAKEeog6)./(length(cast_WAKEeog6)))).^2;      % spektrum eog
% spektrumeog6WAKE=eogsp6(:,1:length(eogsp6)/2);
% 
% eogsp7=(abs(fft(cast_WAKEeog7)./(length(cast_WAKEeog7)))).^2;      % spektrum eog
% spektrumeog7WAKE=eogsp7(:,1:length(eogsp7)/2);
% 
% eogsp8=(abs(fft(cast_WAKEeog8)./(length(cast_WAKEeog8)))).^2;      % spektrum eog
% spektrumeog8WAKE=eogsp8(:,1:length(eogsp8)/2);
% 
% eogsp9=(abs(fft(cast_WAKEeog9)./(length(cast_WAKEeog9)))).^2;      % spektrum eog
% spektrumeog9WAKE=eogsp9(:,1:length(eogsp9)/2);
% 
% eogsp10=(abs(fft(cast_WAKEeog10)./(length(cast_WAKEeog10)))).^2;      % spektrum eog
% spektrumeog10WAKE=eogsp10(:,1:length(eogsp10)/2);
% 
% emgsp1=(abs(fft(cast_WAKEemg1)./(length(cast_WAKEemg1)))).^2;      % spektrum eog
% spektrumemg1WAKE=emgsp1(:,1:length(emgsp1)/2);
% 
% emgsp2=(abs(fft(cast_WAKEemg2)./(length(cast_WAKEemg2)))).^2;      % spektrum eog
% spektrumemg2WAKE=emgsp2(:,1:length(emgsp2)/2);
% 
% emgsp3=(abs(fft(cast_WAKEemg3)./(length(cast_WAKEemg3)))).^2;      % spektrum eog
% spektrumemg3WAKE=emgsp3(:,1:length(emgsp3)/2);
% 
% emgsp4=(abs(fft(cast_WAKEemg4)./(length(cast_WAKEemg4)))).^2;      % spektrum eog
% spektrumemg4WAKE=emgsp4(:,1:length(emgsp4)/2);
% 
% emgsp5=(abs(fft(cast_WAKEemg5)./(length(cast_WAKEemg5)))).^2;      % spektrum eog
% spektrumemg5WAKE=emgsp5(:,1:length(emgsp5)/2);
% 
% emgsp6=(abs(fft(cast_WAKEemg6)./(length(cast_WAKEemg6)))).^2;      % spektrum eog
% spektrumemg6WAKE=emgsp6(:,1:length(emgsp6)/2);
% 
% emgsp7=(abs(fft(cast_WAKEemg7)./(length(cast_WAKEemg7)))).^2;      % spektrum eog
% spektrumemg7WAKE=emgsp7(:,1:length(emgsp7)/2);
% 
% emgsp8=(abs(fft(cast_WAKEemg8)./(length(cast_WAKEemg8)))).^2;      % spektrum eog
% spektrumemg8WAKE=emgsp8(:,1:length(emgsp8)/2);
% 
% emgsp9=(abs(fft(cast_WAKEemg9)./(length(cast_WAKEemg9)))).^2;      % spektrum eog
% spektrumemg9WAKE=emgsp9(:,1:length(emgsp9)/2);
% 
% emgsp10=(abs(fft(cast_WAKEemg10)./(length(cast_WAKEemg10)))).^2;      % spektrum eog
% spektrumemg10WAKE=emgsp10(:,1:length(emgsp10)/2);
% 
% % REM
% 
% eogsp1=(abs(fft(cast_REMeog1)./(length(cast_REMeog1)))).^2;      % spektrum eog
% spektrumeog1REM=eogsp1(:,1:length(eogsp1)/2);
% 
% eogsp2=(abs(fft(cast_REMeog2)./(length(cast_REMeog2)))).^2;      % spektrum eog
% spektrumeog2REM=eogsp2(:,1:length(eogsp2)/2);
% 
% % 
% % eogsp3=(abs(fft(cast_REMeog3(1,:))./(length(cast_REMeog3)))).^2;      % spektrum eog
% % spektrumeog3REM=eogsp3(:,1:length(eogsp3)/2);
% 
% eogsp4=(abs(fft(cast_WAKEeog4)./(length(cast_REMeog4)))).^2;      % spektrum eog
% spektrumeog4REM=eogsp4(:,1:length(eogsp4)/2);
% 
% eogsp5=(abs(fft(cast_REMeog5)./(length(cast_REMeog5)))).^2;      % spektrum eog
% spektrumeog5REM=eogsp5(:,1:length(eogsp5)/2)
% 
% eogsp6=(abs(fft(cast_REMeog6)./(length(cast_REMeog6)))).^2;      % spektrum eog
% spektrumeog6REM=eogsp6(:,1:length(eogsp6)/2);
% 
% eogsp7=(abs(fft(cast_REMeog7)./(length(cast_REMeog7)))).^2;      % spektrum eog
% spektrumeog7REM=eogsp7(:,1:length(eogsp7)/2);
% 
% eogsp8=(abs(fft(cast_REMeog8)./(length(cast_REMeog8)))).^2;      % spektrum eog
% spektrumeog8REM=eogsp8(:,1:length(eogsp8)/2);
% 
% eogsp9=(abs(fft(cast_REMeog9)./(length(cast_REMeog9)))).^2;      % spektrum eog
% spektrumeog9REM=eogsp9(:,1:length(eogsp9)/2);
% 
% eogsp10=(abs(fft(cast_REMeog10)./(length(cast_REMeog10)))).^2;      % spektrum eog
% spektrumeog10REM=eogsp10(:,1:length(eogsp10)/2);
% 
% emgsp1=(abs(fft(cast_REMemg1)./(length(cast_REMemg1)))).^2;      % spektrum eog
% spektrumemg1REM=emgsp1(:,1:length(emgsp1)/2);
% 
% emgsp2=(abs(fft(cast_REMemg2)./(length(cast_REMemg2)))).^2;      % spektrum eog
% spektrumemg2REM=emgsp2(:,1:length(emgsp2)/2);
% 
% % emgsp3=(abs(fft(cast_REMemg3(1,:))./(length(cast_REMemg3)))).^2;      % spektrum eog
% % spektrumemg3REM=emgsp3(:,1:length(emgsp3)/2);
% 
% emgsp4=(abs(fft(cast_REMemg4)./(length(cast_REMemg4)))).^2;      % spektrum eog
% spektrumemg4REM=emgsp4(:,1:length(emgsp4)/2);
% 
% emgsp5=(abs(fft(cast_REMemg5)./(length(cast_REMemg5)))).^2;      % spektrum eog
% spektrumemg5REM=emgsp5(:,1:length(emgsp5)/2);
% 
% emgsp6=(abs(fft(cast_REMemg6)./(length(cast_REMemg6)))).^2;      % spektrum eog
% spektrumemg6REM=emgsp6(:,1:length(emgsp6)/2);
% 
% emgsp7=(abs(fft(cast_REMemg7)./(length(cast_REMemg7)))).^2;      % spektrum eog
% spektrumemg7REM=emgsp7(:,1:length(emgsp7)/2);
% 
% emgsp8=(abs(fft(cast_REMemg8)./(length(cast_REMemg8)))).^2;      % spektrum eog
% spektrumemg8REM=emgsp8(:,1:length(emgsp8)/2);
% 
% emgsp9=(abs(fft(cast_REMemg9)./(length(cast_REMemg9)))).^2;      % spektrum eog
% spektrumemg9REM=emgsp9(:,1:length(emgsp9)/2);
% 
% emgsp10=(abs(fft(cast_REMemg10)./(length(cast_REMemg10)))).^2;      % spektrum eog
% spektrumemg10REM=emgsp10(:,1:length(emgsp10)/2);
% 
% % N1
% 
% eogsp1=(abs(fft(cast_N1eog1 )./(length(cast_N1eog1)))).^2;      % spektrum eog
% spektrumeog1N1=eogsp1(:,1:length(eogsp1)/2);
% 
% eogsp2=(abs(fft(cast_N1eog2 )./(length(cast_N1eog2)))).^2;      % spektrum eog
% spektrumeog2N1=eogsp2(:,1:length(eogsp2)/2);
% 
% eogsp3=(abs(fft(cast_N1eog3 )./(length(cast_N1eog3)))).^2;      % spektrum eog
% spektrumeog3N1=eogsp3(:,1:length(eogsp3)/2);
% 
% eogsp4=(abs(fft(cast_N1eog4 )./(length(cast_N1eog4)))).^2;      % spektrum eog
% spektrumeog4N1=eogsp4(:,1:length(eogsp4)/2);
% 
% eogsp5=(abs(fft(cast_N1eog5 )./(length(cast_N1eog5)))).^2;      % spektrum eog
% spektrumeog5N1=eogsp5(:,1:length(eogsp5)/2);
% 
% eogsp6=(abs(fft(cast_N1eog6 )./(length(cast_N1eog6)))).^2;      % spektrum eog
% spektrumeog6N1=eogsp6(:,1:length(eogsp6)/2);
% 
% eogsp7=(abs(fft(cast_N1eog7 )./(length(cast_N1eog7)))).^2;      % spektrum eog
% spektrumeog7N1=eogsp7(:,1:length(eogsp7)/2);
% 
% eogsp8=(abs(fft(cast_N1eog8 )./(length(cast_N1eog8)))).^2;      % spektrum eog
% spektrumeog8N1=eogsp8(:,1:length(eogsp8)/2);
% 
% eogsp9=(abs(fft(cast_N1eog9 )./(length(cast_N1eog9)))).^2;      % spektrum eog
% spektrumeog9N1=eogsp9(:,1:length(eogsp9)/2);
% 
% eogsp10=(abs(fft(cast_N1eog10 )./(length(cast_N1eog10)))).^2;      % spektrum eog
% spektrumeog10N1=eogsp10(:,1:length(eogsp10)/2);
% 
% emgsp1=(abs(fft(cast_N1emg1 )./(length(cast_N1emg1)))).^2;      % spektrum eog
% spektrumemg1N1=emgsp1(:,1:length(emgsp1)/2);
% 
% emgsp2=(abs(fft(cast_N1emg2 )./(length(cast_N1emg2)))).^2;      % spektrum eog
% spektrumemg2N1=emgsp2(:,1:length(emgsp2)/2);
% 
% emgsp3=(abs(fft(cast_N1emg3 )./(length(cast_N1emg3)))).^2;      % spektrum eog
% spektrumemg3N1=emgsp3(:,1:length(emgsp3)/2);
% 
% emgsp4=(abs(fft(cast_N1emg4 )./(length(cast_N1emg4)))).^2;      % spektrum eog
% spektrumemg4N1=emgsp4(:,1:length(emgsp4)/2);
% 
% emgsp5=(abs(fft(cast_N1emg5 )./(length(cast_N1emg5)))).^2;      % spektrum eog
% spektrumemg5N1=emgsp5(:,1:length(emgsp5)/2);
% 
% emgsp6=(abs(fft(cast_N1emg6 )./(length(cast_N1emg6)))).^2;      % spektrum eog
% spektrumemg6N1=emgsp6(:,1:length(emgsp6)/2);
% 
% emgsp7=(abs(fft(cast_N1emg7 )./(length(cast_N1emg7)))).^2;      % spektrum eog
% spektrumemg7N1=emgsp7(:,1:length(emgsp7)/2);
% 
% emgsp8=(abs(fft(cast_N1emg8 )./(length(cast_N1emg8)))).^2;      % spektrum eog
% spektrumemg8N1=emgsp8(:,1:length(emgsp8)/2);
% 
% emgsp9=(abs(fft(cast_N1emg9 )./(length(cast_N1emg9)))).^2;      % spektrum eog
% spektrumemg9N1=emgsp9(:,1:length(emgsp9)/2);
% 
% emgsp10=(abs(fft(cast_N1emg10 )./(length(cast_N1emg10)))).^2;      % spektrum eog
% spektrumemg10N1=emgsp10(:,1:length(emgsp10)/2);
% 
% % N2
% 
% eogsp1=(abs(fft(cast_N2eog1 )./(length(cast_N2eog1)))).^2;      % spektrum eog
% spektrumeog1N2=eogsp1(:,1:length(eogsp1)/2);
% 
% eogsp2=(abs(fft(cast_N2eog2 )./(length(cast_N2eog2)))).^2;      % spektrum eog
% spektrumeog2N2=eogsp2(:,1:length(eogsp2)/2);
% 
% eogsp3=(abs(fft(cast_N2eog3 )./(length(cast_N2eog3)))).^2;      % spektrum eog
% spektrumeog3N2=eogsp3(:,1:length(eogsp3)/2);
% 
% eogsp4=(abs(fft(cast_N2eog4 )./(length(cast_N2eog4)))).^2;      % spektrum eog
% spektrumeog4N2=eogsp4(:,1:length(eogsp4)/2);
% 
% eogsp5=(abs(fft(cast_N2eog5 )./(length(cast_N2eog5)))).^2;      % spektrum eog
% spektrumeog5N2=eogsp5(:,1:length(eogsp5)/2);
% 
% eogsp6=(abs(fft(cast_N2eog6 )./(length(cast_N2eog6)))).^2;      % spektrum eog
% spektrumeog6N2=eogsp6(:,1:length(eogsp6)/2);
% 
% eogsp7=(abs(fft(cast_N2eog7 )./(length(cast_N2eog7)))).^2;      % spektrum eog
% spektrumeog7N2=eogsp7(:,1:length(eogsp7)/2);
% 
% eogsp8=(abs(fft(cast_N2eog8 )./(length(cast_N2eog8)))).^2;      % spektrum eog
% spektrumeog8N2=eogsp8(:,1:length(eogsp8)/2);
% 
% eogsp9=(abs(fft(cast_N2eog9 )./(length(cast_N2eog9)))).^2;      % spektrum eog
% spektrumeog9N2=eogsp9(:,1:length(eogsp9)/2);
% eogsp91=(abs(fft(cast_N2eog9 )./(length(cast_N2eog9)))).^2;      % spektrum eog
% spektrumeog9N21=eogsp91(:,1:length(eogsp91)/2);
% 
% eogsp10=(abs(fft(cast_N2eog10 )./(length(cast_N2eog10)))).^2;      % spektrum eog
% spektrumeog10N2=eogsp10(:,1:length(eogsp10)/2);
% 
% emgsp1=(abs(fft(cast_N2emg1 )./(length(cast_N2emg1)))).^2;      % spektrum eog
% spektrumemg1N2=emgsp1(:,1:length(emgsp1)/2);
% 
% emgsp2=(abs(fft(cast_N2emg2 )./(length(cast_N2emg2)))).^2;      % spektrum eog
% spektrumemg2N2=emgsp2(:,1:length(emgsp2)/2);
% 
% emgsp3=(abs(fft(cast_N2emg3 )./(length(cast_N2emg3)))).^2;      % spektrum eog
% spektrumemg3N2=emgsp3(:,1:length(emgsp3)/2);
% 
% emgsp4=(abs(fft(cast_N2emg4 )./(length(cast_N2emg4)))).^2;      % spektrum eog
% spektrumemg4N2=emgsp4(:,1:length(emgsp4)/2);
% 
% emgsp5=(abs(fft(cast_N2emg5 )./(length(cast_N2emg5)))).^2;      % spektrum eog
% spektrumemg5N2=emgsp5(:,1:length(emgsp5)/2);
% 
% emgsp6=(abs(fft(cast_N2emg6 )./(length(cast_N2emg6)))).^2;      % spektrum eog
% spektrumemg6N2=emgsp6(:,1:length(emgsp6)/2);
% 
% emgsp7=(abs(fft(cast_N2emg7 )./(length(cast_N2emg7)))).^2;      % spektrum eog
% spektrumemg7N2=emgsp7(:,1:length(emgsp7)/2);
% 
% emgsp8=(abs(fft(cast_N2emg8 )./(length(cast_N2emg8)))).^2;      % spektrum eog
% spektrumemg8N2=emgsp8(:,1:length(emgsp8)/2);
% 
% emgsp9=(abs(fft(cast_N2emg9 )./(length(cast_N2emg9)))).^2;      % spektrum eog
% spektrumemg9N2=emgsp9(:,1:length(emgsp9)/2);
% 
% emgsp10=(abs(fft(cast_N2emg10 )./(length(cast_N2emg10)))).^2;      % spektrum eog
% spektrumemg10N2=emgsp10(:,1:length(emgsp10)/2);
% 
% % N3
% 
% eogsp1=(abs(fft(cast_N3eog1 )./(length(cast_N3eog1)))).^2;      % spektrum eog
% spektrumeog1N3=eogsp1(:,1:length(eogsp1)/2);
% 
% eogsp2=(abs(fft(cast_N3eog2 )./(length(cast_N3eog2)))).^2;      % spektrum eog
% spektrumeog2N3=eogsp2(:,1:length(eogsp2)/2);
% 
% % eogsp3=(abs(fft(cast_N3eog3 )./(length(cast_N3eog3)))).^2;      % spektrum eog
% % spektrumeog3N3=eogsp3(:,1:length(eogsp3)/2);
% 
% eogsp4=(abs(fft(cast_N3eog4 )./(length(cast_N3eog4)))).^2;      % spektrum eog
% spektrumeog4N3=eogsp4(:,1:length(eogsp4)/2);
% 
% eogsp5=(abs(fft(cast_N3eog5 )./(length(cast_N3eog5)))).^2;      % spektrum eog
% spektrumeog5N3=eogsp5(:,1:length(eogsp5)/2);
% 
% eogsp6=(abs(fft(cast_N3eog6 )./(length(cast_N3eog6)))).^2;      % spektrum eog
% spektrumeog6N3=eogsp6(:,1:length(eogsp6)/2);
% 
% eogsp7=(abs(fft(cast_N3eog7 )./(length(cast_N3eog7)))).^2;      % spektrum eog
% spektrumeog7N3=eogsp7(:,1:length(eogsp7)/2);
% 
% eogsp8=(abs(fft(cast_N3eog8 )./(length(cast_N3eog8)))).^2;      % spektrum eog
% spektrumeog8N3=eogsp8(:,1:length(eogsp8)/2);
% 
% eogsp9=(abs(fft(cast_N3eog9 )./(length(cast_N3eog9)))).^2;      % spektrum eog
% spektrumeog9N3=eogsp9(:,1:length(eogsp9)/2);
% 
% eogsp10=(abs(fft(cast_N3eog10 )./(length(cast_N3eog10)))).^2;      % spektrum eog
% spektrumeog10N3=eogsp10(:,1:length(eogsp10)/2);
% 
% emgsp1=(abs(fft(cast_N3emg1 )./(length(cast_N3emg1)))).^2;      % spektrum eog
% spektrumemg1N3=emgsp1(:,1:length(emgsp1)/2);
% 
% emgsp2=(abs(fft(cast_N3emg2 )./(length(cast_N3emg2)))).^2;      % spektrum eog
% spektrumemg2N3=emgsp2(:,1:length(emgsp2)/2);
% 
% % emgsp3=(abs(fft(cast_N3emg3 )./(length(cast_N3emg3)))).^2;      % spektrum eog
% % spektrumemg3N3=emgsp3(:,1:length(emgsp3)/2);
% % emgsp31=(abs(fft(cast_N3emg3 )./(length(cast_N3emg3)))).^2;      % spektrum eog
% % spektrumemg3N31=emgsp31(:,1:length(emgsp31)/2);
% 
% emgsp4=(abs(fft(cast_N3emg4 )./(length(cast_N3emg4)))).^2;      % spektrum eog
% spektrumemg4N3=emgsp4(:,1:length(emgsp4)/2);
% 
% emgsp5=(abs(fft(cast_N3emg5 )./(length(cast_N3emg5)))).^2;      % spektrum eog
% spektrumemg5N3=emgsp5(:,1:length(emgsp5)/2);
% 
% emgsp6=(abs(fft(cast_N3emg6 )./(length(cast_N3emg6)))).^2;      % spektrum eog
% spektrumemg6N3=emgsp6(:,1:length(emgsp6)/2);
% 
% emgsp7=(abs(fft(cast_N3emg7 )./(length(cast_N3emg7)))).^2;      % spektrum eog
% spektrumemg7N3=emgsp7(:,1:length(emgsp7)/2);
% 
% emgsp8=(abs(fft(cast_N3emg8 )./(length(cast_N3emg8)))).^2;      % spektrum eog
% spektrumemg8N3=emgsp8(:,1:length(emgsp8)/2);
% 
% emgsp9=(abs(fft(cast_N3emg9 )./(length(cast_N3emg9)))).^2;      % spektrum eog
% spektrumemg9N3=emgsp9(:,1:length(emgsp9)/2);
% 
% emgsp10=(abs(fft(cast_N3emg10 )./(length(cast_N3emg10)))).^2;      % spektrum eog
% spektrumemg10N3=emgsp10(:,1:length(emgsp10)/2);

%% celé spektrum EEG, EOG a EMG -> fází

eegsp1=(abs(fft(cast_WAKEeeg)./(length(cast_WAKEeeg)))).^2;      % spektrum eeg
spektrumeegWAKE=eegsp1(:,1:length(eegsp1)/2);

eegsp1=(abs(fft(cast_N1eeg)./(length(cast_N1eeg)))).^2;      % spektrum eeg
spektrumeegN1=eegsp1(:,1:length(eegsp1)/2);

eegsp1=(abs(fft(cast_N2eeg)./(length(cast_N2eeg)))).^2;      % spektrum eeg
spektrumeegN2=eegsp1(:,1:length(eegsp1)/2);

eegsp1=(abs(fft(cast_N3eeg)./(length(cast_N3eeg)))).^2;      % spektrum eeg
spektrumeegN3=eegsp1(:,1:length(eegsp1)/2);

eegsp1=(abs(fft(cast_REMeeg)./(length(cast_REMeeg)))).^2;      % spektrum eeg
spektrumeegREM=eegsp1(:,1:length(eegsp1)/2);


eogsp1=(abs(fft(cast_WAKEeog)./(length(cast_WAKEeog)))).^2;      % spektrum eog
spektrumeogWAKE=eogsp1(:,1:length(eogsp1)/2);

eogsp1=(abs(fft(cast_N1eog)./(length(cast_N1eog)))).^2;      % spektrum eog
spektrumeogN1=eogsp1(:,1:length(eogsp1)/2);

eogsp1=(abs(fft(cast_N2eog)./(length(cast_N2eog)))).^2;      % spektrum eog
spektrumeogN2=eogsp1(:,1:length(eogsp1)/2);

eogsp1=(abs(fft(cast_N3eog)./(length(cast_N3eog)))).^2;      % spektrum eog
spektrumeogN3=eogsp1(:,1:length(eogsp1)/2);

eogsp1=(abs(fft(cast_REMeog)./(length(cast_REMeog)))).^2;      % spektrum eog
spektrumeogREM=eogsp1(:,1:length(eogsp1)/2);

emgsp1=(abs(fft(cast_WAKEemg)./(length(cast_WAKEemg)))).^2;      % spektrum emg
spektrumemgWAKE=emgsp1(:,1:length(emgsp1)/2);

emgsp1=(abs(fft(cast_N1emg)./(length(cast_N1emg)))).^2;      % spektrum emg
spektrumemgN1=emgsp1(:,1:length(emgsp1)/2);

emgsp1=(abs(fft(cast_N2emg)./(length(cast_N2emg)))).^2;      % spektrum emg
spektrumemgN2=emgsp1(:,1:length(emgsp1)/2);

emgsp1=(abs(fft(cast_N3emg)./(length(cast_N3emg)))).^2;      % spektrum emg
spektrumemgN3=emgsp1(:,1:length(emgsp1)/2);

emgsp1=(abs(fft(cast_REMemg)./(length(cast_REMemg)))).^2;      % spektrum emg
spektrumemgREM=emgsp1(:,1:length(emgsp1)/2);


%% Další parametry -> min, max, mean,...
for h=1:size(spektrumeogWAKE,1)
mineogWAKE(h,:)=min(spektrumeogWAKE(h,:));
minemgWAKE(h,:)=min(spektrumemgWAKE(h,:));
maxeogWAKE(h,:)=max(spektrumeogWAKE(h,:));
mineegWAKE(h,:)=min(spektrumeegWAKE(h,:));
maxemgWAKE(h,:)=max(spektrumemgWAKE(h,:));
maxeegWAKE(h,:)=max(spektrumeegWAKE(h,:));
meaneogWAKE(h,:)=mean(spektrumeogWAKE(h,:));
meanemgWAKE(h,:)=mean(spektrumemgWAKE(h,:));
meaneegWAKE(h,:)=mean(spektrumeegWAKE(h,:));
h=h+1;
end 
for h=1:size(spektrumeogN1,1)
mineogN1(h,:)=min(spektrumeogN1(h,:));
minemgN1(h,:)=min(spektrumemgN1(h,:));
maxeogN1(h,:)=max(spektrumeogN1(h,:));
mineegN1(h,:)=min(spektrumeegN1(h,:));
maxemgN1(h,:)=max(spektrumemgN1(h,:));
maxeegN1(h,:)=max(spektrumeegN1(h,:));
meaneogN1(h,:)=mean(spektrumeogN1(h,:));
meanemgN1(h,:)=mean(spektrumemgN1(h,:));
meaneegN1(h,:)=mean(spektrumeegN1(h,:));
h=h+1;
end
for h=1:size(spektrumeogN2,1)
mineogN2(h,:)=min(spektrumeogN2(h,:));
minemgN2(h,:)=min(spektrumemgN2(h,:));
maxeogN2(h,:)=max(spektrumeogN2(h,:));
mineegN2(h,:)=min(spektrumeegN2(h,:));
maxemgN2(h,:)=max(spektrumemgN2(h,:));
maxeegN2(h,:)=max(spektrumeegN2(h,:));
meaneogN2(h,:)=mean(spektrumeogN2(h,:));
meanemgN2(h,:)=mean(spektrumemgN2(h,:));
meaneegN2(h,:)=mean(spektrumeegN2(h,:));
h=h+1;
end
for h=1:size(spektrumeogN3,1)
mineogN3(h,:)=min(spektrumeogN3(h,:));
minemgN3(h,:)=min(spektrumemgN3(h,:));
maxeogN3(h,:)=max(spektrumeogN3(h,:));
mineegN3(h,:)=min(spektrumeegN3(h,:));
maxemgN3(h,:)=max(spektrumemgN3(h,:));
maxeegN3(h,:)=max(spektrumeegN3(h,:));
meaneogN3(h,:)=mean(spektrumeogN3(h,:));
meanemgN3(h,:)=mean(spektrumemgN3(h,:));
meaneegN3(h,:)=mean(spektrumeegN3(h,:));
h=h+1;
end
for h=1:size(spektrumeogREM,1)
mineogREM(h,:)=min(spektrumeogREM(h,:));
minemgREM(h,:)=min(spektrumemgREM(h,:));
maxeogREM(h,:)=max(spektrumeogREM(h,:));
mineegREM(h,:)=min(spektrumeegREM(h,:));
maxemgREM(h,:)=max(spektrumemgREM(h,:));
maxeegREM(h,:)=max(spektrumeegREM(h,:));
meaneogREM(h,:)=mean(spektrumeogREM(h,:));
meanemgREM(h,:)=mean(spektrumemgREM(h,:));
meaneegREM(h,:)=mean(spektrumeegREM(h,:));
h=h+1;
end



%% Příklad -> Statistika

test=[aktivitaREMemg(1:476) aktivitaN1emg(1:476) aktivitaN2emg(1:476) aktivitaN3emg(1:476) aktivitaWAKEemg(1:476)];
[p,tbl,stats] = kruskalwallis(test,[],'off')
cn1 = multcompare(stats)

% N1vsechny=[vykon_theta_r(1:476) vykon_theta_n1(1:476) vykon_theta_n2(1:476) vykon_theta_n3(1:476) vykon_theta_w(1:476)];
% [p,tbl,stats] = kruskalwallis(N1vsechny,[],'off')
% cn1 = multcompare(stats)
% 
% 
% N1vsechny=[spektrumeog5REM(1:50)' spektrumeog5N1(1:50)' spektrumeog5N2(1:50)' spektrumeog5N3(1:50)' spektrumeog5WAKE(1:50)'];
% [p,tbl,stats] = kruskalwallis(N1vsechny,[],'off')
% cn1 = multcompare(stats)
% 
% N1vsechny=[spektrumeogREM(1:476)' spektrumeogN1(1:476)' spektrumeogN2(1:476)' spektrumeogN3(1:476)' spektrumeogWAKE(1:476)'];
% [p,tbl,stats] = kruskalwallis(N1vsechny,[],'off')
% cn1 = multcompare(stats)
% 
% N1vsechny=[spektrumemgREM(1:476)' spektrumemgN1(1:476)' spektrumemgN2(1:476)' spektrumemgN3(1:476)' spektrumemgWAKE(1:476)'];
% [p,tbl,stats] = kruskalwallis(N1vsechny,[],'off')
% cn1 = multcompare(stats)
% 
% N1vsechny=[mineegREM' mineegN1' mineegN2' mineegN3' mineegWAKE'];
% [p,tbl,stats] = kruskalwallis(N1vsechny,[],'off')
% cn1 = multcompare(stats)
% 



