close all;
clear;

iter = 5;                         % vyskladanie p(t) pomocou phi(t)
wav = 'db2';
figure('name','ukazka ze pomocou phi(t) sa da vyskladat polynom p(t) zvoleneho stupna');
[phi,psi,xval] = wavefun(wav,iter);
pole=zeros(1,500)
pole(1:97)=phi(1:97)
hold on
for i=0:10
pole(1+(i*32):97+(i*32))= pole(1+(i*32):97+(i*32)) + (1-0.5*(i+1)) * phi(1:97)
end
plot (pole(100:300),'-r')

wav = 'db4'                       % nulovanie p(t) pomocou psi(t)
skladani=3;
sklon=1;
rad_polynomu=3;
figure('name','nulovanie polynomu p(t) pomocou psi(t)');
[phi,psi,xval] = wavefun(wav,iter);
[x, velkost] = size(xval);
nosic = xval(velkost);
total_size=floor(velkost+skladani*velkost/nosic)+10;
func_long = zeros(1, total_size);
for(i=1:total_size) 
    func_long(i)=i-1;
end
func_long=(sklon*func_long/total_size).^rad_polynomu;
plot(func_long,'-r');
hold on
posun = floor(velkost/nosic);
for i=1:skladani
    pole = zeros(1, total_size);
    pole(1+posun*i:1+(posun)*i+(velkost-1)) = psi(1:velkost);
    plot(pole);
    skalarny_sucin=func_long*pole';
    msg=sprintf('[%d] = %f' , i, skalarny_sucin);
    disp(msg);
end

[h_,g_,h,g]=wfilters(wav);    % vyskladanie a nulovanie polynomu pomocou h(n) a g(n)

k=1;
p1=k*h(1);                            % vyskladanie
p2=2*k*h(1)+k*h(2);
p3=4*k*h(1)+2*k*h(2)+k*h(3);
p4=6*k*h(1)+4*k*h(2)+2*k*h(3)+k*h(4);
p5=8*k*h(1)+6*k*h(2)+4*k*h(3)+2*k*h(4);
p6=10*k*h(1)+8*k*h(2)+6*k*h(3)+4*k*h(4);
p7=12*k*h(1)+10*k*h(2)+8*k*h(3)+6*k*h(4);
p8=12*k*h(2)+10*k*h(3)+8*k*h(4);
p9=12*k*h(3)+10*k*h(4);
p10=12*k*h(4);
pole=[p1 p2 p3 p4 p5 p6 p7 p8 p9 p10];

figure
n=1:10;
stem(n,pole,'-.xr')
x=1:12
priamka=(2*x).^3;                     % nulovanie
a=g.*priamka(1:8);
b=sum(a)
