clear;clc;close all;

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

[xdat,t] = importData( 'A1A.txt' );
x = xdat(6,:);

testnoise = gauss(3,x)-x;
power = sum(abs(testnoise))/length(x);
adapt = power/0.05;
clear testnoise power;

y0 = gauss(round(adapt*10),x);
y1 = gaussADAPT(y0,t,1,0.05,0.1,2,round(adapt*100),1,diff(gauss(10,x)),50,[1*1e-3 10 0.01 30 3]);
y2 = gaussADAPT(y1,t,5,0.2,0.2,2,round(adapt*100),1,diff(gauss(10,x)),5,[1*1e-3 5 0.01 30 3]);
y3 = gaussADAPT(gauss(5,x),t,1,0.05,0.05,2,round(adapt*100),1,diff(y2),5,[1*1e-3 5 0.01 20 6]);
y4 = gaussADAPT(y3,t,1,0.2,0.2,2,round(adapt*50),1,diff(y3),5,[1*1e-3 5 0.01 30 3]);

figure(1) %Obr 4.9,4.10
plot(t,y4-x);
xlabel('$\tau [s]$');
ylabel('$dT_e[^{\circ}C]$');
xlim([0,t(end)])
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(2) %Obr 4.8
plot(t,x,t,y4,'r');
xlabel('$\tau [s]$');
ylabel('$T_e[^{\circ}C]$');
xlim([0,t(end)])
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)

noise = y4-x;
indexes = getNOISEindexes( noise, round(adapt*30), 2, 0 );
noisenext = gauss(round(adapt*200),noise);
noisenext(indexes) = noise(indexes);
noisenext = gauss(round(adapt*30),noisenext);
figure(3) %Obr 4.11
plot(t,y4-x,t,noisenext,'k');
xlabel('$\tau [s]$');
ylabel('$dT_e[^{\circ}C]$');
xlim([0,t(end)])
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)
legend('aktuálny šum','modifikovaný šum');

y5 = y4-noisenext;
figure(4) %Obr 4.12
plot(t,x,t,y4,'r',t,y5,'k');
xlabel('$\tau [s]$');
ylabel('$T_e[^{\circ}C]$');
xlim([0,t(end)])
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)
legend('nameraná teplota','teplota po filtrácii','teplota po oprave šumom')
