function f = SPL( x, m, j, k, a )
% SPL generates B-splines of order m at scale j with translation
% parameter k, B(a^j*x-k). Multiple knots for construction
% boundary functions are considered.
%
% Usage:    f = SPL( x, m, j, k, a );
%
% Inputs:
%   x       a dicretization of the given interval
%   j       scale level (a^j is the dilation) 
%   m       order of splines
%   k       translation parameter
%   a       scale factor
% Output:
%   f       B-splines of order m at scale j with translation parameter k  
% 
% Note:
% The interval [x(1) x(end)] must be [0,K] type where K is an integer

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

if x(1)~=0 | x(end)~=ceil(x(end))
    error('This family is implemented only on [0,K], (K being integer)')
end
int=x(end)-x(1);
s0=ceil(log(m/int)/log(a));
if j<s0
    error('Please take j>%d, no inner function found',s0);
end;

s=m+1;

if k<=-1 && k>=-m+1
    t=(k:k+m).*a^(-s0);t=min(t,int);t=max(t,0);
    f=(t(s)-t(1))*Differ(a^(j-s0)*x,t,m);
elseif k<=int*(a^(j))-1 && k>=int*(a^(j))-m+1
    k=int*(a^j)-m-k;
    t=(k:k+m).*a^(-s0);t=min(t,int);t=max(t,0);
    f=(t(s)-t(1))*Differ(a^(j-s0)*x(end)-a^(j-s0)*x,t,m);
elseif k>=0 && k<=int*(a^(j))-m
    t=(0:m).*a^(-s0);
    f=(t(s)-t(1))*Differ(a^(j-s0)*x-k*a^(-s0),t,m);
else f=0*x;
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.
