close all;
clear;

% Nastavenie a vykreslenie waveletov:
typ='db2';
iter=10;

[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='db2';
[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);




%1) phi(t) je ortogonalne na svoje posuny


k=-(floor(max));
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;
    if(k==0)
%        plot(t-k,phi,'red');
    else
 %       plot(t-k,phi,'blue');
    end
    k=k+1;
    clear sucin;

end

figure('name','Ortogonalita phi na svoje celociselne posuny (autokorelacia)');
stem(K,autokorelacia,'-ob');

%2) Zistit integral phi(t) (jednosmernu zlozku)


jednosmerna_zlozka_phi=integral(phi,t)

%3) h(n) je ortogonalne na svoje parne posuny

for j=1:2*poceth
    k=j-poceth;
    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','Ortogonalita h(n) na svoje parne posuny (autokorelacia)');
stem(K,autokorelaciah);

%4) h(n) je ortogonalne na g(n) a jeho posuny


for j=1:2*poceth
    k=j-poceth;
    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','kroskorelacia h(n) a g(n) (vzajomna ortogonalita)');
stem(K,kroskorelacia);
axis([1-2*poceth,2*poceth,0,1]);

%5) su splnene podmienky na sum(h(n))=sgrt(2) a sum(g(n))=0? 


suma_hn=sum(h)
suma_gn=sum(g)


%1) V oblasti OMEGA, ze plati veta 2.2

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

disp('=bod 1======================================================');
disp('Suma podla vety 2.2:');

suma22'

%2) ze H(Z) a G(z) su energeticky komplementarne filtre

Hom=fft(h);
Gom=fft(g)
for i=1:poceth
    suma(i)=(abs(Hom(i)))^2+(abs(Gom(i))^2);
end

disp('=bod 2======================================================');
disp('| H(e^j.Om) |^2 + | G(e^j.Om) |^2 pre celu periodu:');
suma'

%3) ze DP filtre formuju polpazmovy filter P(z) a HP filtre P(-z)

P=conv(h_,h)
P_=conv(g_,g)

%pozn: niekde chyba v znamienku




