### Learning Wavelet Transform by MATLAB Toolbox

```Learning Wavelet Transform by
MATLAB Toolbox
Professor : R.J. Chang
Student : Che-Wei Chen
Date :2013/12/13
Outline
 Wavelet evolution
 Wavelet transform toolbox in MATLAB
 Wavelet function in MATLAB
 Wavelet packet transform toolbox in MATLAB
 Wavelet packet function in MATLAB
 Definition of SNR
1. Wavelet evolution
 Fourier transform:
F ( ) 

i t

f (t ) e

dt
 Time-frequency tile for Fourier transform:
f
t
 Poor time-localization
1. Wavelet evolution(count.)
 Short-time Fourier transform:
S ( ,  ) 



f (t ) w (t   ) e
 i t
dt
 Time-frequency tile for STFT:
f
f
f
t
t
 w(t-τ) is the window function.
t
1. Wavelet evolution(count.)
 Wavelet transform:
 a ,b ( t ) 
1
(
tb
)
a,b  Z
a
a

 (a , b )   a , b ( t ), x ( t ) 

x ( t )  a ,b d t
*

 Time-frequency tile for wavelet transform:
f
t
Morlet
1. Wavelet evolution(count.)
 Compare these three methods:
Fourier transform
STFT
Wavelet
Resolution in time domain
and frequency domain
No resolution in
time domain
Low resolution in
time domain.
High resolution in
time domain.
Can analyze the nonstationary signal?
No
Yes
Good
2. Wavelet transform toolbox in MATLAB
 Decomposition and reconstruction :
2
h[n ]
~
h [n]
2
x[n ]
~y [ n ]
H
y H [ n ]
y H [n]
g[n]
~y [ n ]
L
y L [ n ]
y L [n]
2
2
~
x [n]
g~ [ n ]
 This structure contains for J = 3 the terminal nodes of the following
tree.
Input signal
Level 1
Level 2
Level 3
2. Wavelet transform toolbox in MATLAB(count.)
 Step 1:
command window and hit the
Wavelet 1-D button.
 Step 2:
Load signal from “*.mat files” or
“workspace”.
 Step 3:
Select the mother wavelet and
levels, for example: db7, level 5.
 Step 4:
Push “Analyze” button.
2. Wavelet transform toolbox in
MATLAB(count.)
 The signals include approximations(a) and Details(d):
s＝a5+d5+d4+d3+d2+d1
d1
d2
d3
d4
a5
d5
Wavelet transform toolbox in MATLAB(count.)
 Step 6:
Push “Statistics” button to show the statistics of signal of each levels.
Wavelet transform toolbox in MATLAB(count.)
 Step 7:
Push “De-noise” button to remove the detail parts.
Wavelet transform toolbox in MATLAB(count.)
3. Wavelet function in MATLAB
 1. Single-level discrete 1-D wavelet transform:
[cA,cD] = dwt(X,'wname')
Example:
s = noissin(1:1000);
[ca1,cd1] = dwt(s,'haar');
plot(s)
subplot(121),plot(ca1)
subplot(122),plot(cd1)
1.5
1
0.5
0
-0.5
-1
-1.5
0
100
200
300
400
500
s
2.5
0.8
2
0.6
1.5
600
700
800
900
1000
0.4
1
0.2
0.5
0
0
-0.2
-0.5
-0.4
-1
-0.6
-1.5
-2
0
50
100
150
200
250
300
ca1
350
400
450
-0.8
500 0
50
100
150
200
250
cd1
300
350
400
450
500
3. Wavelet function in MATLAB(count.)
 2. Single-level inverse discrete 1-D wavelet transform:
X = idwt(cA,cD,'wname')
Example:
s = noissin(1:1000);
[ca1,cd1] = dwt(s,'haar');
X = idwt(ca1,cd1,'haar');
plot(X)
2.5
2
1.5
1
0.5
0
-0.5
1.5
1.5
-1
-1.5
1
-2
1
0
50
100
150
0.5
200
250
300
ca1
+
350
400
450
500
0.5
0.8
0
0
0.6
0.4
-0.5
-0.5
0.2
0
-1
-1
-0.2
-0.4
-1.5
0
100
200
300
400
s
500
-1.5
-0.6
600
700
800
900
1000
-0.8
0
50
100
150
200
250
300
cd1
350
400
450
500
0
100
200
300
400
500
X
600
700
800
900
1000
3. Wavelet function in MATLAB(count.)
 3. Multilevel 1-D wavelet decomposition:
[C,L] = wavedec(X,N,'wname')
Example:
s = sumsin;
[c,l] = wavedec(s,3, 'db1');
3. Wavelet function in MATLAB(count.)
 4. Reconstruct single branch from 1-D wavelet coefficients:
X = wrcoef('type',C,L,'wname',N)
Example:
s = sumsin;
[c,l] = wavedec(s,5, 'sym4');
a5 = wrcoef('a',c,l, 'sym4',5);
4. Wavelet packet transform toolbox in
MATLAB
 Step 1:
command window and hit the
Wavelet Packet 1-D button.
 Step 2:
Load signal from “*.mat files” or
“workspace”.
 Step 3:
Select the mother wavelet and
levels, for example: db7, level 5,
shannon.
 Step 4:
Push “Analyze” button.
4. Wavelet packet transform toolbox in
MATLAB
Select the mother
wavelet, this step will
Suggest you choose
haar, db, sym.
You can chose different
packet.
Some wavelet must
be defined, you can
compare results
with different value
at this button.
This button decides wavelet
packet levels.
Tapping different nodes
will show you results.
4. Wavelet packet transform toolbox in
MATLAB
5. Wavelet packet function in MATLAB
1. Single-level discrete 1-D wavelet packet transform:
T = wpdec(X,N,'wname',E)
Example:
s = noissin(1:1000);
wpt = wpdec(s,3,'haar','shannon');
plot(wpt)
5. Wavelet packet function in MATLAB
2. Single-level denoise discrete 1-D wavelet packet transform:
[XD,TREED,PERF0,PERFL2]=wpdencmp(X,SORH,N,'wname',CRIT,PAR,K
EEPAPP)
Example:
s = noissin(1:1000);
n = length(s);
keepapp = 1
SORH=soft or hard
30
20
10
0
-10
-20
entropy criterion= CRIT
thr = sqrt(2*log(n*log(n)/log(2)));
xwpd = wpdencmp(s,'s',3,'haar','sure',thr,1);
plot(t,xx,'r',t,xwpd)
-30
-40
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
6. Definition of SNR
 This definition in time-domain is the basic definition of SNR. It is defined to be
the average power of signal divided by that of noise, and referred as Time
Domain 1.
N
2
1
SN R1  10 log 1 0
N
1

N 
0
N
0
y S (t )
2
y N (t )
 This definition in time-domain is defined by Mitaim and Kosko, and referred as
Time Domain 2. (Signal frequency=f0)
SN R 2  10 log 10
2 Y [k0 ]

L 1
k 0
k 0  f 0 L Ts
2
2
Y [k ]  2 Y [k0 ]
2
L 1
Y [k ] 

i
yt e
2 k
t
L
t0
 This definition in frequency-domain is defined to be the power spectrum at
signal frequency divided by the noise spectrum at signal frequency, and
referred as Narrow Band 1.(Signal frequency=)
  
lim
SN R  10 log 1 0
  0

S S ( ) d 
  
S N ( )
6. Definition of SNR
 This definition in frequency-domain is defined to be the power spectrum of
signal and noise at signal frequency divided by the noise spectrum, and referred
as Narrow Band 2.(Signal frequency=)
  
lim
S N R  1 0 lo g 1 0
  0

S ( ) d 
  
S N ( )
 This definition in frequency-domain is defined to be the total signal spectrum
divided by the total noise spectrum, and referred as Wide Band. .(Signal
k   

frequency=)

SN R w  10 log 10
k 1

lim
  0
S S ( ) d 
k   

S
0
N
( ) d 