function D = WavLevel( name, x, j, a, b )
% WavLevel generates a set of all translated spline wavelets, w(a^j*x-b*k), having
% non-trivial intersection with the given interval. It can be also used for construction (Chui) 
% cubic B-spline wavelet basis (for b=1 only).
%
% Usage:    D = WavLevel( name, x, j, a, b );
%
% Inputs:
%   name    specifies the type of spline wavelets
%   x       a dicretization of the given interval
%   j       scale level (a^j is the dilation)
%   a       scaling factor
%   b       translation factor
%
% Available types of spline wavelets:
% name=1            Haar dictionary (cut-off construction)
%     =2            linear dictionary (cut-off construction)
%     =4            cubic dictionary (cut-off construction)
%     ='chui_cubic' cubic spline wavelet basis (multiple knots)
%
% Output:
%   D       set of all normalized spline wavelets at scale level j having non-trivial 
%           intersection with the given interval

% See http://www.ncrg.aston.ac.uk/Projects/BiOrthog/ for more details

L=length(x);
c=x(1);d=x(L);
delta=x(2)-x(1);
start=STPoint(name,'wavelet',c,j,a,b);
nn=NumFun(name,'wavelet',c,d,j,a,b)-1;

D=zeros(L,nn+1);
index=1;
if isnumeric(name)
    w=SplineWavelet(x,j,0,name,a,b)';
    for k=start:start+nn,
        posun=round((b*k/(a^j))/delta);
        if posun >=0
            D(1+posun:L,index)=w(1:L-posun);
        else
            D(1:L+posun,index)=w(1-posun:L);
        end
        %normalization
        nor=norm(D(:,index));
        if nor~=0
            D(:,index)= D(:,index)/nor;
        end
        index=index+1;
    end
elseif strcmp(name,'chui_cubic')
    w=SplineChuiWav(x,j,0,a);
    for i=1:3
        D(:,i)=SplineChuiWav(x,j,i-4,a)';
        %D(:,nn-i+2)=splinechuiwav(x,j,start+nn-i+1,a)';
        D(:,nn-i+2)=D(end:-1:1,i);
    end
    for k=0:nn-6,
        posun=round((k/(a^j))/delta);
        D(1+posun:L,index+3)=w(1:L-posun);
        index=index+1;
    end
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.
