A Haar wavelet expansion


Any function in L2 can be expanded as a weighted sum of the Haar wavelet scaled by factors 2n and displaced an integer number of times this quantity. The following figures show the partial sums with |n|<N for for the function x in [0,1) and 0 otherwise.

If N=1 then n=0 and we only have a multiple of the original Haar wavelet. Recall that the latter is

haar0

For higher values we start to guess the aspect of the function
haar1
N=1

haar2
N=2



haar3
N=3

haar4
N=4


Note that we are approximating a function of average 1/2 with functions of average 0 then we have not L1 convergence, the long tail weighs a lot for its norm. It converges in L2 and uniformly.


The code

The images above were generated with the following SAGE code:

from sage.plot.colors import rgbcolor
h = sgn(x)/2+sgn(1/2-x)-sgn(1-x)/2

P = point([(0,0)], size=0)
f = 0

N = 1
for l in srange(1,N):
    f += 2^(-l)*h(x = x/(2^l))
    P += plot(f,x,-0.001,33, color = rgbcolor([l/N,0,0]), thickness = 3 )



thi = 4
f = 2

def mcirg(a,b):
    P = circle( (a,b),0.035*f, fill=True, color='white', zorder= 190 )
    P += circle( (a,b),0.035*f, fill=False, thickness=2, zorder= 200 )
    return P

def mcirbg(a,b):
    P = circle( (a,b),0.035*f, fill=True, zorder= 190 )
    return P

   
##### HAAR

b = 3

P = line( [(-b,0), (0,0)], thickness=thi)
P += line( [(0,1), (1/2,1)], thickness=thi)
P += line( [(1/2,-1), (1,-1)], thickness=thi)
P += line( [(1,0),(b,0)], thickness=thi)
P += mcirg(0,0)
P += mcirbg(0,1)
P += mcirg(1/2,1)
P += mcirbg(1/2,-1)
P += mcirg(1,-1)
P += mcirbg(1,0)

P.set_aspect_ratio(1)
#P.axes(False)
P.fontsize(25)
P.save('./images/haar0.png')


P = point([(0,0)], size=0)
f = -h/4
N = 5
for l in srange(1,N):
#    P = plot(f,x,-0.001,10, color = rgbcolor([l/N,0,0]), thickness = 3 )
    P = plot(f,x,-0.5,5, thickness = 3 , plot_points = 500)
    P.fontsize(25)
    #P.set_aspect_ratio(1)
    #P.axes(False)
    P.save('./images/haar'+str(l)+'.png')
    f += 2^(-l-1)*h(x = x/(2^l))
    for k in srange(2^l):
        f += -2^(-l-2)*h(x = 2^l*x-k)