function w = SplineWavelet( x, j, k, m, a, b )
% SplineWavelet generates semi-orthogonal spline wavelet,  w(a^j*x-b*k), of order 1,2 or 4
% on the given interval
%
% Usage:    w = SplineWavelet( x, j, k, m, a, b );
%
% Inputs:
%   x       a dicretization of the given interval
%   j,k     dilation and translation parameters
%   a       scaling factor
%   b       translation factor
%   m       order of spline wavelet (1,2 or 4)
%
% Output:
%   w       normalized dilated/translated spline wavelet of a given order


% See http://www.ncrg.aston.ac.uk/Projects/BiOrthog/ for more details
switch m
    case 1
        coef=[0 1;0 -1];
    case 2
        coef=[1 0;-7 4; 16 -19;-16 29;7 -17;-1 3];
        coef=coef/6;
    case 4
        coef=[1/6 0 0 0; -127/6 32 -16 8/3];
        coef(3,1:4)= [342 -1057.5 1073.5 -360.5];
        coef(4,1:4)= [-2218 10462.5 -16206.5 8279.5];
        coef(5,1:4)= [7891.5 -50194.5 105107.5 -72596.5];
        coef(6,1:4)= [-17516.5 140365.5 -371292.5 324403.5];
        coef(7,1:4)= [77312/3 -249219 797461 -844350];
        coef(8,1:4)= [-77312/3 291965 -1096683 4096454/3];
        coef(9,1:4)= [17516.5 -227481 981101 -1404894];
        coef(10,1:4)= [-7891.5 115527 -562435 910410];
        coef(11,1:4)= [2218 -36115.5 195777.5 -353277.5];
        coef(12,1:4)= [-342 6124.5 -36542.5 72642.5];
        coef(13,1:4)= [127/6 -412.5 2679.5 -5801.5];
        coef(14,1:4)= [-1/6 3.5 -24.5 343/6];
        coef=coef/5040;
    otherwise
        error('This order of spline wavelets is not implemented');
end

nods=0:0.5:2*m-1;         % nodes of wavelet
pocet=length(nods);           %POCET is the number of nods
x=a^j*x-b*k;
w=[];
w = [w 0*(x(x<nods(1)))];
for i=2:pocet
    z=x((x>=nods(i-1)) & (x<nods(i)));
    w=[w polyval(coef(i-1,:),z)];
end
w=[w 0*(x(x>=nods(pocet)))];

%normalization
nor=norm(w);
if nor~=0; w=w/nor;end;


%Copyright (C) 2006 Miroslav ANDRLE and Laura REBOLLO-NEIRA
%
%This program is free software; you can redistribute it and/or modify it under the terms 
%of the GNU General Public License as published by the Free Software Foundation; either 
%version 2 of the License, or (at your option) any later version.
%
%This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
%without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%See the GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License along with this program;
%if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
%Boston, MA  02110-1301, USA.
