ROWE2.MWS

>

This MAPLE 6 worksheet simultaneously displays a continuous function along

with its Haar approximation. The insequence command is used

to update the approximation.

Author: Dr. E. Rowe

Department of Mathematics

North Carolina A & T State Univ.

Greensboro, NC 27411

rowee@ncat.edu

Date: 13 Nov. 2000

>

>

Example: Continuous function: The associated function f is approximated at

f(n) = y_ n, n = 0, 1, 2, ..., 2^m. We assume that f belongs Haar's multiresolution

space V _ 0 .

> restart:

>

> with(plots):

Warning, the name changecoords has been redefined

>

>

>

Build the father wavelet - also called the scaling function.

> phi := t -> piecewise(0 <= t and t <= 1,1);#scaling funciton

phi := proc (t) options operator, arrow; piecewise(...

>

>

>

Next we build the mother wavelet.

> psi := t -> piecewise(0 <= t and t < 0.5, 1,

> 0.5 <= t and t < 1, -1);

psi := proc (t) options operator, arrow; piecewise(...

> plot(psi(t), t = -1..2);

[Maple Plot]

>

Enter the number of subspaces on which to perform the

approximation: This is the same as the number of

offspring generations.

> nGens := 4; nGensP1 := nGens + 1;

nGens := 4

nGensP1 := 5

>

>

Build the signal:

>

>

> f := t -> sin(20*t)*(log(t))^2;

f := proc (t) options operator, arrow; sin(20*t)*lo...

> #f(10^(-15)); #This is just to check function near origin.

> #evalf(%);

> plot(f(t), t=0..1);

[Maple Plot]

>

> for n from 0 to nGens do

> for k from 0 to (2^n - 1) do

> psi||n||k := psi(2^n * t - k):

> psi||n||k := unapply(psi||n||k,t);

> od:

> od:

>

> with(LinearAlgebra): #NAG's Linear Algebra Package!

Next we build the matrix corresponding to the Haar

wavelets.

>

> M := Matrix(2^nGensP1,2^nGensP1);

M := _rtable[19503120]

> for i from 1 to 2^nGensP1 do

> M[i,1] := 1:

> od:

>

> mColumn := 1:

> for i from 0 to nGens do

> genSize := 2^i:

> for j from 1 to genSize do

> mColumn := mColumn + 1;

> for k from 1 to 2^nGensP1 do #Evaluate psi.i.j at left endpoint.

> M[k,mColumn] := psi||i||(j-1)((k-1)/2^nGensP1):

> od:

> od:

> od:

>

> M: evalm(%): #Evaluate entries of matrix.

>

>

Sample signal:

>

> b := Vector(2^nGensP1);

>

b := _rtable[19468568]

> b[1] := 0:#Warning: this signal (i.e., f) starts out at zero!

> for i from 2 to 2^nGensP1 do

> b[i] := evalf(f((i-1)/2^nGensP1));

> od:

> coef := LinearSolve(M, b): #Get coefficients of wavelet functions.

> myApprox := proc(n::integer,coef::Vector,phi,psi,t)

> #

> #

> if n = -1 then

> coef[1]*phi(t);

> elif n = 0 then

> coef[1]*phi(t) + coef[2]*psi(t);

> elif n = 1 then

> coef[1]*phi(t) + coef[2]*psi(t)

> + coef[3]*psi(2*t) + coef[4]*psi(2*t - 1);

> else

> indx := 2^n: indxj := indx - 1:

> myApprox(n-1,coef,phi,psi,t) +

> add(coef[indx + j + 1]*psi(2^n*t - j),j=0..indxj);

> fi;

> end:

Warning, `indx` is implicitly declared local to procedure `myApprox`

Warning, `indxj` is implicitly declared local to procedure `myApprox`

Display original signal and Haar approximation.

>

> display([seq(

> display(array([plot(f(t),t=0..1, title=`Signal`),

> plot(myApprox(i,coef,phi,psi,t), t=0..1.05, title=`Haar Approx.`)])),i=-1..nGens)], insequence=true);

[Maple Plot]

>

>