%
%
% Optical Imaging and Spectroscopy
%
% David J. Brady
% Duke University
% www.opticalimaging.org
%
% Figure 3.16
%
% Script to generate expansion coefficients p(k) of B-spline analysis
% functions with orthogonal filter as a function of B-spline basis
%
%
% p(k) is the kth order Fourier series coefficient of QQ(u), where Q is
% 1/the FT of the autocorrelation of phi
clear all;
close all;
figure(1);set(gcf,'color','white');
for m=0:3
    nC=20;
    p=zeros(1,nC);
    F=@(x)QQ(x,m);
    p(1)=quad(F,0,1);
    for k=2:nC
        F=@(x)(QQ(x,m).*cos(2*pi*(k-1)*x));
        p(k)=quad(F,0,1,10^-7);
    end
    % generate mth order bspline
    xS=1/64;
    xA=(-16+xS):xS:16;
    if m==0
        betaM=rect(xA-0.5);
    else
        betaM=conv(rect(xA+0.5),rect(xA-0.5));
        betaM=xS*betaM(1025:3072);
    end
    for cc=2:m
        betaM=conv(rect(xA-((-1)^cc)*0.5),betaM);
        betaM=xS*betaM(1025:3072);
    end
    checkP=p(1)*betaM;
    for shift=2:16
        checkP=checkP+p(shift)*(circshift(betaM',(shift-1)*64)'+circshift(betaM',-(shift-1)*64)');
    end
    ms=num2str(m);
    ts=['\beta^' ms '(x)'];
    checkts=['m=' ms];
   % subplot(4,2,2*m+1);plot(xA,betaM);title(ts);axis([-2.5 2.5 0 1.2]);
    subplot(2,2,m+1);plot(xA,checkP,'-k');title(checkts);axis([-5 5 -2 2.5]);
end

