clear all; close all; clc;


% nacist vsechny signaly, co mam
load('SIGS.mat');

sn=4;
b=zeros(size(SIGS,2), size(SIGS,3));
sigs=[];
for s=1:sn
    b(:,:) = SIGS(s,:,:);
    sigs = [sigs; b'];
end;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pocet_features = 23;                    %pocet vstupnich parametru
pocet_udalosti = 128;                   % celkovy pocet signalu
fs = 10e7;

thr_level_mV = 22;
pocet_vystupu = 7; %
pocet_urovni_rozkladu = 3;   % pocet rozkladu wpt
pocet_vlnek = 5;
res = ones(8,pocet_features,pocet_udalosti);
res2 = ones(8,pocet_vlnek*pocet_features,pocet_udalosti);

for wvlt = 5:5
[wavelet] = vlnky(wvlt);
[i, u] = size(wavelet);

for wav = 1:i
    w = wavelet(wav,:);
    
    for k = 1:pocet_udalosti
            x = sigs(k,:);
             wpacket = wpdec(x,pocet_urovni_rozkladu,w,'shannon');
    
    % rozlozeni puvodniho signalu na jednotlive urovne
       
        for k_uroven = 0:pocet_vystupu
            cfs = wpcoef(wpacket,[3 k_uroven]);
            [q, v] = size(cfs);
            res(k_uroven+1,:,k) = identify_signal_features(cfs, fs/(2000/v), thr_level_mV);
        end
       
       
    end 
    m = (pocet_features*wav) - 22;
    n = pocet_features*wav;
    res2(:, m:n, :) = res;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sn=8;
d=zeros(size(res2,2), size(res2,3));
res3=[];
for l=1:sn
    d(:,:) = res2(l,:,:);
    res3 = [res3; d'];
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

normovaci_metody = {'var','range','log', 'logistic', 'histD', 'histC'};

pocet_norm_metod = 6;
r = 8;
vys = [];
vysled = ones(pocet_norm_metod*pocet_vlnek,4)
koef = ones(4,1);
features_o = [];

for h = 1:pocet_vlnek

 features_o(:,:) = res3(((r-1)*pocet_udalosti)+1:r*pocet_udalosti,h*pocet_features-22:h*pocet_features); % použití každého výstupu zvlášť
   %features_o(:,:) = res3(:,h*pocet_features-22:h*pocet_features); % použití všech vystupů
for g = 1:pocet_norm_metod
    
metoda_normalizace_hodnot = normovaci_metody{g};

POPIS_SHLUKOVE_ANALYZY = 'Casova oblast';

[koeficient_rozlisitelnosti{1}, metody] = shlukova_analyza_umele_zdrojeAE(features_o(:,1:12), metoda_normalizace_hodnot, POPIS_SHLUKOVE_ANALYZY);

koef = koeficient_rozlisitelnosti{1,1};
vys(g,:) = koef;

end
vysled(g*h-5:g*h,:) =vys;

end