%ap2f.m - Functional Mfile for Harr wavelets -- lev >= 0
%Usage:  figs = ap2f(lev)  % lev can be -2, -1, 0, 1, 2, 3, etc

function out=ap2f(lev)
  if nargin<1, help ap2f, return, end
  x=(-10:0.01:10)'; figure
  global total num color
    total = lev+3; num = 0; color=1;
    out = total; 
for j=-2:lev
    num = num + 1;
 for k_shift=-10*2^j : 10*2^j 
  my_plot(x,j,k_shift)
 end 
    if j==-2,title(['Levels =' num2str(out)]),end
end 
    set(gca,'color','y') % Mark the finest level
return

%__________________________________
function my_plot(x,j_scale,k_shift)
  global total num color
  str = sprintf('subplot(%d,1,%d)',total,num); eval(str)
  hold on
Scale = 2^(j_scale/2);
y = 2^j_scale * x - k_shift; yy=zeros(size(y));
yy = (y>=0 & y<1/2) - ...
     (y<1 & y>=1/2) + ...
     (y<0 | y>1) * 0;
 p=plot(x,yy*Scale);
 if color==1, set(p,'color','r'); color=2; else
              set(p,'color','b'); color=1; end
 hold off
return
