close all;
clear;

typ='db3';                               %zvoleny typ wavletu je db3
iter=5;                                  %vykreslenie db3

[phi,psi,t]=wavefun(typ,iter);

figure('name','vykreslenie zloziek phi a psi');
hold on;
plot(t,phi,'green');
plot(t,psi,'red');
pocet=length(t);
min=t(1);
max=t(pocet);
dlzka=max-min;

typ='db3';
[h_,g_,h,g]=wfilters(typ);

figure('name','vykreslenie h(n) a g(n)');
hold on;
stem(h,'-og');
stem(g,'-.+r');
poceth=length(h);

k=-(floor(max));                    % autokorelacia funkcie phi(t) 
for j=1:(2*max)+1
    m=round(k*pocet/dlzka);
    for i=1:pocet
        
        if (i-m)>0 & (i-m)<=pocet
            sucin(i)=phi(i)*phi(i-m);
        else
            sucin(i)=0;
        end  
    end
    autokorelacia(j)=integral(sucin,t);
    K(j)=k;
    k=k+1;
    clear sucin;

end

figure('name','Autokorelacna funkcia phi(t)');
stem(K,autokorelacia,'-.xg');

integral_phi=integral(phi,t)   % integral phi(t)

for j=1:2*poceth
    k=j-poceth;                % autokorelacia h(n) na parne posuny
    sucet=0;
    for n=1:poceth
        if n-2*k>0 & n-2*k<=poceth
            sucet=sucet+h(n)*h(n-2*k);
        end
    end
    autokorelaciah(j)=sucet;
    K(j)=2*k;
end

figure('name','Autokorelacna funkcia h(n)');
stem(K,autokorelaciah,'-.xg');

for j=1:2*poceth
    k=j-poceth;              % korelacia h(n) a g(n)
    sucet=0;
    for n=1:poceth
        if n-2*k>0 & n-2*k<=poceth
            sucet=sucet+h(n)*g(n-2*k);
        end
    end
    kroskorelacia(j)=sucet;
    K(j)=2*k;
end

figure('name','Korelacna funkcia h(n) a g(n)');
stem(K,kroskorelacia,'-.xg');
axis([1-2*poceth,2*poceth,0,1]);

suma_hn=sum(h)              % podmienka sum(h) = odmocnina z 2
suma_gn=sum(g)              % podmienka sum(g) = 0

Hom=fft(h);
for i=1:poceth/2
    suma22(i)=(abs(Hom(i)))^2+(abs(Hom(i+poceth/2))^2);     %platnost vety 2.2
end

disp('veta 2.2:');

suma22'

Hom=fft(h);
Gom=fft(g)                        % energeticka komplenentarita H(z) a G(z)
for i=1:poceth
    suma(i)=(abs(Hom(i)))^2+(abs(Gom(i))^2);
end

disp('komplenentarita H(z) a G(z) podla vety 3.29');
suma'




