clear;clc;close all;

set(0,'defaulttextinterpreter','Latex');

x1 = importData( 'A1A.txt' ); cut1 = 1;
[x2,t] = importData( 'A1B.txt' ); cut2 = 3;

x1 = x1(1:end-cut1,:);
x2 = x2(1:end-cut2,:);

x = [x1;x2];

y = zeros(size(x,1),size(x,2));

for i = 1:size(y,1)
   y(i,:) = CONTIadapt(x(i,:),t);
end

noise = y-x;
chip = zeros(1,size(noise,1));
ttestp = zeros(1,size(noise,1));

for i=1:size(noise,1)
   figure(i);
   qqplot(noise(i,:)); % figure3 = Obr 4.14, figure17 = Obr 4.13
   chip(i) = noiseNORMALITYtest(noise(i,:));
   [~,ttestp(i)] = ttest(noise(i,:));
   xlabel('teoretick\''e kvantily');
    ylabel('empirick\''e kvantily');
    title('');
    set(gca,'FontSize',25)
end

figure(19) %Obr 4.15
plot(t,noise(17,:))
xlabel('$\tau [s]$');
ylabel('$dT_e[^{\circ}C]$');
ylh = get(gca,'ylabel');
gyl = get(ylh);                                                        
ylp = get(ylh, 'Position');
set(ylh, 'Rotation',0, 'Position',ylp, 'VerticalAlignment','middle', 'HorizontalAlignment','right')
set(gca,'FontSize',25)

figure(20) %Obr 4.17
plot(t,x(17,:),t,y(17,:),'r');
xlabel('$\tau [s]$');
ylabel('$T_e[^{\circ}C]$');
ylh = get(gca,'ylabel');
gyl = get(ylh);                                                        
ylp = get(ylh, 'Position');
set(ylh, 'Rotation',0, 'Position',ylp, 'VerticalAlignment','middle', 'HorizontalAlignment','right')
set(gca,'FontSize',25)

figure(21) %výsledná filtrácia vzorových dát
plot(t,x',t,y','r');
legendCell = cell(1,size(x,1));
for i = 1:18
   legendCell{i} = sprintf('T%u',i);
end
title('Použitie AF na dáta z experimentu')
legend(legendCell);


spectrum(noise(17,:),t); %Obr 4.16
set(gca,'FontSize',25)

