Wavelets For Kids B
Wavelets For Kids B
Mathematica Activities
Off[General::spell]
Packages needed:
<<waves.m
<<Statistics`NormalDistribution`
Filters corresponding to Daubechies wavelets
d2={0.482962913145, 0.836516303738,
0.224143868042, -0.129409522551};
d4={0.230377813309, 0.714846570553, 0.630880767930,
-0.027983769417,-0.187034811719, 0.030841381836
0.032883011667 -0.010597401785};
d6={0.1115407433501098, 0.4946238903984543,
0.7511339080210969, 0.3152503517091975,
-0.2262646939654413,-0.1297668675672621,
1
Appl
0.0975016055873234, 0.0275228655303057,
-0.0315820393174862, 0.0005538422011614892,
0.004777257510945529, -0.001077301085308485};
d10={0.026670057901, 0.188176800078, 0.527201188932,
0.688459039454, 0.281172343661,-0.249846424327,
-0.195946274377, 0.127369340336, 0.093057364604,
-0.071394147166,-0.029457536822, 0.033212674059,
0.003606553567,-0.010733175483, 0.001395351747,
0.001992405295,-0.000685856695,-0.000116466855,
0.000093588670,-0.000013264203};
ThresHard[list_List,thresh_]:=Module[{},
Table[ If[ Abs[list[[i]]] < thresh , 0 , list[[i]]] ,
{i,1,Length[list]}] ]
Soft Thresholding
ThresSoft[list_List, thresh_]:=
Module[{ll=Length[list]},
Table[ If [Abs[ list[[i]]] - thresh > 0,
Sign[list[[i]]] ( Abs[list[[i]]] - thresh), 0],
{i, 1,ll} ]
];
2
Appl
Universal Thresholding
ThresUniv[ list_List]:=
Module[{ll=Length[list], s, unithresh},
s=N[Sqrt[1/(ll-1) Apply[Plus,
(list - Apply[Plus, list]/ll)^2 ] ]];
unithresh=N[s Sqrt[ 2 Log[ll]] ];
Table[ If[Abs[ list[[i]] ] - unithresh >0,
Sign[ list[[i]] ] (Abs[list[[i]]] - unithresh),0],
{i,1, ll} ]
];
Trimming
Trimm[list_List, lam_]:=
Table[ Abs[list[[i]]] Tanh[ lam list[[i]] ],
{i,1, Length[list]}
];
Examples
Example from the tutorial, page 6.
example={1,0,-3,2,1,0,1,2};
3
Appl
DataPlot[example]
2
-2
-3
-Graphics-
ed1=WT[ example, d1]
{0.7071067811865475, -3.53553, 0.7071067811865475, -0.707107, 1., -1., -1.41421,
1.41421}
et1=ThresHard[ed1, 0.9]
{0, -3.53553, 0, 0, 1., -1., -1.41421, 1.41421}
er1=WR[et1, d1]
{0.5, 0.5, -3., 2., 0.5, 0.5, 1.5, 1.5}
4
Appl
DataPlot[er1]
2
-2
-3
-Graphics-
Function Sin[x]+Sin[2 x]: Denoising by different
wavelet bases and thresholding policies.
1.5
1
0.5
1 2 3 4 5 6
-0.5
-1
-1.5
-Graphics-
RandomSeed[125];
5
Appl
li=Table[N[Sin[x]+Sin[2 x]+Random[
NormalDistribution[0, 0.4]]],
{x, 2 Pi/1024, 2 Pi, 2 Pi/1024}];
Short[li, 3]
{0.489125, 0.759563, 0.203772, 0.687917, -0.553575, -0.145796, 0.11052, 0.782839,
-2
-Graphics-
lid1=WT[li, d1];
Short[lid1,3]
{-0.191229, -0.342343, -0.288343, -0.475401, -0.510271, 0.0194839, -0.227568,
6
Appl
lit1=ThresHard[lid1, 1.2];
Short[lit1, 3]
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1
-2
-Graphics-
lid4=WT[ li, d4];
lit4=ThresHard[ lid4,1.2];
lin4=WR[ lit4, d4];
7
Appl
DataPlot[lin4]
1.5
1
0.5
-Graphics-
8
Appl
Different thresholding policies and DAUB #6.
lid6=WT[li, d6];
lith6=ThresHard[lid6, 1.2];
linh6=WR[lith6, d6];
DataPlot[linh6]
1.5
1
0.5
-Graphics-
9
Appl
lits6=ThresSoft[lid6, 1];
lins6=WR[ lits6, d6];
DataPlot[lins6]
1.5
1
0.5
-Graphics-
10
Appl
litu6=ThresUniv[lid6];
linu6=WR[ litu6, d6];
DataPlot[linu6]
0.5
-1
-Graphics-
litt6=Trimm[lid6, 0.1];
lint6=WR[litt6, d6];
DataPlot[lint6]
1.5
1
0.5
-1.5
-Graphics-
11
Appl
1.5
1
0.5
-Graphics-
aa=Table[N[Sign[x] Cos[x]],{x,-1, 511/512, 1/512}];
DataPlot[aa]
1
0.5
-0.5
-1
-Graphics-
12
Appl
bb=aa+Table[(Random[]-0.5),{1024}];
DataPlot[bb]
1.5
0.5
-1
-1.5
-Graphics-
cc=WT[bb,d4];
dd=ThresSoft[cc, 1.3];
ee=WR[dd,d4];
DataPlot[ee]
0.6
0.4
0.2
-0.4
-0.6
-Graphics-
ff=WT[bb,d10];
13
Appl
gg=ThresSoft[ff,0.9];
hh=WR[gg, d10];
DataPlot[hh]
1
0.5
-0.5
-Graphics-
ii=WT[bb,d2];
jj=ThresSoft[ii,1];
kk=WR[jj, d2]
14
Appl
DataPlot[kk]
1
0.5
-0.5
-1
-Graphics-
ll=WT[bb,d1];
mm=ThresSoft[ll,0.9];
nn=WR[mm,d1];
DataPlot[nn]
0.75
0.5
0.25
-Graphics-
15