891
Computation Visualization Programming For Use with MATLAB ® User’s Guide Version 2.1 Michel Misiti Yves Misiti Georges Oppenheim Jean-Michel Poggi Wavelet Toolbox

Wavelet ug

Embed Size (px)

Citation preview

Page 1: Wavelet ug

Computation

Visualization

Programming

For Use with MATLAB®

User’s GuideVersion 2.1

Michel MisitiYves Misiti

Georges OppenheimJean-Michel Poggi

WaveletToolbox

Page 2: Wavelet ug

How to Contact The MathWorks:

www.mathworks.com Webcomp.soft-sys.matlab Newsgroup

[email protected] Technical [email protected] Product enhancement [email protected] Bug [email protected] Documentation error [email protected] Order status, license renewals, [email protected] Sales, pricing, and general information

508-647-7000 Phone

508-647-7001 Fax

The MathWorks, Inc. Mail3 Apple Hill DriveNatick, MA 01760-2098

For contact information about worldwide offices, see the MathWorks Web site.

Wavelet Toolbox User’s Guide COPYRIGHT 1997 - 2001 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro-duced in any form without prior written consent from The MathWorks, Inc.

FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by or for the federal government of the United States. By accepting delivery of the Program, the government hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part 252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain to the government’s use and disclosure of the Program and Documentation, and shall supersede any conflicting contractual terms or conditions. If this license fails to meet the government’s minimum needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to MathWorks.

MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and Target Language Compiler is a trademark of The MathWorks, Inc.

Other product or brand names are trademarks or registered trademarks of their respective holders.

Printing History: March 1997 First printing New for MATLAB 5.1 September 2000 Second printing Revised for MATLAB 6.0 (Release 12)

June 2001 (Online only) Revised for MATLAB 6.1 (Release 12)

Page 3: Wavelet ug

i

Contents

Preface

About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx

Notes by Yves Meyer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

Notes by Ingrid Daubechies . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv

What Is the Wavelet Toolbox? . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

Using This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviCaution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi

For More Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii

Installing the Wavelet Toolbox . . . . . . . . . . . . . . . . . . . . . . . xxviiiSystem Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviiiPlatform-Specific Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii

Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx

Related Products List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi

1Wavelets: A New Tool for Signal Analysis

Wavelet Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3Scale aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3Time aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

Page 4: Wavelet ug

ii Contents

Wavelet Decomposition as a Whole . . . . . . . . . . . . . . . . . . . . . . . 1-4

Fourier Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

Short-Time Fourier Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

Wavelet Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7What Can Wavelet Analysis Do? . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

What Is Wavelet Analysis? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9Number of Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

The Continuous Wavelet Transform . . . . . . . . . . . . . . . . . . . 1-10Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11Shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12Five Easy Steps to a Continuous Wavelet Transform . . . . . . . 1-12Scale and Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15The Scale of Nature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15What’s Continuous About the Continuous Wavelet Transform? . . . . . . . . . . . . . . . . . . . . . . . . 1-17

The Discrete Wavelet Transform . . . . . . . . . . . . . . . . . . . . . . 1-18One-Stage Filtering: Approximations and Details . . . . . . . . . . 1-18Multiple-Level Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21

Wavelet Reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22Reconstruction Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23Reconstructing Approximations and Details . . . . . . . . . . . . . . 1-23Relationship of Filters to Wavelet Shapes . . . . . . . . . . . . . . . . 1-25Multistep Decomposition and Reconstruction . . . . . . . . . . . . . 1-27

Wavelet Packet Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29

History of Wavelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31

An Introduction to the Wavelet Families . . . . . . . . . . . . . . . 1-32Haar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33Daubechies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33Biorthogonal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34

Page 5: Wavelet ug

iii

Coiflets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35Symlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35Morlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36Mexican Hat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36Meyer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37Other Real Wavelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37Complex Wavelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37

2Using Wavelets

One-Dimensional Continuous Wavelet Analysis . . . . . . . . . . 2-3Continuous Analysis Using the Command Line . . . . . . . . . . . . 2-4Continuous Analysis Using the Graphical Interface . . . . . . . . . 2-7Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14

One-Dimensional Complex Continuous Wavelet Analysis 2-16Complex Continuous Analysis Using the Command Line . . . . 2-17Complex Continuous Analysis Using the Graphical Interface 2-19Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23

One-Dimensional Discrete Wavelet Analysis . . . . . . . . . . . . 2-24One-Dimensional Analysis Using the Command Line . . . . . . 2-26One-Dimensional Analysis Using the Graphical Interface . . . 2-34Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49

Two-Dimensional Discrete Wavelet Analysis . . . . . . . . . . . . 2-57Two-Dimensional Analysis Using the Command Line . . . . . . 2-59Two-Dimensional Analysis Using the Graphical Interface . . . 2-66Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-74

Wavelets: Working with Images . . . . . . . . . . . . . . . . . . . . . . . 2-82Understanding Images in MATLAB . . . . . . . . . . . . . . . . . . . . . 2-82

Page 6: Wavelet ug

iv Contents

Indexed Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-82Wavelet Decomposition of Indexed Images . . . . . . . . . . . . . . . 2-83Other Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-84Image Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-85

One-Dimensional Discrete Stationary Wavelet Analysis . 2-88One-Dimensional Analysis Using the Command Line . . . . . . 2-89One-Dimensional Analysis for De-noising Using the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-97Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-101

Two-Dimensional Discrete Stationary Wavelet Analysis 2-103Two-Dimensional Analysis Using the Command Line . . . . . 2-104Two-Dimensional Analysis for De-noising Using the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-113Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-118

One-Dimensional Wavelet Regression Estimation . . . . . . 2-120One-Dimensional Estimation Using the GUI for Equally Spaced Observations (Fixed Design) . . . . . . . . . . . . . 2-120One-Dimensional Estimation Using the GUI for Randomly Spaced Observations (Stochastic Design) . . . . . . . 2-125Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-127

One-Dimensional Wavelet Density Estimation . . . . . . . . . 2-129One-Dimensional Estimation Using the Graphical Interface 2-129Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-134

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-136

One-Dimensional Local Thresholding for De-noising Using the Graphical Interface . . . . . . . . . . . . . . . 2-137Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-143

Page 7: Wavelet ug

v

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . 2-145

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . 2-153

One-Dimensional Extension . . . . . . . . . . . . . . . . . . . . . . . . . . 2-160One-Dimensional Extension Using the Command Line . . . . 2-160One-Dimensional Extension Using the Graphical Interface . 2-160Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-166

Two-Dimensional Extension . . . . . . . . . . . . . . . . . . . . . . . . . 2-167Two-Dimensional Extension Using the Command Line . . . . 2-167Two-Dimensional Extension Using the Graphical Interface . 2-167Importing and Exporting Information from the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-169

3Wavelet Applications

Detecting Discontinuities and Breakdown Points I . . . . . . . 3-3Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

Detecting Discontinuities and Breakdown Points II . . . . . . 3-6Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

Detecting Long-Term Evolution . . . . . . . . . . . . . . . . . . . . . . . . 3-8Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9

Detecting Self-Similarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10Wavelet Coefficients and Self-Similarity . . . . . . . . . . . . . . . . . 3-10Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11

Identifying Pure Frequencies . . . . . . . . . . . . . . . . . . . . . . . . . 3-12Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

Page 8: Wavelet ug

vi Contents

Suppressing Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16

De-Noising Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18

De-noising Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22

Compressing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

Fast Multiplication of Large Matrices . . . . . . . . . . . . . . . . . . 3-28

4Wavelets in Action: Examples and Case Studies

Illustrated Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3Advice to the Reader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5Example 1: A Sum of Sines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8Example 2: A Frequency Breakdown . . . . . . . . . . . . . . . . . . . . 4-10Example 3: Uniform White Noise . . . . . . . . . . . . . . . . . . . . . . . 4-12Example 4: Colored AR(3) Noise . . . . . . . . . . . . . . . . . . . . . . . . 4-14Example 5: Polynomial + White Noise . . . . . . . . . . . . . . . . . . . 4-16Example 6: A Step Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18Example 7: Two Proximal Discontinuities . . . . . . . . . . . . . . . . 4-20Example 8: A Second-Derivative Discontinuity . . . . . . . . . . . . 4-22Example 9: A Ramp + White Noise . . . . . . . . . . . . . . . . . . . . . . 4-24Example 10: A Ramp + Colored Noise . . . . . . . . . . . . . . . . . . . 4-26Example 11: A Sine + White Noise . . . . . . . . . . . . . . . . . . . . . . 4-28Example 12: A Triangle + A Sine . . . . . . . . . . . . . . . . . . . . . . . 4-30Example 13: A Triangle + A Sine + Noise . . . . . . . . . . . . . . . . 4-32Example 14: A Real Electricity Consumption Signal . . . . . . . . 4-34

Case Study: An Electrical Signal . . . . . . . . . . . . . . . . . . . . . . . 4-36Data and the External Information . . . . . . . . . . . . . . . . . . . . . 4-36Analysis of the Midday Period . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38

Page 9: Wavelet ug

vii

Analysis of the End of the Night Period . . . . . . . . . . . . . . . . . . 4-40Suggestions for Further Analysis . . . . . . . . . . . . . . . . . . . . . . . 4-43

5Using Wavelet Packets

About Wavelet Packet Analysis . . . . . . . . . . . . . . . . . . . . . . . . . 5-3

One-Dimensional Wavelet Packet Analysis . . . . . . . . . . . . . . 5-7Compressing a Signal Using Wavelet Packets . . . . . . . . . . . . . 5-12De-Noising a Signal Using Wavelet Packets . . . . . . . . . . . . . . 5-15

Two-Dimensional Wavelet Packet Analysis . . . . . . . . . . . . . 5-21Compressing an Image Using Wavelet Packets . . . . . . . . . . . . 5-25

Importing and Exporting from Graphical Tools . . . . . . . . . 5-29Saving Information to Disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29Loading Information into the Graphical Tools . . . . . . . . . . . . . 5-33

6Advanced Concepts

Mathematical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2

General Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5Wavelets: A New Tool for Signal Analysis . . . . . . . . . . . . . . . . . 6-5Wavelet Decomposition: A Hierarchical Organization . . . . . . . 6-5Finer and Coarser Resolutions . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6Wavelet Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6Wavelets and Associated Families . . . . . . . . . . . . . . . . . . . . . . . 6-7Wavelet Transforms: Continuous and Discrete . . . . . . . . . . . . 6-12Local and Global Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14Synthesis: an Inverse Transform . . . . . . . . . . . . . . . . . . . . . . . 6-15Details and Approximations . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15

Page 10: Wavelet ug

viii Contents

The Fast Wavelet Transform (FWT) Algorithm . . . . . . . . . . 6-19Filters Used to Calculate the DWT and IDWT . . . . . . . . . . . . 6-19Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-23Why Does Such an Algorithm Exist? . . . . . . . . . . . . . . . . . . . . 6-28One-Dimensional Wavelet Capabilities . . . . . . . . . . . . . . . . . . 6-32Two-Dimensional Wavelet Capabilities . . . . . . . . . . . . . . . . . . 6-33

Dealing with Border Distortion . . . . . . . . . . . . . . . . . . . . . . . 6-35Signal Extensions: Zero-Padding, Symmetrization, and Smooth Padding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-35

Discrete Stationary Wavelet Transform (SWT) . . . . . . . . . . 6-44e-decimated DWT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-44How to Calculate the e-decimated DWT: SWT . . . . . . . . . . . . . 6-45Inverse Discrete Stationary Wavelet Transform (ISWT) . . . . 6-50More about SWT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-50

Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . 6-51

Wavelet Families: Additional Discussion . . . . . . . . . . . . . . . 6-61Daubechies Wavelets: dbN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-62Symlet Wavelets: symN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-64Coiflet Wavelets: coifN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-65Biorthogonal Wavelet Pairs: biorNr.Nd . . . . . . . . . . . . . . . . . . 6-66Meyer Wavelet: meyr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-68Battle-Lemarie Wavelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-69Mexican Hat Wavelet: mexh . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-70Morlet Wavelet: morl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-71Other Real Wavelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-72Complex Wavelets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-74Summary of Wavelet Families and Associated Properties (Part 1) . . . . . . . . . . . . . . . . . . . . . . . . . . 6-78Summary of Wavelet Families and Associated Properties (Part 2) . . . . . . . . . . . . . . . . . . . . . . . . . . 6-79

Wavelet Applications: More Detail . . . . . . . . . . . . . . . . . . . . . 6-80Suppressing Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-80Splitting Signal Components . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-83Noise Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-83

Page 11: Wavelet ug

ix

De-Noising . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-84Data Compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-98Function Estimation: Density and Regression . . . . . . . . . . . . 6-101Available Methods for De-noising, Estimation and Compression Using GUI Tools . . . . . . . . . . . . . . . . . . . . . . . . 6-109

Wavelet Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-117From Wavelets to Wavelet Packets: Decomposing the Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-117Wavelet Packets in Action: an Introduction . . . . . . . . . . . . . . 6-118Building Wavelet Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-122Wavelet Packet Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-124Organizing the Wavelet Packets . . . . . . . . . . . . . . . . . . . . . . . 6-127Choosing the Optimal Decomposition . . . . . . . . . . . . . . . . . . . 6-128Some Interesting Subtrees . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-133Wavelet Packets 2-D Decomposition Structure . . . . . . . . . . . 6-134Wavelet Packets for Compression and De-Noising . . . . . . . . 6-134

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-135

7Adding Your Own Wavelets

Preparing to Add a New Wavelet Family . . . . . . . . . . . . . . . . 7-3Choose the Wavelet Family Full Name . . . . . . . . . . . . . . . . . . . 7-3Choose the Wavelet Family Short Name . . . . . . . . . . . . . . . . . . 7-3Determine the Wavelet Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4Define the Orders of Wavelets Within the Given Family . . . . . 7-4Build a MAT-File or M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5Define the Effective Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7

Adding a New Wavelet Family . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8Example 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8Example 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12

After Adding a New Wavelet Family . . . . . . . . . . . . . . . . . . . 7-16

Page 12: Wavelet ug

x Contents

8Function Reference

Functions by Category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3

Alphabetical List of Functions . . . . . . . . . . . . . . . . . . . . . . . . 8-11allnodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15appcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17appcoef2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19bestlevt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-21besttree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-23biorfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-26biorwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-31centfrq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-32cgauwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-35cmorwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-37coifwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39cwt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-40dbaux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45dbwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-48ddencmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-49depo2ind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-52detcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-54detcoef2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-56disp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-58drawtree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-59dtree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-61dwt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-63dwt2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-67dwtmode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-71dyaddown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-74dyadup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-76entrupd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-79fbspwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-80gauswavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-82get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-84idwt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-86idwt2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-90ind2depo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-93intwave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-95

Page 13: Wavelet ug

xi

isnode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-97istnode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-99iswt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-101iswt2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-103leaves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-105mexihat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-108meyer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-109meyeraux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-112morlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-113nodeasc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-114nodedesc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-116nodejoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-119nodepar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-121nodesplt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-123noleaves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-125ntnode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-127ntree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-128orthfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-131plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-135qmf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-140rbiowavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-142read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-143readtree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-146scal2frq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-148set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-158shanwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-160swt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-162swt2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-166symaux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-171symwavf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-173thselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-174tnodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-176treedpth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-178treeord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-179upcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-180upcoef2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-184upwlev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-186upwlev2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-188wavedec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-190wavedec2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-194

Page 14: Wavelet ug

xii Contents

wavedemo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-198wavefun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-199wavefun2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-203waveinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-205wavemenu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-207wavemngr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-209waverec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-220waverec2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-221wbmpen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-222wcodemat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-226wdcbm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-227wdcbm2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-230wden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-233wdencmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-238wentropy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-245wextend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-249wfilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-253wkeep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-256wmaxlev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-258wnoise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-260wnoisest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-262wp2wtree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-264wpbmpen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-266wpcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-270wpcutree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-272wpdec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-274wpdec2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-277wpdencmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-279wpfun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-285wpjoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-288wprcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-290wprec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-292wprec2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-293wpsplt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-294wpthcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-296wptree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-297wpviewcf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-300wrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-302wrcoef2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-304wrev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-306

Page 15: Wavelet ug

xiii

write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-307wtbo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-309wthcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-310wthcoef2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-311wthresh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-312wthrmngr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-313Discrete Wavelet 1-D options. . . . . . . . . . . . . . . . . . . . . . . . . . 8-314Discrete Stationary Wavelet 1-D options. . . . . . . . . . . . . . . . 8-315Discrete Wavelet 2-D options. . . . . . . . . . . . . . . . . . . . . . . . . . 8-315Discrete Stationary Wavelet 2-D options. . . . . . . . . . . . . . . . 8-316Discrete Wavelet Packet 1-D options. . . . . . . . . . . . . . . . . . . . 8-317Discrete Wavelet Packet 2-D options. . . . . . . . . . . . . . . . . . . . 8-317wtreemgr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-319wvarchg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-320

AGUI Reference

General Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-3Color Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-3Connection of Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-3Using the Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-4Controlling the Colormap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-6Using Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-10Using the View Axes Button . . . . . . . . . . . . . . . . . . . . . . . . . . . A-14Using the Interval-Dependent Threshold Settings Tool . . . . . A-17

Continuous Wavelet Tool Features . . . . . . . . . . . . . . . . . . . . A-19

Wavelet 1-D Tool Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-20Tree Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-20More Display Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-20

Wavelet 2-D Tool Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-22

Wavelet Packet Tool Features (1-D and 2-D) . . . . . . . . . . . . A-23Node Action Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-24

Page 16: Wavelet ug

xiv Contents

Wavelet Display Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-28

Wavelet Packet Display Tool . . . . . . . . . . . . . . . . . . . . . . . . . . A-29

BObject-Oriented Programming

Short Description of Objects in the Toolbox . . . . . . . . . . . . . B-3

Simple Use of Objects Through Four Examples . . . . . . . . . . B-4Example 1: plot and wpviewcf . . . . . . . . . . . . . . . . . . . . . . . . . . . B-4Example 2: drawtree and readtree . . . . . . . . . . . . . . . . . . . . . . . B-7Example 3: A Funny One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-9Example 4: Thresholding Wavelet Packets . . . . . . . . . . . . . . . B-11

Detailed Description of Objects in the Toolbox . . . . . . . . . B-15WTBO object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-15NTREE object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16DTREE object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-17WPTREE object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-19

Advanced Use of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-22Example 1: Building a Wavelet Tree Object (WTREE) . . . . . . B-22Example 2: Building a Right Wavelet Tree Object (RWVTREE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-23Example 3: Building a Wavelet Tree Object (WVTREE) . . . . . B-25Example 4: Building a Wavelet Tree Object (EDWTTREE) . . B-26

Page 17: Wavelet ug

Preface

About the Authors . . . . . . . . . . . . . . . . . xx

Notes by Yves Meyer . . . . . . . . . . . . . . . . xxi

Notes by Ingrid Daubechies . . . . . . . . . . . . . xxiii

Acknowledgements . . . . . . . . . . . . . . . . . xxiv

What Is the Wavelet Toolbox? . . . . . . . . . . . . xxv

Using This Guide . . . . . . . . . . . . . . . . . . xxvi

For More Background . . . . . . . . . . . . . . xxvii

Installing the Wavelet Toolbox . . . . . . . . . . xxviii

Typographical Conventions . . . . . . . . . . . . . xxx

Related Products List . . . . . . . . . . . . . . . . xxxi

Page 18: Wavelet ug

Preface

xvi

About the AuthorsMichel Misiti, Georges Oppenheim, and Jean-Michel Poggi are mathematics professors at Ecole Centrale de Lyon, University of Marne-La-Vallée and Paris 5 University. Yves Misiti is a research engineer specializing in Computer Sciences at Paris 11 University.

The authors are members of the “Laboratoire de Mathématique” at Orsay-Paris 11 University France.

Their fields of interest are statistical signal processing, stochastic processes, adaptive control, and wavelets.

The authors’ group, established more than 15 years ago, has published numerous theoretical papers and carried out applications in close collaboration with industrial teams. For instance:

• Robustness of the piloting law for a civilian space launcher for which an expert system was developed

• Forecasting of the electricity consumption by nonlinear methods

• Forecasting of air pollution

Page 19: Wavelet ug

Notes by Yves Meyer

xvii

Notes by Yves MeyerThe history of wavelets is not very old, at most 10 to 15 years. The field experienced a fast and impressive start, characterized by a close-knit international community of researchers who freely circulated scientific information and were driven by the researchers’ youthful enthusiasm. Even as the commercial rewards promised to be significant, the ideas were shared, the trials were pooled together, and the successes were shared by the community.

There are lots of successes for the community to share. Why? Probably because the time is ripe. Fourier techniques were liberated by the appearance of windowed Fourier methods that operate locally on a time-frequency approach. In another direction, Burt-Adelson’s pyramidal algorithms, the quadrature mirror filters, and filter banks and subband coding are available. The mathematics underlying those algorithms existed earlier, but new computing techniques enabled researchers to try out new ideas rapidly. The numerical image and signal processing areas are blooming.

The wavelets bring their own strong benefits to that environment: a local outlook, a multiscaled outlook, cooperation between scales, and a time-scale analysis. They demonstrate that sines and cosines are not the only useful functions and that other bases made of weird functions serve to look at new foreign signals, as strange as most fractals or some transient signals.

Recently, wavelets were determined to be the best way to compress a huge library of fingerprints. This is not only a milestone that highlights the practical value of wavelets, but it has also proven to be an instructive process for the researchers involved in the project. Our initial intuition generally was that the proper way to tackle this problem of interweaving lines and textures was to use wavelet packets, a flexible technique endowed with quite a subtle sharpness of analysis and a substantial compression capability. However, it was a biorthogonal wavelet that emerged victorious and at this time represents the best method in terms of cost as well as speed. Our intuitions led one way, but implementing the methods settled the issue by pointing us in the right direction.

For wavelets, the period of growth and intuition is becoming a time of consolidation and implementation. In this context, a toolbox is not only possible, but valuable. It provides a working environment that permits experimentation and enables implementation.

Since the field still grows, it has to be vast and open. The MATLAB Wavelet

Page 20: Wavelet ug

Preface

xviii

Toolbox addresses this need, offering an array of tools that can be organized according to several criteria:

• Synthesis and analysis tools

• Wavelet and wavelet packets approaches

• Signal and image processing

• Discrete and continuous analyses

• Orthogonal and redundant approaches

• Coding, de-noising and compression approaches

What can we anticipate for the future, at least in the short term? It is difficult to make an accurate forecast. Nonetheless, it is reasonable to think that the pace of development and experimentation will carry on in many different fields. Numerical analysis constantly uses new bases of functions to encode its operators or to simplify its calculations to solve partial differential equations. The analysis and synthesis of complex transient signals touches musical instruments by studying the striking up, when the bow meets the cello string. The analysis and synthesis of multifractal signals, whose regularity (or rather irregularity) varies with time, localizes information of interest at its geographic location. Compression is a booming field, and coding and de-noising are promising.

For each of these areas, the MATLAB Wavelet Toolbox provides a way to introduce, learn, and apply the methods, regardless of the user’s experience. It includes a command-line mode and a graphical user interface mode, each very capable and complementing to the other. The user interfaces help the novice to get started and the expert to implement trials. The command line provides an open environment for experimentation and addition to the graphical interface.

In the journey to the heart of a signal’s meaning, the toolbox gives the traveler both guidance and freedom: going from one point to the other, wandering from a tree structure to a superimposed mode, jumping from low to high scale, and skipping a breakdown point to spot a quadratic chirp. The time-scale graphs of continuous analysis are often breathtaking and more often than not enlightening as to the structure of the signal.

Here are the tools, waiting to be used.

Yves MeyerProfessor at Ecole Normale Supérieure de Cachan and Institut de France

Page 21: Wavelet ug

Notes by Ingrid Daubechies

xix

Notes by Ingrid Daubechies Wavelet transforms, in their different guises, have come to be accepted as a set of tools useful for various applications. Wavelet transforms are good to have at one’s fingertips, along with many other mostly more traditional tools.

The MATLAB Wavelet Toolbox is a great way to work with wavelets. The toolbox, together with the power of MATLAB, really allows one to write complex and powerful applications, in a very short amount of time. The Graphic User Interface is both user-friendly and intuitive. It provides an excellent interface to explore the various aspects and applications of wavelets; it takes away the tedium of typing and remembering the various function calls.

Ingrid C. Daubechies

Professor at Princeton University,

Department of Mathematics and Program in Applied and Computational Mathematics

Page 22: Wavelet ug

Preface

xx

AcknowledgementsThe authors wish to express their gratitude to all the colleagues who directly or indirectly contributed to the making of the Wavelet Toolbox.

Specifically

• For the wavelet questions to Pierre-Gilles Lemarié-Rieusset (Evry) and Yves Meyer (ENS Cachan)

• For the statistical questions to Lucien Birgé (Paris 6), Pascal Massart (Paris 11) and Marc Lavielle (Paris 5)

• To David Donoho (Stanford) and to Anestis Antoniadis (Grenoble), who give generously so many valuable ideas

Colleagues and friends who have helped us steadily are: Patrice Abry (ENS Lyon), Samir Akkouche (Ecole Centrale de Lyon), Mark Asch (Paris 11), Patrice Assouad (Paris 11), Roger Astier (Paris 11), Jean Coursol (Paris 11), Didier Dacunha-Castelle (Paris 11), Claude Deniau (Marseille), Patrick Flandrin (Ecole Normale de Lyon), Eric Galin (Ecole Centrale de Lyon), Christine Graffigne (Paris 5), Anatoli Juditsky (Grenoble), Gérard Kerkyacharian (Paris 10), Gérard Malgouyres (Paris 11), Olivier Nowak (Ecole Centrale de Lyon), Dominique Picard (Paris 7), and Franck Tarpin-Bernard (Ecole Centrale de Lyon).

Several student groups have tested preliminary versions.

One of our first opportunities to apply the ideas of wavelets connected with signal analysis and its modeling occurred during a close and pleasant cooperation with the team “Analysis and Forecast of the Electrical Consumption” of Electricité de France (Clamart-Paris) directed first by Jean-Pierre Desbrosses, and then by Hervé Laffaye, and which included Xavier Brossat, Yves Deville, and Marie-Madeleine Martin.

Many thanks to those who tested and helped to refine the software and the printed matter and at last to The MathWorks group and specially to Roy Lurie, Jim Tung, Bruce Sesnovich, Jad Succari, Jane Carmody, and Paul Costa.

And finally, apologies to those we may have omitted.

Page 23: Wavelet ug

What Is the Wavelet Toolbox?

xxi

What Is the Wavelet Toolbox?The Wavelet Toolbox is a collection of functions built on the MATLAB® Technical Computing Environment. It provides tools for the analysis and synthesis of signals and images, and tools for statistical applications, using wavelets and wavelet packets within the framework of MATLAB.

The toolbox provides two categories of tools:

• Command line functions

• Graphical interactive tools

The first category of tools is made up of functions that you can call directly from the command line or from your own applications. Most of these functions are M-files, series of statements that implement specialized wavelet analysis or synthesis algorithms. You can view the code for these functions using the following statement:

type function_name

You can view the header of the function, the help part, using the statement:

help function_name

A summary list of the Wavelet Toolbox functions is available to you by typing:

help wavelet

You can change the way any toolbox function works by copying and renaming the M-file, then modifying your copy. You can also extend the toolbox by adding your own M-files.

The second category of tools is a collection of graphical interface tools that afford access to extensive functionality. Access these tools by typing:

wavemenu

from the command line.

Page 24: Wavelet ug

Preface

xxii

Using This GuideIf you are new to wavelet analysis and synthesis and need an overview of the concepts, read Chapter 1, “Wavelets: A New Tool for Signal Analysis”. It presents the main ideas without mathematical complexity.

After this you can refer to Chapter 2 and Chapter 5, for instructions on using the wavelet and wavelet packet analysis tools, respectively; Chapter 3, which discusses practical applications of wavelet analysis; and Chapter 4, which provides examples and a case study.

If you have experience with signal analysis and wavelets, you may want to turn directly to:

• Chapter 2 and Chapter 5, for instructions on using the wavelet and wavelet packet analysis tools, respectively.

• Chapter 6, for a discussion of the technical underpinnings of wavelet analysis.

• Chapter 7, for instructions on extending the Wavelet Toolbox by adding your own wavelets.

All toolbox users should look to the:

• Reference Guide, the complete online reference information about the Wavelet Toolbox command line functions,

• Appendix A, for more detailed information on using the many functions provided by the graphical tools,

• Appendix B, for more information on using object-oriented programming.

Caution

1 The examples of this guide are generated using the Wavelet Toolbox with the DWT extension mode set to 'zpd' (for zero padding), except when it is explicitly mentioned. So if you want to obtain exactly the same numerical results, type: dwtmode('zpd'), before to execute the example code.

2 In most of the command line examples, figures are displayed. To clarify the presentation, the plotting commands are partially or completely omitted. So if you want to reproduce the displayed figures, you need probably to insert some simple graphical commands in the example code.

Page 25: Wavelet ug

For More Background

xxiii

For More BackgroundThe Wavelet Toolbox provides a complete introduction to wavelets and assumes no previous knowledge of the area. The toolbox allows you to use wavelet techniques on your own data immediately and develop new insights.

It is our hope that, through the use of these practical tools, you may want to explore the beautiful underlying mathematics and theory.

Excellent supplementary texts provide complementary treatments of wavelet theory and practice (see “References” on page 6-145). For instance:

• Burke-Hubbard [Bur96] is an historical and up-to-date text presenting the concepts using everyday words

• Daubechies [Dau92], is a classic for the mathematics

• Kaiser, [Kai94], is a mathematical tutorial, and a physics oriented book

• Mallat [Mal98] is a 1998 book, which includes recent developments, and consequently is one of the most complete

• Meyer [Mey93] is the “father” of the wavelet books

• Strang-Nguyen [StrN96], is especially useful for signal processing engineers. It offers a clear and easy-to-understand introduction to two central ideas: filter banks for discrete signals, and for wavelets. It fully explains the connection between the two. Many exercises in the book are drawn from the Wavelet Toolbox.

For other interesting books by Cohen, Chui, Lemarié, Vetterli-Kovacevic, Wickerhauser, and so on, refer also to “References” on page 6-145.

The Wavelet Digest Internet site (http://www.wavelet.org) provides many useful and practical information.

Page 26: Wavelet ug

Preface

xxiv

Installing the Wavelet ToolboxTo install this toolbox on your computer, see the appropriate platform-specific MATLAB Installation Guide. To determine if the Wavelet Toolbox is already installed on your system, check for a subdirectory named wavelet within the main toolbox directory or folder.

The Wavelet Toolbox can perform signal or image analysis. Since MATLAB stores most numbers in double precision, even a single image takes up a lot of memory. For instance, one copy of a 512-by-512 image uses 2 MB of memory. To avoid Out of Memory errors, it is important to allocate enough memory to process various image sizes.

The memory can be real RAM or can be a combination of RAM and virtual memory. See your operating system documentation for how to set up virtual memory.

System RecommendationsWhile not a requirement, we recommend you obtain the Signal Processing and Image Processing Toolboxes to use in conjunction with the Wavelet Toolbox. These toolboxes provide complementary functionality that will give you maximum flexibility in analyzing and processing signals and images.

This manual makes no assumption that your computer is running any other MATLAB toolboxes.

Platform-Specific DetailsSome details of the use of the Wavelet Toolbox may depend on your hardware or operating system.

Windows 95 or 98 FontsWe recommend you set the system to use “Small Fonts.” Some of the labels in the GUI figures may be illegible if large fonts are used.

Set this option by clicking the Display icon in your desktop’s Control Panel (accessible through the Settings⇒Control Panel submenu). Select the Configuration option, and then use the Font Size menu to change to Small Fonts. You’ll have to restart Windows for this change to take effect.

Page 27: Wavelet ug

Installing the Wavelet Toolbox

xxv

Other Platforms FontsWe recommend you set the system to use standard default fonts. Some of the labels in the GUI windows may be illegible if other fonts are used.

Mouse CompatibilityThe Wavelet Toolbox was designed for three distinct types of mouse control:

Note The functionality of the Middle Mouse Button and the Right Mouse Button can be inverted depending on the platform.

For more information, see “Using the Mouse” on page A-4.

Left Mouse Button Middle Mouse Button Right Mouse Button

Make selections, activate controls

Display a cross-hair to show position-dependent information

Translate plots up and down, and left and right

Shift + Option +

Page 28: Wavelet ug

Preface

xxvi

Typographical ConventionsThis manual uses some or all of these conventions.

Item Convention Used Example

Example code Monospace font To assign the value 5 to A, enter

A = 5

Function names/syntax Monospace font The cos function finds the cosine of each array element.Syntax line example isMLGetVar ML_var_name

Keys Boldface with an initial capital letter

Press the Return key.

Literal strings (in syntax descriptions in reference chapters)

Monospace bold for literals f = freqspace(n,'whole')

Mathematicalexpressions

Italics for variablesStandard text font for functions, operators, and constants

This vector represents the polynomial

p = x2 + 2x + 3

MATLAB output Monospace font MATLAB responds withA =

5

Menu titles, menu items, dialog boxes, and controls

Boldface with an initial capital letter

Choose the File menu.

New terms Italics An array is an ordered collection of information.

Omitted input arguments (...) ellipsis denotes all of the input/output arguments from preceding syntaxes.

[c,ia,ib] = union(...)

String variables (from a finite list)

Monospace italics sysc = d2c(sysd,'method')

Page 29: Wavelet ug

Related Products List

xxvii

Related Products ListThe MathWorks provides several products that are especially relevant to the kinds of tasks you can perform with the Wavelet Toolbox. In particular, the Wavelet Toolbox requires these products:

• MATLAB®

For more information about any of these products, see either:

• The online documentation for that product, if it is installed or if you are reading the documentation from the CD

•The MathWorks Web site, at http://www.mathworks.com; see the “products” section

Note The products listed below complement the functionality of the Wavelet toolbox.

Product Description

Image Processing Toolbox

Complete suite of digital image processing and analysis tools for MATLAB

Signal Processing Toolbox

Tool for algorithm development, signal and linear system analysis, and time-series data modeling

Page 30: Wavelet ug

Preface

xxviii

Page 31: Wavelet ug

1Wavelets: A New Tool for Signal Analysis

Wavelet Applications . . . . . . . . . . . . . . . . 1-3

Fourier Analysis . . . . . . . . . . . . . . . . . . 1-5

Short-Time Fourier Analysis . . . . . . . . . . . . 1-6

Wavelet Analysis . . . . . . . . . . . . . . . . . . 1-7

What Is Wavelet Analysis? . . . . . . . . . . . . . . 1-9

The Continuous Wavelet Transform . . . . . . . . . 1-10

The Discrete Wavelet Transform . . . . . . . . . . . 1-18

Wavelet Reconstruction . . . . . . . . . . . . . . . 1-22

Wavelet Packet Analysis . . . . . . . . . . . . . . 1-29

History of Wavelets . . . . . . . . . . . . . . . . . 1-31

An Introduction to the Wavelet Families . . . . . . . 1-32

Page 32: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-2

Everywhere around us are signals that can be analyzed. For example, there are seismic tremors, human speech, engine vibrations, medical images, financial data, music, and many other types of signals. Wavelet analysis is a new and promising set of tools and techniques for analyzing these signals.

Before introducing wavelet concepts, let’s start with a quick overview of wavelet applications.

Page 33: Wavelet ug

Wavelet Applications

1-3

Wavelet ApplicationsWavelets have scale aspects and time aspects, consequently every application has scale and time aspects. To clarify them we try to untangle the aspects somewhat arbitrarily.

For scale aspects, we present one idea around the notion of local regularity. For time aspects, we present a list of domains. When the decomposition is taken as a whole, the de-noising and compression processes are center points.

Scale aspectsAs a complement to the spectral signal analysis, new signal forms appear. They are less regular signals than the usual ones.

The cusp signal presents a very quick local variation. Its equation is with t close to 0 and 0 < r < 1. The lower r the sharper the signal.

To illustrate this notion physically, imagine you take a piece of aluminum foil; The surface is very smooth, very regular. You first crush it into a ball, and then you spread it out so that it looks like a surface. The asperities are clearly visible. Each one represents a two-dimension cusp and analog of the one dimensional cusp. If you crush again the foil, more tightly, in a more compact ball, when you spread it out, the roughness increases and the regularity decreases.

Several domains use the wavelet techniques of regularity study:

• Biology for cell membrane recognition, to distinguish the normal from the pathological membranes

• Metallurgy for the characterization of rough surfaces

• Finance (which is more surprising), for detecting the properties of quick variation of values

• In Internet traffic description, for designing the services size

Time aspectsLet’s switch to time aspects. The main goals are:

• Rupture and edges detection

• Study of short-time phenomena as transient processes

tr

Page 34: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-4

As domain applications, we get:

• Industrial supervision of gear-wheel

• Checking undue noises in craned or dented wheels, and more generally in non destructive control quality processes

• Detection of short pathological events as epileptic crises or normal ones as evoked potentials in EEG (medicine)

• SAR imagery

• Automatic target recognition

• Intermittence in physics

Wavelet Decomposition as a WholeMany applications use the wavelet decomposition taken as a whole. The common goals concern the signal or image clearance and simplification, which are parts of de-noising or compression.

We find many published papers in oceanography and earth studies.

One of the most popular successes of the wavelets is the compression of the FBI fingerprints.

When trying to classify the applications by domain, it is almost impossible to sum up several thousand papers written within the last 15 years. Moreover, it is difficult to get information on real-world industrial applications from companies. They understandably protect their own information.

Some domains are very productive. Medicine is one of them. We can find studies on micro-potential extraction in EKGs, on time localization of His bundle electrical heart activity, in ECG noise removal. In EEGs, a quick transitory signal is drowned in the usual one. The wavelets are able to determine if a quick signal exists, and if so, can localize it. There are attempts to enhance mammograms to discriminate tumors from calcifications.

Another prototypical application is a classification of Magnetic Resonance Spectra. The study concerns the influence of the fat we eat on our body fat. The type of feeding is the basic information and the study is intended to avoid taking a sample of the body fat. Each Fourier spectrum is encoded by some of its wavelet coefficients. A few of them are enough to code the most interesting features of the spectrum. The classification is performed on the coded vectors.

Page 35: Wavelet ug

Fourier Analysis

1-5

Fourier AnalysisSignal analysts already have at their disposal an impressive arsenal of tools. Perhaps the most well-known of these is Fourier analysis, which breaks down a signal into constituent sinusoids of different frequencies. Another way to think of Fourier analysis is as a mathematical technique for transforming our view of the signal from time-based to frequency-based.

For many signals, Fourier analysis is extremely useful because the signal’s frequency content is of great importance. So why do we need other techniques, like wavelet analysis?

Fourier analysis has a serious drawback. In transforming to the frequency domain, time information is lost. When looking at a Fourier transform of a signal, it is impossible to tell when a particular event took place.

If the signal properties do not change much over time — that is, if it is what is called a stationary signal — this drawback isn’t very important. However, most interesting signals contain numerous nonstationary or transitory characteristics: drift, trends, abrupt changes, and beginnings and ends of events. These characteristics are often the most important part of the signal, and Fourier analysis is not suited to detecting them.

FFourier

Transform

Am

plitu

de

Time

Am

plitu

de

Frequency

Page 36: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-6

Short-Time Fourier AnalysisIn an effort to correct this deficiency, Dennis Gabor (1946) adapted the Fourier transform to analyze only a small section of the signal at a time — a technique called windowing the signal. Gabor’s adaptation, called the Short-Time Fourier Transform (STFT), maps a signal into a two-dimensional function of time and frequency.

The STFT represents a sort of compromise between the time- and frequency-based views of a signal. It provides some information about both when and at what frequencies a signal event occurs. However, you can only obtain this information with limited precision, and that precision is determined by the size of the window.

While the STFT compromise between time and frequency information can be useful, the drawback is that once you choose a particular size for the time window, that window is the same for all frequencies. Many signals require a more flexible approach — one where we can vary the window size to determine more accurately either time or frequency.

Short

Transform

Am

plitu

de

TimeTime

Time

Fourier

Fre

quen

cy

window

Page 37: Wavelet ug

Wavelet Analysis

1-7

Wavelet AnalysisWavelet analysis represents the next logical step: a windowing technique with variable-sized regions. Wavelet analysis allows the use of long time intervals where we want more precise low-frequency information, and shorter regions where we want high-frequency information.

Here’s what this looks like in contrast with the time-based, frequency-based, and STFT views of a signal:

You may have noticed that wavelet analysis does not use a time-frequency region, but rather a time-scale region. For more information about the concept of scale and the link between scale and frequency, see “How to Connect Scale to Frequency?” on page 6-59.

Am

plitu

de

TimeTime

Sca

le

Wavelet Analysis

WWavelet

Transform

Time

Fre

quen

cy

Time

Sca

le

STFT (Gabor) Wavelet Analysis

TimeTime Domain (Shannon)

Fre

quen

cy

Frequency Domain (Fourier)Amplitude

Am

plitu

de

Page 38: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-8

What Can Wavelet Analysis Do?One major advantage afforded by wavelets is the ability to perform local analysis — that is, to analyze a localized area of a larger signal.

Consider a sinusoidal signal with a small discontinuity — one so tiny as to be barely visible. Such a signal easily could be generated in the real world, perhaps by a power fluctuation or a noisy switch.

A plot of the Fourier coefficients (as provided by the fft command) of this signal shows nothing particularly interesting: a flat spectrum with two peaks representing a single frequency. However, a plot of wavelet coefficients clearly shows the exact location in time of the discontinuity.

Wavelet analysis is capable of revealing aspects of data that other signal analysis techniques miss, aspects like trends, breakdown points, discontinuities in higher derivatives, and self-similarity. Furthermore, because it affords a different view of data than those presented by traditional techniques, wavelet analysis can often compress or de-noise a signal without appreciable degradation.

Indeed, in their brief history within the signal processing field, wavelets have already proven themselves to be an indispensable addition to the analyst’s collection of tools and continue to enjoy a burgeoning popularity today.

Sinusoid with a small discontinuity

Fourier Coefficients Wavelet Coefficients

Page 39: Wavelet ug

What Is Wavelet Analysis?

1-9

What Is Wavelet Analysis?Now that we know some situations when wavelet analysis is useful, it is worthwhile asking “What is wavelet analysis?” and even more fundamentally, “What is a wavelet?”

A wavelet is a waveform of effectively limited duration that has an average value of zero.

Compare wavelets with sine waves, which are the basis of Fourier analysis. Sinusoids do not have limited duration — they extend from minus to plus infinity. And where sinusoids are smooth and predictable, wavelets tend to be irregular and asymmetric.

Fourier analysis consists of breaking up a signal into sine waves of various frequencies. Similarly, wavelet analysis is the breaking up of a signal into shifted and scaled versions of the original (or mother) wavelet.

Just looking at pictures of wavelets and sine waves, you can see intuitively that signals with sharp changes might be better analyzed with an irregular wavelet than with a smooth sinusoid, just as some foods are better handled with a fork than a spoon.

It also makes sense that local features can be described better with wavelets that have local extent.

Number of DimensionsThus far, we’ve discussed only one-dimensional data, which encompasses most ordinary signals. However, wavelet analysis can be applied to two-dimensional data (images) and, in principle, to higher dimensional data.

This toolbox uses only one- and two-dimensional analysis techniques.

Sine Wave Wavelet (db10)

......

Page 40: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-10

The Continuous Wavelet TransformMathematically, the process of Fourier analysis is represented by the Fourier transform:

which is the sum over all time of the signal f(t) multiplied by a complex exponential. (Recall that a complex exponential can be broken down into real and imaginary sinusoidal components.)

The results of the transform are the Fourier coefficients , which when multiplied by a sinusoid of frequency , yield the constituent sinusoidal components of the original signal. Graphically, the process looks like:

Similarly, the continuous wavelet transform (CWT) is defined as the sum over all time of the signal multiplied by scaled, shifted versions of the wavelet function :

The result of the CWT are many wavelet coefficients C, which are a function of scale and position.

F ω( ) f t( )e jωt–

∞–

∫ dt=

F ω( )ω

Signal

...

Constituent sinusoids of different frequencies

Fourier

Transform

ψ

C scale position,( ) f t( )ψ scale position t,,( ) td∞–

∫=

Page 41: Wavelet ug

The Continuous Wavelet Transform

1-11

Multiplying each coefficient by the appropriately scaled and shifted wavelet yields the constituent wavelets of the original signal:

ScalingWe’ve already alluded to the fact that wavelet analysis produces a time-scale view of a signal, and now we’re talking about scaling and shifting wavelets. What exactly do we mean by scale in this context?

Scaling a wavelet simply means stretching (or compressing) it.

To go beyond colloquial descriptions such as “stretching,” we introduce the scale factor, often denoted by the letter If we’re talking about sinusoids, for example, the effect of the scale factor is very easy to see:

Signal Constituent wavelets of different scales and positions

...

Wavelet

Transform

a.

f t( ) t( )sin=

f t( ) 2t( )sin=

f t( ) 4t( )sin=

a; 1=

; a 12---=

; a 14---=

Page 42: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-12

The scale factor works exactly the same with wavelets. The smaller the scale factor, the more “compressed” the wavelet.

It is clear from the diagrams that, for a sinusoid , the scale factor is related (inversely) to the radian frequency . Similarly, with wavelet analysis, the scale is related to the frequency of the signal. We’ll return to this topic later.

ShiftingShifting a wavelet simply means delaying (or hastening) its onset. Mathematically, delaying a function by k is represented by :

Five Easy Steps to a Continuous Wavelet TransformThe continuous wavelet transform is the sum over all time of the signal multiplied by scaled, shifted versions of the wavelet. This process produces wavelet coefficients that are a function of scale and position.

It’s really a very simple process. In fact, here are the five steps of an easy recipe for creating a CWT:

f t( ) ψ t( )=

f t( ) ψ 2t( )=

f t( ) ψ 4t( )=

; a 1=

; a 12---=

; a 14---=

ωt( )sin aω

f t( ) f t k–( )

Wavelet functionψ t( ) ψ t k–( )

Shifted wavelet function

0 0

Page 43: Wavelet ug

The Continuous Wavelet Transform

1-13

1 Take a wavelet and compare it to a section at the start of the original signal.

2 Calculate a number, C, that represents how closely correlated the wavelet is with this section of the signal. The higher C is, the more the similarity. More precisely, if the signal energy and the wavelet energy are equal to one, C may be interpreted as a correlation coefficient.

Note that the results will depend on the shape of the wavelet you choose.

3 Shift the wavelet to the right and repeat steps 1 and 2 until you’ve covered the whole signal.

4 Scale (stretch) the wavelet and repeat steps 1 through 3.

5 Repeat steps 1 through 4 for all scales.

Signal

Wavelet

C = 0.0102

Signal

Wavelet

Signal

Wavelet

C = 0.2247

Page 44: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-14

When you’re done, you’ll have the coefficients produced at different scales by different sections of the signal. The coefficients constitute the results of a regression of the original signal performed on the wavelets.

How to make sense of all these coefficients? You could make a plot on which the x-axis represents position along the signal (time), the y-axis represents scale, and the color at each x-y point represents the magnitude of the wavelet coefficient C. These are the coefficient plots generated by the graphical tools.

These coefficient plots resemble a bumpy surface viewed from above. If you could look at the same surface from the side, you might see something like this:

The continuous wavelet transform coefficient plots are precisely the time-scale view of the signal we referred to earlier. It is a different view of signal data than the time-frequency Fourier view, but it is not unrelated.

LargeCoefficients

SmallCoefficients

Sca

le

Time

Time

Sca

leC

oef

s

Page 45: Wavelet ug

The Continuous Wavelet Transform

1-15

Scale and FrequencyNotice that the scales in the coefficients plot (shown as y-axis labels) run from 1 to 31. Recall that the higher scales correspond to the most “stretched” wavelets. The more stretched the wavelet, the longer the portion of the signal with which it is being compared, and thus the coarser the signal features being measured by the wavelet coefficients.

Thus, there is a correspondence between wavelet scales and frequency as revealed by wavelet analysis:

• Low scale a ⇒ Compressed wavelet ⇒ Rapidly changing details ⇒ High frequency .

• High scale a ⇒ Stretched wavelet ⇒ Slowly changing, coarse features ⇒ Low frequency .

The Scale of NatureIt’s important to understand that the fact that wavelet analysis does not produce a time-frequency view of a signal is not a weakness, but a strength of the technique.

Not only is time-scale a different way to view data, it is a very natural way to view data deriving from a great number of natural phenomena.

Signal

Wavelet

Low scale High scale

ω

ω

Page 46: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-16

Consider a lunar landscape, whose ragged surface (simulated below) is a result of centuries of bombardment by meteorites whose sizes range from gigantic boulders to dust specks.

If we think of this surface in cross-section as a one-dimensional signal, then it is reasonable to think of the signal as having components of different scales — large features carved by the impacts of large meteorites, and finer features abraded by small meteorites.

Here is a case where thinking in terms of scale makes much more sense than thinking in terms of frequency. Inspection of the CWT coefficients plot for this signal reveals patterns among scales and shows the signal’s possibly fractal nature.

Even though this signal is artificial, many natural phenomena — from the intricate branching of blood vessels and trees, to the jagged surfaces of mountains and fractured metals — lend themselves to an analysis of scale.

Page 47: Wavelet ug

The Continuous Wavelet Transform

1-17

What’s Continuous About the Continuous Wavelet Transform?Any signal processing performed on a computer using real-world data must be performed on a discrete signal — that is, on a signal that has been measured at discrete time. So what exactly is “continuous” about it?

What’s “continuous” about the CWT, and what distinguishes it from the discrete wavelet transform (to be discussed in the following section), is the set of scales and positions at which it operates.

Unlike the discrete wavelet transform, the CWT can operate at every scale, from that of the original signal up to some maximum scale that you determine by trading off your need for detailed analysis with available computational horsepower.

The CWT is also continuous in terms of shifting: during computation, the analyzing wavelet is shifted smoothly over the full domain of the analyzed function.

Page 48: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-18

The Discrete Wavelet TransformCalculating wavelet coefficients at every possible scale is a fair amount of work, and it generates an awful lot of data. What if we choose only a subset of scales and positions at which to make our calculations?

It turns out, rather remarkably, that if we choose scales and positions based on powers of two — so-called dyadic scales and positions — then our analysis will be much more efficient and just as accurate. We obtain such an analysis from the discrete wavelet transform (DWT).

An efficient way to implement this scheme using filters was developed in 1988 by Mallat (see [Mal89] in “References” on page 6-145). The Mallat algorithm is in fact a classical scheme known in the signal processing community as a two-channel subband coder (see page 1 of the book Wavelets and Filter Banks, by Strang and Nguyen [StrN96]).

This very practical filtering algorithm yields a fast wavelet transform — a box into which a signal passes, and out of which wavelet coefficients quickly emerge. Let’s examine this in more depth.

One-Stage Filtering: Approximations and DetailsFor many signals, the low-frequency content is the most important part. It is what gives the signal its identity. The high-frequency content, on the other hand, imparts flavor or nuance. Consider the human voice. If you remove the high-frequency components, the voice sounds different, but you can still tell what’s being said. However, if you remove enough of the low-frequency components, you hear gibberish.

In wavelet analysis, we often speak of approximations and details. The approximations are the high-scale, low-frequency components of the signal. The details are the low-scale, high-frequency components.

Page 49: Wavelet ug

The Discrete Wavelet Transform

1-19

The filtering process, at its most basic level, looks like this:

The original signal, S, passes through two complementary filters and emerges as two signals.

Unfortunately, if we actually perform this operation on a real digital signal, we wind up with twice as much data as we started with. Suppose, for instance, that the original signal S consists of 1000 samples of data. Then the resulting signals will each have 1000 samples, for a total of 2000.

These signals A and D are interesting, but we get 2000 values instead of the 1000 we had. There exists a more subtle way to perform the decomposition using wavelets. By looking carefully at the computation, we may keep only one point out of two in each of the two 2000-length samples to get the complete information. This is the notion of downsampling. We produce two sequences called cA and cD.

The process on the right, which includes downsampling, produces DWT coefficients.

To gain a better appreciation of this process, let’s perform a one-stage discrete wavelet transform of a signal. Our signal will be a pure sinusoid with high-frequency noise added to it.

S

highpass

A D

Filterslowpass

S

cD

cA

1000 samples

~500 coefs

~500 coefs

S

D

A

1000 samples

~1000 samples

~1000 samples

Page 50: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-20

Here is our schematic diagram with real signals inserted into it:

The MATLAB code needed to generate s, cD, and cA is:

s = sin(20.*linspace(0,pi,1000)) + 0.5.*rand(1,1000);[cA,cD] = dwt(s,'db2');

where db2 is the name of the wavelet we want to use for the analysis.

Notice that the detail coefficients cD are small and consist mainly of a high-frequency noise, while the approximation coefficients cA contain much less noise than does the original signal.

[length(cA) length(cD)]

ans = 501 501

You may observe that the actual lengths of the detail and approximation coefficient vectors are slightly more than half the length of the original signal. This has to do with the filtering process, which is implemented by convolving the signal with a filter. The convolution “smears” the signal, introducing several extra samples into the result.

1000 data points

~500 DWT coefficients

~500 DWT coefficients

S

cD High Frequency

cA Low Frequency

Page 51: Wavelet ug

The Discrete Wavelet Transform

1-21

Multiple-Level DecompositionThe decomposition process can be iterated, with successive approximations being decomposed in turn, so that one signal is broken down into many lower resolution components. This is called the wavelet decomposition tree.

Looking at a signal’s wavelet decomposition tree can yield valuable information.

Number of LevelsSince the analysis process is iterative, in theory it can be continued indefinitely. In reality, the decomposition can proceed only until the individual details consist of a single sample or pixel. In practice, you’ll select a suitable number of levels based on the nature of the signal, or on a suitable criterion such as entropy (see “Choosing the Optimal Decomposition” on page 6-137).

S

cA1 cD1

cA2 cD2

cA3 cD3

S

cA1 cD1

cA2 cD2

cA3 cD3

Page 52: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-22

Wavelet ReconstructionWe’ve learned how the discrete wavelet transform can be used to analyze, or decompose, signals and images. This process is called decomposition or analysis. The other half of the story is how those components can be assembled back into the original signal without loss of information. This process is called reconstruction, or synthesis. The mathematical manipulation that effects synthesis is called the inverse discrete wavelet transform (IDWT).

To synthesize a signal in the Wavelet Toolbox, we reconstruct it from the wavelet coefficients:

Where wavelet analysis involves filtering and downsampling, the wavelet reconstruction process consists of upsampling and filtering. Upsampling is the process of lengthening a signal component by inserting zeros between samples:

The Wavelet Toolbox includes commands, like idwt and waverec, that perform single-level or multilevel reconstruction, respectively, on the components of one-dimensional signals. These commands have their two-dimensional analogs, idwt2 and waverec2.

S

H’

L’

H’

L’

Signal component Upsampled signal component

1 2 3 4 5 1 2 3 4 5 6 7 8 9 10

Page 53: Wavelet ug

Wavelet Reconstruction

1-23

Reconstruction FiltersThe filtering part of the reconstruction process also bears some discussion, because it is the choice of filters that is crucial in achieving perfect reconstruction of the original signal.

The downsampling of the signal components performed during the decomposition phase introduces a distortion called aliasing. It turns out that by carefully choosing filters for the decomposition and reconstruction phases that are closely related (but not identical), we can “cancel out” the effects of aliasing.

A technical discussion of how to design these filters is available on page 347 of the book Wavelets and Filter Banks, by Strang and Nguyen. The low- and highpass decomposition filters (L and H), together with their associated reconstruction filters (L' and H'), form a system of what is called quadrature mirror filters:

Reconstructing Approximations and DetailsWe have seen that it is possible to reconstruct our original signal from the coefficients of the approximations and details.

S S

Decomposition Reconstruction

H

L

H’

L’

cD

cA

cD

cA

S

H’

L’

cD

cA

1000 samples~500 coefs

~500 coefs

Page 54: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-24

It is also possible to reconstruct the approximations and details themselves from their coefficient vectors. As an example, let’s consider how we would reconstruct the first-level approximation A1 from the coefficient vector cA1.

We pass the coefficient vector cA1 through the same process we used to reconstruct the original signal. However, instead of combining it with the level-one detail cD1, we feed in a vector of zeros in place of the detail coefficients vector:

The process yields a reconstructed approximation A1, which has the same length as the original signal S and which is a real approximation of it.

Similarly, we can reconstruct the first-level detail D1, using the analogous process:

The reconstructed details and approximations are true constituents of the original signal. In fact, we find when we combine them that:

Note that the coefficient vectors cA1 and cD1 — because they were produced by downsampling and are only half the length of the original signal — cannot directly be combined to reproduce the signal. It is necessary to reconstruct the approximations and details before combining them.

A1

H’

L’

0

cA1

1000 samples~500 zeros

~500 coefs

D1

H’

L’

cD1

0

1000 samples~500 coefs

~500 zeros

A1 D1+ S=

Page 55: Wavelet ug

Wavelet Reconstruction

1-25

Extending this technique to the components of a multilevel analysis, we find that similar relationships hold for all the reconstructed signal constituents. That is, there are several ways to reassemble the original signal:

Relationship of Filters to Wavelet ShapesIn the section “Reconstruction Filters” on page 1-23, we spoke of the importance of choosing the right filters. In fact, the choice of filters not only determines whether perfect reconstruction is possible, it also determines the shape of the wavelet we use to perform the analysis.

To construct a wavelet of some practical utility, you seldom start by drawing a waveform. Instead, it usually makes more sense to design the appropriate quadrature mirror filters, and then use them to create the waveform. Let’s see how this is done by focusing on an example.

Consider the lowpass reconstruction filter (L') for the db2 wavelet.

The filter coefficients can be obtained from the dbaux command:

Lprime = dbaux(2)

Lprime = 0.3415 0.5915 0.1585 –0.0915

S

A1 D1

A2 D2

A3 D3

= A2 D2 D1+ +

S A1 D1+=

= A3 D3 D2 D1+ + +

ReconstructedSignal

Components

0 1 2 3

−1

0

1

db2 wavelet

Page 56: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-26

If we reverse the order of this vector (see wrev), and then multiply every even sample by –1, we obtain the highpass filter H':

Hprime = –0.0915 –0.1585 0.5915 –0.3415

Next, upsample Hprime by two (see dyadup), inserting zeros in alternate positions:

HU = –0.0915 0 –0.1585 0 0.5915 0 –0.3415 0

Finally, convolve the upsampled vector with the original lowpass filter:

H2 = conv(HU,Lprime);plot(H2)

If we iterate this process several more times, repeatedly upsampling and convolving the resultant vector with the four-element filter vector Lprime, a pattern begins to emerge:

1 2 3 4 5 6 7 8 9 10

−0.2

−0.1

0

0.1

0.2

0.3

5 10 15 20

−0.1−0.05

00.050.1

0.15

Second Iteration

10 20 30 40

−0.05

0

0.05

0.1Third Iteration

20 40 60 80−0.04

−0.02

0

0.02

0.04

Fourth Iteration

50 100 150−0.02

−0.01

0

0.01

0.02

Fifth Iteration

Page 57: Wavelet ug

Wavelet Reconstruction

1-27

The curve begins to look progressively more like the db2 wavelet. This means that the wavelet’s shape is determined entirely by the coefficients of the reconstruction filters.

This relationship has profound implications. It means that you cannot choose just any shape, call it a wavelet, and perform an analysis. At least, you can’t choose an arbitrary wavelet waveform if you want to be able to reconstruct the original signal accurately. You are compelled to choose a shape determined by quadrature mirror decomposition filters.

The Scaling FunctionWe’ve seen the interrelation of wavelets and quadrature mirror filters. The wavelet function is determined by the highpass filter, which also produces the details of the wavelet decomposition.

There is an additional function associated with some, but not all wavelets. This is the so-called scaling function, . The scaling function is very similar to the wavelet function. It is determined by the lowpass quadrature mirror filters, and thus is associated with the approximations of the wavelet decomposition.

In the same way that iteratively upsampling and convolving the highpass filter produces a shape approximating the wavelet function, iteratively upsampling and convolving the lowpass filter produces a shape approximating the scaling function.

Multistep Decomposition and ReconstructionA multistep analysis-synthesis process can be represented as:

ψ

φ

S 1000~250

~250

S1000

~500

AnalysisDecompositionDWT

SynthesisReconstruction

IDWTWavelet

Coefficients

. . . . . .

H

L

H

L

H’

L’

H’

L’

Page 58: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-28

This process involves two aspects: breaking up a signal to obtain the wavelet coefficients, and reassembling the signal from the coefficients.

We’ve already discussed decomposition and reconstruction at some length. Of course, there is no point breaking up a signal merely to have the satisfaction of immediately reconstructing it. We may modify the wavelet coefficients before performing the reconstruction step. We perform wavelet analysis because the coefficients thus obtained have many known uses, de-noising and compression being foremost among them.

But wavelet analysis is still a new and emerging field. No doubt, many uncharted uses of the wavelet coefficients lie in wait. The Wavelet Toolbox can be a means of exploring possible uses and hitherto unknown applications of wavelet analysis. Explore the toolbox functions and see what you discover.

Page 59: Wavelet ug

Wavelet Packet Analysis

1-29

Wavelet Packet AnalysisThe wavelet packet method is a generalization of wavelet decomposition that offers a richer range of possibilities for signal analysis.

In wavelet analysis, a signal is split into an approximation and a detail. The approximation is then itself split into a second-level approximation and detail, and the process is repeated. For an n-level decomposition, there are n+1 possible ways to decompose or encode the signal.

In wavelet packet analysis, the details as well as the approximations can be split.

This yields more than different ways to encode the signal. This is the wavelet packet decomposition tree.

The wavelet decomposition tree is a part of this complete binary tree.

For instance, wavelet packet analysis allows the signal S to be represented as A1 + AAD3 + DAD3 + DD2. This is an example of a representation that is not possible with ordinary wavelet analysis.

S

A1 D1

A2 D2

A3 D3

= A2 D2 D1+ +

S A1 D1+=

= A3 D3 D2 D1+ + +

22n 1–

S

A1 D1

AA2 DA2

AAA3 DAA3

AD2 DD2

ADA3 DDA3 AAD3 DAD3 ADD3 DDD3

Page 60: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-30

Choosing one out of all these possible encodings presents an interesting problem. In this toolbox, we use an entropy-based criterion to select the most suitable decomposition of a given signal. This means we look at each node of the decomposition tree and quantify the information to be gained by performing each split.

Simple and efficient algorithms exist for both wavelet packet decomposition and optimal decomposition selection. This toolbox uses an adaptive filtering algorithm, based on work by Coifman and Wickerhauser (see [CoiW92] in “References” on page 6-145), with direct applications in optimal signal coding and data compression.

Such algorithms allow the Wavelet Packet 1-D and Wavelet Packet 2-D tools to include “Best Level” and “Best Tree” features that optimize the decomposition both globally and with respect to each node.

Page 61: Wavelet ug

History of Wavelets

1-31

History of WaveletsFrom an historical point of view, wavelet analysis is a new method, though its mathematical underpinnings date back to the work of Joseph Fourier in the nineteenth century. Fourier laid the foundations with his theories of frequency analysis, which proved to be enormously important and influential.

The attention of researchers gradually turned from frequency-based analysis to scale-based analysis when it started to become clear that an approach measuring average fluctuations at different scales might prove less sensitive to noise.

The first recorded mention of what we now call a “wavelet” seems to be in 1909, in a thesis by Alfred Haar.

The concept of wavelets in its present theoretical form was first proposed by Jean Morlet and the team at the Marseille Theoretical Physics Center working under Alex Grossmann in France.

The methods of wavelet analysis have been developed mainly by Y. Meyer and his colleagues, who have ensured the methods’ dissemination. The main algorithm dates back to the work of Stephane Mallat in 1988. Since then, research on wavelets has become international. Such research is particularly active in the United States, where it is spearheaded by the work of scientists such as Ingrid Daubechies, Ronald Coifman, and Victor Wickerhauser.

Barbara Burke Hubbard describes the birth, the history and the seminal concepts in a very clear text. See “The World According to Wavelets” A.K. Peters Wellesley 1996.

The wavelet domain is growing up very quickly. A lot of mathematical papers and practical trials are published every month.

Page 62: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-32

An Introduction to the Wavelet FamiliesSeveral families of wavelets that have proven to be especially useful are included in this toolbox. What follows is an introduction to some wavelet families. To explore all wavelet families on your own, check out the Wavelet Display tool:

1 Type wavemenu from the MATLAB command line. The Wavelet Toolbox Main Menu appears.

2 Click on the Wavelet Display menu item. The Wavelet Display tool appears.

3 Select a family from the Wavelet menu at the top right of the tool.

4 Click the Display button. Pictures of the wavelets and their associated filters appear.

5 Obtain more information by clicking on the information buttons located at the right.

Page 63: Wavelet ug

An Introduction to the Wavelet Families

1-33

HaarAny discussion of wavelets begins with Haar wavelet, the first and simplest. Haar wavelet is discontinuous, and resembles a step function. It represents the same wavelet as Daubechies db1. See “Haar” on page 6-67 for more detail.

DaubechiesIngrid Daubechies, one of the brightest stars in the world of wavelet research, invented what are called compactly supported orthonormal wavelets — thus making discrete wavelet analysis practicable.

The names of the Daubechies family wavelets are written dbN, where N is the order, and db the “surname” of the wavelet. The db1 wavelet, as mentioned above, is the same as Haar wavelet. Here are the wavelet functions psi of the next nine members of the family:

You can obtain a survey of the main properties of this family by typing waveinfo('db') from the MATLAB command line. See “Daubechies Wavelets: dbN” on page 6-66 for more detail.

0 0.5 1

−1

0

1

Wavelet function psi

0 1 2 3

−1

0

1

db2 db3 db4

0 2 4

−1

0

1

0 2 4 6

−1

0

1

0 2 4 6 8

−1

0

1

db5 db6

0 5 10

−1

0

1

db7 db8 db9 db10

0 5 10

−1

0

1

0 5 10 15

−1

0

1

0 5 10 15

−1

0

1

0 5 10 15

−1

0

1

Page 64: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-34

BiorthogonalThis family of wavelets exhibits the property of linear phase, which is needed for signal and image reconstruction. By using two wavelets, one for decomposition (on the left side) and the other for reconstruction (on the right side) instead of the same single one, interesting properties are derived.

0 1 2 3 4

−1

0

1

0 2 4 6 8

−1

0

1

bior1.3 bior1.50 1 2 3 4

−1

0

1

0 2 4 6 8

−1

0

1

0 1 2 3 4−4

−2

0

2

4

0 2 4 6 8

−1

0

1

2

bior2.2 bior2.40 1 2 3 4

0

1

0 2 4 6 8

0

1

0 5 10

−1

0

1

0 5 10 15

−1

0

1

bior2.6 bior2.80 5 10

0

1

0 5 10 15

0

1

0 1 2−100

−50

0

50

100

0 2 4 6

−4

−2

0

2

4

bior3.1 bior3.30 1 2

−1

0

1

0 2 4 6

−1

0

1

0 5 10

−2

−1

0

1

2

0 5 10

−2

−1

0

1

2

bior3.5 bior3.70 5 10

−1

0

1

0 5 10

−0.5

0

0.5

0 5 10

−0.5

0

1

0 5 10 15−1

0

1

bior5.5 bior6.80 5 10

−1

0

1

0 5 10 15

0

1

0 5 10 15

−2

−1

0

1

2

0 2 4 6 8

−1

0

1

bior3.9 bior4.40 5 10 15

−0.5

0

0.5

0 2 4 6 8

0

1

Page 65: Wavelet ug

An Introduction to the Wavelet Families

1-35

You can obtain a survey of the main properties of this family by typing waveinfo('bior') from the MATLAB command line. See “Biorthogonal Wavelet Pairs: biorNr.Nd” on page 6-70 for more detail.

CoifletsBuilt by I. Daubechies at the request of R. Coifman. The wavelet function has 2N moments equal to 0 and the scaling function has 2N-1 moments equal to 0. The two functions have a support of length 6N-1. You can obtain a survey of the main properties of this family by typing waveinfo('coif') from the MATLAB command line. See “Coiflet Wavelets: coifN” on page 6-69 for more detail.

SymletsThe symlets are nearly symmetrical wavelets proposed by Daubechies as modifications to the db family. The properties of the two wavelet families are similar. Here are the wavelet functions psi.

You can obtain a survey of the main properties of this family by typing waveinfo('sym') from the MATLAB command line. See “Symlet Wavelets: symN” on page 6-68 for more detail.

0 5 10 15−1

0

1

0 5 10−1

0

1

0 2 4

−1

0

1

coif1

0 5 10 15 20

−1

0

1

0 5 10 15 20 25

−1

0

1

coif2 coif3 coif4 coif5

0 5 10 15

−1

0

1

0 5 10

−1

0

1

0 5 10−1

0

1

0 1 2 3

−1

0

1

0 2 4

−1

0

1

sym20 2 4 6

−1

0

1

0 2 4 6 8

−1

0

1

sym3 sym4 sym5

sym6 sym7 sym8

Page 66: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-36

Morlet This wavelet has no scaling function, but is explicit.

You can obtain a survey of the main properties of this family by typing waveinfo('morl') from the MATLAB command line. See “Morlet Wavelet: morl” on page 6-76 for more detail.

Mexican HatThis wavelet has no scaling function and is derived from a function that is proportional to the second derivative function of the Gaussian probability density function.

You can obtain a survey of the main properties of this family by typing waveinfo('mexh') from the MATLAB command line. See “Mexican Hat Wavelet: mexh” on page 6-75 for more information.

−8 −6 −4 −2 0 2 4 6 8

−0.5

0

0.5

Wavelet function psi

−8 −6 −4 −2 0 2 4 6 8

−0.2

0

0.2

0.4

0.6

0.8

Wavelet function psi

Page 67: Wavelet ug

An Introduction to the Wavelet Families

1-37

MeyerThe Meyer wavelet and scaling function are defined in the frequency domain.

You can obtain a survey of the main properties of this family by typing waveinfo('meyer') from the MATLAB command line. See “Meyer Wavelet: meyr” on page 6-73 for more detail.

Other Real WaveletsSome other real wavelets are available in the toolbox:

• Reverse Biorthogonal

• Gaussian derivatives family

• FIR based approximation of the Meyer Wavelet

See “Other Real Wavelets” on page 6-78 for more information.

Complex WaveletsSome complex wavelet families are available in the toolbox:

• Gaussian derivatives

• Morlet

• Frequency B-Spline

• Shannon

See “Complex Wavelets” on page 6-80 for more information.

−5 0 5

−0.5

0

0.5

1

Wavelet function psi

Page 68: Wavelet ug

1 Wavelets: A New Tool for Signal Analysis

1-38

Page 69: Wavelet ug

2

Using Wavelets

One-Dimensional Continuous Wavelet Analysis . . . . 2-3

One-Dimensional Complex Continuous Wavelet Analysis . . . . . . . . . . . . . . . . . . . 2-16

One-Dimensional Discrete Wavelet Analysis . . . . . 2-24

Two-Dimensional Discrete Wavelet Analysis . . . . . 2-57

Wavelets: Working with Images . . . . . . . . . . . 2-82

One-Dimensional Discrete Stationary Wavelet Analysis . . . . . . . . . . . . . . . . 2-88

Two-Dimensional Discrete Stationary Wavelet Analysis . . . . . . . . . . . . . . . 2-103

One-Dimensional Wavelet Regression Estimation . . 2-120

One-Dimensional Wavelet Density Estimation . . . 2-129

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients . . . . . . . . . . . . 2-136

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface . . . . . . . . . . . . 2-145

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface . . . . . . . . . . . . 2-153

One-Dimensional Extension . . . . . . . . . . . . 2-160

Two-Dimensional Extension . . . . . . . . . . . . 2-167

Page 70: Wavelet ug

2 Using Wavelets

2-2

The Wavelet Toolbox contains graphical tools and command line functions that let you:

• Examine and explore properties of individual wavelets and wavelet packets

• Examine statistics of signals and signal components

• Perform a continuous wavelet transform of a one-dimensional signal

• Perform discrete analysis and synthesis of one- and two-dimensional signals

• Perform wavelet packet analysis of one- and two-dimensional signals

• Compress and remove noise from signals and images

In addition to the above, the toolbox makes it easy to customize the presentation and visualization of your data. You choose:

• Which signals to display

• A region of interest to magnify

• A coloring scheme for display of wavelet coefficient details

This chapter takes you step-by-step through examples that teach you how to use the graphical tools and command line functions. These examples include:

• Continuous Wavelet Analysis (One-Dimensional)

• Complex Continuous Wavelet Analysis (One-Dimensional)

• One-Dimensional Discrete Wavelet Analysis

• Two-Dimensional Discrete Wavelet Analysis

• One-Dimensional Discrete Stationary Wavelet Analysis

• Two-Dimensional Discrete Stationary Wavelet Analysis

• One-Dimensional Wavelet Regression Estimation

• One-Dimensional Wavelet Density Estimation

• One-Dimensional Local Variance Adaptive Thresholding of Wavelet Coefficients for Estimation, De-noising and Compression

• One-Dimensional Selection of Wavelet Coefficients

• Two-Dimensional Selection of Wavelet Coefficients

• Signal Extension

• Image Extension

To perform wavelet packet analysis see “Using Wavelet Packets” on page 5-1.

Page 71: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-3

One-Dimensional Continuous Wavelet AnalysisThis section takes you through the features of continuous wavelet analysis using the MATLAB Wavelet Toolbox.

The Wavelet Toolbox requires only one function for continuous wavelet analysis: cwt. You’ll find full information about this function in its reference page.

In this section, you’ll learn how to:

• Load a signal

• Perform a continuous wavelet transform of a signal

• Produce a plot of the coefficients

• Produce a plot of coefficients at a given scale

• Produce a plot of local maxima of coefficients across scales

• Select the displayed plots

• Switch from scale to pseudo-frequency information

• Zoom in on detail

• Display coefficients in normal or absolute mode

• Choose the scales at which analysis is performed

Since you can perform analyses either from the command line or using the graphical interface tools, this section has subsections covering each method.

The final subsection discusses how to exchange signal and coefficient information between the disk and the graphical tools.

Page 72: Wavelet ug

2 Using Wavelets

2-4

Continuous Analysis Using the Command LineThis example involves a noisy sinusoidal signal.

Loading a Signal.

1 From the MATLAB prompt, type:

load noissin;

You now have the signal noissin in your workspace:

whos

Performing a Continuous Wavelet Transform.

2 Use the cwt command. Type:

c = cwt(noissin,1:48,'db4');

The arguments to cwt specify the signal to be analyzed, the scales of the analysis, and the wavelet to be used. The returned argument c contains the coefficients at various scales. In this case, c is a 48-by-1000 matrix with each row corresponding to a single scale.

Name Size Bytes Class

noissin 1x1000 8000 double array

100 200 300 400 500 600 700 800 900 1000

−1

−0.5

0

0.5

1

Page 73: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-5

Plotting the Coefficients.

The cwt command accepts a fourth argument. This is a flag that, when present, causes cwt to produce a plot of the absolute values of the continuous wavelet transform coefficients.

The cwt command can accept more arguments to define the different characteristics of the produced plot. For more information, see the cwt reference page.

3 Type:

c = cwt(noissin,1:48,'db4','plot');

A plot appears.

Of course, coefficient plots generated from the command line can be manipulated using ordinary MATLAB graphics commands.

Absolute Values of Ca,b Coefficients for a = 1 2 3 4 5 ...

time (or space) b

scal

es a

100 200 300 400 500 600 700 800 900 1000 1

4

7

10

13

16

19

22

25

28

31

34

37

40

43

46

Page 74: Wavelet ug

2 Using Wavelets

2-6

Choosing Scales for the Analysis.

The second argument to cwt gives you fine control over the scale levels on which the continuous analysis is performed. In the previous example, we used all scales from 1 to 48, but you can construct any scale vector subject to these constraints:

• All scales must be real positive numbers.

• The scale increment must be positive.

• The highest scale cannot exceed a maximum value depending on the signal.

4 Let’s repeat the analysis using every other scale from 2 to 128. Type:

c = cwt(noissin,2:2:128,'db4','plot');

A new plot appears:

This plot gives a clearer picture of what’s happening with the signal, highlighting the periodicity.

Absolute Values of Ca,b Coefficients for a = 2 4 6 8 10 ...

time (or space) b

scal

es a

100 200 300 400 500 600 700 800 900 1000 2

10

18

26

34

42

50

58

66

74

82

90

98

106

114

122

Page 75: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-7

Continuous Analysis Using the Graphical InterfaceWe now use the Continuous Wavelet 1-D tool to analyze the same noisy sinusoidal signal we examined earlier using the command line interface in “Continuous Analysis Using the Command Line” on page 2-4.

Starting the Continuous Wavelet 1-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

2 Click the Continuous Wavelet 1-D menu item.

The continuous wavelet analysis tool for one-dimensional signal data appears.

Page 76: Wavelet ug

2 Using Wavelets

2-8

Loading a Signal.

3 Choose the File⇒Load Signal menu option.

4 When the Load Signal dialog box appears, select the demo MAT-file noissin.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

The noisy sinusoidal signal is loaded into the Continuous Wavelet 1-D tool.

The default value for the sampling period is equal to 1 (second).

Performing a Continuous Wavelet Transform.

To start our analysis, let’s perform an analysis using the db4 wavelet at scales 1 through 48, just as we did using command line functions in the previous section.

5 In the upper right portion of the Continuous Wavelet 1-D tool, select the db4 wavelet and scales 1–48.

Select db4

Select scales 1 to 48 in steps of 1

Page 77: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-9

6 Click the Analyze button.

After a pause for computation, the tool displays the coefficients plot, the coefficients line plot corresponding to the scale a = 24, and the local maxima plot, which displays the chaining across scales (from a = 48 down to a = 1) of the coefficients local maxima.

Viewing Wavelet Coefficients Line.

7 Select another scale a = 40 by clicking in the coefficients plot with the right mouse button. See step 9 below to know, more precisely, how to select the desired scale.

Click the New Coefficients Line button, the tool updates the plot.

Page 78: Wavelet ug

2 Using Wavelets

2-10

Viewing Maxima Line.

8 Click the Refresh Maxima Line button, the local maxima plot displays the chaining across scales of the coefficients local maxima from a = 40 down to a = 1.

9 Hold down the right mouse button over the coefficients plot, the position of the mouse is given by the Info frame (located at the bottom of the screen) in terms of location (X) and scale (Sca).

Page 79: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-11

Switching from Scale to Pseudo-Frequency Information.

10 Using the radio button on the right part of the screen, select Frequencies instead of Scales. Again hold down the right mouse button over the coefficients plot, the position of the mouse is given in terms of location (X) and frequency (Frq) in Hertz.

This facility allows you to interpret scale in terms of an associated pseudo-frequency, which depends on the wavelet and the sampling period.

Page 80: Wavelet ug

2 Using Wavelets

2-12

11 Deselect the last two plots using the check boxes in the Selected Axes frame.

Zooming in on Detail.

12 Drag a rubber band box (by holding down the left mouse button) over the portion of the signal you want to magnify.

13 Click the X+ button (located at the bottom of the screen) to zoom horizontally only.

Page 81: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-13

The Continuous Wavelet 1-D tool enlarges the displayed signal and coefficients plot.

As with the command line analysis on the preceding pages, you can change the scales or the analyzing wavelet and repeat the analysis. To do this, just edit the necessary fields and press the Analyze button.

Viewing Normal or Absolute Coefficients.

The Continuous Wavelet 1-D tool allows you to plot either the absolute values of the wavelet coefficients, or the coefficients themselves.

More generally, the coefficients coloration can be done in several different ways. For more details on the Coloration Mode, see “Controlling the Coloration Mode” on page A-8.

14 Choose either one of the absolute modes or normal modes from the Coloration Mode menu. In normal modes, the colors are scaled between the minimum and maximum of the coefficients. In absolute modes, the colors are scaled between zero and the maximum absolute value of the coefficients.

Page 82: Wavelet ug

2 Using Wavelets

2-14

The coefficients plot is redisplayed in the mode you select.

Importing and Exporting Information from the Graphical InterfaceThe Continuous Wavelet 1-D graphical interface tool lets you import information from and export information to disk.

You can:

• Load signals from disk into the Continuous Wavelet 1-D tool.

• Save wavelet coefficients from the Continuous Wavelet 1-D tool to disk.

Loading Signals into the Continuous Wavelet 1-D ToolTo load a signal you’ve constructed in your MATLAB workspace into the Continuous Wavelet 1-D tool, save the signal in a MAT-file (with extension mat or other).

For instance, suppose you’ve designed a signal called warma and want to analyze it in the Continuous Wavelet 1-D tool.

save warma warma

The workspace variable warma must be a vector.

sizwarma = size(warma)

sizwarma = 1 1000

To load this signal into the Continuous Wavelet 1-D tool, use the menu option File⇒Load Signal.

Absolute Mode Normal Mode

Page 83: Wavelet ug

One-Dimensional Continuous Wavelet Analysis

2-15

A dialog box appears that lets you select the appropriate MAT-file to be loaded.

Note The first one-dimensional variable encountered in the file is considered the signal. Variables are inspected in alphabetical order.

Saving Wavelet CoefficientsThe Continuous Wavelet 1-D tool lets you save wavelet coefficients to disk. The toolbox creates a MAT-file in the current directory with the extension wc1 and a name you give it.

To save the continuous wavelet coefficients from the present analysis, use the menu option File⇒Save⇒Coefficients.

A dialog box appears that lets you specify a directory and filename for storing the coefficients.

Consider the example analysis:

File⇒Example Analysis⇒with haar at scales [1:1:64] −−> Cantor curve.

After saving the continuous wavelet coefficients to the file cantor.wc1, load the variables into your workspace.

load cantor.wc1 -matwhos

Variables coefs and scales contain the continuous wavelet coefficients and the associated scales. More precisely, in the above example, coefs is a 64-by-2188 matrix, one row for each scale; and scales is the 1-by-64 vector 1:64. Variable wname contains the wavelet name.

Name Size Bytes Class

coefs 64x2188 1120256 double arrayscales 1x64 512 double arraywname 1x4 8 char array

Page 84: Wavelet ug

2 Using Wavelets

2-16

One-Dimensional Complex Continuous Wavelet AnalysisThis section takes you through the features of complex continuous wavelet analysis using the MATLAB Wavelet Toolbox and focuses on the differences between the real and complex continuous analysis.

You can refer to the section “One-Dimensional Continuous Wavelet Analysis” on page 2-3 if you want to learn how to:

• Zoom in on detail

• Display coefficients in normal or absolute mode

• Choose the scales at which the analysis is performed

• Switch from scale to pseudo-frequency information

• Exchange signal and coefficient information between the disk and the graphical tools.

The Wavelet Toolbox requires only one function for complex continuous wavelet analysis of a real valued signal: cwt. You’ll find full information about this function in its reference page.

In this section, you’ll learn how to:

• Load a signal

• Perform a complex continuous wavelet transform of a signal

• Produce plots of the coefficients

Since you can perform analyses either from the command line or using the graphical interface tools, this section has subsections covering each method.

Page 85: Wavelet ug

One-Dimensional Complex Continuous Wavelet Analysis

2-17

Complex Continuous Analysis Using the Command LineThis example involves a cusp signal.

Loading a Signal.

1 From the MATLAB prompt, type:

load cuspamax;

You now have the signal cuspamax in your workspace:

whos

caption

caption =x = linspace(0,1,1024);y = exp(-128*((x-0.3).^2))-3*(abs(x-0.7).^0.4);

caption is a string that contains the signal definition.

Name Size Bytes Class

caption 1x71 142 char arraycuspamax 1x1024 8192 double array

0 200 400 600 800 1000 12000

0.5

1

1.5

2

2.5

Page 86: Wavelet ug

2 Using Wavelets

2-18

Performing a Continuous Wavelet Transform.

2 Use the cwt command. Type:

c = cwt(cuspamax,1:2:64,'cgau4');

The arguments to cwt specify the signal to be analyzed, the scales of the analysis, and the wavelet to be used. The returned argument c contains the coefficients at various scales. In this case, c is a complex 32-by-1024 matrix, each row of which corresponds to a single scale.

Plotting the Coefficients.

The cwt command accepts a fourth argument. This is a flag that, when present, causes cwt to produce four plots related to the complex continuous wavelet transform coefficients:

• Real and imaginary parts

• Modulus and angle.

The cwt command can accept more arguments to define the different characteristics of the produced plots. For more information, see the cwt reference page.

3 Type:

c = cwt(cuspamax,1:2:64,'cgau4','plot');

Page 87: Wavelet ug

One-Dimensional Complex Continuous Wavelet Analysis

2-19

A plot appears:

Of course, coefficient plots generated from the command line can be manipulated using ordinary MATLAB graphics commands.

Complex Continuous Analysis Using the Graphical InterfaceWe now use the Complex Continuous Wavelet 1-D tool to analyze the same cusp signal we examined using the command line interface in the previous section.

Starting the Complex Continuous Wavelet 1-D Tool.

1 From the MATLAB prompt, type:

wavemenu

Real part of Ca,b for a = 1 3 5 7 9 ...

time (or space) b

scal

es a

200 400 600 800 1000 1 5 913172125293337414549535761

Imaginary part of Ca,b for a = 1 3 5 7 9 ...

time (or space) b

scal

es a

200 400 600 800 1000 1 5 913172125293337414549535761

Modulus of Ca,b for a = 1 3 5 7 9 ...

time (or space) b

scal

es a

200 400 600 800 1000 1 5 913172125293337414549535761

Angle of Ca,b for a = 1 3 5 7 9 ...

time (or space) b

scal

es a

200 400 600 800 1000 1 5 913172125293337414549535761

Page 88: Wavelet ug

2 Using Wavelets

2-20

The Wavelet Toolbox Main Menu appears.

2 Click the Complex Continuous Wavelet 1-D menu item.

The continuous wavelet analysis tool for one-dimensional signal data appears.

Page 89: Wavelet ug

One-Dimensional Complex Continuous Wavelet Analysis

2-21

Loading a Signal.

3 Choose the File⇒Load Signal menu option.

4 When the Load Signal dialog box appears, select the demo MAT-file cuspamax.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

The cusp signal is loaded into the Complex Continuous Wavelet 1-D tool.

The default value for the sampling period is equal to 1 (second).

Performing a Complex Continuous Wavelet Transform.

To start our analysis, let’s perform an analysis using the cgau4 wavelet at scales 1 through 64 in steps of 2, just as we did using command line functions in “Complex Continuous Analysis Using the Command Line” on page 2-17.

5 In the upper right portion of the Complex Continuous Wavelet 1-D tool, select the cgau4 wavelet and scales 1–64 in steps of 2.

Select cgau4

Select scales from 1 to 64 in steps of 2

Page 90: Wavelet ug

2 Using Wavelets

2-22

6 Click the Analyze button.

After a pause for computation, the tool displays the usual plots associated to the modulus of the coefficients on the left side, and the angle of the coefficients on the right side.

Each side has exactly the same representation that we found in the section “Continuous Analysis Using the Graphical Interface” on page 2-7.

7 Select the plots related to the modulus of the coefficients using the Modulus radio button in the Selected Axes frame.

Page 91: Wavelet ug

One-Dimensional Complex Continuous Wavelet Analysis

2-23

The figure now looks like the one in the real Continuous Wavelet 1-D tool.

Importing and Exporting Information from the Graphical InterfaceTo know how to import and export information from the Complex Continuous Wavelet Graphical Interface, please refer to the corresponding paragraph in “One-Dimensional Continuous Wavelet Analysis” on page 2-3.

The only difference is that the variable coefs is a complex matrix (see “Saving Wavelet Coefficients” on page 2-15).

Page 92: Wavelet ug

2 Using Wavelets

2-24

One-Dimensional Discrete Wavelet AnalysisThis section takes you through the features of one-dimensional discrete wavelet analysis using the MATLAB Wavelet Toolbox.

The Wavelet Toolbox provides these functions for one-dimensional signal analysis. For more information, see the reference pages.

Analysis-Decomposition Functions

Synthesis-Reconstruction Functions

Decomposition Structure Utilities

Function Name Purpose

dwt Single-level decomposition

wavedec Decomposition

wmaxlev Maximum wavelet decomposition level

Function Name Purpose

idwt Single-level reconstruction

waverec Full reconstruction

wrcoef Selective reconstruction

upcoef Single reconstruction

Function Name Purpose

detcoef Extraction of detail coefficients

appcoef Extraction of approximation coefficients

upwlev Recomposition of decomposition structure

Page 93: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-25

De-noising and Compression

In this section, you’ll learn how to:

• Load a signal

• Perform a single-level wavelet decomposition of a signal

• Construct approximations and details from the coefficients

• Display the approximation and detail

• Regenerate a signal by inverse wavelet transform

• Perform a multilevel wavelet decomposition of a signal

• Extract approximation and detail coefficients

• Reconstruct the level 3 approximation

• Reconstruct the level 1, 2, and 3 details

• Display the results of a multilevel decomposition

• Reconstruct the original signal from the level 3 decomposition

• Remove noise from a signal

• Refine an analysis

• Compress a signal

• Show a signal’s statistics and histograms

Since you can perform analyses either from the command line or using the graphical interface tools, this section has subsections covering each method.

Function Name Purpose

ddencmp Provide default values for de-noising and compression

wbmpen Penalized threshold for wavelet 1-D or 2-D de-noising

wdcbm Thresholds for wavelet 1-D using Birgé-Massart strategy

wdencmp Wavelet de-noising and compression

wden Automatic wavelet de-noising

wthrmngr Threshold settings manager

Page 94: Wavelet ug

2 Using Wavelets

2-26

The final subsection discusses how to exchange signal and coefficient information between the disk and the graphical tools.

One-Dimensional Analysis Using the Command LineThis example involves a real-world signal — electrical consumption measured over the course of 3 days. This signal is particularly interesting because of noise introduced when a defect developed in the monitoring equipment as the measurements were being made. Wavelet analysis effectively removes the noise.

Loading a Signal.

1 From the MATLAB prompt, type:

load leleccum;

2 Set the variables. Type:

s = leleccum(1:3920); l_s = length(s);

Performing A Single-Level Wavelet Decomposition of a Signal.

3 Perform a single-level decomposition of the signal using the db1 wavelet. Type:

[cA1,cD1] = dwt(s,'db1');

This generates the coefficients of the level 1 approximation (cA1) and detail (cD1).

Page 95: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-27

Constructing Approximations and Details from the Coefficients.

4 To construct the level 1 approximation and detail (A1 and D1) from the coefficients cA1 and cD1, type:

A1 = upcoef('a',cA1,'db1',1,l_s); D1 = upcoef('d',cD1,'db1',1,l_s);

or

A1 = idwt(cA1,[],'db1',l_s); D1 = idwt([],cD1,'db1',l_s);

Displaying the Approximation and Detail.

5 To display the results of the level-one decomposition, type:

subplot(1,2,1); plot(A1); title('Approximation A1')subplot(1,2,2); plot(D1); title('Detail D1')

Regenerating a Signal by Using the Inverse Wavelet Transform.

6 To find the inverse transform, type:

A0 = idwt(cA1,cD1,'db1',l_s);err = max(abs(s-A0))

err = 2.2737e-013

0 1000 2000 3000 4000100

150

200

250

300

350

400

450

500

550Approximation A1

0 1000 2000 3000 4000−25

−20

−15

−10

−5

0

5

10

15

20

25Detail D1

Page 96: Wavelet ug

2 Using Wavelets

2-28

Performing a Multilevel Wavelet Decomposition of a Signal.

7 To perform a level 3 decomposition of the signal (again using the db1 wavelet), type:

[C,L] = wavedec(s,3,'db1');

The coefficients of all the components of a third-level decomposition (that is, the third-level approximation and the first three levels of detail) are returned concatenated into one vector, C. Vector L gives the lengths of each component.

Extracting Approximation and Detail Coefficients.

8 To extract the level 3 approximation coefficients from C, type:

cA3 = appcoef(C,L,'db1',3);

9 To extract the levels 3, 2, and 1 detail coefficients from C, type:

cD3 = detcoef(C,L,3); cD2 = detcoef(C,L,2); cD1 = detcoef(C,L,1);

or

[cD1,cD2,cD3] = detcoef(C,L,[1,2,3]);

S

cA1 cD1

cA2 cD2

cA3 cD3

cD1cD2cA3 cD3

C

Page 97: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-29

Results are displayed in the figure below, which contains the signal s, the approximation coefficients at level 3 (cA3), and the details coefficients from level 3 to 1 (cD3, cD2 and cD1) from the top to the bottom.

Reconstructing the Level 3 Approximation.

10 To reconstruct the level 3 approximation from C, type:

A3 = wrcoef('a',C,L,'db1',3);

Reconstructing the Level 1, 2, and 3 Details.

11 To reconstruct the details at levels 1, 2 and 3, from C, type:

D1 = wrcoef('d',C,L,'db1',1);D2 = wrcoef('d',C,L,'db1',2);D3 = wrcoef('d',C,L,'db1',3);

0 5000

1000

20000 500 1000 1500 2000 2500 3000 3500 4000

0

500

1000Original signal s and coefficients.

0 500−100

0

100

0 500 1000−50

0

50

0 500 1000 1500 2000−50

0

50

Page 98: Wavelet ug

2 Using Wavelets

2-30

Displaying the Results of a Multilevel Decomposition.

12 To display the results of the level 3 decomposition, type:

subplot(2,2,1); plot(A3); title('Approximation A3')subplot(2,2,2); plot(D1); title('Detail D1')subplot(2,2,3); plot(D2); title('Detail D2')subplot(2,2,4); plot(D3); title('Detail D3')

Reconstructing the Original Signal From the Level 3 Decomposition.

13 To reconstruct the original signal from the wavelet decomposition structure, type:

A0 = waverec(C,L,'db1');

err = max(abs(s-A0))

err = 4.5475e-013

0 1000 2000 3000 4000100

200

300

400

500

600Approximation A3

0 1000 2000 3000 4000−40

−20

0

20

40Detail D1

0 1000 2000 3000 4000−40

−20

0

20

40Detail D2

0 1000 2000 3000 4000−40

−20

0

20

40Detail D3

Page 99: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-31

Crude De-noising of a Signal.

Using wavelets to remove noise from a signal requires identifying which component or components contain the noise, and then reconstructing the signal without those components.

In this example, we note that successive approximations become less and less noisy as more and more high-frequency information is filtered out of the signal.

The level 3 approximation, A3, is quite clean as a comparison between it and the original signal.

14 To compare the approximation to the original signal, type:

subplot(2,1,1);plot(s);title('Original'); axis offsubplot(2,1,2);plot(A3);title('Level 3 Approximation');axis off

Of course, in discarding all the high-frequency information, we’ve also lost many of the original signal’s sharpest features.

Optimal de-noising requires a more subtle approach called thresholding. This involves discarding only the portion of the details that exceeds a certain limit.

Original

Level 3 Approximation

Page 100: Wavelet ug

2 Using Wavelets

2-32

Removing Noise by Thresholding.

Let’s look again at the details of our level 3 analysis.

15 To display the details D1, D2, and D3, type:

subplot(3,1,1); plot(D1); title('Detail Level 1'); axis offsubplot(3,1,2); plot(D2); title('Detail Level 2'); axis offsubplot(3,1,3); plot(D3); title('Detail Level 3'); axis off

Most of the noise occurs in the latter part of the signal, where the details show their greatest activity. What if we limited the strength of the details by restricting their maximum values? This would have the effect of cutting back the noise while leaving the details unaffected through most of their durations. But there’s a better way.

Note that cD1, cD2, and cD3 are just MATLAB vectors, so we could directly manipulate each vector, setting each element to some fraction of the vectors’ peak or average value. Then we could reconstruct new detail signals D1, D2, and D3 from the thresholded coefficients.

16 To de-noise the signal, use the ddencmp command to calculate the default parameters and the wdencmp command to perform the actual de-noising, type:

[thr,sorh,keepapp] = ddencmp('den','wv',s);clean = wdencmp('gbl',C,L,'db1',3,thr,sorh,keepapp);

Detail Level 1

Detail Level 2

Detail Level 3

Setting a threshold

Page 101: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-33

Note that wdencmp uses the results of the decomposition (C and L) that we calculated in Step 7 on page 2-28. We also specify that we used the db1 wavelet to perform the original analysis, and we specify the global thresholding option 'gbl'. See ddencmp and wdencmp in the reference pages for more information about the use of these commands.

17 To display both the original and de-noised signals, type:

subplot(2,1,1); plot(s(2000:3920)); title('Original')subplot(2,1,2); plot(clean(2000:3920)); title('De-noised')

We’ve plotted here only the noisy latter part of the signal. Notice how we’ve removed the noise without compromising the sharp detail of the original signal. This is a strength of wavelet analysis.

While using command line functions to remove the noise from a signal can be cumbersome, the Wavelet Toolbox graphical interface tools include an easy-to-use de-noising feature that includes automatic thresholding.

More information on the de-noising process can be found in the following sections:

• “Removing Noise From a Signal” on page 2-41

• “De-Noising” on page 6-91

200 400 600 800 1000 1200 1400 1600 1800

200

300

400

500

Original

200 400 600 800 1000 1200 1400 1600 1800

200

300

400

500

De−noised

Page 102: Wavelet ug

2 Using Wavelets

2-34

• “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 2-136

• “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 6-102

One-Dimensional Analysis Using the Graphical InterfaceIn this section, we explore the same electrical consumption signal as in the previous section, but we use the graphical interface tools to analyze the signal.

Starting the 1-D Wavelet Analysis Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 103: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-35

2 Click the Wavelet 1-D menu item.

The discrete wavelet analysis tool for one-dimensional signal data appears.

Loading a Signal.

3 From the File menu, choose the Load⇒Signal option.

Page 104: Wavelet ug

2 Using Wavelets

2-36

4 When the Load Signal dialog box appears, select the demo MAT-file leleccum.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

The electrical consumption signal is loaded into the Wavelet 1-D tool.

Performing a Single-Level Wavelet Decomposition of a Signal.

To start our analysis, let’s perform a single-level decomposition using the db1 wavelet, just as we did using the command line functions in “One-Dimensional Analysis Using the Command Line” on page 2-26.

5 In the upper right portion of the Wavelet 1-D tool, select the db1 wavelet and single-level decomposition.

Page 105: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-37

6 Click the Analyze button.

After a pause for computation, the tool displays the decomposition.

Zooming in on Relevant Detail.

One advantage of using the graphical interface tools is that you can zoom in easily on any part of the signal and examine it in greater detail.

7 Drag a rubber band box (by holding down the left mouse button) over the portion of the signal you want to magnify. Here, we’ve selected the noisy part of the original signal.

Page 106: Wavelet ug

2 Using Wavelets

2-38

8 Click the X+ button (located at the bottom of the screen) to zoom horizontally.

The Wavelet 1-D tool zooms all the displayed signals.

The other zoom controls do more or less what you’d expect them to. The X- button, for example, zooms out horizontally. The history function keeps track of all your views of the signal. Return to a previous zoom level by clicking the left arrow button.

Page 107: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-39

Performing a Multilevel Decomposition of a Signal.

Again, we’ll use the graphical tools to emulate what we did in the previous section using command line functions. To perform a level 3 decomposition of the signal using the db1 wavelet:

9 Simply select 3 from the Level menu at the upper right, and then click the Analyze button again.

After the decomposition is performed, you’ll see a new analysis appear in the Wavelet 1-D tool.

Selecting Different Views of the Decomposition.

The Display mode menu (middle right) lets you choose different views of the wavelet decomposition.

The default display mode is called “Full Decomposition Mode.” Other alternatives include:

Select a view

Page 108: Wavelet ug

2 Using Wavelets

2-40

• “Separate Mode,” which shows the details and the approximations in separate columns.

• “Superimpose Mode,” which shows the details on a single plot superimposed in different colors. The approximations are plotted similarly.

• “Tree Mode,” which shows the decomposition tree, the original signal, and one additional component of your choice. Click on the decomposition tree to select the signal component you’d like to view.

• “Show and Scroll Mode,” which displays three windows. The first shows the original signal superimposed on an approximation you select. The second window shows a detail you select. The third window shows the wavelet coefficients.

• “Show and Scroll Mode (Stem Cfs)” very similar to the “Show and Scroll Mode” except that it displays, in the third window, the wavelet coefficients as stem plots instead of colored blocks.

Separate Mode Superimpose Mode Tree Mode

Show & Scroll Mode Show & Scroll Mode (Stem Cfs)

Page 109: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-41

You can change the default display mode on a per-session basis. Select the desired mode from the View ⇒Default Display Mode submenu.

Note The Compression and De-noising windows opened from the Wavelet 1-D tool will inherit the current coefficient visualization attribute (stems or colored blocks).

Depending on which display mode you select, you may have access to additional display options through the More Display Options button.

These options include the ability to suppress the display of various components, and to choose whether or not to display the original signal along with the details and approximations.

Removing Noise From a Signal.

The graphical interface tools feature a de-noising option with a predefined thresholding strategy. This makes it very easy to remove noise from a signal.

10 Bring up the de-noising tool: click the De-noise button, located in the middle right of the window, underneath the Analyze button.

Page 110: Wavelet ug

2 Using Wavelets

2-42

The Wavelet 1-D De-noising window appears.

While a number of options are available for fine-tuning the de-noising algorithm, we’ll accept the defaults of soft fixed form thresholding and unscaled white noise.

11 Continue by clicking the De-noise button.

The de-noised signal appears superimposed on the original. The tool also plots the wavelet coefficients of both signals.

Page 111: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-43

Zoom in on the plot of the original and de-noised signals for a closer look.

12 Drag a rubber band box around the pertinent area, and then click the XY+ button.

The De-noise window magnifies your view. By default, the original signal is shown in red, and the de-noised signal in yellow.

Page 112: Wavelet ug

2 Using Wavelets

2-44

13 Dismiss the Wavelet 1-D De-noising window: click the Close button.

You cannot have the De-noise and Compression windows open simultaneously, so close the Wavelet 1-D De-noising window to continue. When the Update Synthesized Signal dialog box appears, click No. If you click Yes, the Synthesized Signal is then available in the Wavelet 1-D main window.

Refining an Analysis.

The graphical tools make it easy to refine an analysis any time you want to. Up to now, we’ve looked at a level 3 analysis using db1. Let’s refine our analysis of the electrical consumption signal using the db3 wavelet at level 5.

14 Select 5 from the Level menu at the upper right, and select the db3 from the Wavelet menu. Click the Analyze button.

Compressing a Signal.

The graphical interface tools feature a compression option with automatic or manual thresholding.

15 Bring up the Compression window: click the Compress button, located in the middle right of the window, underneath the Analyze button.

Page 113: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-45

The Compression window appears.

While you always have the option of choosing by level thresholding, here we’ll take advantage of the global thresholding feature for quick and easy compression.

Note If you want to experiment with manual thresholding, choose the By Level thresholding option from the menu located at the top right of the Wavelet 1-D Compression window. The sliders located below this menu then control the level-dependent thresholds, indicated by yellow dotted lines running horizontally through the graphs on the left of the window. The yellow dotted lines can also be dragged directly using the left mouse button.

16 Click the Compress button, located at the center right.

After a pause for computation, the electrical consumption signal is redisplayed in red with the compressed version superimposed in yellow. Below, we’ve zoomed in to get a closer look at the noisy part of the signal.

Thresholding method menus

Threshold slider

Compress button

Page 114: Wavelet ug

2 Using Wavelets

2-46

You can see that the compression process removed most of the noise, but preserved 99.74% of the energy of the signal. The automatic thresholding was very efficient, zeroing out all but 3.2% of the wavelet coefficients.

Showing Residuals.

17 From the Wavelet 1-D Compression tool, click the Residuals button. The More on Residuals for Wavelet 1-D Compression window appears.

Page 115: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-47

Displayed statistics include measures of tendency (mean, mode, median) and dispersion (range, standard deviation). In addition, the tool provides frequency-distribution diagrams (histograms and cumulative histograms), as well as time-series diagrams: autocorrelation function and spectrum. The same feature exists for the Wavelet 1-D De-noising tool.

18 Dismiss the Wavelet 1-D Compression window: click the Close button. When the Update Synthesized Signal dialog box appears, click No.

Showing Statistics.

You can view a variety of statistics about your signal and its components.

19 From the Wavelet 1-D tool, click the Statistics button.

The Wavelet 1-D Statistics window appears displaying by default statistics on the original signal.

Page 116: Wavelet ug

2 Using Wavelets

2-48

20 Select the synthesized signal or signal component whose statistics you want to examine. Click on the appropriate radio button, and then press the Show Statistics button. Here, we’ve chosen to examine the compressed signal using more 100 bins instead of 30, which is the default:

Displayed statistics include measures of tendency (mean, mode, median) and dispersion (range, standard deviation).

In addition, the tool provides frequency-distribution diagrams (histograms and cumulative histograms). You can plot these histograms separately using the Histograms button from the Wavelets 1-D window.

21 Select the Approximation radio button. A menu appears from which you choose the level of the approximation you want to examine.

Page 117: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-49

22 Select Level 1 and again click the Show Statistics button.

Statistics appear for the level 1 approximation.

Importing and Exporting Information from the Graphical InterfaceThe Wavelet 1-D graphical interface tool lets you import information from and export information to disk.

Saving Information to DiskYou can save synthesized signals, coefficients, and decompositions from the Wavelet 1-D tool to the disk, where the information can be manipulated and later reimported into the graphical tool.

Page 118: Wavelet ug

2 Using Wavelets

2-50

Saving Synthesized Signals.

You can process a signal in the Wavelet 1-D tool and then save the processed signal to a MAT-file (with extension mat or other).

For example, load the example analysis: File⇒Example Analysis⇒Basic Signals⇒with db3 at level 5 −−> Sum of sines, and perform a compression or de-noising operation on the original signal. When you close the De-noising or Compression window, update the synthesized signal by clicking Yes in the dialog box.

Then, from the Wavelet 1-D tool, select the File⇒Save⇒Synthesized Signal menu option.

A dialog box appears allowing you to select a directory and filename for the MAT-file. For this example, choose the name synthsig.

To load the signal into your workspace, simply type:

load synthsig

When the synthesized signal is obtained using any thresholding method except a global one, the saved structure is:

whos

Name Size Bytes Class

synthsig 1x1000 8000 double array

Save information to disk

Page 119: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-51

The synthesized signal is given by the variable synthsig. In addition, the parameters of the de-noising or compression process are given by the wavelet name (wname) and the level dependent thresholds contained in the thrParams variable, which is a cell array of length 5 (same as the level of the decomposition).

For i from 1 to 5, thrParams{i} contains the lower and upper bounds of the thresholding interval and the threshold value (since interval dependent thresholds are allowed, see the section “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 2-136).

For example, for level 1:

thrParams{1}

ans =1.0e+03 *0.0010 1.0000 0.0014

When the synthesized signal is obtained using a global thresholding method, the saved structure is:

where the variable valTHR contains the global threshold:

valTHR

valTHR =1.2922

thrParams 1x5 580 cell arraywname 1x3 6 char array

Name Size Bytes Class

synthsig 1x1000 8000 double array valTHR 1x1 8 double array wname 1x3 6 char array

Page 120: Wavelet ug

2 Using Wavelets

2-52

Saving Discrete Wavelet Transform Coefficients.

The Wavelet 1-D tool lets you save the coefficients of a discrete wavelet transform (DWT) to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the DWT coefficients from the present analysis, use the menu option File⇒Save⇒Coefficients.

A dialog box appears that lets you specify a directory and filename for storing the coefficients.

Consider the example analysis:

File⇒Example Analysis⇒Basic Signals⇒with db1 at level 5 −−> Cantor curve.

After saving the wavelet coefficients to the file cantor.mat, load the variables into your workspace.

load cantorwhos

Variable coefs contains the discrete wavelet coefficients. More precisely, in the above example coefs is a 1-by-2190 vector of concatenated coefficients, and longs is a vector giving the lengths of each component of coefs.

Variable wname contains the wavelet name and thrParams is empty since the synthesized signal does not exist.

Saving Decompositions.

The Wavelet 1-D tool lets you save the entire set of data from a discrete wavelet analysis to disk. The toolbox creates a MAT-file in the current directory with a name you choose, followed by the extension wa1 (wavelet analysis 1-D).

Open the Wavelet 1-D tool and load the example analysis:

Name Size Bytes Class

coefs 1x2190 17520 double array longs 1x7 56 double array thrParams 0x0 0 double array wname 1x3 6 char array

Page 121: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-53

File⇒Example Analysis⇒Basic Signals⇒with db3 at level 5 −−> Sum of sines

To save the data from this analysis, use the menu option:

File⇒Save⇒Decomposition

A dialog box appears that lets you specify a directory and filename for storing the decomposition data. Type the name wdecex1d.

After saving the decomposition data to the file wdecex1d.wa1, load the variables into your workspace.

load wdecex1d.wa1 -matwhos

Note Save options are also available when performing de-noising or compression inside the Wavelet 1-D tool. In the Wavelet 1-D De-noising window, you can save de-noised signal and decomposition. The same holds true for the Wavelet 1-D Compression window. This way, you can save many different trials from inside the De-noising and Compression windows without going back to the main Wavelet 1-D window during a fine-tuning process.

Note When saving a synthesized signal, a decomposition or coefficients to a MAT-file, the extension of this file is free. The mat extension is not necessary.

Name Size Bytes Class

coefs 1x1023 8184 double array data_name 1x6 12 char array longs 1x7 56 double arraythrParams 0x0 0 double arraywave_name 1x3 6 char array

Page 122: Wavelet ug

2 Using Wavelets

2-54

Loading Information into the Wavelet 1-D ToolYou can load signals, coefficients, or decompositions into the graphical interface. The information you load may have been previously exported from the graphical interface, and then manipulated in the workspace, or it may have been information you generated initially from the command line.

In either case, you must observe the strict file formats and data structures used by the Wavelet 1-D tool, or else errors will result when you try to load information.

Loading Signals.

To load a signal you’ve constructed in your MATLAB workspace into the Wavelet 1-D tool, save the signal in a MAT-file (with extension mat or other).

For instance, suppose you’ve designed a signal called warma and want to analyze it in the Wavelet 1-D tool.

save warma warma

The workspace variable warma must be a vector.

sizwarma = size(warma)

sizwarma = 1 1000

To load this signal into the Wavelet 1-D tool, use the menu option:

File⇒Load⇒Signal

A dialog box appears that lets you select the appropriate MAT-file to be loaded.

Load information from disk

Page 123: Wavelet ug

One-Dimensional Discrete Wavelet Analysis

2-55

Note The first one-dimensional variable encountered in the file is considered the signal. Variables are inspected in alphabetical order.

Loading Discrete Wavelet Transform Coefficients.

To load discrete wavelet transform coefficients into the Wavelet 1-D tool, you must first save the appropriate data in a MAT-file, which must contain at least the two variables coefs and longs.

Variable coefs must be a vector of DWT coefficients (concatenated for the various levels), and variable longs a vector specifying the length of each component of coefs, as well as the length of the original signal.

After constructing or editing the appropriate data in your workspace, type:

save myfile coefs longs

Use the File⇒Load⇒Coefficients menu option from the Wavelet 1-D tool to load the data into the graphical tool.

A dialog box appears, allowing you to choose the directory and file in which your data reside.

Loading Decompositions.

To load discrete wavelet transform decomposition data into the Wavelet 1-D graphical interface, you must first save the appropriate data in a MAT-file (with extension wa1 or other).

S

cA1 cD1

cA2 cD2

cA3 cD3

cD1cD2cA3 cD3

coefs

longs

Decomposition

1000

501

252

127 127

501 1000127 127 252501

252

Page 124: Wavelet ug

2 Using Wavelets

2-56

The MAT-file contains the following variables.

After constructing or editing the appropriate data in your workspace, type:

save myfile coefs longs wave_name

Use the File⇒Load⇒Decomposition menu option from the Wavelet 1-D tool to load the decomposition data into the graphical tool.

A dialog box appears, allowing you to choose the directory and file in which your data reside.

Note When loading a signal, a decomposition or coefficients from a MAT-file, the extension of this file is free. The mat extension is not necessary.

Variable Status Description

coefs Required Vector of concatenated DWT coefficients

longs Required Vector specifying lengths of components of coefs and of the original signal

wave_name Required String specifying name of wavelet used for decomposition (e.g., db3)

data_name Optional String specifying name of decomposition

Page 125: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-57

Two-Dimensional Discrete Wavelet AnalysisThis section takes you through the features of two-dimensional discrete wavelet analysis using the MATLAB Wavelet Toolbox.

The Wavelet Toolbox provides these functions for image analysis. For more information, see the reference pages.

Analysis-Decomposition Functions

Synthesis-Reconstruction Functions

Decomposition Structure Utilities

Function Name Purpose

dwt2 Single-level decomposition

wavedec2 Decomposition

wmaxlev Maximum wavelet decomposition level

Function Name Purpose

idwt2 Single-level reconstruction

waverec2 Full reconstruction

wrcoef2 Selective reconstruction

upcoef2 Single reconstruction

Function Name Purpose

detcoef2 Extraction of detail coefficients

appcoef2 Extraction of approximation coefficients

upwlev2 Recomposition of decomposition structure

Page 126: Wavelet ug

2 Using Wavelets

2-58

De-noising and Compression

In this section, you’ll learn:

• How to load an image

• How to analyze an image

• How to perform single-level and multilevel image decompositions and reconstructions (command line only)

• How to use Square and Tree mode features (GUI only)

• How to zoom in on detail (GUI only)

• How to compress an image

Function Name Purpose

ddencmp Provide default values for de-noising and compression

wbmpen Penalized threshold for wavelet 1-D or 2-D de-noising

wdcbm2 Thresholds for wavelet 2-D using Birgé-Massart strategy

wdencmp Wavelet de-noising and compression

wthrmngr Threshold settings manager

Page 127: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-59

Two-Dimensional Analysis Using the Command LineIn this example we’ll show how you can use two-dimensional wavelet analysis to compress an image efficiently without sacrificing its clarity.

Note Instead of directly using image(I) to visualize the image I, we use image(wcodemat(I)), which displays a rescaled version of I leading to a clearer presentation of the details and approximations (see wcodemat reference page).

Loading an Image.

1 From the MATLAB prompt, type:

load wbarb; whos

2 Display the image. Type:

image(X); colormap(map); colorbar;

Name Size Bytes Class

X 256x256 524288 double array map 192x3 4608 double array

Page 128: Wavelet ug

2 Using Wavelets

2-60

Converting an Indexed Image to a Grayscale Image.

3 If the colormap is smooth, the wavelet transform can be directly applied to the indexed image; otherwise the indexed image should be converted to grayscale format. For more information, see “Wavelets: Working with Images” on page 2-82.

Since the colormap is smooth in this image, you can now perform the decomposition.

Performing a Single-Level Wavelet Decomposition of an Image.

4 Perform a single-level decomposition of the image using the bior3.7 wavelet. Type:

[cA1,cH1,cV1,cD1] = dwt2(X,'bior3.7');

This generates the coefficient matrices of the level-one approximation (cA1) and horizontal, vertical and diagonal details (cH1,cV1,cD1, respectively).

Constructing Approximations and Details from the Coefficients.

5 To construct the level-one approximation and details (A1, H1, V1, and D1) from the coefficients cA1, cH1, cV1, and cD1, type:

A1 = upcoef2('a',cA1,'bior3.7',1); H1 = upcoef2('h',cH1,'bior3.7',1);V1 = upcoef2('v',cV1,'bior3.7',1);D1 = upcoef2('d',cD1,'bior3.7',1);

or

sx = size(X);A1 = idwt2(cA1,[],[],[],'bior3.7',sx); H1 = idwt2([],cH1,[],[],'bior3.7',sx); V1 = idwt2([],[],cV1,[],'bior3.7',sx); D1 = idwt2([],[],[],cD1,'bior3.7',sx);

Displaying the Approximation and Details.

6 To display the results of the level 1 decomposition, type:

colormap(map);subplot(2,2,1); image(wcodemat(A1,192));

Page 129: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-61

title('Approximation A1')subplot(2,2,2); image(wcodemat(H1,192));title('Horizontal Detail H1')subplot(2,2,3); image(wcodemat(V1,192));title('Vertical Detail V1')subplot(2,2,4); image(wcodemat(D1,192));title('Diagonal Detail D1')

Regenerating an Image by Single-Level Inverse Wavelet Transform.

7 To find the inverse transform, type:

Xsyn = idwt2(cA1,cH1,cV1,cD1,'bior3.7');

This reconstructs or synthesizes the original image from the coefficients of the level 1 approximation and details.

Page 130: Wavelet ug

2 Using Wavelets

2-62

Performing a Multilevel Wavelet Decomposition of an Image.

8 To perform a level 2 decomposition of the image (again using the bior3.7 wavelet), type:

[C,S] = wavedec2(X,2,'bior3.7');

where X is the original image matrix, and 2 is the level of decomposition.

The coefficients of all the components of a second-level decomposition (that is, the second-level approximation and the first two levels of detail) are returned concatenated into one vector, C. Argument S is a bookkeeping matrix that keeps track of the sizes of each component.

Extracting Approximation and Detail Coefficients.

9 To extract the level 2 approximation coefficients from C, type:

cA2 = appcoef2(C,S,'bior3.7',2);

10 To extract the first- and second-level detail coefficients from C, type:

cH2 = detcoef2('h',C,S,2);cV2 = detcoef2('v',C,S,2); cD2 = detcoef2('d',C,S,2); cH1 = detcoef2('h',C,S,1);cV1 = detcoef2('v',C,S,1); cD1 = detcoef2('d',C,S,1);

or

[cH2,cV2,cD2] = detcoef2('all',C,S,2); [cH1,cV1,cD1] = detcoef2('all',C,S,1);

where the first argument ('h', 'v', or 'd') determines the type of detail (horizontal, vertical, diagonal) extracted, and the last argument determines the level.

Reconstructing the Level 2 Approximation.

11 To reconstruct the level 2 approximation from C, type:

A2 = wrcoef2('a',C,S,'bior3.7',2);

Page 131: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-63

Reconstructing the Level 1 and 2 Details.

12 To reconstruct the level 1 and 2 details from C, type:

H1 = wrcoef2('h',C,S,'bior3.7',1); V1 = wrcoef2('v',C,S,'bior3.7',1); D1 = wrcoef2('d',C,S,'bior3.7',1); H2 = wrcoef2('h',C,S,'bior3.7',2);V2 = wrcoef2('v',C,S,'bior3.7',2); D2 = wrcoef2('d',C,S,'bior3.7',2);

Displaying the Results of a Multilevel Decomposition.

Note With all the details involved in a multilevel image decomposition, it makes sense to import the decomposition into the Wavelet 2-D graphical tool in order to more easily display it. For information on how to do this, see “Loading Decompositions” on page 2-81.

13 To display the results of the level 2 decomposition, type:

colormap(map);subplot(2,4,1);image(wcodemat(A1,192));title('Approximation A1')subplot(2,4,2);image(wcodemat(H1,192));title('Horizontal Detail H1')subplot(2,4,3);image(wcodemat(V1,192));title('Vertical Detail V1')subplot(2,4,4);image(wcodemat(D1,192));title('Diagonal Detail D1')subplot(2,4,5);image(wcodemat(A2,192));title('Approximation A2')subplot(2,4,6);image(wcodemat(H2,192));title('Horizontal Detail H2')subplot(2,4,7);image(wcodemat(V2,192));title('Vertical Detail V2')subplot(2,4,8);image(wcodemat(D2,192));title('Diagonal Detail D2')

Page 132: Wavelet ug

2 Using Wavelets

2-64

Reconstructing the Original Image from the Multilevel Decomposition.

14 To reconstruct the original image from the wavelet decomposition structure, type:

X0 = waverec2(C,S,'bior3.7');

This reconstructs or synthesizes the original image from the coefficients C of the multilevel decomposition.

Compressing an Image.

15 To compress the original image X, use the ddencmp command to calculate the default parameters and the wdencmp command to perform the actual compression. Type:

[thr,sorh,keepapp] = ddencmp('cmp','wv',X);[Xcomp,CXC,LXC,PERF0,PERFL2] = wdencmp('gbl',C,S,'bior3.7',2,thr,sorh,keepapp);

Note that we pass in to wdencmp the results of the decomposition (C and S) we calculated in Step 8 on page 2-62. We also specify the bior3.7 wavelets, because we used this wavelet to perform the original analysis. Finally, we specify the global thresholding option 'gbl'. See ddencmp and wdencmp reference pages for more information about the use of these commands.

Page 133: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-65

Displaying the Compressed Image.

16 To view the compressed image side by side with the original, type:

colormap(map);subplot(121); image(X); title('Original Image');axis squaresubplot(122); image(Xcomp); title('Compressed Image');axis square

PERF0

PERF0 =49.8076

PERFL2

PERFL2 =99.9817

These returned values tell, respectively, what percentage of the wavelet coefficients was set to zero and what percentage of the image’s energy was preserved in the compression process.

Note that, even though the compressed image is constructed from only about half as many nonzero wavelet coefficients as the original, there is almost no detectable deterioration in the image quality.

Page 134: Wavelet ug

2 Using Wavelets

2-66

Two-Dimensional Analysis Using the Graphical InterfaceIn this section we explore the same image as in the previous section, but we use the graphical interface tools to analyze the image.

Starting the 2-D Wavelet Analysis Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Tool Main Menu appears.

2 Click the Wavelet 2-D menu item.

The discrete wavelet analysis tool for two-dimensional image data appears.

Page 135: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-67

Loading an Image.

3 From the File menu, choose the Load⇒Image option.

4 When the Load Image dialog box appears, select the demo MAT-file wbarb.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

The image is loaded into the Wavelet 2-D tool.

Analyzing an Image.

5 Using the Wavelet and Level menus located to the upper right, determine the wavelet family, the wavelet type, and the number of levels to be used for the analysis.

For this analysis, select the bior3.7 wavelet at level 2.

Page 136: Wavelet ug

2 Using Wavelets

2-68

6 Click the Analyze button.

After a pause for computation, the Wavelet 2-D tool displays its analysis.

Visualization

Decomposition

Original image

Synthesized image

Page 137: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-69

Using Square Mode Features.

By default, the analysis appears in “Square Mode.” This mode includes four different displays. In the upper left is the original image. Below that is the image reconstructed from the various approximations and details. To the lower right is a decomposition showing the coarsest approximation coefficients and all the horizontal, diagonal, and vertical detail coefficients. Finally, the visualization space at the top right displays any component of the analysis that you want to look at more closely.

7 Click on any decomposition component in the lower right window.

A green border highlights the selected component. At the lower right of the Wavelet 2-D window, there is a set of three buttons labeled “Operations on selected image. Note that if you click again on the same component, you’ll deselect it and the green border disappear.

8 Click the Visualize button.

The selected image is displayed in the visualization area. You are seeing the raw, unreconstructed two-dimensional wavelet coefficients. Using the other buttons, you can display the reconstructed version of the selected image component, or you can view the selected component at full screen resolution.

Page 138: Wavelet ug

2 Using Wavelets

2-70

Using Tree Mode Features.

9 Choose Tree from the View Mode menu.

Your display changes to reveal the following.

Approximation coefficients cA2 Reconstructed Approximation A2

Page 139: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-71

This is the same information shown in square mode, with in addition all the approximation coefficients, but arranged to emphasize the tree structure of the decomposition. The various buttons and menus work just the same as they do in square mode.

Zooming in on Detail.

10 Drag a rubber band box (by holding down the left mouse button) over the portion of the image you want to magnify.

11 Click the XY+ button (located at the bottom of the screen) to zoom horizontally and vertically.

The Wavelet 2-D tool enlarges the displayed images.

To zoom back to original magnification, click the History <<− button.

Page 140: Wavelet ug

2 Using Wavelets

2-72

Compressing an Image.

12 Click the Compress button, located to the upper right of the Wavelet 2-D window.

The Wavelet 2-D Compression window appears.

The tool automatically selects thresholding levels to provide a good initial balance between retaining the image’s energy while minimizing the number of coefficients needed to represent the image.

However, you can also adjust thresholds manually using the By Level thresholding option, and then the sliders or edits corresponding to each level.

For this example, select the By Level thresholding option and select the Remove near 0 method from the Select thresholding method menu.

The following window is displayed.

Threshold menus

Compress button

Page 141: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-73

Select from the direction menu whether you want to adjust thresholds for horizontal, diagonal or vertical details. To make the actual adjustments for each level, use the sliders or use the left mouse button to directly drag the yellow vertical lines.

13 To compress the original image, click the Compress button.

After a pause for computation, the compressed image is displayed beside the original. Notice that compression eliminates almost half the coefficients, yet no detectable deterioration of the image appears.

Threshold menus

Direction menu

Compress button

Page 142: Wavelet ug

2 Using Wavelets

2-74

Showing Residuals.

14 From the Wavelet 2-D Compression tool, click the Residuals button. The More on Residuals for Wavelet 2-D Compression window appears.

Displayed statistics include measures of tendency (mean, mode, median) and dispersion (range, standard deviation). In addition, the tool provides frequency-distribution diagrams (histograms and cumulative histograms). The same tool exists for the Wavelet 2-D De-noising tool.

Importing and Exporting Information from the Graphical InterfaceThe Wavelet 2-D graphical tool lets you import information from and export information to disk, if you adhere to the proper file formats.

Saving Information to DiskYou can save synthesized images, coefficients, and decompositions from the Wavelet 2-D tool to disk, where the information can be manipulated and later reimported into the graphical tool.

Page 143: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-75

Saving Synthesized Images.

You can process an image in the Wavelet 2-D tool, and then save the processed image to a MAT-file (with extension mat or other).

For example, load the example analysis:

File⇒Example Analysis⇒at level 3, with sym4 −−> detail Durer

and perform a compression on the original image. When you close the Wavelet 2-D Compression window, update the synthesized image by clicking Yes in the dialog box that appears.

Then, from the Wavelet 2-D tool, select the File⇒Save⇒Synthesized Image menu option.

A dialog box appears allowing you to select a directory and filename for the MAT-file (with extension mat or other). For this example, choose the name symage.

To load the image into your workspace, simply type:

load symagewhos

Name Size Bytes Class

X 359x371 1065512 double array map 64x3 1536 double array valTHR 1x1 8 double array wname 1x4 8 char array

Save information to disk

Page 144: Wavelet ug

2 Using Wavelets

2-76

The synthesized image is given by X and map contains the colormap. In addition, the parameters of the de-noising or compression process are given by the wavelet name (wname) and the global threshold (valTHR).

Saving Discrete Wavelet Transform Coefficients.

The Wavelet 2-D tool lets you save the coefficients of a discrete wavelet transform (DWT) to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the DWT coefficients from the present analysis, use the menu option File⇒Save⇒Coefficients.

A dialog box appears that lets you specify a directory and filename for storing the coefficients.

Consider the example analysis:

File⇒Example Analysis⇒at level 3, with sym4 −−> Detail Durer

After saving the discrete wavelet coefficients to the file cfsdurer.mat, load the variables into your workspace.

load cfsdurerwhos

Variable map contains the colormap. Variable wname contains the wavelet name and valTHR is empty since the synthesized image is the same as the original one.

Variables coefs and sizes contain the discrete wavelet coefficients and the associated matrix sizes. More precisely, in the above example, coefs is a 1-by-142299 vector of concatenated coefficients, and sizes gives the length of each component.

Name Size Bytes Class

coefs 1x142299 1138392 double array map 64x3 1536 double array sizes 5x2 80 double array valTHR 0x0 0 double array wname 1x4 8 char array

Page 145: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-77

Saving Decompositions.

The Wavelet 2-D tool lets you save the entire set of data from a discrete wavelet analysis to disk. The toolbox creates a MAT-file in the current directory with a name you choose, followed by the extension wa2 (wavelet analysis 2-D).

Open the Wavelet 2-D tool and load the example analysis:

File⇒Example Analysis⇒at level 3, with sym4 −−> Detail Durer.

To save the data from this analysis, use the menu option File⇒Save⇒Decomposition.

A dialog box appears that lets you specify a directory and filename for storing the decomposition data. Type the name decdurer.

After saving the decomposition data to the file decdurer.wa2, load the variables into your workspace.

load decdurer.wa2 -matwhos

Variables coefs and sizes contain the wavelet decomposition structure. Other variables contain the wavelet name, the colormap, and the filename containing the data. Variable valTHR is empty since the synthesized image is the same as the original one.

Name Size Bytes Class

coefs 1x142299 1138392 double array data_name 1x6 12 char array map 64x3 1536 double arraysizes 5x2 80 double array valTHR 0x0 0 double arraywave_name 1x4 8 char array

Page 146: Wavelet ug

2 Using Wavelets

2-78

Note Save options are also available when performing de-noising or compression inside the Wavelet 2-D tool. In the Wavelet 2-D De-noising window, you can save de-noised image and decomposition. The same holds true for the Wavelet 2-D Compression window. This way, you can save many different trials from inside the De-noising and Compression windows without going back to the main Wavelet 2-D window during a fine-tuning process.

Note When saving a synthesized image, a decomposition, or coefficients to a MAT-file, the extension of this file is free. The mat extension is not necessary.

Loading Information into the Wavelet 2-D ToolYou can load images, coefficients, or decompositions into the graphical interface. The information you load may have been previously exported from the graphical interface, and then manipulated in the workspace; or it may have been information you generated initially from the command line.

In either case, you must observe the strict file formats and data structures used by the Wavelet 2-D tool, or else errors will result when you try to load information.

Loading Images.

This toolbox supports only indexed images. An indexed image is a matrix containing only integers from 1 to n, where n is the number of colors in the image.

Load information from disk

Page 147: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-79

This image may optionally be accompanied by a n-by-3 matrix called map. This is the colormap associated with the image. When MATLAB displays such an image, it uses the values of the matrix to look up the desired color in this colormap. If the colormap is not given, the Wavelet 2-D tool uses a monotonic colormap with max(max(X))–min(min(X))+1 colors.

To load an image you’ve constructed in your MATLAB workspace into the Wavelet 2-D tool, save the image (and optionally, the variable map) in a MAT-file (with extension mat or other).

For instance, suppose you’ve created an image called brain and want to analyze it in the Wavelet 2-D tool. Type:

X = brain;map = pink(256);save myfile X map

To load this image into the Wavelet 2-D tool, use the menu option:

File⇒Load⇒Image.

A dialog box appears that lets you select the appropriate MAT-file to be loaded.

Note The graphical tools allow you to load an image that does not contain integers from 1 to n. The computations will be correct since they act directly on the matrix, but the display of the image will be strange. The values less than 1 will be evaluated as 1, the values greater than n will be evaluated as n, and a real value within the interval [1,n] will be evaluated as the closest integer.

Note that the coefficients, approximations, and details produced by wavelet decomposition are not indexed image matrices.

To display these images in a suitable way, the Wavelet 2-D tool follows these rules:

• Reconstructed approximations are displayed using the colormap map.

• The coefficients and the reconstructed details are displayed using the colormap map applied to a rescaled version of the matrices.

Page 148: Wavelet ug

2 Using Wavelets

2-80

Note The first two-dimensional variable encountered in the file (except the variable map, which is reserved for the colormap) is considered the image. Variables are inspected in alphabetical order.

Loading Discrete Wavelet Transform Coefficients.

To load discrete wavelet transform (DWT) coefficients into the Wavelet 2-D tool, you must first save the appropriate data in a MAT-file, which must contain at least the two variables: coefficients vector coefs, and bookkeeping matrix sizes.

Variable coefs must be a vector of concatenated DWT coefficients. The coefs vector for an n-level decomposition contains 3n+1 sections, consisting of the level-n approximation coefficients, followed by the horizontal, vertical, and diagonal detail coefficients, in that order for each level. Variable sizes is a matrix, the rows of which specify: the size of cAn, the size of cHn (or cVn, or cDn),..., the size of cH1 (or cV1, or cD1), and the size of the original image X. The sizes of vertical and diagonal details are the same as the horizontal detail.

After constructing or editing the appropriate data in your workspace, type:

save myfile coefs sizes

cAn

coefs (3n+1 sections)

cHn cVn cDn cHn–1 cVn–1 cDn–1 cH1 cV1 cD1...

32 32

...

32 32

256 256

sizes (n+2-by-2)

512 512 X

Page 149: Wavelet ug

Two-Dimensional Discrete Wavelet Analysis

2-81

Use the File⇒Load Coefficients menu option from the Wavelet 2-D tool to load the data into the graphical tool.

A dialog box appears, allowing you to choose the directory and file in which your data reside.

Loading Decompositions.

To load discrete wavelet transform decomposition data into the Wavelet 2-D tool, you must first save the appropriate data in a MAT-file (with extension wa2 or other).

The MAT-file contains the variables:

After constructing or editing the appropriate data in your workspace, type:

save myfile.wa2 coefs sizes wave_name

Use the File⇒Load⇒Decomposition menu option from the Wavelet 2-D tool to load the image decomposition data.

A dialog box appears, allowing you to choose the directory and file in which your data reside.

Note When loading an image, a decomposition, or coefficients from a MAT-file, the extension of this file is free. The mat extension is not necessary.

Variable Status Description

coefs Required Vector of concatenated DWT coefficients

sizes Required Matrix specifying sizes of components of coefs and of the original image

wave_name Required String specifying name of wavelet used for decomposition (e.g., db3)

map Optional n-by-3 colormap matrix.

data_name Optional String specifying name of decomposition

Page 150: Wavelet ug

2 Using Wavelets

2-82

Wavelets: Working with ImagesThis section provides additional information about working with images in the Wavelet Toolbox. It describes the types of supported images and how MATLAB represents them, as well as techniques for analyzing color images.

Understanding Images in MATLABThe basic data structure in MATLAB is the rectangular matrix, an ordered set of real or complex elements. This object is naturally suited to the representation of images, which are real-valued, ordered sets of color or intensity data. (This toolbox does not support complex-valued images.)

The word pixel is derived from picture element and usually denotes a single dot on a computer display, or a single element in an image matrix. You can select a single pixel from an image matrix using normal matrix subscripting. For example,

I(2,15)

returns the value of the pixel at row 2 and column 15 of the image I. By default, MATLAB scales images to fill the display axes; therefore, an image pixel may use more than a single pixel on the screen.

Indexed ImagesA typical color image requires two matrices: a colormap, and an image matrix. The colormap is an ordered set of values that represents the colors in the image. For each image pixel, the image matrix contains a corresponding index into the colormap. (The elements of the image matrix are floating-point integers, or flints, which MATLAB stores as double-precision values.)

The size of the colormap matrix is n-by-3 for an image containing n colors. Each row of the colormap matrix is a 1-by-3 red, green, blue (RGB) color vector

color = [R G B]

that specifies the intensity of the red, green, and blue components of that color. R, G, and B are real scalars that range from 0.0 (black) to 1.0 (full intensity). MATLAB translates these values into display intensities when you display an image and its colormap.

Page 151: Wavelet ug

Wavelets: Working with Images

2-83

When MATLAB displays an indexed image, it uses the values in the image matrix to look up the desired color in the colormap. For instance, if the image matrix contains the value 18 in matrix location (86,198), then the color for pixel (86,198) is the color from row 18 of the colormap.

Outside MATLAB, indexed images with n colors often contain values from 0 to n–1. These values are indices into a colormap with 0 as its first index. Since MATLAB matrices start with index 1, you must increment each value in the image, or shift up the image, to create an image that you can manipulate with toolbox functions.

Wavelet Decomposition of Indexed ImagesThe Wavelet Toolbox supports only indexed images with linear, monotonic colormaps. These images can be thought of as scaled intensity images, with matrix elements containing only integers from 1 to n, where n is the number of discrete shades in the image.

Page 152: Wavelet ug

2 Using Wavelets

2-84

If the colormap is not provided, the graphical user interface tools display the image and processing results using a monotonic colormap with max(max(X))-min(min(X))+1 colors.

Since the image colormap is only used for display purposes, some indexed images may need to be preprocessed to achieve the correct results from the wavelet decomposition.

In general, color indexed images do not have linear, monotonic colormaps and need to be converted to the appropriate gray-scale indexed image before performing a wavelet decomposition.

How Decompositions Are DisplayedNote that the coefficients, approximations, and details produced by wavelet decomposition are not indexed image matrices.

To display these images in a suitable way, the graphical user interface tools follow these rules:

• Reconstructed approximations are displayed using the colormap map.

• The coefficients and the reconstructed details are displayed using the colormap map applied to a rescaled version of the matrices.

Other Images The Wavelet Toolbox let’s you work with some other type of images. Using the imread function, the various tools using images try to load indexed images from files that are not MAT files (for example PCX -files).

These tools are:

• Two-Dimensional Discrete Wavelet Analysis

• Two-Dimensional Wavelet Packet Analysis

• Two-Dimensional Stationary Wavelet Analysis

• Two-Dimensional Extension tool

For more information on the supported file types, type: help imread.

Use the imfinfo function to find the type of image stored in the file. If the file does not contain an indexed image, the load operation fails.

Page 153: Wavelet ug

Wavelets: Working with Images

2-85

Image ConversionThe Image Processing Toolbox provides a comprehensive set of functions that let you easily convert between image types. Should you not have the Image Processing Toolbox, the examples below demonstrate how this conversion may be performed using basic MATLAB commands.

Example 1 - Converting Color Indexed Images.load xpmndrllwhos

image(X2)title('Original Color Indexed Image')colormap(map); colorbar

Name Size Bytes Class

X2 192x200 307200 double array map 64x3 1536 double array

Orignal Color Indexed Image

20 40 60 80 100 120 140 160 180 200

20

40

60

80

100

120

140

160

180

10

20

30

40

50

60

Page 154: Wavelet ug

2 Using Wavelets

2-86

The color bar to the right of the image is not smooth and does not monotonically progress from dark to light. This type of indexed image is not suitable for direct wavelet decomposition with the toolbox and needs to be preprocessed.

First we separate the color indexed image into its RGB components,

R = map(X2,1); R = reshape(R,size(X2));G = map(X2,2); G = reshape(G,size(X2));B = map(X2,3); B = reshape(B,size(X2));

Next we convert the RGB matrices into a gray-scale intensity image, using the standard perceptual weightings for the three-color components,

Xrgb = 0.2990*R + 0.5870*G + 0.1140*B;

Then, we convert the gray-scale intensity image back to a gray-scale indexed image with 64 distinct levels, and create a new colormap with 64 levels of gray.

n = 64; % Number of shades in new indexed imageX = round(Xrgb*(n-1)) + 1;map2 = gray(n);figureimage(X), title('Processed Gray Scale Indexed Image')colormap(map2), colorbar

0

10

20

30

40

50

60

Processed Gray Scale Indexed Image

20 40 60 80 100 120 140 160 180 200

20

40

60

80

100

120

140

160

180

Page 155: Wavelet ug

Wavelets: Working with Images

2-87

The color bar of the converted image is now linear and has a smooth transition from dark to light. The image is now suitable for wavelet decomposition.

Finally, we save the converted image in a form compatible with the Wavelet Toolbox graphical user interface,

baboon= X;map = map2;save baboon baboon map

Example 2 - Converting an RGB tif-Image.Suppose the file myImage.tif contains an RGB image (noncompressed) of size S1xS2, you can use the following basic MATLAB commands to convert this image.

A = imread('myImage.tif'); % A is an S1xS2x3 array of uint8.

A = double(A);Xrgb = 0.2990*A(:,:,1) + 0.5870*A(:,:,2) + 0.1140*A(:,:,3);NbColors = 255;X = wcodemat(Xrgb,NbColors);map = pink(NbColors);

The same program can be used to convert bmp or jpeg files.

Page 156: Wavelet ug

2 Using Wavelets

2-88

One-Dimensional Discrete Stationary Wavelet AnalysisThis section takes you through the features of one-dimensional discrete stationary wavelet analysis using the MATLAB Wavelet Toolbox. For more information see “Discrete Stationary Wavelet Transform (SWT)” on page 6-47.

The Wavelet Toolbox provides these functions for one-dimensional discrete stationary wavelet analysis. For more information on the functions, see the reference pages.

Analysis-Decomposition Functions

Synthesis-Reconstruction Functions

The stationary wavelet decomposition structure is more tractable than the wavelet one. So the utilities, useful for the wavelet case, are not necessary for the stationary wavelet transform (SWT).

In this section, you’ll learn to:

• Load a signal

• Perform a stationary wavelet decomposition of a signal

• Construct approximations and details from the coefficients

• Display the approximation and detail at level 1

• Regenerate a signal by using inverse stationary wavelet transform

• Perform a multilevel stationary wavelet decomposition of a signal

• Reconstruct the level 3 approximation

• Reconstruct the level 1, 2, and 3 details

• Reconstruct the level 1 and 2 approximations

• Display the results of a decomposition

Function Name Purpose

swt Decomposition

Function Name Purpose

iswt Reconstruction

Page 157: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-89

• Reconstruct the original signal from the level 3 decomposition

• Remove noise from a signal

Since you can perform analyses either from the command line or using the graphical interface tools, this section has subsections covering each method.

The final subsection discusses how to exchange signal and coefficient information between the disk and the graphical tools.

One-Dimensional Analysis Using the Command LineThis example involves a noisy Doppler test signal.

Loading a Signal.

1 From the MATLAB prompt, type:

load noisdopp

2 Set the variables. Type:

s = noisdopp;

Let us mention that for the SWT, if a decomposition at level k is needed, 2^k must divide evenly into the length of the signal. If your original signal does not have the correct length, you can use the Signal Extension GUI tool or the wextend function to extend it.

Performing a Single-Level Stationary Wavelet Decomposition of a Signal.

3 Perform a single-level decomposition of the signal using the db1 wavelet. Type:

[swa,swd] = swt(s,1,'db1');

This generates the coefficients of the level 1 approximation (swa) and detail (swd). Both are of the same length as the signal. Type:

whos

Name Size Bytes Class

noisdopp 1x1024 8192 double array s 1x1024 8192 double array

Page 158: Wavelet ug

2 Using Wavelets

2-90

Displaying the Coefficients of Approximation and Detail.

4 To display the coefficients of approximation and detail at level 1, type:

subplot(1,2,1), plot(swa); title('Approximation cfs')subplot(1,2,2), plot(swd); title('Detail cfs')

Regenerating a Signal by Inverse Stationary Wavelet Transform.

5 To find the inverse transform, type:

A0 = iswt(swa,swd,'db1');

To check the perfect reconstruction, type:

err = norm(s-A0)

err = 2.1450e-14

swa 1x1024 8192 double array swd 1x1024 8192 double array

200 400 600 800 1000−15

−10

−5

0

5

10

15Approximation cfs

200 400 600 800 1000−4

−3

−2

−1

0

1

2

3

4Detail cfs

Page 159: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-91

Constructing Approximation and Detail from the Coefficients.

6 To construct the level 1 approximation and detail (A1 and D1) from the coefficients swa and swd, type:

nulcfs = zeros(size(swa));A1 = iswt(swa,nulcfs,'db1'); D1 = iswt(nulcfs,swd,'db1');

Displaying the Approximation and Detail.

7 To display the approximation and detail at level 1, type:

subplot(1,2,1), plot(A1); title('Approximation A1');subplot(1,2,2), plot(D1); title('Detail D1');

200 400 600 800 1000−8

−6

−4

−2

0

2

4

6

8Approximation A1

200 400 600 800 1000−2.5

−2

−1.5

−1

−0.5

0

0.5

1

1.5

2

2.5Detail D1

Page 160: Wavelet ug

2 Using Wavelets

2-92

Performing a Multilevel Stationary Wavelet Decomposition of a Signal.

8 To perform a decomposition at level 3 of the signal (again using the db1 wavelet), type:

[swa,swd] = swt(s,3,'db1');

This generates the coefficients of the approximations at levels 1, 2, and 3 (swa) and the coefficients of the details (swd). Observe that the rows of swa and swd are the same length as the signal length. Type:

clear A0 A1 D1 err nulcfs

whos

Displaying the Coefficients of Approximations and Details.

9 To display the coefficients of approximations and details, type:

kp = 0;for i = 1:3

subplot(3,2,kp+1), plot(swa(i,:)); title(['Approx. cfs level ',num2str(i)])subplot(3,2,kp+2), plot(swd(i,:)); title(['Detail cfs level ',num2str(i)])kp = kp + 2;

end

Name Size Bytes Class

noisdopp 1x1024 8192 double array s 1x1024 8192 double array swa 3x1024 24576 double array swd 3x1024 24576 double array

Page 161: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-93

Reconstructing Approximation at Level 3 From Coefficients.

10 To reconstruct the approximation at level 3, type:

mzero = zeros(size(swd));A = mzero;A(3,:) = iswt(swa,mzero,'db1');

Reconstructing Details From Coefficients.

11 To reconstruct the details at levels 1, 2 and 3, type:

D = mzero;for i = 1:3

swcfs = mzero;swcfs(i,:) = swd(i,:);D(i,:) = iswt(mzero,swcfs,'db1');

end

200 400 600 800 1000−20

−10

0

10

20Approx. cfs level 1

200 400 600 800 1000−4

−2

0

2

4Detail cfs level 1

200 400 600 800 1000−20

−10

0

10

20Approx. cfs level 2

200 400 600 800 1000−10

−5

0

5Detail cfs level 2

200 400 600 800 1000−40

−20

0

20

40Approx. cfs level 3

200 400 600 800 1000−10

−5

0

5

10Detail cfs level 3

Page 162: Wavelet ug

2 Using Wavelets

2-94

Reconstructing Approximations at Levels 1 and 2 from Approximation at Level 3 and Details at Levels 2 and 3.

12 To reconstruct the approximations at levels 2 and 3, type:

A(2,:) = A(3,:) + D(3,:);A(1,:) = A(2,:) + D(2,:);

Displaying the Approximations and Details.

13 To display the approximations and details at levels 1, 2 and 3, type:

kp = 0;for i = 1:3

subplot(3,2,kp+1), plot(A(i,:));title(['Approx. level ',num2str(i)])subplot(3,2,kp+2), plot(D(i,:));title(['Detail level ',num2str(i)])kp = kp + 2;

end

200 400 600 800 1000−10

−5

0

5

10Approx. level 1

200 400 600 800 1000−4

−2

0

2

4Detail level 1

200 400 600 800 1000−10

−5

0

5

10Approx. level 2

200 400 600 800 1000−2

−1

0

1

2Detail level 2

200 400 600 800 1000−10

−5

0

5

10Approx. level 3

200 400 600 800 1000−2

−1

0

1

2Detail level 3

Page 163: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-95

Removing Noise by Thresholding.

14 To de-noise the signal, use the ddencmp command to calculate a default global threshold. Use the wthresh command to perform the actual thresholding of the detail coefficients, and then use the iswt command to obtain the de-noised signal.

[thr,sorh] = ddencmp('den','wv',s);dswd = wthresh(swd,sorh,thr);clean = iswt(swa,dswd,'db1');

15 To display both the original and de-noised signals, type:

subplot(2,1,1), plot(s);title('Original signal')subplot(2,1,2), plot(clean);title('De-noised signal')

16 The obtained signal remains a little bit noisy. The result can be improved by considering the decomposition of s at level 5 instead of level 3, and repeating steps 14 and 15. To improve the previous de-noising, type:

[swa,swd] = swt(s,5,'db1');

200 400 600 800 1000−10

−5

0

5

10Original signal

200 400 600 800 1000−10

−5

0

5

10De−noised signal

Page 164: Wavelet ug

2 Using Wavelets

2-96

[thr,sorh] = ddencmp('den','wv',s);dswd = wthresh(swd,sorh,thr);clean = iswt(swa,dswd,'db1');subplot(2,1,1), plot(s); title('Original signal')subplot(2,1,2), plot(clean); title('De-noised signal')

17 A second syntax can be used for the swt and iswt functions, giving the same results:

lev = 5;swc = swt(s,lev,'db1');swcden = swc;swcden(1:end-1,:) = wthresh(swcden(1:end-1,:),sorh,thr);clean = iswt(swcden,'db1');

You can obtain the same plot by using the same plot commands than in step 16 above.

200 400 600 800 1000−10

−5

0

5

10Original signal

200 400 600 800 1000−10

−5

0

5

10De−noised signal

Page 165: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-97

One-Dimensional Analysis for De-noising Using the Graphical InterfaceIn this section, we explore a strategy to de-noise signals, based on the one-dimensional stationary wavelet analysis using the graphical interface tools. The basic idea is to average many slightly different discrete wavelet analyses.

Starting the Stationary Wavelet Transform De-noising 1-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

2 Click the SWT De-noising 1-D menu item.

The discrete stationary wavelet transform de-noising tool for one-dimensional signals appears.

Page 166: Wavelet ug

2 Using Wavelets

2-98

Loading Data.

3 From the File menu, choose the Load Signal option.

4 When the Load Signal dialog box appears, select the MAT-file noisbloc.mat, which should reside in the Matlab directory toolbox/wavelet/wavedemo.

Click the OK button. The noisy blocks signal is loaded into the SWT De-noising 1-D tool.

Page 167: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-99

Performing a Stationary Wavelet Decomposition of the Signal.

5 Select the db1 wavelet from the Wavelet menu and select 5 from the Level menu, and then click the Decompose Signal button. After a pause for computation, the tool displays the stationary wavelet approximation and detail coefficients of the decomposition. These are also called nondecimated coefficients since they are obtained using the same scheme as for the DWT, but omitting the decimation step (see “The Fast Wavelet Transform (FWT) Algorithm” on page 6-20).

De-noising a Signal Using the Stationary Wavelet Transform.

6 While a number of options are available for fine-tuning the de-noising algorithm, we’ll accept the defaults of fixed form soft thresholding and unscaled white noise. The sliders located on the right part of the window control the level-dependent thresholds, indicated by yellow dotted lines running horizontally through the graphs of the detail coefficients to the left of the window. The yellow dotted lines can also be dragged directly using the left mouse button over the graphs.

Note that the approximation coefficients are not thresholded.

Page 168: Wavelet ug

2 Using Wavelets

2-100

Click the De-noise button.

The result is quite satisfactory, but seems to be oversmoothed around the discontinuities of the signal. This can be seen by looking at the residuals, and zooming on a breakdown point, for example around position 800.

The residuals clearly contain some signal information

Page 169: Wavelet ug

One-Dimensional Discrete Stationary Wavelet Analysis

2-101

Selecting a Thresholding Method.

7 Select hard for the thresholding mode instead of soft, and then click the De-noise button.

The result is of good quality and the residuals look like a white noise sample. To investigate this last point, you can get more information on residuals by clicking the Residuals button.

Importing and Exporting Information from the Graphical InterfaceThe tool lets you save the de-noised signal to disk. The toolbox creates a MAT-file in the current directory with a name of your choice.

8 To save the present de-noised signal, use the menu option File⇒Save De-noised Signal. A dialog box appears that lets you specify a directory and filename for storing the signal. Type the name dnoibloc. After saving the signal data to the file dnoibloc.mat, load the variables into your workspace.

Page 170: Wavelet ug

2 Using Wavelets

2-102

load dnoiblocwhos

The de-noised signal is given by dnoibloc. In addition, the parameters of the de-noising process are available. The wavelet name is contained in wname:

wname

wname =db1

and the level dependent thresholds are encoded in thrParams, which is a cell array of length 5 (the level of the decomposition). For i from 1 to 5, thrParams{i} contains the lower and upper bounds of the interval of thresholding and the threshold value (since interval dependent thresholds are allowed). For more information, see “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 2-136.

For example, for level 1:

thrParams{1}

ans =

1.0e+03 *

0.0010 1.0240 0.0041

Here the lower bound is 1, the upper bound is 1024, and the threshold value is 4.1. The total time-interval is not segmented and the procedure does not use the interval dependent thresholds.

Name Size Bytes Class

dnoibloc 1x1024 8192 double array thrParams 1x5 580 cell array wname 1x3 6 char array

Page 171: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-103

Two-Dimensional Discrete Stationary Wavelet AnalysisThis section takes you through the features of two-dimensional discrete stationary wavelet analysis using the MATLAB Wavelet Toolbox. For more information, see “Available Methods for De-noising, Estimation and Compression Using GUI Tools” on page 6-117.

The Wavelet Toolbox provides these functions for image analysis. For more information, see the reference pages.

Analysis-Decomposition Function

Synthesis-Reconstruction Function

The stationary wavelet decomposition structure is more tractable than the wavelet one. So, the utilities useful for the wavelet case are not necessary for the Stationary Wavelet Transform (SWT).

In this section, you’ll learn to:

• Load an image

• Analyze an image

• Perform single-level and multilevel image decompositions and reconstructions (command line only)

• De-noise an image

Function Name Purpose

swt2 Decomposition

Function Name Purpose

iswt2 Reconstruction

Page 172: Wavelet ug

2 Using Wavelets

2-104

Two-Dimensional Analysis Using the Command LineIn this example, we’ll show how you can use two-dimensional stationary wavelet analysis to de-noise an image.

Note Instead of using image(I) to visualize the image I, we use image(wcodemat(I)), which displays a rescaled version of I leading to a clearer presentation of the details and approximations (see the wcodemat reference page).

This example involves a noisy woman image.

Loading an Image.

1 From the MATLAB prompt, type:

load noiswomwhos

Let us mention that for the SWT, if a decomposition at level k is needed, 2^k must divide evenly into size(X,1) and size(X,2). If your original image is not of correct size, you can use the Image Extension GUI tool or the function wextend to extend it. For more information, see the wextend reference page.

Performing a Single-Level Stationary Wavelet Decomposition of an Image.

2 Perform a single-level decomposition of the image using the db1 wavelet. Type:

[swa,swh,swv,swd] = swt2(X,1,'db1');

This generates the coefficients matrices of the level-one approximation (swa) and horizontal, vertical and diagonal details (swh, swv, and swd, respectively). Both are of size-the-image size. Type:

Name Size Bytes Class

X 96x96 73728 double array map 255x3 6120 double array

Page 173: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-105

whos

Displaying the Coefficients of Approximation and Details.

3 To display the coefficients of approximation and details at level 1, type:

map = pink(size(map,1));colormap(map)subplot(2,2,1), image(wcodemat(swa,192));title('Approximation swa')subplot(2,2,2), image(wcodemat(swh,192));title('Horiz. Detail swh')subplot(2,2,3), image(wcodemat(swv,192));title('Vertical Detail swv')subplot(2,2,4), image(wcodemat(swd,192));title('Diag. Detail swd').

Name Size Bytes Class

X 96x96 73728 double array map 255x3 6120 double array swa 96x96 73728 double array swh 96x96 73728 double array swv 96x96 73728 double array swd 96x96 73728 double array

Approximation swa

20 40 60 80

20

40

60

80

Horiz. Detail swh

20 40 60 80

20

40

60

80

Vertical Detail swv

20 40 60 80

20

40

60

80

Diag. Detail swd

20 40 60 80

20

40

60

80

Page 174: Wavelet ug

2 Using Wavelets

2-106

Regenerating an Image by Inverse Stationary Wavelet Transform.

4 To find the inverse transform, type:

A0 = iswt2(swa,swh,swv,swd,'db1');

To check the perfect reconstruction, type:

err = max(max(abs(X-A0)))

err = 1.1369e-13

Constructing Approximation and Details from the Coefficients.

5 To construct the level 1 approximation and details (A1, H1, V1 and D1) from the coefficients swa, swh, swv and swd, type:

nulcfs = zeros(size(swa));A1 = iswt2(swa,nulcfs,nulcfs,nulcfs,'db1'); H1 = iswt2(nulcfs,swh,nulcfs,nulcfs,'db1');V1 = iswt2(nulcfs,nulcfs,swv,nulcfs,'db1');D1 = iswt2(nulcfs,nulcfs,nulcfs,swd,'db1');

Displaying the Approximation and Details.

6 To display the approximation and details at level 1, type:

colormap(map)subplot(2,2,1), image(wcodemat(A1,192));title('Approximation A1')subplot(2,2,2), image(wcodemat(H1,192));title('Horiz. Detail H1')subplot(2,2,3), image(wcodemat(V1,192));title('Vertical Detail V1')subplot(2,2,4), image(wcodemat(D1,192));title('Diag. Detail D1')

Page 175: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-107

Performing a Multilevel Stationary Wavelet Decomposition of an Image.

7 To perform a decomposition at level 3 of the image (again using the db1 wavelet), type:

[swa,swh,swv,swd] = swt2(X,3,'db1');

This generates the coefficients of the approximations at levels 1, 2, and 3 (swa) and the coefficients of the details (swh, swv and swd). Observe that the matrices swa(:,:,i), swh(:,:,i), swv(:,:,i), and swd(:,:,i) for a given level i are of size-the-image size. Type:

clear A0 A1 D1 H1 V1 err nulcfswhos

Name Size Bytes Class

X 96x96 73728 double array map 255x3 6120 double array swa 96x96x3 221184 double array

Approximation A1

20 40 60 80

20

40

60

80

Horiz. Detail H1

20 40 60 80

20

40

60

80

Vertical Detail V1

20 40 60 80

20

40

60

80

Diag. Detail D1

20 40 60 80

20

40

60

80

Page 176: Wavelet ug

2 Using Wavelets

2-108

Displaying the Coefficients of Approximations and Details.

8 To display the coefficients of approximations and details, type:

colormap(map)kp = 0;for i = 1:3

subplot(3,4,kp+1), image(wcodemat(swa(:,:,i),192));title(['Approx. cfs level ',num2str(i)])subplot(3,4,kp+2), image(wcodemat(swh(:,:,i),192));title(['Horiz. Det. cfs level ',num2str(i)])subplot(3,4,kp+3), image(wcodemat(swv(:,:,i),192));title(['Vert. Det. cfs level ',num2str(i)])subplot(3,4,kp+4), image(wcodemat(swd(:,:,i),192));title(['Diag. Det. cfs level ',num2str(i)])kp = kp + 4;

end

swh 96x96x3 221184 double array swv 96x96x3 221184 double array swd 96x96x3 221184 double array

Page 177: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-109

Reconstructing Approximation at Level 3 From Coefficients.

9 To reconstruct the approximation at level 3, type:

mzero = zeros(size(swd));A = mzero;A(:,:,3) = iswt2(swa,mzero,mzero,mzero,'db1');

Approx. cfs level 1

20 40 60 80

20

40

60

80

Horiz. Det. cfs level 1

20 40 60 80

20

40

60

80

Vert. Det. cfs level 1

20 40 60 80

20

40

60

80

Diag. Det. cfs level 1

20 40 60 80

20

40

60

80

Approx. cfs level 2

20 40 60 80

20

40

60

80

Horiz. Det. cfs level 2

20 40 60 80

20

40

60

80

Vert. Det. cfs level 2

20 40 60 80

20

40

60

80

Diag. Det. cfs level 2

20 40 60 80

20

40

60

80

Approx. cfs level 3

20 40 60 80

20

40

60

80

Horiz. Det. cfs level 3

20 40 60 80

20

40

60

80

Vert. Det. cfs level 3

20 40 60 80

20

40

60

80

Diag. Det. cfs level 3

20 40 60 80

20

40

60

80

Page 178: Wavelet ug

2 Using Wavelets

2-110

Reconstructing Details From Coefficients.

10 To reconstruct the details at levels 1, 2 and 3, type:

H = mzero; V = mzero;D = mzero;for i = 1:3

swcfs = mzero; swcfs(:,:,i) = swh(:,:,i);H(:,:,i) = iswt2(mzero,swcfs,mzero,mzero,'db1');swcfs = mzero; swcfs(:,:,i) = swv(:,:,i);V(:,:,i) = iswt2(mzero,mzero,swcfs,mzero,'db1');swcfs = mzero; swcfs(:,:,i) = swd(:,:,i);D(:,:,i) = iswt2(mzero,mzero,mzero,swcfs,'db1');

end

Reconstructing Approximations at Levels 1, 2 from Approximation at Level 3 and Details at Levels 1, 2 and 3.

11 To reconstruct the approximations at levels 2 and 3, type:

A(:,:,2) = A(:,:,3) + H(:,:,3) + V(:,:,3) + D(:,:,3);A(:,:,1) = A(:,:,2) + H(:,:,2) + V(:,:,2) + D(:,:,2);

Displaying the Approximations and Details.

12 To display the approximations and details at levels 1, 2, and 3, type:

colormap(map)kp = 0;for i = 1:3

subplot(3,4,kp+1), image(wcodemat(A(:,:,i),192));title(['Approx. level ',num2str(i)])subplot(3,4,kp+2), image(wcodemat(H(:,:,i),192));title(['Horiz. Det. level ',num2str(i)])subplot(3,4,kp+3), image(wcodemat(V(:,:,i),192));title(['Vert. Det. level ',num2str(i)])subplot(3,4,kp+4), image(wcodemat(D(:,:,i),192));title(['Diag. Det. level ',num2str(i)])kp = kp + 4;

end

Page 179: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-111

Removing Noise by Thresholding.

13 To de-noise an image, use the threshold value we find using the GUI tool (see the next section), use the wthresh command to perform the actual thresholding of the detail coefficients, and then use the iswt2 command to obtain the de-noised image.

thr = 44.5;sorh = 's';dswh = wthresh(swh,sorh,thr);dswv = wthresh(swv,sorh,thr);dswd = wthresh(swd,sorh,thr);clean = iswt2(swa,dswh,dswv,dswd,'db1');

Approx. level 1

20 40 60 80

20

40

60

80

Horiz. Det. level 1

20 40 60 80

20

40

60

80

Vert. Det. level 1

20 40 60 80

20

40

60

80

Diag. Det. level 1

20 40 60 80

20

40

60

80

Approx. level 2

20 40 60 80

20

40

60

80

Horiz. Det. level 2

20 40 60 80

20

40

60

80

Vert. Det. level 2

20 40 60 80

20

40

60

80

Diag. Det. level 2

20 40 60 80

20

40

60

80

Approx. level 3

20 40 60 80

20

40

60

80

Horiz. Det. level 3

20 40 60 80

20

40

60

80

Vert. Det. level 3

20 40 60 80

20

40

60

80

Diag. Det. level 3

20 40 60 80

20

40

60

80

Page 180: Wavelet ug

2 Using Wavelets

2-112

14 To display both the original and de-noised images, type:

colormap(map)subplot(1,2,1), image(wcodemat(X,192));title('Original image')subplot(1,2,2), image(wcodemat(clean,192));title('De-noised image')

15 A second syntax can be used for the swt2 and iswt2 functions, giving the same results:

lev = 4;swc = swt2(X,lev,'db1');swcden = swc;swcden(:,:,1:end-1) = wthresh(swcden(:,:,1:end-1),sorh,thr);clean = iswt2(swcden,'db1');

You obtain the same plot by using the plot commands than in Step 14 above,

Original image

20 40 60 80

10

20

30

40

50

60

70

80

90

De−noised image

20 40 60 80

10

20

30

40

50

60

70

80

90

Page 181: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-113

Two-Dimensional Analysis for De-noising Using the Graphical InterfaceIn this section, we explore a strategy for de-noising images based on the two-dimensional stationary wavelet analysis using the graphical interface tools. The basic idea is to average many slightly different discrete wavelet analyses.

Starting the Stationary Wavelet Transform De-noising 2-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

2 Click the SWT De-noising 2-D menu item.

The discrete stationary wavelet transform de-noising tool for images appears.

Page 182: Wavelet ug

2 Using Wavelets

2-114

Loading Data.

3 From the File menu, choose the Load Image option.

4 When the Load Image dialog box appears, select the MAT-file noiswom.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. The noisy woman image is loaded into the SWT De-noising 2-D tool.

Page 183: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-115

Performing a Stationary Wavelet Decomposition of the Image.

5 Select the haar wavelet from the Wavelet menu, select 4 from the Level menu, and then click the Decompose Image button.

The tool displays the histograms of the stationary wavelet detail coefficients of the image on the left of the window. These histograms are organized as follows:

- From the bottom for level 1 to the top for level 4

- On the left horizontal coefficients, in the middle diagonal coefficients, and on the right vertical coefficients

Page 184: Wavelet ug

2 Using Wavelets

2-116

De-noising an Image Using the Stationary Wavelet Transform.

6 While a number of options are available for fine-tuning the de-noising algorithm, we’ll accept the defaults of fixed form soft thresholding and unscaled white noise. The sliders located to the right of the window control the level dependent thresholds indicated by yellow dotted lines running vertically through the histograms of the coefficients on the left of the window. Click the De-noise button.

The result seems to be oversmoothed and the selected thresholds too aggressive. Nevertheless, the histogram of the residuals is quite good since it is close to a Gaussian distribution, which is the noise introduced to produce the analyzed image noiswom.mat from a piece of the original image woman.mat.

Page 185: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-117

Selecting a Thresholding Method.

7 From the Select thresholding method menu, choose the Penalize low item. The associated default for the thresholding mode is automatically set to hard; accept it. Use the Sparsity slider to adjust the threshold value close to 44.5, and then click the De-noise button.

The result is quite satisfactory. It’s possible to improve it slightly.

8 Select the sym6 wavelet and click the Decompose Image button. Use the Sparsity slider to adjust the threshold value close to 40.44, and then click the De-noise button.

Page 186: Wavelet ug

2 Using Wavelets

2-118

Importing and Exporting Information from the Graphical InterfaceThe tool lets you save the de-noised image to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the de-noised image from the present de-noising process, use the menu option File⇒Save De-noised Image. A dialog box appears that lets you specify a directory and filename for storing the image. Type the name dnoiswom. After saving the image data to the file dnoiswom.mat, load the variables into your workspace.

load dnoiswom

Page 187: Wavelet ug

Two-Dimensional Discrete Stationary Wavelet Analysis

2-119

whos

The de-noised image is X and map is the colormap. In addition, the parameters of the de-noising process are available. The wavelet name is contained in wname, and the level dependent thresholds are encoded in valTHR. The variable valTHR has four columns (the level of the decomposition) and three rows (one for each detail orientation).

Name Size Bytes Class

X 96x96 73728 double array map 255x3 6120 double array valTHR 3x4 96 double array wname 1x4 8 char array

Page 188: Wavelet ug

2 Using Wavelets

2-120

One-Dimensional Wavelet Regression Estimation This section takes you through the features of one-dimensional wavelet regression estimation using one of the MATLAB Wavelet Toolbox specialized tools. The MATLAB Wavelet Toolbox provides a graphical interface tool to explore some de-noising schemes for equally or unequally sampled data.

For the examples in this section, switch the extension mode to symmetric padding, using the command:

dwtmode('sym')

One-Dimensional Estimation Using the GUI for Equally Spaced Observations (Fixed Design)

Starting the Regression Estimation 1-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 189: Wavelet ug

One-Dimensional Wavelet Regression Estimation

2-121

2 Click the Regression Estimation 1-D menu item.

The discrete wavelet analysis tool for one-dimensional regression estimation appears.

Loading Data.

3 From the File menu, choose the Load Data for Fixed Design Regression option.

Page 190: Wavelet ug

2 Using Wavelets

2-122

4 When the Load data for Fixed Design Regression dialog box appears, select the demo MAT-file noisbloc.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo.

Click the OK button. The noisy blocks data is loaded into the Regression Estimation 1-D - Fixed Design tool.

The loaded data denoted (X,Y) and the processed data obtained after a binning, are displayed.

Choosing the Processed Data.

5 The default value for the number of bins is 256 for this example. Enter 64 in the Nb bins (number of bins) edit box, or use the slider to adjust the value. The new binned data to be processed appears.

The binned data appears to be very smoothed. Select 1000 from the Nb bins edit and press Enter or use the slider. The new data to be processed appears.

Initial data Processesed data

after a binning

Select number of bins

for the processed data

Page 191: Wavelet ug

One-Dimensional Wavelet Regression Estimation

2-123

The binned data appears to be very close to the initial data, since noisbloc is of length 1024.

Performing a Wavelet Decomposition of the Processed Data.

6 Select the haar wavelet from the Wavelet menu and select 5 from the Level menu, and then click the Decompose button. After a pause for computation, the tool displays the detail coefficients of the decomposition.

Performing a Regression Estimation.

While a number of options are available for fine-tuning the estimation algorithm, we’ll accept the defaults of fixed form soft thresholding and unscaled

Page 192: Wavelet ug

2 Using Wavelets

2-124

white noise. The sliders located to the right of the window control the level dependent thresholds, indicated by yellow dotted lines running horizontally through the graphs on the left part of the window.

7 Continue by clicking the Estimate button.

You can see that the process removed the noise and that the blocks are well reconstructed. The regression estimate (in yellow) is the sum of the signals located below it: the approximation a5 and the reconstructed details after coefficient thresholding.

You can experiment with the various predefined thresholding strategies by selecting the appropriate options from the menu located on the right part of the window or directly by dragging the yellow horizontal lines with the left mouse button.

Let us now illustrate the regression estimation using the graphical interface for randomly or irregularly spaced observations, focusing on the differences from the previous situation.

Page 193: Wavelet ug

One-Dimensional Wavelet Regression Estimation

2-125

One-Dimensional Estimation Using the GUI for Randomly Spaced Observations (Stochastic Design)

1 From the File menu, choose the Load⇒Data for Stochastic Design Regression option. When the Load data for Stochastic Design Regression dialog box appears, select the demo MAT-file ex1nsto.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. This short set of data (of size 500) is loaded into the Regression Estimation 1-D -- Stochastic Design tool.

The loaded data denoted (X,Y), the histogram of X, and the processed data obtained after a binning are displayed. The histogram is interesting, because the values of X are randomly distributed. The binning step is essential since it transforms a problem of regression estimation for irregularly spaced X data into a classical fixed design scheme for which fast wavelet transform can be used.

2 Select the sym4 wavelet from the Wavelet menu, select 5 from the Level menu, and enter 125 in the Nb bins edit box. Click the Decompose button. The tool displays the detail coefficients of the decomposition.

Page 194: Wavelet ug

2 Using Wavelets

2-126

3 From the Select thresholding method menu, select the item Penalize low and click the Estimate button.

4 Check Show Estimated Function to validate the fit of the original data.

Page 195: Wavelet ug

One-Dimensional Wavelet Regression Estimation

2-127

Importing and Exporting Information from the Graphical Interface

Saving FunctionThis tool lets you save the estimated function to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the estimated function from the present estimation, use the menu option File==>Save Estimated Function. A dialog box appears that lets you specify a directory and filename for storing the function. Type the name fex1nsto. After saving the function data to the file fex1nsto.mat, load the variables into your workspace

load fex1nsto whos

The estimated function is given by xdata and ydata. The length of these vectors is equal to the number of bins you choose in step 2. In addition, the parameters of the estimation process are given by the wavelet name contained in wname:

wname

wname =sym4

and the level dependent thresholds contained in thrParams, which is a cell array of length 5 (the level of the decomposition). For i from 1 to 5, thrParams{i} contains the lower and upper bounds of the interval of thresholding and the threshold value (since interval dependent thresholds are allowed). For more information, see “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 2-136.

Name Size Bytes Class

thrParams 1x5 580 cell array wname 1x4 8 char array xdata 1x125 1000 double array ydata 1x125 1000 double array

Page 196: Wavelet ug

2 Using Wavelets

2-128

For example, for level 1:

thrParams{1}

ans =-0.4987 0.4997 1.0395

Loading DataTo load data for regression estimation, your file must contain at least one vector. If your file contains only one vector, this vector is considered as ydata and an xdata vector is automatically generated.

If your file contains at least two vectors, they must be called xdata and ydata or x and y.

These vectors must be the same length.

For example, load the file containing the data considered in the previous example:

clearload ex1nstowhos

At the end of this section, turn back the extension mode to zero padding using the command:

dwtmode('zpd')

Name Size Bytes Class

x 1x500 4000 double array y 1x500 4000 double array

Page 197: Wavelet ug

One-Dimensional Wavelet Density Estimation

2-129

One-Dimensional Wavelet Density Estimation This section takes you through the features of one-dimensional wavelet density estimation using one of the MATLAB Wavelet Toolbox specialized tools. For more information, see “Function Estimation: Density and Regression” on page 6-109.

The MATLAB Wavelet Toolbox provides a graphical interface tool to estimate the density of a sample and complement well known tools like the histogram (available from the core of MATLAB) or kernel based estimates.

For the examples in this section, switch the extension mode to symmetric padding, using the command:

dwtmode('sym')

One-Dimensional Estimation Using the Graphical Interface

Starting the Density Estimation 1-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 198: Wavelet ug

2 Using Wavelets

2-130

2 Click the Density Estimation 1-D menu item.

The discrete wavelet analysis tool for one-dimensional density estimation appears.

Loading Data.

3 From the File menu, choose the Load⇒Data for Density Estimate option.

Page 199: Wavelet ug

One-Dimensional Wavelet Density Estimation

2-131

4 When the Load data for Density Estimate dialog box appears, select the demo MAT-file ex1cusp1.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. The noisy cusp data is loaded into the Density Estimation 1-D tool.

The sample, a 64-bin histogram, and the processed data obtained after a binning, are displayed. In this example, we’ll accept the default value for the number of bins (250). The binned data will be processed by wavelet decomposition.

Initial data Binned data

A 64-bins histogram of the data Select number of bins for the processed data

Page 200: Wavelet ug

2 Using Wavelets

2-132

Performing a Wavelet Decomposition of the Binned Data.

5 Select the sym6 wavelet from the Wavelet menu and select 4 from the Level menu, and then click the Decompose button. After a pause for computation, the tool displays the detail coefficients of the decomposition of the binned data.

Performing a Density Estimation.

We’ll accept the defaults of global soft thresholding. The sliders located on the right of the window control the level dependent thresholds, indicated by yellow dotted lines running horizontally through the graphs on the left of the window.

Page 201: Wavelet ug

One-Dimensional Wavelet Density Estimation

2-133

6 Continue by clicking the Estimate button.

You can see that the estimation process delivers a very irregular resulting density. The density estimate (in yellow) is the normalized sum of the signals located below it: the approximation a4 and the reconstructed details after coefficient thresholding.

You can experiment with the various predefined thresholding strategies by selecting the appropriate options from the menu located on the right of the window or directly by dragging the yellow lines with the left mouse button. Let’s try another estimation method.

Page 202: Wavelet ug

2 Using Wavelets

2-134

7 From the menu Select thresholding method, select the item By level threshold 2. For more information about these methods, see “Function Estimation: Density and Regression” on page 6-109. Next, click the Estimate button.

The estimated density is more satisfactory. It correctly identifies the smooth part of the density and the cusp at 0.7.

Importing and Exporting Information from the Graphical InterfaceThe tool lets you save the estimated density to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the estimated density, use the menu option File==>Save Density. A dialog box appears that lets you specify a directory and filename for storing the density. Type the name dex1cusp. After saving the density data to the file dex1cusp.mat, load the variables into your workspace.

load dex1cuspwhos

Page 203: Wavelet ug

One-Dimensional Wavelet Density Estimation

2-135

The estimated density is given by xdata and ydata. The length of these vectors is of the same as the number of bins you choose in step 4. In addition, the parameters of the estimation process are given by the wavelet name contained in wname.

wname

wname =sym6

and the level dependent thresholds contained in thrParams, which is a cell array of length 4 (the level of the decomposition). For i from 1 to 4, thrParams{i} contains the lower and upper bounds of the interval of thresholding and the threshold value (since interval dependent thresholds are allowed). For more information, see “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 2-136. For example, for level 1:

thrParams{1}

ans =0.0560 0.9870 7.9184

Note When you load data from a file using the menu option File⇒Load data for Density Estimate, the first one-dimensional variable encountered in the file is considered the signal. Variables are inspected in alphabetical order.

At the end of this section, turn the extension mode back to zero padding using the command:

dwtmode('zpd')

Name Size Bytes Class

thrParams 1x4 464 cell array wname 1x4 8 char array xdata 1x250 2000 double array ydata 1x250 2000 double array

Page 204: Wavelet ug

2 Using Wavelets

2-136

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients

This section takes you through the features of local thresholding of wavelet coefficients for one-dimensional signals or data. This capability is available through graphical interface tools throughout the MATLAB Wavelet Toolbox:

• Wavelet De-noising 1-D

• Wavelet Compression 1-D

• SWT De-noising 1-D

• Regression Estimation 1-D

• Density Estimation 1-D

This tool allows you to define, level by level, time-dependent (x-axis-dependent) thresholds, and then increase the capability of the de-noising strategies handling nonstationary variance noise. More precisely, the model assumes that the observation is equal to the interesting signal superimposed on noise. The noise variance can vary with time. There are several different variance values on several time intervals. The values as well as the intervals are unknown. This section will use one of the graphical interface tool (SWT De-noising 1-D) to illustrate this capability. The behavior of all the above mentioned tools is similar.

Page 205: Wavelet ug

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients

2-137

One-Dimensional Local Thresholding for De-noising Using the Graphical Interface

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

2 Click the SWT De-noising 1-D menu item.

The discrete stationary wavelet transform de-noising tool for one-dimensional signals appears.

Page 206: Wavelet ug

2 Using Wavelets

2-138

Loading Data.

3 From the File menu, choose the Load Signal option.

4 When the Load Signal dialog box appears, select the MAT-file nblocr1.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. The noisy blocks signal with two change points in the noise variance located at positions 200 and 600, is loaded into the SWT De-noising 1-D tool.

5 Select the db1 wavelet from the Wavelet menu and select 5 from the Level menu, and then click the Decompose Signal button. After a pause for computation, the tool displays the stationary wavelet approximation and detail coefficients of the decomposition.

6 Accept the defaults of Fixed form soft thresholding and Unscaled white noise. Click the De-noise button.

The result is quite satisfactory, but seems to be oversmoothed when the signal is irregular.

7 Select hard for the thresholding mode instead of soft, and then click the De-noise button.

Page 207: Wavelet ug

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients

2-139

The result is not satisfactory. The de-noised signal remains noisy before position 200 and after position 700. This illustrates the limits of the classical de-noising strategies. In addition, the residuals obtained during the last trials clearly suggest to try a local thresholding strategy.

Generating Interval Dependent Thresholds.

8 Click the Int. dependent threshold Settings button located at the bottom of the thresholding method frame. A new window entitled Int. Dependent Threshold Settings for figure ... appears.

Page 208: Wavelet ug

2 Using Wavelets

2-140

9 Click the Generate button. After a pause for computation, the tool displays the default intervals associated with adapted thresholds.

Three intervals are proposed. Since the variances for the three intervals are very different, the optimization program easily detects the correct structure. Nevertheless, you can visualize the intervals proposed for a number of intervals from 1 to 6 using the Select Number of Intervals menu (which replaces the Generate button). Using the default intervals automatically propagates the interval delimiters and associated thresholds to all levels.

De-noising with Interval Dependent Thresholds.

10 Click the Close button of the Int. Dependent Threshold Settings for ... window. When the Update thresholds dialog box appears, click Yes. The SWT De-noising 1-D main window is updated. The sliders located to the right of the window control the level and interval dependent thresholds. For a given interval, the threshold is indicated by yellow dotted lines running horizontally through the graphs on the left of the window. The red dotted lines running vertically through the graphs indicate the interval delimiters. Next click the De-noise button.

Page 209: Wavelet ug

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients

2-141

The result is quite satisfactory, but some unpleasant coefficients remain.

Modifying Interval Dependent Thresholds.

11 The thresholds can be increased to keep only the highest values of the wavelet coefficients at each level. Do this by dragging the yellow lines directly on the graphs on the left of the window, or using the View Axes button (located at the bottom of the screen near the Close button), which allows you to see each axis in full size. Another way is to edit the thresholds by selecting the interval number located near the sliders and typing the desired value.

Page 210: Wavelet ug

2 Using Wavelets

2-142

Note that you can also change the interval limits by holding down the left mouse button over the vertical dotted red lines, and dragging them.

12 You can also define your own interval dependent strategy. Click the Int. dependent threshold settings button. The Int. Dependent Threshold Settings for ... window appears again. We shall explore this window for a little while. Click the Delete button, so that the interval delimiters disappear. Double click the left mouse button to define new interval delimiters; for example at positions 300 and 500 and adjust the thresholds manually. Each level must be considered separately using the Level menu for adjusting the thresholds. The current interval delimiters can be propagated to all levels by clicking the Propagate button. So click the Propagate button. Adjust the thresholds for each level, one by one. At the end, click the Close button of the Int. Dependent Threshold settings for ... window. When the Update thresholds dialog box appears, click Yes. Then click the De-noise button.

Note that:

a By double clicking again on an interval delimiter with the left mouse button, you delete it.

b You can move the interval delimiters (vertical red dotted lines) and the threshold levels (horizontal yellow dotted lines) by holding down the left mouse button over these lines and dragging them.

c The maximum number of interval delimiters at each level is 10.

Some Examples of De-noising with Interval Dependent Thresholds.

13 From the File menu, choose the Example Analysis⇒Noisy Signals - Dependent Noise Variance option. The proposed items contain, in addition to the usual information, the “true” number of intervals. You can then experiment with various signals for which local thresholding is needed.

For example, choose the last item, which is a real-world electrical signal. The entire process performed on steps 4, 5, 8, 9 and 10 is demonstrated.

Page 211: Wavelet ug

One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients

2-143

Importing and Exporting Information from the Graphical InterfaceThe tool lets you save the de-noised signal to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the de-noised signal from the present de-noising process, use the menu option File==>Save De-noised Signal. A dialog box appears that lets you specify a directory and filename for storing the signal. Type the name dnelec. After saving the signal data to the file dnelec.mat, load the variables into your workspace.

load dnelec whos

Name Size Bytes Class

dnelec 1x2000 16000 double array thrParams 1x4 656 cell array wname 1x4 8 char array

Page 212: Wavelet ug

2 Using Wavelets

2-144

The de-noised signal is given by dnelec. In addition, the parameters of the de-noising process are given by the wavelet name contained in wname:

wname

wname =haar

and the level dependent thresholds contained in thrParams, which is a cell array of length 4 (the level of the decomposition). For i from 1 to 4, thrParams{i} is an array nbintx3 (where nbint is the number of intervals, here 3), and each row contains the lower and upper bounds of the interval of thresholding and the threshold value. For example, for level 1:

thrParams{1}ans =

1.0e+03 *

0.0010 0.0980 0.00600.0980 1.1240 0.02041.1240 2.0000 0.0049

Page 213: Wavelet ug

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-145

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

This section takes you through the features of one-dimensional selection of wavelet coefficients using one of the MATLAB Wavelet Toolbox specialized tools. The MATLAB Wavelet Toolbox provides a graphical interface tool to explore some reconstruction schemes based on various wavelet coefficients selection strategies:

• Global selection of biggest coefficients (in absolute value)

• By level selection of biggest coefficients

• Automatic selection of biggest coefficients

• Manual selection of coefficients

For this section, switch the extension mode to symmetric padding using the command:

dwtmode('sym')

Starting the Wavelet Coefficients Selection 1-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 214: Wavelet ug

2 Using Wavelets

2-146

2 Click the Wavelet Coefficients Selection 1-D menu item.

The discrete wavelet coefficients selection tool for one-dimensional signals appears.

Loading Data.

3 From the File menu, choose the Load Signal option.

4 When the Load Signal dialog box appears, select the demo MAT-file noisbump.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. The noisy bumps data is loaded into the Wavelet Coefficients Selection 1-D tool.

Performing a Wavelet Decomposition.

5 Select the db3 wavelet from the Wavelet menu and select 6 from the Level menu, and then click the Analyze button.

Page 215: Wavelet ug

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-147

The tool displays below the original signal (on the left) its wavelet decomposition: the approximation coefficients A6 and detail coefficients from D6 at the top to D1 at the bottom. In the middle of the window, below the synthesized signal (which at this step is the same, since all the wavelet coefficients are kept) it displays the selected coefficients.

Selecting Biggest Coefficients Globally.

6 On the right of the window, find a column labeled Kept. The last line shows the total number of coefficients: 1049. This is a little bit more than the number of observations, which is 1024. You can choose the number of selected biggest coefficients by typing a number instead of 1049 or by using the slider. Type 40 and press Enter. The numbers of selected biggest coefficients level by level are updated (but cannot be modified since Global is the current selection method). Then click the Apply button. The resulting coefficients are now displayed.

Page 216: Wavelet ug

2 Using Wavelets

2-148

7 In the previous trial, the approximation coefficients were all kept. It is possible to relax this constraint by selecting another option from the App. cfs menu (Approximation Coefficients abbreviation). Choose the Unselect option and click the Apply button.

None of the approximation coefficients are kept.

Page 217: Wavelet ug

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-149

8 From the App. cfs menu, select the Selectable option. Type 80 for the number of selected biggest coefficients and press Enter. Then, click the Apply button.

Some of the approximation coefficients (15) have been kept.

Selecting Biggest Coefficients by Level.

9 From the Define Selection method menu, select the By Level option. You can choose the number of selected biggest coefficients by level or select it using the sliders. Type 4 for the approximation and each detail, and then click the Apply button.

Page 218: Wavelet ug

2 Using Wavelets

2-150

Selecting Coefficients Manually.

10 From the Define Selection method menu, select the Manual option. The tool displays on the left part, below the original signal, its wavelet decomposition. At the beginning, no coefficients are kept so no selected coefficient is visible and the synthesized signal is null.

11 Select seven coefficients individually by double clicking each of them using the left mouse button. The color of selected coefficients switches from green to yellow for the details and from blue to yellow for the approximation, which appear on the left of the window and appear in yellow on the middle part. Click the Apply button.

Page 219: Wavelet ug

One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-151

12 You can deselect the currently selected coefficients by double clicking each of them. Another way to select or deselect a set of coefficients is to use the selection box. Drag a rubber band box (hold down the left mouse button) over a portion of the coefficient axes (original or selected) containing all the currently selected coefficients. Click the Unselect button located on the right of the window. Click the Apply button. The tool displays the null signal again.

Note that when the coefficients are very close, it is easier to zoom in before selecting or deselecting them.

13 Drag a rubber band box over the portion of the coefficient axes around the position 800 and containing all scales and click the Select button. Click the Apply button.

This illustrates that wavelet analysis is a local analysis since the signal is perfectly reconstructed around the position 800. Check the Show Original Signal to magnify it.

Selecting Coefficients Automatically.

14 From the Define Selection method menu, select the Stepwise movie option. The tool displays the same initial window as in the manual selection mode, except for the left part of it.

Page 220: Wavelet ug

2 Using Wavelets

2-152

Let’s perform the stepwise movie using the k biggest coefficients, from k = 1 to k = 31 in steps of 1, click the Start button. As soon as the result is satisfactory, click the Stop button.

Saving the Synthesized Signal.

The tool lets you save the synthesized signal to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

15 To save the synthesized signal from the present selection, use the menu option File==>Save Synthesized Signal. A dialog box appears that lets you specify a directory and filename for storing the signal and the wavelet name.

At the end of this section, turn back the extension mode to zero padding using the command:

dwtmode('zpd')

Page 221: Wavelet ug

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-153

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

This section takes you through the features of two-dimensional selection of wavelet coefficients using one of the MATLAB Wavelet Toolbox specialized tools. The MATLAB Wavelet Toolbox provides a graphical interface tool to explore some reconstruction schemes based on various wavelet coefficient selection strategies:

• Global selection of biggest coefficients (in absolute value)

• By level selection of biggest coefficients

• Automatic selection of biggest coefficients.

This section will be short since the functionality are similar to the one-dimensional ones examined in the previous section.

For this section, switch the extension mode to symmetric padding using the command:

dwtmode('sym')

Starting the Wavelet Coefficients Selection 2-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 222: Wavelet ug

2 Using Wavelets

2-154

2 Click the Wavelet Coefficients Selection 2-D menu item.

The discrete wavelet coefficients selection tool for images appears.

Loading Data.

3 From the File menu, choose the Load Image option.

4 When the Load Image dialog box appears, select the demo MAT-file noiswom.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. The noisy woman data is loaded into the Wavelet Coefficients Selection 2-D tool.

Performing a Wavelet Decomposition.

5 Select the sym4 wavelet from the Wavelet menu and select 4 from the Level menu, and then click the Analyze button.

Page 223: Wavelet ug

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-155

The tool displays its wavelet decomposition below the original image (on the left). The selected coefficients are displayed in the middle of the window, below the synthesized image (which, at this step, is the same since all the wavelet coefficients are kept). There are 11874 coefficients, a little bit more than the original image number of pixels, which is 96x96 = 9216.

Note The difference between 9216 and 11874 comes from the extra coefficients generated by the redundant DWT using the current extension mode (symmetric, ’sym’). Let us mention that since 96 is divisible evenly into 24 = 16, using the periodic extension mode (’per’) for the DWT, you obtain for each level the minimum number of coefficients. More precisely, if you type dwtmode('per') and repeat steps 2 to 5, you get the figure displayed below

Page 224: Wavelet ug

2 Using Wavelets

2-156

.

Selecting Biggest Coefficients Globally.

6 On the right of the window, find a column labeled Kept. The last line shows the total number of coefficients: 11874. This is a little bit more than the original image number of pixels. You can choose the number of selected biggest coefficients by typing a number instead of 11874, or by using the slider. Type 1100 and press Enter. The numbers of selected biggest coefficients level by level are updated (but cannot be modified, since Global is the current selection method).

Then click the Apply button.

Page 225: Wavelet ug

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-157

7 In the previous trial, the approximation coefficients were all kept. It is possible to relax this constraint by selecting another option from the App. cfs menu (see “One-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface” on page 2-145).

Selecting Biggest Coefficients by Level.

8 From the Define Selection method menu, select the By Level option. You can choose the number of selected biggest coefficients by level, or select it using the sliders. Type 100 for each detail, and then click the Apply button.

Page 226: Wavelet ug

2 Using Wavelets

2-158

Selecting Coefficients Automatically.

9 From the Define Selection method menu, select the Stepwise movie option. The tool displays its wavelet decomposition on the left, below the original image. At the beginning, no coefficients are kept so the synthesized image is null. Perform the stepwise movie using the k biggest coefficients, from k = 144 to k = 1500, in steps of 20. Click the Start button. As soon as the result is satisfactory, click the Stop button.

Page 227: Wavelet ug

Two-Dimensional Selection of Wavelet Coefficients Using the Graphical Interface

2-159

We’ve stopped the movie at 864 coefficients (including the number of approximation coefficients).

Saving the Synthesized Image.

This tool lets you save the synthesized image to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

10 To save the synthesized image from the present selection, use the menu option File==>Save Synthesized Image. A dialog box appears that lets you specify a directory and filename for storing the image and, in addition, the colormap and the wavelet name.

At the end of this section, turn back the extension mode to zero padding using the command:

dwtmode('zpd')

Page 228: Wavelet ug

2 Using Wavelets

2-160

One-Dimensional ExtensionThis section takes you through the features of one-dimensional extension or truncation using one of the MATLAB Wavelet Toolbox utilities.

One-Dimensional Extension Using the Command LineThe function wextend performs signal extension. For more information, see the wextend reference page.

One-Dimensional Extension Using the Graphical Interface

Starting the Signal Extension Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 229: Wavelet ug

One-Dimensional Extension

2-161

2 Click the Signal Extension menu item.

Loading Data.

3 From the File menu, choose the Load Signal option.

4 When the Load Signal dialog box appears, select the demo MAT-file noisbloc.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button. The noisy blocks data is loaded into the Signal Extension tool.

Extending the Signal.

5 Enter 1300 in the Desired Length box of the extended signal, and select the Left option from the Direction to extend menu. Then accept the default Symmetric for the Extension mode, and click the Extend button.

Page 230: Wavelet ug

2 Using Wavelets

2-162

The tool displays the original signal delimited by a red box and the transformed signal delimited by a yellow box. The signal has been extended by left symmetric boundary values replication.

6 Select the Both option from the Direction to extend menu and select the Continuous option from the Extension mode menu. Click the Extend button.

Page 231: Wavelet ug

One-Dimensional Extension

2-163

The signal is extended in both directions by replicating the first value to the left and the last value to the right, respectively.

Extending Signal for SWT.

Since the decomposition at level k of a signal using SWT requires that 2^k divides evenly into the length of the signal, the tool provides a special option dedicated to this kind of extension.

7 Select the For SWT option from the Extension mode menu. Click the Extend button.

Page 232: Wavelet ug

2 Using Wavelets

2-164

Since the signal is of length 1024 = 2^10, no extension is needed so the Extend button is ineffective.

8 From the File menu, choose the Example Extension option and select the last item of the list

.

Page 233: Wavelet ug

One-Dimensional Extension

2-165

Since the signal is of length 1000 and the decomposition level needed for SWT is 10, the tool performs a minimal right periodic extension. The extended signal is of length 1024.

9 Select 4 from the SWT Decomposition Level menu, and then click the Extend button. The tool performs a minimal right periodic extension leading to an extended signal of length 1008 (because 1008 is the smallest integer greater than 1000 divisible by 2^4 = 16).

10 Select 2 from the SWT Decomposition Level menu. Since 1000 is divisible by 4, no extension is needed.

Truncating Signal.

The same tool allows you to truncate a signal.

11 Since truncation is not allowed for the special mode For SWT, select the Periodic option from the Extension mode menu. Type 900 for the desired length and press Enter. Click the Truncate button

.

Page 234: Wavelet ug

2 Using Wavelets

2-166

The tool displays the original signal delimited by a red box and the truncated signal delimited by a yellow box. The signal has been truncated by deleting 100 values on the right side.

Importing and Exporting Information from the Graphical InterfaceThis tool lets you save the transformed signal to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the transformed signal, use the menu option File==>Save Transformed Signal. A dialog box appears that lets you specify a directory and filename for storing the image. Type the name tfrqbrk. After saving the signal data to the file tfrqbrk.mat, load the variable into your workspace.

load tfrqbrkwhos

Name Size Bytes Class

tfrqbrk 1x900 7200 double array

Page 235: Wavelet ug

Two-Dimensional Extension

2-167

Two-Dimensional ExtensionThis section takes you through the features of two-dimensional extension or truncation using one of the MATLAB Wavelet Toolbox utilities. This section is short since it is very similar to “One-Dimensional Extension” on page 2-160.

Two-Dimensional Extension Using the Command LineThe function wextend performs image extension. For more information, see the wextend reference page.

Two-Dimensional Extension Using the Graphical Interface

Starting the Image Extension Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

Page 236: Wavelet ug

2 Using Wavelets

2-168

2 Click the Image Extension menu item.

Extending (or Truncating) Image.

3 From the File menu, choose the Example Extension option and select the first item of the list.

The tool displays the original image delimited by a red box and the transformed image delimited by a yellow box. The image has been extended by zero padding. The right part of the window allows you to control the parameters of the extension/truncation process for the vertical and horizontal directions, respectively. The possibilities are similar to the one-dimensional ones described in “One-Dimensional Extension” on page 2-160.

To see some more extension cases, look at the general demos of the toolbox (using the wavedemo command).

Page 237: Wavelet ug

Two-Dimensional Extension

2-169

Importing and Exporting Information from the Graphical InterfaceThis tool lets you save the transformed image to disk. The toolbox creates a MAT-file in the current directory with a name you choose.

To save the transformed image, use the menu option:

File==>Save Transformed Image.

A dialog box appears that lets you specify a directory and filename for storing the image. Type the name woman2. After saving the image data to the file woman2.mat, load the variable into your workspace.

load woman2whos

The transformed image is stored together with its colormap.

Name Size Bytes Class

woman2 200x220 352000 double array map 253x3 6120 double array

Page 238: Wavelet ug

2 Using Wavelets

2-170

Page 239: Wavelet ug

3

Wavelet Applications

Detecting Discontinuities and Breakdown Points I . . 3-3Discussion . . . . . . . . . . . . . . . . . . . . . 3-4

Detecting Discontinuities and Breakdown Points II . . 3-6Discussion . . . . . . . . . . . . . . . . . . . . . 3-7

Detecting Long-Term Evolution . . . . . . . . . . . 3-8Discussion . . . . . . . . . . . . . . . . . . . . . 3-9

Detecting Self-Similarity . . . . . . . . . . . . . . 3-10Wavelet Coefficients and Self-Similarity . . . . . . . . . 3-10Discussion . . . . . . . . . . . . . . . . . . . . . 3-11

Identifying Pure Frequencies . . . . . . . . . . . . 3-12Discussion . . . . . . . . . . . . . . . . . . . . . 3-12

Suppressing Signals . . . . . . . . . . . . . . . . 3-15Discussion . . . . . . . . . . . . . . . . . . . . . 3-16

De-Noising Signals . . . . . . . . . . . . . . . . . 3-18Discussion . . . . . . . . . . . . . . . . . . . . . 3-18

De-noising Images . . . . . . . . . . . . . . . . . 3-21Discussion . . . . . . . . . . . . . . . . . . . . . 3-22

Compressing Images . . . . . . . . . . . . . . . . 3-26Discussion . . . . . . . . . . . . . . . . . . . . . 3-27

Fast Multiplication of Large Matrices . . . . . . . . 3-28

Page 240: Wavelet ug

3 Wavelet Applications

3-2

This chapter explores various applications of wavelets by presenting a series of sample analyses. Major sections are:

• “Detecting Discontinuities and Breakdown Points I”

• “Detecting Discontinuities and Breakdown Points II” on page 3-6

• “Detecting Long-Term Evolution” on page 3-8

• “Detecting Self-Similarity” on page 3-10

• “Identifying Pure Frequencies” on page 3-12

• “Suppressing Signals” on page 3-15

• “De-Noising Signals” on page 3-18

• “De-noising Images” on page 3-21

• “Compressing Images” on page 3-26

• “Fast Multiplication of Large Matrices” on page 3-28

Each example is followed by a discussion of the usefulness of wavelet analysis for the particular application area under consideration.

Use the graphical interface tools to follow along:

1 From the MATLAB command line, type:

wavemenu

2 Click on Wavelets 1-D (or another tool as appropriate).

3 Load the sample analysis by selecting the appropriate submenu item from File⇒Example Analysis.

Feel free to explore on your own — use the different options provided in the graphical interface to look at different components of the signal, to compress or de-noise the signal, to examine signal statistics, or to zoom in and out on different signal features.

If you want, try loading the corresponding MAT-file from the MATLAB command line, and use the Wavelet Toolbox functions to further investigate the sample signals. The MAT-files are located in the directory: toolbox/wavelet/wavedemo.

There are also other signals in the wavedemo directory that you can analyze on your own.

Page 241: Wavelet ug

Detecting Discontinuities and Breakdown Points I

3-3

Detecting Discontinuities and Breakdown Points IThe purpose of this example is to show how analysis by wavelets can detect the exact instant when a signal changes. The discontinuous signal consists of a slow sine wave abruptly followed by a medium sine wave.

The first- and second-level details (D1 and D2) show the discontinuity most clearly, because the rupture contains the high-frequency part. Note that if we were only interested in identifying the discontinuity, db1 would be a more useful wavelet to use for the analysis than db5.

The discontinuity is localized very precisely: only a small domain around time = 500 contains any large first- or second-level details.

Here is a noteworthy example of an important advantage of wavelet analysis over Fourier. If the same signal had been analyzed by the Fourier transform,

100 200 300 400 500 600 700 800 900 1000

−0.20

0.20.4

d1

−0.10

0.10.2

d2

−0.5

0

0.5

d3

−1

0

1

d4

−0.2

0

0.2

d5

−1

0

1

a5

−1

0

1

s

Decomposition at level 5 : s = a5 + d5 + d4 + d3 + d2 + d1 . Example Analysis:Frequency breakdownMAT-file:freqbrk.mat

Wavelet:db5

Level:5

Page 242: Wavelet ug

3 Wavelet Applications

3-4

we would not have been able to detect the instant when the signal’s frequency changed, whereas it is clearly observable here.

Details D3 and D4 contain the medium sine wave. The slow sine is clearly isolated in approximation A5, from which the higher-frequency information has been filtered.

DiscussionThe deterministic part of the signal may undergo abrupt changes such as a jump, or a sharp change in the first or second derivative. In image processing, one of the major problems is edge detection, which also involves detecting abrupt changes. Also in this category, we find signals with very rapid evolutions such as transient signals in dynamic systems.

The main characteristic of these phenomena is that the change is localized in time or in space.

The purpose of the analysis is to determine:

• The site of the change (e.g., time or position)

• The type of change (a rupture of the signal, or an abrupt change in its first or second derivative)

• The amplitude of the change

The local aspects of wavelet analysis are well adapted for processing this type of event, as the processing scales are linked to the speed of the change.

Guidelines for Detecting DiscontinuitiesShort wavelets are often more effective than long ones in detecting a signal rupture. In the initial analysis scales, the support is small enough to allow fine analysis. The shapes of discontinuities that can be identified by the smallest wavelets are simpler than those that can be identified by the longest wavelets.

Therefore, to identify:

• A signal discontinuity, use the haar wavelet

• A rupture in the j-th derivative, select a sufficiently regular wavelet with at least j vanishing moments. (See “Detecting Discontinuities and Breakdown Points II” on page 3-6.)

Page 243: Wavelet ug

Detecting Discontinuities and Breakdown Points I

3-5

The presence of noise, which is after all a fairly common situation in signal processing, makes identification of discontinuities more complicated. If the first levels of the decomposition can be used to eliminate a large part of the noise, the rupture is sometimes visible at deeper levels in the decomposition.

Check, for example, the sample analysis File⇒Example Analysis⇒Basic Signals⇒ramp + white noise (MAT-file wnoislop). The rupture is visible in the level-six approximation (A6) of this signal.

Page 244: Wavelet ug

3 Wavelet Applications

3-6

Detecting Discontinuities and Breakdown Points IIThe purpose of this example is to show how analysis by wavelets can detect a discontinuity in one of a signal’s derivatives. The signal, while apparently a single smooth curve, is actually composed of two separate exponentials that are connected at time = 500. The discontinuity occurs only in the second derivative, at time = 500.

We have zoomed in on the middle part of the signal to show more clearly what happens around time = 500. The details are high only in the middle of the signal and are negligible elsewhere. This suggests the presence of high-frequency information — a sudden change or discontinuity — around time = 500.

400 450 500 550 600−6

−4

−2

0

2

4

x 10−7

d1

−2

−1

0

1

2

x 10−6

d2

0.6

0.8

1

1.2

a2

0.7

0.8

0.9

1

1.1

1.2

s

Decomposition at level 2 : s = a2 + d2 + d1 . Example Analysis:Second derivative breakdown

MAT-file:scddvbrk.mat

Wavelet:db4

Level:2

Page 245: Wavelet ug

Detecting Discontinuities and Breakdown Points II

3-7

DiscussionRegularity can be an important criterion in selecting a wavelet. We have chosen to use db4, which is sufficiently regular for this analysis. Had we chosen the haar wavelet, the discontinuity would not have been detected. If you try repeating this analysis using haar at level two, you’ll notice that the details are equal to zero at time = 500.

Note that to detect a singularity, the selected wavelet must be sufficiently regular, which implies a longer filter impulse response.

See the sections “Frequently Asked Questions” on page 6-54 and “Wavelet Families: Additional Discussion” on page 6-65 for a discussion of the mathematical meaning of regularity and a comparison of the regularity of various wavelets.

Page 246: Wavelet ug

3 Wavelet Applications

3-8

Detecting Long-Term EvolutionThe purpose of this example is to show how analysis by wavelets can detect the overall trend of a signal. The signal in this case is a ramp obscured by “colored” (limited-spectrum) noise. (We have zoomed in along the x-axis to avoid showing edge effects.)

There is so much noise in the original signal, s, that its overall shape is not apparent upon visual inspection. In this level-6 analysis, we note that the trend becomes more and more clear with each approximation, A1 to A6. Why is this?

The trend represents the slowest part of the signal. In wavelet analysis terms, this corresponds to the greatest scale value. As the scale increases, the resolution decreases, producing a better estimate of the unknown trend.

100 200 300 400 500 600 700 800 900 10000

0.5

1a1

0.20.40.60.8

11.2

a2

0.20.40.60.8

11.2

a3

0.5

1

a4

0.5

1

a5

0.5

1

a6

−10123

s

Signal and Approximation(s) Example Analysis:Ramp + colored noise

MAT-file:cnoislop.mat

Wavelet:db3

Level:6

Page 247: Wavelet ug

Detecting Long-Term Evolution

3-9

Another way to think of this is in terms of frequency. Successive approximations possess progressively less high-frequency information. With the higher frequencies removed, what’s left is the overall trend of the signal.

DiscussionWavelet analysis is useful in revealing signal trends, a goal that is complementary to the one of revealing a signal hidden in noise. It’s important to remember that the trend is the slowest part of the signal. If the signal itself includes sharp changes, then successive approximations look less and less similar to the original signal.

Consider the demo analysis File⇒Example Analysis⇒Basic Signals⇒Step signal (MAT-file wstep.mat). It is instructive to analyze this signal using the Wavelet 1-D tool and see what happens to the successive approximations. Try it.

Page 248: Wavelet ug

3 Wavelet Applications

3-10

Detecting Self-SimilarityThe purpose of this example is to show how analysis by wavelets can detect a self-similar, or fractal, signal. The signal here is the Koch curve — a synthetic signal that is built recursively.

This analysis was performed with the Continuous Wavelet 1-D graphical tool. A repeating pattern in the wavelet coefficients plot is characteristic of a signal that looks similar on many scales.

Wavelet Coefficients and Self-SimilarityFrom an intuitive point of view, the wavelet decomposition consists of calculating a “resemblance index” between the signal and the wavelet. If the index is large, the resemblance is strong, otherwise it is slight. The indices are the wavelet coefficients.

3300 3400 3500 3600 3700 3800 3900 4000 41000

0.05

0.1

Analyzed Signal (length = 8192)

Scale of colors from MIN to MAX

Ca,b Coefficients − Coloration mode : current + by scale + abs

2

10

18

26

34

42

50

58

66

74

82

90

98

106

114

122

Example Analysis:Koch curve

MAT-file:vonkoch.mat

Wavelet:coif3

Level:Continuous, 2:2:128

Page 249: Wavelet ug

Detecting Self-Similarity

3-11

If a signal is similar to itself at different scales, then the “resemblance index,” or wavelet coefficients also will be similar at different scales. In the coefficients plot, which shows scale on the vertical axis, this self-similarity generates a characteristic pattern.

DiscussionThe work of many authors and the trials that they have carried out suggest that wavelet decomposition is very well adapted to the study of the fractal properties of signals and images.

When the characteristics of a fractal evolve with time and become local, the signal is called a multifractal. The wavelets then are an especially suitable tool for practical analysis and generation.

Page 250: Wavelet ug

3 Wavelet Applications

3-12

Identifying Pure FrequenciesThe purpose of this example is to show how analysis by wavelets can effectively perform what is thought of as a Fourier-type function — that is, resolving a signal into constituent sinusoids of different frequencies. The signal is a sum of three pure sine waves.

DiscussionThe signal is a sum of three sines: slow, medium, and rapid, which have periods (relative to the sampling period of 1) of 200, 20, and 2, respectively.

The slow, medium, and rapid sinusoids appear most clearly in approximation A4, detail D4, and detail D1, respectively. The slight differences that can be observed on the decompositions can be attributed to the sampling period.

200 400 600 800 1000

−1

0

1

a1

−2

0

2

a2

−2

0

2

a3

−1

0

1

a4

−1

0

1

a5

−2

0

2

s

Signal and Approximation(s)

−2

0

2

s

Signal and Detail(s)

−0.1

0

0.1

d5

−1

0

1

d4

−0.5

0

0.5

d3

−0.1

0

0.1

d2

200 400 600 800 1000−1

0

1

d1

Example Analysis:Sum of sines

MAT-file:sumsin.mat

Wavelet:db3

Level:5

Page 251: Wavelet ug

Identifying Pure Frequencies

3-13

Detail D1 contains primarily the signal components whose period is between 1 and 2 (i.e., the rapid sine), but this period is not visible at the scale which is used for the graph. Zooming in on detail D1 (see below) reveals that each “belly” is composed of 10 oscillations, and this can be used to estimate the period. We indeed find that it is close to 2.

The detail D3 and (to an even greater extent), the detail D4 contain the medium sine frequencies. We notice that there is a breakdown between approximations A3 and A4, from which the medium frequency information has been subtracted. We should therefore use approximations A1 to A3 to estimate the period of the medium sine. Zooming in on A1 reveals a period of around 20.

Now only the period of the slow sine remains to be determined. Examination of approximation A4 (see the figure in “Identifying Pure Frequencies” on page 3-12) shows that the distance between two successive maximums is 200.

Page 252: Wavelet ug

3 Wavelet Applications

3-14

This slow sine still is visible in approximation A5, but were we to extend this analysis to further levels, we would find that it disappears from the approximation and moves into the details at level 8.

This also can be obtained automatically using the scal2frq function, which associates for a given wavelet, pseudo-frequencies to scales.

lev = [1:5]; a = 2.^lev; % scales.wname ='db3';delta = 1;f = scal2frq(a,wname,delta); % corresponding pseudo-frequencies.per = 1./f; % corresponding pseudo-periods.

Leading to

In summation, we have used wavelet analysis to determine the frequencies of pure sinusoidal signal components. We were able to do this because the different frequencies predominate at a different scales, and each scale is taken into account by our analysis.

Signal Component Found in Period Frequency

Slow sine Approximation A4 200 0.005

Medium sine Detail D4 20 0.05

Rapid sine Detail D1 2 0.5

Level Scale Pseudo-Period Pseudo-Frequency

1 2 2.5 0.4

2 4 5 0.2

3 8 10 0.1

4 16 20 0.05

5 32 40 0.025

Page 253: Wavelet ug

Suppressing Signals

3-15

Suppressing SignalsThe purpose of this example is to illustrate the property that causes the decomposition of a polynomial to produce null details, provided the number of vanishing moments of the wavelet (N for a Daubechies wavelet dbN) exceeds the degree of the polynomial. The signal here is a second-degree polynomial combined with a small amount of white noise.

Note that only the noise comes through in the details. The peak-to-peak magnitude of the details is about 2, while the amplitude of the polynomial signal is on the order of 105.

The db3 wavelet, which has three vanishing moments, was used for this analysis. Note that a wavelet of the Daubechies family with fewer vanishing moments would fail to suppress the polynomial signal. For more information, see the section “Daubechies Wavelets: dbN” on page 6-66.

0

2

4

6

8

x 105

s

Signal and Detail(s)

−1

0

1

d4

−1

0

1

d3

−1

0

1

d2

350 400 450 500 550 600 650−1

0

1

d1

Example Analysis:Noisy polynomial

MAT-file:noispol.mat

Wavelet:db3

Level:4

Page 254: Wavelet ug

3 Wavelet Applications

3-16

Here is what the first three details look like when we perform the same analysis with db2.

The peak-to-peak magnitudes of the details D1, D2, and D3 are 2, 10, and 40, respectively. These are much higher detail magnitudes than those obtained using db3.

DiscussionFor the db2 analysis, the details for levels 2 to 4 show a periodic form that is very regular, and that increases with the level. This is explained by the fact that the detail for level j takes into account primarily the fluctuations of the polynomial function around its mean value on dyadic intervals that are 2j long. The fluctuations are periodic and very large in relation to the details of the noise decomposition.

−20

−10

0

10

20

d3

Detail(s)

−5

0

5

d2

350 400 450 500 550 600 650−2

−1

0

1

2

d1

Page 255: Wavelet ug

Suppressing Signals

3-17

On the other hand, for the db3 analysis, we find the presence of white noise thus indicating that the polynomial does not come into play in any of the details. The wavelet suppresses the polynomial part and analyzes the noise.

Suppressing part of a signal allows us to highlight the remainder.

Vanishing MomentsThe ability of a wavelet to suppress a polynomial depends on a crucial mathematical characteristic of the wavelet called its number of vanishing moments. A technical discussion of vanishing moments appears in the sections “Frequently Asked Questions” on page 6-54 and “Wavelet Families: Additional Discussion” on page 6-65. For the present discussion, it suffices to think of “moment” as an extension of “average.” Since a wavelet’s average value is zero, it has (at least) one vanishing moment.

More precisely, if the average value of is zero (where is the wavelet function), for then the wavelet has vanishing moments and polynomials of degree n are suppressed by this wavelet.

xkψ x( ) ψ x( )k 0 … n,, ,= n 1+

Page 256: Wavelet ug

3 Wavelet Applications

3-18

De-Noising SignalsThe purpose of this example is to show how to de-noise a signal using wavelet analysis. This example also gives us an opportunity to demonstrate the automatic thresholding feature of the Wavelet 1-D graphical interface tool. The signal to be analyzed is a Doppler-shifted sinusoid with some added noise.

DiscussionWe note that the highest frequencies appear at the start of the original signal. The successive approximations appear less and less noisy; however, they also lose progressively more high-frequency information. In approximation A5, for example, about the first 20% of the signal is truncated.

200 400 600 800 1000

−5

0

5

a1

−5

0

5

a2

−5

0

5

a3

−5

0

5

a4

−5

0

5

a5

−5

0

5

s

Signal and Approximation(s)

−5

0

5

s

cfs

Coefs, Signal and Detail(s)

54321

−4−2

02

d5

−5

0

5

d4

−20

2

d3

−2

0

2

d2

200 400 600 800 1000−2

0

2

d1

Example Analysis:Noisy Doppler

MAT-file:noisdopp.mat

Wavelet:sym4

Level:5

Page 257: Wavelet ug

De-Noising Signals

3-19

Click the De-noise button to bring up the Wavelet 1-D De-noising window. This window shows each detail along with its automatically set de-noising threshold.

Press the De-noise button. On the screen, the original and de-noised signals appear superimposed in red and yellow, respectively.

−20

0

20

d5

Original details coefficients

−10

0

10

d4

−5

0

5

d3

−4

−2

0

2

4

d2

200 400 600 800 1000

−2

0

2

d1

200 400 600 800 1000

−5

0

5

Original and de−noised signals

Page 258: Wavelet ug

3 Wavelet Applications

3-20

Note that the de-noised signal is flat initially. Some of the highest-frequency signal information was lost during the de-noising process, although less was lost here than in the higher level approximations A4 and A5.

For this signal, wavelet packet analysis does a better job of removing the noise without compromising the high-frequency information. Explore on your own: try repeating this analysis using the Wavelet Packet 1-D tool. Select the menu item File⇒Example Analysis⇒noisdopp.

Page 259: Wavelet ug

De-noising Images

3-21

De-noising ImagesThe purpose of this example is to show how to de-noise an image using both a two-dimensional wavelet analysis and a two-dimensional stationary wavelet analysis. De-noising is one of the most important applications of wavelets.

The image to be de-noised is a noisy version of a piece of the following image.

For this example, switch the extension mode to symmetric padding using the command:

dwtmode('sym')

Open the Wavelet 2-D tool, select from the File menu the Load Image option and select the MAT-file noiswom.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo.

The image is loaded into the Wavelet 2-D tool. Select the haar wavelet and select 4 from the level menu, and then click the Analyze button.

Original Image

50 100 150 200 250

50

100

150

200

250

Page 260: Wavelet ug

3 Wavelet Applications

3-22

The analysis appears in the Wavelet 2-D window.

Click the De-noise button (located at the middle right) to bring up the Wavelet 2-D -- De-noising window.

DiscussionThe graphical tool provides automatically generated thresholds. From the Select thresholding method menu, select the item Penalize low and click the De-noise button.

Example Analysis:Noisy Woman

MAT-file:noiswom.mat

Wavelet:haar

Level:4

Page 261: Wavelet ug

De-noising Images

3-23

The de-noised image exhibits some blocking effects. Let’s try another wavelet. Click the Close button to go back to the Wavelet 2-D window. Select the sym6 wavelet, and then click the Analyze button. Click the De-noise button to bring up the Wavelet 2-D -- De-noising window again.

From the Select thresholding method menu, select the item Penalize low, and click the De-noise button.

The de-noised image exhibits some ringing effects. Let’s try another strategy based on the two-dimensional stationary wavelet analysis to de-noise images.

Page 262: Wavelet ug

3 Wavelet Applications

3-24

The basic idea is to average many slightly different discrete wavelet analyses. For more information, see the section “Discrete Stationary Wavelet Transform (SWT)” on page 6-47.

Click the Close button to go back to the Wavelet 2-D window and click the Close button again. Open the SWT De-noising 2-D tool, select from the File menu the Load Image option and select the MAT-file noiswom.mat. Select the haar wavelet and select 4 from the level menu, and then click the Decompose Image button.

The selected thresholding method is Penalize low. Use the Sparsity slider to adjust the threshold value close to 44.5 (the same as before to facilitate the comparison with the first trial), and then click the De-noise button.

Original Image (I)

20 40 60 80

20

40

60

80

De−Noised Image (DI)

20 40 60 80

20

40

60

80

−50 0 500

0.02

0.04

Histogram of residuals: (I) − (DI)

00.050.1L

1Horizontal Details

00.020.040.06

Diagonal Details0

0.050.1

Vertical Details

00.050.1

0.15L

20

0.050.1

00.050.1

0.15

00.050.1L

30

0.050.1

00.050.1

00.020.040.060.08

L4

00.020.040.06

00.020.040.060.08

Page 263: Wavelet ug

De-noising Images

3-25

The result is more satisfactory. It’s possible to improve it slightly.

Select the sym6 wavelet and click the Decompose Image button. Use the Sparsity slider to adjust the threshold value close to 40.44 (the same as before to facilitate the comparison with the second trial), and then click the De-noise button.

At the end of this example, turn back the extension mode to zero-padding using the command:

dwtmode('zpd')

Page 264: Wavelet ug

3 Wavelet Applications

3-26

Compressing ImagesThe purpose of this example is to show how to compress an image using two-dimensional wavelet analysis. Compression is one of the most important applications of wavelets. The image to be compressed is a fingerprint.

For this example, open the Wavelet 2-D tool and select the menu item File⇒Example Analysis⇒at level 3, with haar −−> finger.

The analysis appears in the Wavelet 2-D tool. Click the Compress button (located at the middle right) to bring up the Wavelet 2-D Compression window.

Example Analysis:Finger

MAT-file:detfingr.mat

Wavelet:haar

Level:3

Page 265: Wavelet ug

Compressing Images

3-27

DiscussionThe graphical tool provides an automatically generated threshold. From the Select thresholding method menu, select Remove near 0, setting the threshold to 3.5. Then, click the Compress button. Values under the threshold are forced to zero, achieving about 42% zeros while retaining almost all (99.96%) the energy of the original image.

The automatic thresholds usually achieve reasonable and various balances between the number of zeros and retained image energy. Depending on your data and your analysis criteria, you may find setting more or less aggressive thresholds achieves better results.

Here we’ve set the global threshold to around 30. This results in a compressed image consisting of about 92% zeros with 97.7% retained energy.

Page 266: Wavelet ug

3 Wavelet Applications

3-28

Fast Multiplication of Large MatricesThis section illustrates matrix-vector multiplication in the wavelet domain.

• The problem is:

let m be a dense matrix of large size (n, n). We want to perform a large number, L, of multiplications of m by vectors v.

• The idea is:

Stage 1: (executed once) Compute the matrix approximation, sm, at a suitable level k. The matrix will be assimilated with an image.

Stage 2: (executed L times) divided in the following three steps:

1 Compute vector approximation.

2 Compute multiplication in wavelet domain.

3 Reconstruct vector approximation.

It is clear that when sm is a sufficiently good approximation of m, the error with respect to ordinary multiplication can be small. This is the case in the first example below where m is a magic square. Conversely, when the wavelet representation of the matrix m is dense the error will be large (for example, if all the coefficients have the same order of magnitude). This is the case in the second example below where m is two-dimensional Gaussian white noise. The Figure 3-1, Wavelet Based Matrix Multiplication by a Vector, on page 3-30 compares for n = 512, the number of flops required by wavelet based method and by ordinary method versus L.

The function flops is used in the following examples to count floating point operations. This function was available in earlier MATLAB versions and is now obsolete. So, the instructions that call this function will not give the displayed results anymore. But, these examples still illustrate the advantage of the wavelet method in matrix multiplication.

Page 267: Wavelet ug

Fast Multiplication of Large Matrices

3-29

Example 1: Effective Fast Matrix Multiplication

n = 512; lev = 5; wav = 'db1';

% Wavelet based matrix multiplication by a vector: % a “good” example % Matrix is magic(512) Vector is (1:512)

m = magic(n); v = (1:n)'; [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters(wav);

% ordinary matrix multiplication by a vector. flops(0);p = m * v; flomv = flops

flomv = 524288

% Compute matrix approximation at level 5. flops(0) sm = m;for i = 1:lev

sm = dyaddown(conv2(sm,Lo_D),'c'); sm = dyaddown(conv2(sm,Lo_D'),'r');

end flmapp = flops

flmapp = 2095154

% The three steps: % 1. Compute vector approximation. % 2. Compute multiplication in wavelet domain. % 3. Reconstruct vector approximation.

Page 268: Wavelet ug

3 Wavelet Applications

3-30

flops(0) sv = v; for i = 1:lev, sv = dyaddown(conv(sv,Lo_D)); end sp = sm * sv; for i = 1:lev, sp = conv(dyadup(sp),Lo_R); end sp = wkeep(sp,length(v)); flwmv = flops

flwmv = 9058

% Plot ordinary versus wavelet based m*v flops in loglog.

Figure 3-1: Wavelet Based Matrix Multiplication by a Vector

% Relative square norm error in percent when using wavelets. rnrm = 100 ∗ (norm(p-sp)/norm(p))

rnrm = 2.9744e-06

100

101

102

103

104

105

105

106

107

108

109

1010

1011

log(L) for a given matrix

log(

flops

)

Ordinary (dashed line) versus wavelet (solid line) based m*v flops

Page 269: Wavelet ug

Fast Multiplication of Large Matrices

3-31

Example 2: Ineffective Fast Matrix MultiplicationThe commands used are the same as in Example 1, but applied to a new matrix m.

% Wavelet based matrix multiplication by a vector: % a “bad” example with a randn matrix.% Change the matrix m of example1 using:randn('state',0);m = randn(n,n);

Then, you obtain

% Relative square norm error in percent rnrm = 100 * (norm(p-sp)/norm(p))

rnrm = 99.2137

Page 270: Wavelet ug

3 Wavelet Applications

3-32

Page 271: Wavelet ug

4Wavelets in Action: Examples and Case Studies

Illustrated Examples . . . . . . . . . . . . . . . . 4-3Advice to the Reader . . . . . . . . . . . . . . . . . 4-5Example 1: A Sum of Sines . . . . . . . . . . . . . . . 4-8Example 2: A Frequency Breakdown . . . . . . . . . . . 4-10Example 3: Uniform White Noise . . . . . . . . . . . . 4-12Example 4: Colored AR(3) Noise . . . . . . . . . . . . 4-14Example 5: Polynomial + White Noise . . . . . . . . . . 4-16Example 6: A Step Signal . . . . . . . . . . . . . . . 4-18Example 7: Two Proximal Discontinuities . . . . . . . . 4-20Example 8: A Second-Derivative Discontinuity . . . . . . 4-22Example 9: A Ramp + White Noise . . . . . . . . . . . 4-24Example 10: A Ramp + Colored Noise . . . . . . . . . . 4-26Example 11: A Sine + White Noise . . . . . . . . . . . 4-28Example 12: A Triangle + A Sine . . . . . . . . . . . . 4-30Example 13: A Triangle + A Sine + Noise . . . . . . . . . 4-32Example 14: A Real Electricity Consumption Signal . . . . 4-34

Case Study: An Electrical Signal . . . . . . . . . . . 4-36Data and the External Information . . . . . . . . . . . 4-36Analysis of the Midday Period . . . . . . . . . . . . . 4-38Analysis of the End of the Night Period . . . . . . . . . 4-40Suggestions for Further Analysis . . . . . . . . . . . . 4-43

Page 272: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-2

This chapter presents the different possibilities offered by wavelet decomposition in the form of examples you can work with on your own. Suggested areas for further exploration follow most examples, along with a summary of the topics addressed by that example.

This chapter also includes a case study that examines the practical uses of wavelet analysis in even greater detail, as well as a demonstration of the application of wavelets for fast multiplication of large matrices.

An extended discussion of many of the topics addressed by the examples can be found in “Advanced Concepts” on page 6-1.

Page 273: Wavelet ug

Illustrated Examples

4-3

Illustrated ExamplesFourteen illustrated examples are included in this section, organized as shown:

Example Figure Page Description of the Signal Signal Name MAT-file

1 4-1 4-9 A sum of sines: s1(t) sumsin

2 4-2 4-11 A frequency breakdown: s2(t) freqbrk

3 4-3 4-12 A uniform white noise:

on the interval

b1(t) whitnois

4 4-4 4-14 A colored AR(3) noise b2(t) warma

5 4-5 4-17 A polynomial + a white noise:

on the interval

s3(t) noispol

6 4-6 4-19 A step signal: s4(t) wstep

7 4-7 4-21 Two proximal discontinuities: s5(t) nearbrk

s1 t( ) 3t( )sin 0.3t( )sin 0.03t( )sin+ +=

1 t 500,≤ ≤501 t 1000,≤ ≤

s2 t( ) 0.03t( )sin=

s2 t( ) 0.3t( )sin=

0.5 – 0.5[ ]

b2 t( ) 1.5b2 t 1–( )– 0.75b2 t 2–( )–=

0.125b2 t 3–( )– b1 t( ) 0.5+ +

1 1000[ ]

s3 t( ) t2 t– 1 b1 t( )+ +=

1 t 500,≤ ≤501 t 1000,≤ ≤

s4 t( ) 0=

s4 t( ) 20=

1 t 499,≤ ≤500 t 510,≤ ≤511 t,≤

s5 t( ) 3t=

s5 t( ) 1500=

s5 t( ) 3t 30–=

Page 274: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-4

8 4-8 4-23 A second-derivative discontinuity:

s6 is f3 sampled at 10-3

s6(t) scddvbrk

9 4-9 4-25 A ramp + a white noise: s7(t) wnoislop

10 4-10 4-27 A ramp + a colored noise: s8(t) cnoislop

11 4-11 4-29 A sine + a white noise: s9(t) noissin

12 4-12 4-31 A triangle + a sine: s10(t) trsin

13 4-13 4-33 A triangle + a sine + a noise: s11(t) wntrsin

14 4-14 4-35 A real electricity consumption signal — leleccum

Example Figure Page Description of the Signal Signal Name MAT-file

t 0.5 – 0.5[ ] R;⊂∈t 0, f3 t( )< 4t2–( )exp=

t 0, f3 t( )≥ t2–( )exp=

1 t 499,≤ ≤

500 t 1000,≤ ≤

s7 t( ) 3t500---------- b1 t( )+=

s7 t( ) 3 b1 t( )+=

1 t 499,≤ ≤

500 t 1000,≤ ≤

s8 t( ) t500---------- b2 t( )+=

s8 t( ) 1 b2 t( )+=

s9 t( ) 0.03t( )sin b1 t( )+=

1 t 500,≤ ≤

501 t 1000,≤ ≤

s10 t( ) t 1–500----------- 0.3t( )sin+=

s10 t( ) 1000 t–500

--------------------- 0.3t( )sin+=

501 t 1000,≤ ≤s11 t( ) 1000 t–

500--------------------- 0.3t( )sin b1 t( )+ +=

1 t 500, s11 t( ) t 1–500----------- 0.3t( )sin b1(+ +=≤ ≤

Page 275: Wavelet ug

Illustrated Examples

4-5

Please note that:

• All the decompositions use Daubechies wavelets

• The examples show the signal, the approximations, and the details

The examples include specific comments and feature distinct domains — for instance, if the level of decomposition is 5:

• The left column contains the signal and the approximations A5 to A1

• The right column contains the signal and the details D5 to D1

• The approximation A1 is located under A2, A2 under A3, and so on; the same is true for the details

• The abscissa axis represents the time; the unit for the ordinate axis for approximations and details is the same as that of the signal

• When the approximations do not provide enough information, they are replaced by details obtained by changing wavelets

• The examples include questions for you to think about:

- What can be seen on the figure?

- What additional questions can be studied?

Advice to the ReaderYou should follow along and process these examples on your own, using either the graphical interface or the command line functions.

Use the graphical interface for immediate signal processing. To execute the analyses included in the figures:

1 To bring up the Wavelet Toolbox Main Menu type:

wavemenu

2 Select the Wavelet 1-D menu option to open the Wavelet 1-D tool.

3 From the Wavelet 1-D tool, choose the File⇒Example Analysis menu option.

4 From the dialog box, select the sample analysis in question.

Page 276: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-6

This triggers the execution of the examples.

When using the command line, follow the process illustrated in this M-file to conduct calculations:

% Load original 1-D signal.load sumsin; s = sumsin;

% Perform the decomposition of s at level 5, using coif3.w = 'coif3'[c,l] = wavedec(s,5,w);

% Reconstruct the approximation signals and detail signals at % levels 1 to 5, using the wavelet decomposition structure [c,l].for i = 1:5

A(i,:) = wrcoef('a',c,l,w,i);D(i,:) = wrcoef('d',c,l,w,i);

end

Note This loop replaces 10 separate wrcoef statements defining approximations and details. The variable A contains the five approximations and the variable D contains the five details.

% Plots. t = 100:900; subplot(6,2,1); plot(t,s(t),'r'); title('Orig. signal and approx. 1 to 5.'); subplot(6,2,2); plot(t,s(t),'r'); title('Orig. signal and details 1 to 5.'); for i = 1:5,

subplot(6,2,2*i+1); plot(t,A(5-i+1,t),'b'); subplot(6,2,2*i+2); plot(t,D(5-i+1,t),'g');

end

Page 277: Wavelet ug

Illustrated Examples

4-7

About Further Exploration

Tip 1: On all figures, visually check that for j = 0, 1, ..., Aj = Aj+1 + Dj+1.

Tip 2: Don’t forget to change wavelets. Test the shortest ones first.

Tip 3: Identify edge effects. They will create problems for a correct analysis. At present, there is no easy way to avoid them perfectly. You can use tools described in the section “Dealing with Border Distortion” on page 6-37 and see also the dwtmode reference page. They should eliminate or greatly reduce these effects.

Tip 4: As much as possible, conduct calculations manually to cross-check results with the values in the graphic representations. Manual calculations are possible with the db1 wavelet.

For the sake of simplicity in the following examples, we use only the haar and db family wavelets, which are the most frequently used wavelets.

Page 278: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-8

Example 1: A Sum of SinesAnalyzing wavelet: db3

Decomposition levels: 5

The signal is composed of the sum of three sines: slow, medium, and rapid. With regard to the sampling period equal to 1, the periods are approximately 200, 20, and 2 respectively. We should, therefore, see this later period in D1, the medium sine in D4, and the slow sine in A4. The slight differences that can be observed on the decompositions can be attributed to the sampling period. The scale of the approximation charts is 2, 4, or 10 times larger than that of the details. D1 contains primarily the components whose period is situated between 1 and 2 (i.e., the rapid sine), but this period is not visible at the scale which is used for the graph. Zooming in on D1 reveals that each “belly” is composed of 10 oscillations, and can be used to estimate the period. We find that the period is close to 2. D2 is very small. This is also seen in the approximations: the first two resemble one another, since

The detail D3 and, to an even greater extent, the detail D4 contain the medium sine. We notice that there is a breakdown between approximations 3 and 4.

Approximations A1 to A3 can be used to estimate the period of the medium sine. Now, only the slow sine, which appears in A4, remains to be determined. The distance between two successive maximums is equal to 200, which is the period of the slow sine. This latter sine is still visible in A5, but will disappear from the approximation and move into the details at level 8.

A1 A2 D2+=

Page 279: Wavelet ug

Illustrated Examples

4-9

Figure 4-1 A Sum of Sines

Example 1: A Sum of Sines

Addressed topics • Detecting breakdown points.

• Detecting long-term evolution.

• Identifying pure frequencies.

• The effect of a wavelet on a sine

• Details and approximations: a signal moves from an approximation to a detail.

• The level at which characteristics appear.

Further exploration • Compare with a Fourier analysis.

• Change the frequencies. Analyze other linear combinations.

−1

0

1

a5

−1

0

1

a4

−2

0

2

a3

−2

0

2

a2

200 400 600 800 1000

−1

0

1

a1

−0.1

0

0.1

d5

−1

0

1

d4

−0.5

0

0.5

d3

−0.1

0

0.1

d2

200 400 600 800 1000−1

0

1

d1

−2

0

2

s

Signal and Approximations

−2

0

2

s

Signal and Details

Page 280: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-10

Example 2: A Frequency BreakdownAnalyzing wavelet: db5

Decomposition levels: 5

The signal is formed of a slow sine and a medium sine, on either side of 500. These two sines are not connected in a continuous manner: D1 and D2 can be used to detect this discontinuity. It is localized very precisely: only a small domain around 500 contains large details. This is because the rupture contains the high-frequency part; the frequencies in the rest of the signal are not as high. It should be noted that if we are interested only in identifying the discontinuity, db1 is more useful than db5.

D3 and D4 contain the medium sine as in the previous analysis. The slow sine appears clearly alone in A5. It is more regular than in the s1 analysis, since db5 is more regular than db3. If the same signal had been analyzed by the Fourier transform, we would not have been able to detect the instant corresponding to the signal’s frequency change, whereas it is clearly observable here.

Page 281: Wavelet ug

Illustrated Examples

4-11

Figure 4-2: A Frequency Breakdown

Example 2: A Frequency Breakdown

Addressed topics • Suppressing signals.

• Detecting long-term evolution.

Further exploration • Compare to the signal s1

• On a longer signal, select a deeper level of decomposition in such a way that the slow sinusoid appears into the details.

• Compare with a Fourier analysis.

• Compare with a windowed Fourier analysis.

−0.5

0

0.5

1

a5

−0.5

0

0.5

1

a4

−1

0

1

a3

−1

0

1

a2

200 400 600 800 1000−1

0

1

a1

−0.2

0

0.2

d5

−1

0

1

d4

−0.4−0.2

00.20.4

d3

−0.1

0

0.1

0.2

d2

200 400 600 800 1000

−0.2

0

0.2

0.4

d1

−0.5

0

0.5

s

Signal and Approximations

−0.5

0

0.5

s

Signal and Details

Page 282: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-12

Example 3: Uniform White NoiseAnalyzing wavelet: db3

Decomposition levels: 5

At all levels we encounter noise-type signals that are clearly irregular. This is because all the frequencies carry the same energy. The variances, however, decrease regularly between one level and the next as can be seen reading the detail chart (on the right) and the approximations (on the left).

The variance decreases two-fold between one level and the next, i.e., variance(Dj) = variance(Dj - 1) / 2. Lastly, it should be noted that the details and approximations are not white noise, and that these signals are increasingly interdependent as the resolution decreases. On the other hand, the wavelet coefficients are random, noncorrelated variables. This property is not evident on the reconstructed signals shown here, but it can be guessed at from the representation of the coefficients.

Figure 4-3: Uniform White Noise

−0.1

0

0.1

a5

−0.2

−0.1

0

0.1

a4

−0.2

0

0.2

a3

−0.2

0

0.2

a2

200 400 600 800 1000−0.5

0

0.5

a1

−0.1

0

0.1

d5

−0.2

0

0.2

d4

−0.2

0

0.2

d3

−0.4−0.2

00.20.4

d2

200 400 600 800 1000−0.5

0

0.5

d1

−0.4−0.2

00.20.4

s

Signal and Approximations

−0.4−0.2

00.20.4

s

Signal and Details

Page 283: Wavelet ug

Illustrated Examples

4-13

Example 3: Uniform White Noise

Addressed topics • Processing noise.

• The shapes of the decomposition values.

• The evolution of these shapes according to level; the correlation increases, the variance decreases.

Further exploration • Compare the frequencies included in the details with those in the approximations.

• Study the values of the coefficients and their distribution.

• On the continuous analysis, identify the chaotic aspect of the colors.

• Replace the uniform white noise by a Gaussian white noise or other noise.

Page 284: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-14

Example 4: Colored AR(3) NoiseAnalyzing wavelet: db3

Decomposition levels: 5

Note AR(3) means AutoRegressive model of order 3.

This figure can be examined in view of the Figure 4-3, on page 4-12, since we are confronted here with a non-white noise whose spectrum is mainly at the higher frequencies. Therefore, it is found primarily in D1, which contains the major portion of the signal. In this situation, which is commonly encountered in practice, the effects of the noise on the analysis decrease considerably more rapidly than in the case of white noise. In A3, A4 and A5, we encounter the same scheme as that in the analysis of (see the table in “Example 3: Uniform White Noise” on page 4-12), the noise from which is built using linear filtering.

Figure 4-4: Colored AR(3) Noise

b1b2

0.12

0.14

0.16

0.18

a5

0.1

0.15

0.2

a4

0.05

0.1

0.15

0.2

a3

0

0.1

0.2

0.3

a2

200 400 600 800 1000

0

0.2

0.4

a1

−0.04−0.02

00.020.04

d5

−0.05

0

0.05

0.1

d4

−0.1

0

0.1

0.2

d3

−0.2

0

0.2

d2

200 400 600 800 1000

−2

0

2

d1

−2

0

2

s

Signal and Approximations

−2

0

2

s

Signal and Details

Page 285: Wavelet ug

Illustrated Examples

4-15

Example 4: Colored AR(3) Noise

Addressed topics • Processing noise.

• The relative importance of different details.

• The relative importance of D1 and A1.

Further exploration • Compare the detail frequencies with those in the approximations.

• Compare approximations A3, A4, and A5 with those shown in Figure 4-3, on page 4-12.

• Replace AR(3) with an ARMA (AutoRegressive Moving Average) model noise. For instance:

• Study an ARIMA (Integrated ARMA) model noise. For instance:

• Check that each detail can be modeled by an ARMA process.

b3 t( ) 1.5– b3 t 1–( ) 0.75b3 t 2–( )– 0.125b3 t 3–( )–=

+ b1 t( ) 0.7b1 t 1–( )–

b4 t( ) b4 t 1–( ) b3 t( )+=

Page 286: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-16

Example 5: Polynomial + White NoiseAnalyzing wavelets: db2 and db3

Decomposition levels: 4

The purpose of this analysis is to illustrate the property that causes the decomposition by dbN of a p-degree polynomial to produce null details as long as N > p. In this case, p=2 and we examine the first four levels of details for two values of N: one is too small, N=2 on the left, and the other is sufficient, N=3 on the right. The approximations are left out since they differ very little from the signal itself.

For db2 (on the left), we obtain the decomposition of t2 + b1(t), since the -t + 1 part of the signal is suppressed by the wavelet. In fact, with the exception of level 1, where noise-generated irregularities can be seen, the details for levels 2 to 4 show a periodic form that is very regular, and which increases with the level. This is because the detail for level j takes into account that the fluctuations of the function around its mean value on dyadic intervals are long. The fluctuations are periodic and very large in relation to the details of the noise decomposition.

On the other hand, for db3 (on the right) we again find the presence of white noise, thus indicating that the polynomial does not come into play in any of the details. The wavelet suppresses the polynomial part and analyzes the noise.

Page 287: Wavelet ug

Illustrated Examples

4-17

Figure 4-5: Polynomial + White Noise

Example 5: Polynomial + White Noise

Addressed topics • Suppressing signals.

• Compare the results of the processing for the following wavelets: the short db2 and the longer db3.

• Explain the regularity that is visible in D3 and D4 in the analysis by db2.

Further exploration • Increase noise intensity and repeat the analysis.

−0.5

0

0.5

d4

−0.5

0

0.5

d3

300 400 500 600 700

−1

0

1

d1

2

4

6

8

x 105

s

Signal and Details with db3

−50

0

50

d4

−20

0

20

d3

−5

0

5

d2

300 400 500 600 700−2

−1

0

1

d1

−0.5

0

0.5

1

d2

2

4

6

8

x 105

s

Signal and Details with db2

Page 288: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-18

Example 6: A Step SignalAnalyzing wavelet: db2

Decomposition levels: 5

In this case, we are faced with the simplest example of a rupture (i.e., a step). The time instant when the jump occurs is equal to 500. The break is detected at all levels, but it is obviously detected with greater precision in the higher resolutions (levels 1 and 2) than in the lower ones (levels 4 and 5). It is very precisely localized at level 1, where only a very small zone around the jump time can be seen.

It should be noted that the reconstructed details are primarily composed of the basic wavelet represented in the initial time.

Furthermore, the rupture is more precisely localized when the wavelet corresponds to a short filter.

Page 289: Wavelet ug

Illustrated Examples

4-19

Figure 4-6: A Step Signal

Example 6: A Step Signal

Addressed topics • Detecting breakdown points.

• Suppressing signals.

• Detecting long-term evolution.

• Identify the range width of the variations of details and approximations.

Further exploration • Use the coefficients of the FIR filter associated with the wavelet to check the values of D1.

• Replace the step by an impulse.

• Add noise to the signal and repeat the analysis.

0

10

20

a5

0

10

20

a4

0

10

20

a3

0

10

20

a2

−10

−5

0

5

d5

−4−2

0246

d4

−2

0

2

d3

−5

0

5

d2

200 400 600 800

−2024

d1

0

10

20

s

Signal and Approximations

0

10

20

s

Signal and Details

200 400 600 8000

10

20

a1

Page 290: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-20

Example 7: Two Proximal DiscontinuitiesAnalyzing wavelet: db2 and db7

Decomposition levels: 5

The signal is formed of two straight lines with identical slopes, extending across a very short plateau. On the initial signal, the plateau is in fact barely visible to the naked eye. Two analyses are thus carried out: one on a well localized wavelet with the short filter (db2, shown on the left side of the figure); and the other on a wavelet having a longer filter (db7, shown on the right side of the figure).

In both analyses, the plateau is detected clearly. With the exception of a fairly limited domain, D1 is equal to zero. The regularity of the signal in the plateau, however, is clearly distinguished for db2 (for which plateau beginning and end time are distinguished), whereas for db7 both discontinuities are fused and only the entire plateau can said to be visible.

This example suggests that the selected wavelets should be associated with short filters to distinguish proximal discontinuities of the first derivative. A look at the other detail levels again shows the lack of precision when detecting at low resolutions. The wavelet filters the straight line and analyzes the discontinuities.

Page 291: Wavelet ug

Illustrated Examples

4-21

Figure 4-7: Two Proximal Discontinuities

Example 7: Two Proximal Discontinuities

Addressed topics • Detecting breakdown points

Further exploration • Move the discontinuities closer together and further apart.

• Add noise to the signal until the rupture is no longer visible.

• Try using other wavelets, haar for instance.

−2

0

2

d5

−10

0

10

d5

−2

0

2

4

d4−2

0246

d4

−4−2

024

d3−1

0

1

d3

−1

0

1

2

d2−0.5

0

0.5

d2

450 500 550 600−0.5

0

0.5

d1

450 500 550 600

−0.2

0

0.2

d1

13001400150016001700

s

Signal and Details with db2

13001400150016001700

s

Signal and Details with db7

Page 292: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-22

Example 8: A Second-Derivative DiscontinuityAnalyzing wavelet: db1 and db4

Decomposition levels: 2

This figure shows that the regularity can be an important criterion in selecting a wavelet. The basic function is composed of two exponentials that are connected at 0, and the analyzed signal is the sampling of the continuous function with increments of 10–3. The sampled signal is analyzed using two different wavelets: db1, which is insufficiently regular (shown on the left side of the figure); and db4, which is sufficiently regular (shown on the right side of the figure).

Looking at the figure on the left we notice that the singularity has not been detected in the extent that the details are equal to 0 at 0. The black areas correspond to very rapid oscillations of the details. These values are equal to the difference between the function and an approximation using a constant function. Close to 0, the slow decrease of the details absolute values followed by a slow increase is due to the fact that the function derivative is zero and continuous at 0. The value of the details is very small (close to 10–3 for db1 and 10–4 for db4) since the signal is very smooth and does not contain any high frequency. This value is even smaller for db4, since the wavelet is more regular than db1.

However, with db4 (right side of the figure), the discontinuity is well detected: the details are high only close to 0, and are 0 everywhere else. This is the only element that can be derived from the analysis. In this case, as a conclusion, we notice that the selected wavelet must be sufficiently regular, which implies a longer filter impulse response to detect the singularity.

Page 293: Wavelet ug

Illustrated Examples

4-23

Figure 4-8: A Second-Derivative Discontinuity

Example 8: A Second-Derivative Discontinuity

Addressed topics • Detecting breakdown points.

• Suppressing signals.

• Identifying a difficult discontinuity.

• Carefully selecting a wavelet to reveal an effect.

Further exploration • Calculate the detail values for the Haar wavelet.

• Be aware of parasitic effects: rapid detail fluctuations may be artifacts.

• Add noise to the signal until the rupture is no longer visible.

1

0

1

2

x 106

d2

5

0

5

x 104

d2

0.95

0.96

0.97

0.98

0.99

1

s

Signal and Details with db1

0.95

0.96

0.97

0.98

0.99

1

1.01

s

Signal and Details with db4

0.1 0.05 0 0.05 0.14

2

0

2

4

x 104

d1

0.1 0.05 0 0.05 0.16

4

2

0

2

4

x 107

d1

Page 294: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-24

Example 9: A Ramp + White NoiseAnalyzing wavelet: db3

Decomposition levels: 6

The signal is built from a trend plus noise. The trend is a slow linear rise from 0 to 3, up to t=500 and becoming constant afterwards. The noise is a uniform zero-mean white noise, varying between -0.5 and 0.5 (see the analyzed signal b1).

Looking at the figure, in the chart on the right, we again find the decomposition of noise in the details. In the charts on the left, the approximations form increasingly precise estimates of the ramp with less and less noise. These approximations are quite acceptable from level 3, and the ramp is well reconstructed at level 6.

We can, therefore, separate the ramp from the noise. Although the noise affects all scales, its effect decreases sufficiently quickly for the low-resolution approximations to restore the ramp. It should also be noted that the breakdown point of the ramp is shown with good precision. This is due to the fact that the ramp is recovered at too low a resolution.

The uniform noise indicates that the ramp might be best estimated using half sums for the higher and lower portions of the signal. This approach is not applicable for other noises.

Page 295: Wavelet ug

Illustrated Examples

4-25

Figure 4-9: A Ramp + White Noise

Example 9: A Ramp + White Noise

Addressed topics • Detecting breakdown points.

• Processing noise.

• Detecting long-term evolution.

• Splitting signal components.

• Identifying noises and approximations.

Further exploration • Compare with the white noise b1(t) shown in Figure 4-3, on page 4-12.

• Identify the number of levels needed to suppress the noise almost entirely.

• Change the noise

1

2

3

a6

1

2

3

a5

1

2

3

a4

1

2

3

a3

0

1

2

3

a2

−0.1

0

0.1

d5

−0.2

0

0.2

d4

−0.2

0

0.2

d3

−0.4−0.2

00.20.4

d2

200 400 600 800−0.5

0

0.5

d1

0123

s

Signal and Approximations

0123

s

Signal and Details

200 400 600 8000123

a1

−0.1

0

0.1

d6

Page 296: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-26

Example 10: A Ramp + Colored NoiseAnalyzing wavelet: db3

Decomposition levels: 6

The signal is built in the same manner as in “Example 9: A Ramp + White Noise” on page 4-24, using a trend plus a noise. The trend is a slow linear increase from 0 to 1, up to t=500. Beyond this time, the value remains constant. The noise is a zero mean AR(3) noise, varying between -3 and 3 (see the analysed signal b2). The scale of the noise is indeed six times greater than that of the ramp. At first glance, the situation seems a little bit less favorable than in the previous example, in terms of the separation between the ramp and the noise. This is actually a misconception, since the two signal components are more precisely separated in frequency.

Looking at the figure, the charts on the right show the detail decomposition of the colored noise. The charts on the left show a decomposition that resembles the one in the previous analysis. Starting at level 3, the curves provide satisfactory approximations of the ramp.

Page 297: Wavelet ug

Illustrated Examples

4-27

Figure 4-10: A Ramp + Colored Noise

Example 10: A Ramp + Colored Noise

Addressed topics • Detecting breakdown points.

• Processing noise.

• Detecting long-term evolution.

• Splitting signal components.

Further exploration • Compare with the s7(t) signal shown in Figure 4-9, on page 4-25.

• Identify the number of levels needed to suppress the noise almost entirely.

• Identify the noise characteristics. Use the coefficients and the command line mode.

0.40.60.8

11.2

a6

0.5

1

a5

0.5

1

a4

0.20.40.60.8

11.2

a3

0.20.40.60.8

11.2

a2

−0.04−0.02

00.020.04

d5

−0.050

0.050.1

d4

−0.10

0.10.2

d3

−0.2

0

0.2

d2

200 400 600 800

−2

0

2

d1

−10123

s

Signal and Approximations

−10123

s

Signal and Details

200 400 600 8000

0.5

1a1

−0.04−0.02

00.020.04

d6

Page 298: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-28

Example 11: A Sine + White NoiseAnalyzing wavelet: db5

Decomposition levels: 5

The signal is formed of the sum of two previously analyzed signals: the slow sine with a period close to 200 and the uniform white noise b1. This example is an illustration of the linear property of decompositions: the analysis of the sum of two signals is equal to the sum of analyses.

The details correspond to those obtained during the decomposition of the white noise.

The sine is found in the approximation A5. This is a high enough level for the effect of the noise to be negligible in relation to the amplitude of the sine.

Page 299: Wavelet ug

Illustrated Examples

4-29

Figure 4-11: A Sine + White Noise

Example 11: A Sine + White Noise

Addressed topics • Processing noise.

• Detecting long-term evolution.

• Splitting signal components.

• Identifying the frequency of a sine.

Further exploration • Identify the noise characteristics. Use the coefficients and the command line mode.

−1

−0.5

0

0.5

a5

−1

0

1

a4

−1

0

1

a3

−1

0

1

a2

200 400 600 800 1000

−1

0

1

a1

−0.1

0

0.1

d5

−0.2

0

0.2

d4

−0.2

0

0.2

d3

−0.4

−0.20

0.20.4

d2

200 400 600 800 1000−0.5

0

0.5

d1

−1

0

1

s

Signal and Approximations

−1

0

1

s

Signal and Details

Page 300: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-30

Example 12: A Triangle + A SineAnalyzing wavelet: db5

Decomposition levels: 6

The signal is the sum of a sine having a period of approximately 20 and of a “triangle”.

D1 and D2 are very small. This suggests that the signal contains no components with periods that are short in relation to the sampling period.

D3 and especially D4 can be attributed to the sine. The jump of the sine from A3 to D4 is clearly visible.

The details for the higher levels D5 and D6 are small, especially D5.

D6 exhibits some edge effects.

A6 contains the triangle which includes only low frequencies.

Page 301: Wavelet ug

Illustrated Examples

4-31

Figure 4-12: A Triangle + A Sine

Example 12: A Triangle + A Sine

Addressed topics • Detecting long-term evolution.

• Splitting signal components.

• Identifying the frequency of a sine.

Further exploration • Try using sinusoids whose period is a power of 2.

−0.4−0.2

00.20.4

a6

−0.20

0.20.4

a5

−0.4−0.2

00.20.4

a4

−1

0

1

a3

−1

0

1

a2

−0.1

0

0.1

d6

−0.04−0.02

00.020.04

d5

−1

0

1

d4

−0.4−0.2

00.20.4

d3

−0.02

0

0.02

d2

200 400 600 800

−5

0

5

x 10−4

d1

−1

0

1

s

Signal and Approximations

−1

0

1

s

Signal and Details

200 400 600 800

−1

0

1

a1

Page 302: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-32

Example 13: A Triangle + A Sine + NoiseNoise Analyzing wavelet: db5

Decomposition levels: 7

The signal examined here is the same as the previous signal plus a uniform white noise divided by 3. The analysis can, therefore, be compared to the previous analysis. All differences are due to the presence of the noise.

D1 and D2 are due to the noise.

D3 and especially D4 are due to the sine.

The higher level details are increasingly low, and originate in the noise.

A7 contains a triangle, although it is not as well reconstructed as in the previous example.

Page 303: Wavelet ug

Illustrated Examples

4-33

Figure 4-13: A Triangle + A Sine + Noise

Example 13: A Triangle + A Sine + Noise

Addressed topics • Detecting long-term evolution.

• Splitting signal components.

Further exploration • Increase the amplitude of the noise.

• Replace the triangle by a polynomial.

• Replace the white noise by an ARMA noise.

−0.20

0.20.4

a7

−0.4−0.2

00.20.4

a6

−0.4−0.2

00.20.4

a5

−0.4−0.2

00.20.4

a4

−101

a3

−1

0

1

a2

−0.1

0

0.1

d7

−0.2

0

0.2

d6

−0.1

0

0.1

d5

−1

0

1

d4

−0.5

0

0.5

d3

−0.4−0.2

00.20.4

d2

200 300 400 500 600 700 800−0.5

0

0.5

d1

−101

s

Signal and Approximations

−101

s

Signal and Details

200 300 400 500 600 700 800

−101

a1

Page 304: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-34

Example 14: A Real Electricity Consumption SignalAnalyzing wavelet: db3

Decomposition levels: 5

The series presents a peak in the center, followed by two drops, a shallow drop, and then a considerably weaker peak.

The details for levels 1 and 2 are of the same order of magnitude and give a good expression of the local irregularities caused by the noise. The detail for level 3 presents high values in the beginning and at the end of the main peak, thus allowing us to locate the corresponding drops. The detail D4 shows coarser morphological aspects for the series (i.e., three successive peaks). This fits the shape of the curve remarkably well, and includes the essential signal components for periods of less than 32 time-units. The approximations show this effect clearly: A1 and A2 bear a strong resemblance; A3 forms a reasonably accurate approximation of the original signal. A look at A4, however, shows that a considerable amount of information has been lost.

In this case, as a conclusion, the multiscale aspect is the most interesting and the most significant feature: the essential components of the electrical signal used to complete the description at 32 time-units (homogeneous to A5) are the components with a period between 8 to 16 time-units.

Page 305: Wavelet ug

Illustrated Examples

4-35

Figure 4-14: A Real Electricity Consumption Signal

This signal is explored in much greater detail in “Case Study: An Electrical Signal” on page 4-36.

Example 14: A Real Electricity Consumption Signal

Addressed topics • Detecting long-term evolution.

• Splitting signal components.

• Detecting breakdown points.

• Multiscale analysis.

Further exploration • Try the same analysis on various sections of the signal. Focus on a range other than the [3600:3700] shown here.

300

320

340

a4

300

320

340

a3

300

320

340

a2

3600 3620 3640 3660 3680 3700300

320

340

a1

300

320

340

a5

300

320

340

s

Signal and Details

300

320

340

s

Signal and Approximations

−10

0

10

d4

−10

0

10

d5

−10

0

10

d3

−10

0

10

d2

3600 3620 3640 3660 3680 3700

−10

0

10

d1

Page 306: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-36

Case Study: An Electrical SignalThe goal of this section is to provide a statistical description of an electrical load consumption using the wavelet decompositions as a multiscale analysis.

Two problems are addressed. They both deal with signal extraction from the load curve corrupted by noise:

1 What information is contained in the signal, and what pieces of information are useful?

2 Are there various kinds of noises, and can they be distinguished from one another?

The context of the study is the forecast of the electrical load. Currently, short-term forecasts are based on the data sampled over 30 minutes. After eliminating certain components linked to weather conditions, calendar effects, outliers and known external actions, a SARIMA parametric model is developed. The model delivers forecasts from 30 minutes to 2 days. The quality of the forecasts is very high at least for 90% of all days, but the method fails when working with the data sampled over 1 minute.

Data and the External InformationThe data consist of measurement of a complex, highly aggregated plant: the electrical load consumption, sampled minute by minute, over a 5-week period. This time series of 50,400 points is partly plotted at the top of the Figure 4-17, on page 4-42.

External information is given by electrical engineers, and additional indications can be found in several papers. This information, used to define reference situations for the purpose of comparison, includes these points:

• The load curve is the aggregation of hundreds of sensors measurements, thus generating measurement errors.

• Roughly speaking, 50% of the consumption is accounted for by industry, and the rest by individual consumers. The component of the load curve produced by industry has a rather regular profile and exhibits low-frequency changes. On the other hand, the consumption of individual consumers may be highly irregular, leading to high-frequency components.

• There are more than 10 millions individual consumers.

Page 307: Wavelet ug

Case Study: An Electrical Signal

4-37

• The fundamental periods are the weekly-daily cycles, linked to economic rhythms.

• Daily consumption patterns also change according to rate changes at different times (e.g., relay-switched water heaters to benefit from special night rates).

• Missing data have been replaced.

• Outliers have not been corrected.

• For the observations 2400 to 3400, the measurement errors are unusually high, due to sensors failures.

From a methodological point of view, the wavelet techniques provide a multiscale analysis of the signal as a sum of orthogonal signals corresponding to different time scales, allowing a kind of time-scale analysis.

Because of the absence of a model for the 1-minute data, the description strategy proceeds essentially by successive uses of various comparative methods applied to signals obtained by the wavelet decomposition.

Without modeling, it is impossible to define a signal or a noise effect. Nevertheless, we say that any repetitive pattern is due to signal and is meaningful.

Finally, it is known that two kinds of noise corrupt the signal: sensors errors and the state noise.

We shall not report here the complete analysis, which is included in the paper [MisMOP94] (see “References” on page 6-145). Instead, we illustrate the contribution of wavelet transforms to the local description of time series. We choose two small samples: one taken at midday, and the other at the end of the night.

In the first period, the signal structure is complex; in the second one, it is much simpler. The midday period has a complicated structure because the intensity of the electricity consumer activity is high and it presents very large changes. At the end of the night, the activity is low and it changes slowly.

For the local analysis, the decomposition is taken up to the level j = 5, because 25 = 32 is very close to 30 minutes. We are then able to study the components of the signal for which the period is less than 30 minutes.

The analyzing wavelet used here is db3. The results are described similarly for the two periods.

Page 308: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-38

Analysis of the Midday PeriodThis signal (see Figure 4-14, on page 4-35) is also analyzed more crudely in “Example 14: A Real Electricity Consumption Signal” on page 4-34.

The shape is a middle mode between 12:30 p.m. and 1:00 p.m., preceded and followed by a hollow off-peak, and next a second smoother mode at 1:15 p.m. The approximation A5, corresponding to the time scale of 32 minutes, is a very crude approximation, particularly for the central mode: there is a peak time lag and an underestimation of the maximum value. So at this level, the most essential information is missing. We have to look at lower scales (4 for instance).

Let us examine the corresponding details.

The details D1 and D2 have small values and may be considered as local short-period discrepancies caused by the high-frequency components of sensor and state noises. In this bandpass, these noises are essentially due to measurement errors and fast variations of the signal induced by millions of state changes of personal electrical appliances.

The detail D3 exhibits high values at times corresponding to the start and the end of the original middle mode. It allows time localization of the local minima.

The detail D4 contains the main patterns: three successive modes. It is remarkably close to the shape of the curve. The ratio of the values of this level to the other levels is equal to 5. The detail D5 does not bear much information. So the contribution of the level 4 is the highest one, both in qualitative and quantitative aspects. It captures the shape of the curve in the concerned period.

Page 309: Wavelet ug

Case Study: An Electrical Signal

4-39

In conclusion, with respect to the approximation A5, the detail D4 is the main additional correction: the components of a period of 8 to 16 minutes contain the crucial dynamics.

Figure 4-15: Analysis of the Midday Period

300

320

340

a4

300

320

340

a3

300

320

340

a2

3600 3620 3640 3660 3680 3700300

320

340

a1

300

320

340

a5

300

320

340

s

Signal and Details

300

320

340

s

Signal and Approximations

−10

0

10

d4

−10

0

10

d5

−10

0

10

d3

−10

0

10

d2

3600 3620 3640 3660 3680 3700

−10

0

10

d1

Page 310: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-40

Analysis of the End of the Night PeriodSee Figure 4-16, on page 4-41.

The shape of the curve during the end of the night is a slow descent, globally smooth, but locally highly irregular. One can hardly distinguish two successive local extrema in the vicinity of time and . The approximation A5 is quite good except at these two modes.

The accuracy of the approximation can be explained by the fact that there remains only a low-frequency signal corrupted by noises. The massive and simultaneous changes of personal electrical appliances are absent.

The details D1, D2, and D3 show the kind of variation and have, roughly speaking, similar shape and mean value. They contain the local short period irregularities caused by noises, and the inspection of D2 and D3 allows you to detect the local minimum around .

The details D4 and D5 exhibit the slope changes of the regular part of the signal, and A4 and A5 are piecewise linear.

In conclusion, none of the time scales brings a significant contribution sufficiently different from the noise level, and no additional correction is needed. The retained approximation is A4 or A5.

t 1600= t 1625=

t 1625=

Page 311: Wavelet ug

Case Study: An Electrical Signal

4-41

Figure 4-16: Analysis of the End of the Night Period

All the figures in this paragraph are generated using the graphical user interface tools, but the user can also process the analysis using the command line mode. The following example corresponds to a command line equivalent for producing Figure 4-17, on page 4-42.

% Load the original 1-D signal, decompose, reconstruct details in % original time and plot.% Load the signal. load leleccum; s = leleccum;

% Decompose the signal s at level 5 using the wavelet db3. w = 'db3'; [c,l] = wavedec(s,5,w);

−5

0

5

d5

−5

0

5

d4

−5

0

5

d3

220240260280300

s

Signal and Approximations

220240260280300

a5

220240260280300

a4

220240260280300

a3

220240260280300

a2

1600 1650 1700

220240260280300

a1

220240260280300

s

Signal and Details

1600 1650 1700−5

0

5

d1

−5

0

5

d2

Page 312: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-42

% Reconstruct the details using the decomposition structure. for i = 1:5

D(i,:) = wrcoef('d',c,l,w,i);end

Note This loop replaces five separate wrcoef statements defining the details. The variable D contains the five details.

% Avoid edge effects by suppressing edge values and plot. tt = 1+100:length(s)-100; subplot(6,1,1); plot(tt,s(tt),'r'); title('Electrical Signal and Details'); for i = 1:5, subplot(6,1,i+1); plot(tt,D(5-i+1,tt),'g'); end

Figure 4-17: Decomposition of 3-Day Electrical Signal at Level 5 Using db3

−20

0

20

d5

−10

0

10

20

d3

−10

010

20

d2

500 1000 1500 2000 2500 3000 3500 4000−20

0

20

d1

−20

0

20

40

d4

200

300

400

500

s

Electrical Signal and Details

Page 313: Wavelet ug

Case Study: An Electrical Signal

4-43

Suggestions for Further AnalysisLet us now make some suggestions for possible further analysis starting from the details of the decomposition at level 5 of 3 days (see Figure 4-17, on page 4-42).

Identify the Sensor FailureFocus on the wavelet decomposition and try to identify the sensor failure directly on the details D1, D2, and D3, and not the other ones. Try to identify the other part of the noise.

Indication: see Figure 4-18 below.

Figure 4-18: Identification of Sensor Failure

−10

0

10

20

d3

2200 2400 2600 2800 3000 3200 3400 3600

−20

−10

0

10

20

d1

200

300

400

500

s

Signal and Details

−10

0

10

20

d2

Page 314: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-44

Suppress the NoiseSuppress measurement noise. Try by yourself and use, afterwards, the de-noising tools.

Indication: study the approximations and compare two successive days, the first without sensor failure and the second corrupted by failure (see Figure 4-19 below).

Figure 4-19: Comparison of Smoothed Versions of the Signal

200

300

400

500

a4

200

300

400

500

a3

200

300

400

500

a2

500 1000 1500 2000 2500 3000 3500 4000

200

300

400

500

a1

200

300

400

500

s

Signal and Approximations

Page 315: Wavelet ug

Case Study: An Electrical Signal

4-45

Identify Patterns in the DetailsThe idea here is to identify a pattern in the details typical of relay-switched water heaters.

Indication: Figure 4-20 below gives an example of such a period. Focus on details D2, D3, and D4 around abscissa 1350, 1383, and 1415 to detect abrupt changes of the signal induced by automatic switches.

Figure 4-20: Location of the Water Heaters and Identification of the Effects on the Details

340360380400420440

s

Signal and Details

−10

0

10

d4

−10

0

10

d3

−5

0

5

d2

1350 1360 1370 1380 1390 1400 1410 1420 1430 1440 1450

−2

0

2

d1

Page 316: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-46

Locate and Suppress Outlying ValuesSuppress the outliers by setting the corresponding values of the details to 0.

Indication: Figure 4-21 below gives two examples of outliers around and . The effect produced on the details is clear when focusing on the low levels. As far as outliers are concerned, D1 and D2 are synchronized with s, while D3 shows a delayed effect.

Figure 4-21: Location of the Outliers and Identification of the Effects on the Details

t 1193=t 1215=

−10

0

10

20

d3

1170 1180 1190 1200 1210 1220 1230

−20

−10

0

10

20

d1

−10

0

10

20

d2

340

360

380

400

s

Signal and Details

Page 317: Wavelet ug

Case Study: An Electrical Signal

4-47

Study Missing DataMissing data have been crudely substituted (around observation 2870) by the estimation of 30 minutes of sampled data and spline smoothing for the intermediate time points. You can improve the interpolation by using an approximation and portions of the details taken elsewhere, thus implementing a sort of “graft.”

Indication: see Figure 4-22 below focusing around time 2870, and use the small variations part of D1 to detect the missing data.

Figure 4-22: Detection of Missing Data Replaced Using Splines

360

380

400

420

440

a2

2840 2860 2880 2900

360

380

400

420

440

a1

−10

−5

0

5

10

d2

2840 2860 2880 2900−10

−5

0

5

10

d1

360

380

400

420

s

Signal and Details

360

380

400

420

s

Signal and Approximations

Page 318: Wavelet ug

4 Wavelets in Action: Examples and Case Studies

4-48

Page 319: Wavelet ug

5

Using Wavelet Packets

About Wavelet Packet Analysis . . . . . . . . . . . 5-3

One-Dimensional Wavelet Packet Analysis . . . . . . 5-7Compressing a Signal Using Wavelet Packets . . . . . . . 5-12De-Noising a Signal Using Wavelet Packets . . . . . . . . 5-15

Two-Dimensional Wavelet Packet Analysis . . . . . . 5-21Compressing an Image Using Wavelet Packets . . . . . . 5-25

Importing and Exporting from Graphical Tools . . . . 5-29Saving Information to Disk . . . . . . . . . . . . . . 5-29Loading Information into the Graphical Tools . . . . . . . 5-33

Page 320: Wavelet ug

5 Using Wavelet Packets

5-2

The Wavelet Toolbox contains graphical tools and command line functions that let you:

• Examine and explore characteristics of individual wavelet packets

• Perform wavelet packet analysis of one- and two-dimensional data

• Use wavelet packets to compress and remove noise from signals and images

This chapter takes you step-by-step through examples that teach you how to use the Wavelet Packet 1-D and Wavelet Packet 2-D graphical tools. The last section discusses how to transfer information from the graphical tools into your disk, and back again.

Because of the inherent complexity of packing and unpacking complete wavelet packet decomposition tree structures, we recommend using the Wavelet Packet 1-D and Wavelet Packet 2-D graphical tools for performing exploratory analyses.

The command line functions are also available and provide the same capabilities. However, it is most efficient to use the command line only for performing batch processing.

Note For more background on the Wavelet Packets, you can see the section “Wavelet Packets” on page 6-125.

Some object-oriented programming features are used for wavelet packet tree structures. For more detail, refer to “Object-Oriented Programming” on page B-1.

Page 321: Wavelet ug

About Wavelet Packet Analysis

5-3

About Wavelet Packet AnalysisThis chapter takes you through the features of one- and two-dimensional wavelet packet analysis using the MATLAB Wavelet Toolbox. You’ll learn how to:

• Load a signal or image

• Perform a wavelet packet analysis of a signal or image

• Compress a signal

• Remove noise from a signal

• Compress an image

• Show statistics and histograms

The Wavelet Toolbox provides these functions for wavelet packet analysis. For more information, see the reference pages. The reference entries for these functions include examples showing how to perform wavelet packet analysis via the command line.

Some more advanced examples mixing command line and GUI functions can be found in the section “Simple Use of Objects Through Four Examples” on page B-4.

Analysis-Decomposition Functions.

Synthesis-Reconstruction Functions.

Function Name Purpose

wpcoef Wavelet packet coefficients

wpdec and wpdec2 Full decomposition

wpsplt Decompose packet

Function Name Purpose

wprcoef Reconstruct coefficients

wprec and wprec2 Full reconstruction

wpjoin Recompose packet

Page 322: Wavelet ug

5 Using Wavelet Packets

5-4

Decomposition Structure Utilities.

De-noising and Compression.

In the wavelet packet framework, compression and de-noising ideas are exactly the same as those developed in the wavelet framework. The only difference is that wavelet packets offer a more complex and flexible analysis, because in wavelet packet analysis, the details as well as the approximations are split.

Function Name Purpose

besttree Find best tree

bestlevt Find best level tree

entrupd Update wavelet packets entropy

get Get WPTREE object fields contents

read Read values in WPTREE object fields

wentropy Entropy

wp2wtree Extract wavelet tree from wavelet packet tree

wpcutree Cut wavelet packet tree

Function Name Purpose

ddencmp Default values for de-noising and compression

wpbmpen Penalized threshold for wavelet packet de-noising

wpdencmp De-noising and compression using wavelet packets

wpthcoef Wavelet packets coefficients thresholding

wthrmngr Threshold settings manager

Page 323: Wavelet ug

About Wavelet Packet Analysis

5-5

A single wavelet packet decomposition gives a lot of bases from which you can look for the best representation with respect to a design objective. This can be done by finding the “best tree” based on an entropy criterion.

De-noising and compression are interesting applications of wavelet packet analysis. The wavelet packet de-noising or compression procedure involves four steps:

1 Decomposition

For a given wavelet, compute the wavelet packet decomposition of signal x at level N.

2 Computation of the best tree

For a given entropy, compute the optimal wavelet packet tree. Of course, this step is optional. The graphical tools provide a Best Tree button for making this computation quick and easy.

3 Thresholding of wavelet packet coefficients

For each packet (except for the approximation), select a threshold and apply thresholding to coefficients.

S

A1 D1

AA2 DA2

AAA3 DAA3

AD2 DD2

ADA3 DDA3 AAD3 DAD3 ADD3 DDD3

Page 324: Wavelet ug

5 Using Wavelet Packets

5-6

The graphical tools automatically provide an initial threshold based on balancing the amount of compression and retained energy. This threshold is a reasonable first approximation for most cases. However, in general you will have to refine your threshold by trial and error so as to optimize the results to fit your particular analysis and design criteria.

The tools facilitate experimentation with different thresholds, and make it easy to alter the tradeoff between amount of compression and retained signal energy.

4 Reconstruction

Compute wavelet packet reconstruction based on the original approximation coefficients at level N and the modified coefficients.

In this example, we’ll show how you can use one-dimensional wavelet packet analysis to compress and to de-noise a signal.

Page 325: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-7

One-Dimensional Wavelet Packet AnalysisWe now turn to the Wavelet Packet 1-D tool to analyze a synthetic signal that is the sum of two linear chirps.

Starting the Wavelet Packet 1-D Tool.

1 From the MATLAB prompt, type wavemenu.

The Wavelet Toolbox Main Menu appears.

2 Click the Wavelet Packet 1-D menu item.

The tool appears on the desktop.

Page 326: Wavelet ug

5 Using Wavelet Packets

5-8

Loading a Signal.

3 From the File menu, choose the Load Signal option.

4 When the Load Signal dialog box appears, select the demo MAT-file sumlichr.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

The sumlichr signal is loaded into the Wavelet Packet 1-D tool.

Page 327: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-9

Analyzing a Signal.

5 Make the appropriate settings for the analysis. Select the db2 wavelet, level 4, entropy threshold, and for the threshold parameter type 1. Click the Analyze button.

The available entropy types are listed below.

Type Description

Shannon Non-normalized entropy involving the logarithm of the squared value of each signal sample — or, more formally:

Threshold The number of samples for which the absolute value of the signal exceeds a threshold .

Norm The concentration in norm with .

Log Energy The logarithm of “energy,” defined as the sum over all samples: .

si2 si

2( )log∑–

ε

l p 1 p≤

si2( )log∑

Page 328: Wavelet ug

5 Using Wavelet Packets

5-10

For more information about the available entropy types, user-defined entropy, and threshold parameters, see the wentropy reference page, and “Choosing the Optimal Decomposition” on page 6-137.

Note Many capabilities are available using the command area on the right of the Wavelet Packet 1-D window. Some of them are used in the sequel. For a more complete description, see “Wavelet Packet Tool Features (1-D and 2-D)” on page A-21.

SURE (Stein’s Unbiased Risk Estimate)

A threshold-based method in which the threshold equals:

where n is the number of samples in the signal.

User An entropy type criterion you define in an M-file.

Type Description

2loge nlog2 n( )( )

Page 329: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-11

Computing the Best Tree.

Because there are so many ways to reconstruct the original signal from the wavelet packet decomposition tree, we select the best tree before attempting to compress the signal.

6 Click the Best Tree button.

After a pause for computation, the Wavelet Packet 1-D tool displays the best tree. Use the top and bottom sliders to spread nodes apart and pan over to particular areas of the tree, respectively.

Observe that, for this analysis, the best tree and the initial tree are almost the same. One branch at the far right of the tree was eliminated.

Pan left or right

Spread or contract tree nodesto improve readability

Page 330: Wavelet ug

5 Using Wavelet Packets

5-12

Compressing a Signal Using Wavelet Packets

Selecting a Threshold for Compression.

1 Click the Compress button.

The Wavelet Packet 1-D Compression window appears with an approximate threshold value automatically selected.

The left most graph shows how the threshold (vertical yellow dotted line) has been chosen automatically (1.482) to balance the number of zeros in the compressed signal (blue curve that increases as the threshold increases) with the amount of energy retained in the compressed signal (purple curve that decreases as the threshold increases).

This threshold means that any signal element whose value is less than 1.482 will be set to zero when we perform the compression.

Threshold controls are located to the right (see the red box in the figure above). Note that the automatic threshold of 1.482 results in a retained energy of only 81.49%. This may cause unacceptable amounts of distortion, especially in the peak values of the oscillating signal. Depending on your

Page 331: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-13

design criteria, you may want to choose a threshold that retains more of the original signal’s energy.

2 Adjust the threshold by typing 0.8938 in the text field opposite the threshold slider, and then press the Enter key.

The value 0.8938 is a number that we have discovered through trial and error yields more satisfactory results for this analysis.

After a pause, the Wavelet Packet 1-D Compression window displays new information.

Note that, as we have reduced the threshold from 1.482 to 0.8938:

- The vertical yellow dotted line has shifted to the left.

- The retained energy has increased from 81.49% to 90.96%.

- The number of zeros (equivalent to the amount of compression) has decreased from 81.55% to 75.28%.

Page 332: Wavelet ug

5 Using Wavelet Packets

5-14

Compressing a Signal.

3 Click the Compress button.

The Wavelet Packet 1-D tool compresses the signal using the thresholding criterion we selected.

The original (red) and compressed (yellow) signals are displayed superimposed. Visual inspection suggests the compression quality is quite good.

Looking more closely at the compressed signal, we can see that the number of zeros in the wavelet packets representation of the compressed signal is about 75.3%, and the retained energy about 91%.

If you try to compress the same signal using wavelets with exactly the same parameters, only 89% of the signal energy is retained, and only 59% of the wavelet coefficients set to zero. This illustrates the superiority of wavelet packets for performing compression, at least on certain signals.

You can demonstrate this to yourself by returning to the main Wavelet Packet 1-D window, computing the wavelet tree, and then repeating the compression.

Page 333: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-15

De-Noising a Signal Using Wavelet PacketsWe now use the Wavelet Packet 1-D tool to analyze a noisy chirp signal. This analysis illustrates the use of Stein’s Unbiased Estimate of Risk (SURE) as a principle for selecting a threshold to be used for de-noising.

This technique calls for setting the threshold T to

where n is the length of the signal.

A more thorough discussion of the SURE criterion appears in “Choosing the Optimal Decomposition” on page 6-137. For now, suffice it to say that this method works well if your signal is normalized in such a way that the data fit the model x(t) = f(t) + e(t), where e(t) is a Gaussian white noise with zero mean and unit variance.

If you’ve already started the Wavelet Packet 1-D tool and it is active on your computer’s desktop, skip ahead to step 3.

Starting the Wavelet Packet 1-D Tool.

1 From the MATLAB prompt, type wavemenu.

The Wavelet Toolbox Main Menu appears.

T 2loge nlog2 n( )( )=

Page 334: Wavelet ug

5 Using Wavelet Packets

5-16

2 Click the Wavelet Packet 1-D menu item.

The tool appears on the desktop.

Loading a Signal.

3 From the File menu, choose the Load Signal option.

4 When the Load Signal dialog box appears, select the demo MAT-file noischir.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

Page 335: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-17

The noischir signal is loaded into the Wavelet Packet 1-D tool. Notice that the signal’s length is 1024. This means we should set the SURE criterion threshold equal to sqrt(2.*log(1024.*log2(1024))), or 4.2975.

Analyzing a Signal.

5 Make the appropriate settings for the analysis. Select the db2 wavelet, level 4, entropy type sure, and threshold parameter 4.2975. Click the Analyze button.

Signal length

Page 336: Wavelet ug

5 Using Wavelet Packets

5-18

There is a pause while the wavelet packet analysis is computed.

Note Many capabilities are available using the command area on the right of the Wavelet Packet 1-D window. Some of them are used in the sequel. For a more complete description, see “Wavelet Packet Tool Features (1-D and 2-D)” on page A-21.

Computing the Best Tree and Performing De-Noising.

6 Click the Best Tree button.

Computing the best tree makes the de-noising calculations more efficient.

7 Click the De-noise button. This brings up the Wavelet Packet 1-D De-Noising window.

Page 337: Wavelet ug

One-Dimensional Wavelet Packet Analysis

5-19

8 Click the De-noise button located at the center right side of the Wavelet Packet 1-D De-Noising window.

The results of the de-noising operation are quite good, as can be seen by looking at the thresholded coefficients. The frequency of the chirp signal increases quadratically over time, and the thresholded coefficients essentially capture the quadratic curve in the time-frequency plane.

Page 338: Wavelet ug

5 Using Wavelet Packets

5-20

You can also use the wpdencmp function to perform wavelet packet de-noising or compression from the command line.

Page 339: Wavelet ug

Two-Dimensional Wavelet Packet Analysis

5-21

Two-Dimensional Wavelet Packet AnalysisIn this section, we employ the Wavelet Packet 2-D tool to analyze and compress an image of a fingerprint. This is a real-world problem: the Federal Bureau of Investigation (FBI) maintains a large database of fingerprints — about 30 million sets of them. The cost of storing all this data runs to hundreds of millions of dollars.

“The FBI uses eight bits per pixel to define the shade of gray and stores 500 pixels per inch, which works out to about 700 000 pixels and 0.7 megabytes per finger to store finger prints in electronic form.” (Wickerhauser, see the reference [Wic94] p. 387, listed in “References” on page 6-145).

“The technique involves a 2-dimensional DWT, uniform scalar quantization (a process that truncates, or quantizes, the precision of the floating-point DWT output) and Huffman entropy coding (i.e., encoding the quantized DWT output with a minimal number of bits).” (Brislawn, see the reference [Bris95] p. 1278, listed in “References” on page 6-145).

By turning to wavelets, the FBI has achieved a 15:1 compression ratio. In this application, wavelet compression is better than the more traditional JPEG compression, as it avoids small square artifacts and is particularly well suited to detect discontinuities (lines) in the fingerprint.

Note that the international standard JPEG 2000 will include the wavelets as a part of the compression and quantization process. This points out the present strength of the wavelets.

Page 340: Wavelet ug

5 Using Wavelet Packets

5-22

Starting the Wavelet Packet 2-D Tool.

1 From the MATLAB prompt, type:

wavemenu

The Wavelet Toolbox Main Menu appears.

2 Click the Wavelet Packet 2-D menu item.

The tool appears on the desktop.

Page 341: Wavelet ug

Two-Dimensional Wavelet Packet Analysis

5-23

Loading an Image.

From the File menu, choose the Load Image option.

3 When the Load Image dialog box appears, select the demo MAT-file detfingr.mat, which should reside in the MATLAB directory toolbox/wavelet/wavedemo. Click the OK button.

The fingerprint image is loaded into the Wavelet Packet 2-D tool.

Page 342: Wavelet ug

5 Using Wavelet Packets

5-24

Analyzing an Image.

4 Make the appropriate settings for the analysis. Select the haar wavelet, level 3, and entropy type shannon. Click the Analyze button.

There is a pause while the wavelet packet analysis is computed.

Note Many capabilities are available using the command area on the right of the Wavelet Packet 2-D window. Some of them are used in the sequel. For a more complete description, see “Wavelet Packet Tool Features (1-D and 2-D)” on page A-21.

5 Click the Best Tree button to compute the best tree before compressing the image.

Page 343: Wavelet ug

Two-Dimensional Wavelet Packet Analysis

5-25

Compressing an Image Using Wavelet Packets

1 Click the Compress button to bring up the Wavelet Packet 2-D Compression window. Select the Bal. sparsity-norm (sqrt) option from the Select thresholding method menu.

Notice that the default threshold (7.125) provides about 64% compression while retaining virtually all the energy of the original image. Depending on your criteria, it may be worthwhile experimenting with more aggressive thresholds to achieve a higher degree of compression. Recall that we are not doing any quantization of the image, merely setting specific coefficients to zero. This can be considered a pre-compression step in a broader compression system.

2 Alter the threshold: type the number 30 in the text field opposite the threshold slider located on the right side of the Wavelet Packet 2-D Compression window. Then press the Enter key.

Page 344: Wavelet ug

5 Using Wavelet Packets

5-26

Setting all wavelet packet coefficients whose value falls below 30 to zero yields much better results. Note that the new threshold achieves around 92% of zeros, while still retaining nearly 98% of the image energy. Compare this wavelet packet analysis to the wavelet analysis of the same image in “Compressing Images” on page 3-26.

3 Click the Compress button to start the compression.

You can see the result obtained by wavelet packet coefficients thresholding and image reconstruction. The visual recovery is correct, but not perfect. The compressed image, shown side-by-side with the original, shows some artifacts.

4 Click the Close button located at the bottom of the Wavelet Packet 2-D Compression window. Update the synthesized image by clicking Yes when the dialog box appears.

Page 345: Wavelet ug

Two-Dimensional Wavelet Packet Analysis

5-27

Take this opportunity to try out your own compression strategy. Adjust the threshold value, the entropy function, and the wavelet, and see if you can obtain better results.

Hint: The bior6.8 wavelet is better suited to this analysis than is haar, and can lead to a better compression ratio. When a biorthogonal wavelet is used, then instead of “Retained energy” the information displayed is “Energy ratio.” For more information, see “Compression Scores” on page 6-101.

Before concluding this analysis, it is worth turning our attention to the “colored coefficients for terminal nodes plot” and considering the best tree decomposition for this image.

This plot is shown in the lower right side of the Wavelet Packet 2-D tool. The plot shows us which details have been decomposed and which have not. Larger squares represent details that have not been broken down to as many levels as smaller squares. Consider, for example, this level 2 decomposition pattern:

Approximation, Level 2

Vertical Detail, Level 2

Diagonal Detail, Level 1

Decomposition of the Level 1Horizontal Detail

Decomposition of the Level 1Vertical Detail

Page 346: Wavelet ug

5 Using Wavelet Packets

5-28

Looking at the pattern of small and large squares in the fingerprint analysis shows that the best tree algorithm has apparently singled out the diagonal details, often sparing these from further decomposition. Why is this?

If we consider the original image, we realize that much of its information is concentrated in the sharp edges that constitute the fingerprint’s pattern. Looking at these edges, we see that they are predominantly oriented horizontally and vertically. This explains why the best tree algorithm has “chosen” not to decompose the diagonal details — they do not provide very much information.

Page 347: Wavelet ug

Importing and Exporting from Graphical Tools

5-29

Importing and Exporting from Graphical ToolsThe Wavelet Packet 1-D and Wavelet Packet 2-D tools let you import information from and export information to your disk.

If you adhere to the proper file formats, you can:

• Save decompositions as well as synthesized signals and images from the wavelet packet graphical tools to disk

• Load signals, images, and one- and two-dimensional decompositions from disk into the Wavelet Packet 1-D and Wavelet Packet 2-D graphical tools

Saving Information to DiskUsing specific file formats, the graphical tools let you save synthesized signals or images, as well as one- or two-dimensional wavelet packet decomposition structures. This feature provides flexibility and allows you to combine command line and graphical interface operations.

Saving Synthesized SignalsYou can process a signal in the Wavelet Packet 1-D tool, and then save the processed signal to a MAT-file.

For example, load the example analysis:

File⇒Example Analysis⇒db1 – depth: 2 – ent: shannon −−> sumsin

and perform a compression or de-noising operation on the original signal. When you close the Wavelet Packet 1-D De-noising or Wavelet Packet 1-D Compression window, update the synthesized signal by clicking Yes in the dialog box.

Then, from the Wavelet Packet 1-D tool, select the File⇒Save⇒Synthesized Signal menu option.

A dialog box appears allowing you to select a directory and filename for the MAT-file. For this example, choose the name synthsig.

Page 348: Wavelet ug

5 Using Wavelet Packets

5-30

To load the signal into your workspace, simply type:

load synthsigwhos

The synthesized signal is given by synthsig. In addition, the parameters of the de-noising or compression process are given by the wavelet name (wname) and the global threshold (valTHR).

valTHR

valTHR = 1.9961

Saving Synthesized ImagesYou can process an image in the Wavelet Packet 2-D tool, and then save the processed image to a MAT-file (with extension mat or other).

For example, load the example analysis:

File⇒Example Analysis⇒db1 – depth: 1 – ent: shannon −−> woman

and perform a compression on the original image. When you close the Wavelet Packet 2-D Compression window, update the synthesized image by clicking Yes in the dialog box that appears.

Then, from the Wavelet 2-D tool, select the File⇒Save⇒Synthesized Image menu option.

A dialog box appears allowing you to select a directory and filename for the MAT-file. For this example, choose the name wpsymage.

Name Size Bytes Class

synthsig 1x1000 8000 double arrayvalTHR 1x1 8 double arraywname 1x3 6 char array

Page 349: Wavelet ug

Importing and Exporting from Graphical Tools

5-31

To load the image into your workspace, simply type:

load wpsymagewhos

The synthesized image is given by X. The variable map contains the associated colormap. In addition, the parameters of the de-noising or compression process are given by the wavelet name (wname) and the global threshold (valTHR).

Saving One-Dimensional Decomposition StructuresThe Wavelet Packet 1-D tool lets you save an entire wavelet packet decomposition tree and related data to your disk. The toolbox creates a MAT-file in the current directory with a name you choose, followed by the extension wp1 (wavelet packet 1-D).

Open the Wavelet Packet 1-D tool and load the example analysis:

File⇒Example Analysis⇒db1 – depth: 2 – ent: shannon −−> sumsin

To save the data from this analysis, use the menu option File⇒Save Decomposition.

A dialog box appears that lets you specify a directory and file name for storing the decomposition data. Type the name wpdecex1d.

After saving the decomposition data to the file wpdecex1d.wp1, load the variables into your workspace.

load wpdecex1d.wp1 -matwhos

Name Size Bytes Class

X 256x256 524288 double array map 255x3 6120 double arrayvalTHR 1x1 8 double array wname 1x3 6 char array

Name Size Bytes Class

data_name 1x6 12 char array

Page 350: Wavelet ug

5 Using Wavelet Packets

5-32

The variable tree_struct contains the wavelet packet tree structure. The variable data_name contains the data name and valTHR contains the global threshold, which is currently empty since the synthesized signal does not exist.

Saving Two-Dimensional Decomposition StructuresThe file format, variables, and conventions are exactly the same as in the one-dimensional case except for the extension, which is wp2 (wavelet packet 2-D). The variables saved are the same as with the one-dimensional case, with the addition of the colormap matrix map:

Save options are also available when performing de-noising or compression inside the Wavelet Packet 1-D and Wavelet Packet 2-D tools.

In the Wavelet Packet De-noising windows, you can save the de-noised signal or image and the decomposition. The same holds true for the Wavelet Packet Compression windows.

This way, you can save directly many different trials from inside the De-noising and Compression windows without going back to the main Wavelet Packet windows during a fine-tuning process.

Note When saving a synthesized signal (1-D), a synthesized image (2-D) or a decomposition to a MAT-file, the extension of this file is free. The mat extension is not necessary.

tree_struct 1x1 11176 wptree objectvalTHR 0x0 0 double array

Name Size Bytes Class

data_name 1x5 10 char array map 255x3 6120 double arraytree_struct 1x1 527400 wptree objectvalTHR 1x1 8 double array

Page 351: Wavelet ug

Importing and Exporting from Graphical Tools

5-33

Loading Information into the Graphical ToolsYou can load signals, images, or one- and two-dimensional wavelet packet decompositions into the graphical interface tools. The information you load may have been previously exported from the graphical interface, and then manipulated in the workspace, or it may have been information you generated initially from the command line.

In either case, you must observe the strict file formats and data structures used by the graphical tools, or else errors will result when you try to load information.

Loading SignalsTo load a signal you’ve constructed in your MATLAB workspace into the Wavelet Packet 1-D tool, save the signal in a MAT-file (with extension mat or other).

For instance, suppose you’ve designed a signal called warma and want to analyze it in the Wavelet Packet 1-D tool.

save warma warma

The workspace variable warma must be a vector.

sizwarma = size(warma)

sizwarma = 1 1000

To load this signal into the Wavelet Packet 1-D tool, use the menu option File⇒Load Signal.

A dialog box appears that lets you select the appropriate MAT-file to be loaded.

Note The first one-dimensional variable encountered in the file is considered the signal. Variables are inspected in alphabetical order.

Page 352: Wavelet ug

5 Using Wavelet Packets

5-34

Loading ImagesThis toolbox supports only indexed images. An indexed image is a matrix containing only integers from 1 to n, where n is the number of colors in the image.

This image may optionally be accompanied by a n-by-3 matrix called map. This is the colormap associated with the image. When MATLAB displays such an image, it uses the values of the matrix to look up the desired color in this colormap. If the colormap is not given, the Wavelet Packet 2-D graphical tool uses a monotonic colormap with max(max(X))–min(min(X))+1 colors.

To load an image you’ve constructed in your MATLAB workspace into the Wavelet Packet 2-D tool, save the image (and optionally, the variable map) in a MAT-file (with extension mat or other).

For instance, suppose you’ve created an image called brain and want to analyze it in the Wavelet Packet 2-D tool. Type:

X = brain;map = pink(256);save myfile X map

To load this image into the Wavelet Packet 2-D tool, use the menu option File⇒Load Image.

A dialog box appears that lets you select the appropriate MAT-file to be loaded.

Note The first two-dimensional variable encountered in the file (except the variable map, which is reserved for the colormap) is considered the image. Variables are inspected in alphabetical order.

Caution The graphical tools allow you to load an image that does not contain integers from 1 to n. The computations will be correct since they act directly on the matrix, but the display of the image will be strange. The values less than 1 will be evaluated as 1, the values greater than n will be evaluated as n, and a real value within the interval [1,n] will be evaluated as the closest integer.

Page 353: Wavelet ug

Importing and Exporting from Graphical Tools

5-35

Note that the coefficients, approximations, and details produced by wavelet packets decomposition are not indexed image matrices. To display these images in a suitable way, the Wavelet Packet 2-D tool follows these rules:

• Reconstructed approximations are displayed using the colormap map. The same holds for the result of the reconstruction of selected nodes.

• The coefficients and the reconstructed details are displayed using the colormap map applied to a rescaled version of the matrices.

Loading Wavelet Packet Decomposition StructuresYou can load one- and two-dimensional wavelet packet decompositions into the graphical tools providing you have previously saved the decomposition data in a MAT-file of the appropriate format.

While it is possible to edit data originally created using the graphical tools, and then exported, you must be careful about doing so. Wavelet packet data structures are complex, and the graphical tools do not do any consistency checking. This can lead to errors if you try to load improperly formatted data.

One-dimensional data file contains the variables:

These variables must be saved in a MAT-file (with extension wp1 or other).

Two-dimensional data file contains the variables:

Variable Status Description

tree_struct Required Object specifying the tree structure

data_name Optional String specifying the name of the decomposition

valTHR Optional Global threshold (can be empty if neither compression nor de-noising has been done)

Variable Status Description

tree_struct Required Object specifying the tree structure

data_name Optional String specifying the name of the decomposition

Page 354: Wavelet ug

5 Using Wavelet Packets

5-36

These variables must be saved in a MAT-file (with extension wp2 or other).

To load the properly-formatted data, use the menu option File⇒Load Decomposition Structure from the appropriate tool, and then select the desired MAT-file from the dialog box that appears.

The Wavelet Packet 1-D or 2-D graphical tool then automatically updates its display to show the new analysis.

Note When loading a signal (1-D), an image (2-D), or a decomposition (1-D or 2-D) from a MAT-file, the extension of this file is free. The mat extension is not necessary.

map Optional Image map

valTHR Optional Global threshold (can be empty if neither compression nor de-noising has been done)

Page 355: Wavelet ug

6

Advanced Concepts

6General Concepts . . . . . . . . . . . . . . . . . 6-5

The Fast Wavelet Transform (FWT) Algorithm . . . . 6-20

Dealing with Border Distortion . . . . . . . . . . . 6-37

Discrete Stationary Wavelet Transform (SWT) . . . . 6-47

Frequently Asked Questions . . . . . . . . . . . . . 6-54

Wavelet Families: Additional Discussion . . . . . . . 6-65

Wavelet Applications: More Detail . . . . . . . . . . 6-87

Wavelet Packets . . . . . . . . . . . . . . . . . 6-125

References . . . . . . . . . . . . . . . . . . . . 6-145

General Concepts . . . . . . . . . . . . . . . . . 6-5

The Fast Wavelet Transform (FWT) Algorithm . . . . 6-19

Dealing with Border Distortion . . . . . . . . . . . 6-35

Discrete Stationary Wavelet Transform (SWT) . . . . 6-44

Frequently Asked Questions . . . . . . . . . . . . . 6-51

Wavelet Families: Additional Discussion . . . . . . . 6-61

Wavelet Applications: More Detail . . . . . . . . . . 6-80

Wavelet Packets . . . . . . . . . . . . . . . . . 6-117

References . . . . . . . . . . . . . . . . . . . . 6-135

Page 356: Wavelet ug

6 Advanced Concepts

6-2

This chapter presents a more advanced treatment of wavelet methods. It assumes that the reader is comfortable with mathematical ideas. For mathematical conventions, see the “Mathematical Conventions” section that follows. For more detail on the theory, see “References” on page 6-135.

For more clarity, this chapter focuses on real wavelets, except in the two sections dedicated to wavelet families (see “Wavelet Families: Additional Discussion” on page 6-61 and “Summary of Wavelet Families and Associated Properties (Part 2)” on page 6-79).

In this chapter, major topics are

• “General Concepts” on page 6-5

• “The Fast Wavelet Transform (FWT) Algorithm” on page 6-19

• “Dealing with Border Distortion” on page 6-35

• “Discrete Stationary Wavelet Transform (SWT)” on page 6-44

• “Frequently Asked Questions” on page 6-51

• “Wavelet Families: Additional Discussion” on page 6-61

• “Wavelet Applications: More Detail” on page 6-80

• “Wavelet Packets” on page 6-117

• “References” on page 6-135

Mathematical ConventionsThis chapter and the reference pages use certain mathematical conventions.

General Notation Interpretation

Dyadic scale. is the level, 1/ or is the resolution

Dyadic translation

Continuous time

or Discrete time

Pixel

Signal or image. The signal is a function defined on or , the image is defined on or

Fourier transform of the function f or the sequence f

a 2j= j Z∈, j a 2 j–

b ka= k Z∈,t

k n

i j,( )s R

Z R2 Z2

Page 357: Wavelet ug

6-3

Continuous Time

Set of signals of finite energy

Energy of the signal

Scalar product of signals and

Set of images of finite energy

Energy of the image

Scalar product of images and

Discrete Time

Set of signals of finite energy

Energy of the signal

Scalar product of signals and

Set of images of finite energy

Energy of the image

Scalar product of images and

General Notation Interpretation

L2 R( )

s2 x( ) xdR

∫ s

s s′,⟨ ⟩ s x( )s′ x( ) xdR

∫= s s′

L2 R2( )

R∫ s2 x y,( ) xd ydR∫

s

s s′,⟨ ⟩ s x y,( )s′ x y,( ) xd ydR

∫R

∫= s s′

l2 Z( )

s2 n( )n Z∈

∑ s

s s′,⟨ ⟩ s n( )s′ n( )n Z∈∑= s s′

l2 Z2( )

n Z∈∑ s2 n m,( )m Z∈∑ s

s s′,⟨ ⟩ s n m,( )s′ n m,( )m Z∈

∑n Z∈

∑= s s′

Page 358: Wavelet ug

6 Advanced Concepts

6-4

Wavelet Notation Interpretation

Aj j-level approximation or approximation at level j

Dj j-level detail or detail at level j

φ Scaling function

ψ Wavelet

Family associated with the one-dimensional wavelet, indexed by and .

Family associated with the two-dimensional wavelet, indexed by

Family associated with the one-dimensional scaling function for dyadic scales ; It should be noted that

Family associated with the one-dimensional for dyadic scales ; It should be noted that

Scaling filter associated with a wavelet

Wavelet filter associated with a wavelet

1a

-------ψ x b–a

------------

a 0> b R∈

1a1a2

-----------------ψx1 b1–

a1------------------

x2 b2–

a2------------------,

x x1 x2( , )= R2∈, a1 0 a2 0 b1 R b2 R∈,∈,>,>

φj k, x( ) 2 j– 2⁄ φ 2 j– x k–( )= j Z∈ k Z∈, , a 2j,b ka= =φ φ0 0,=

ψj k, x( ) 2 j– 2⁄ ψ 2 j– x k–( )= j Z∈ k Z∈, , ψa 2j,b ka= =

ψ ψ0 0,=

hk( ) k Z∈,gk( ) k Z∈,

Page 359: Wavelet ug

General Concepts

6-5

General ConceptsThis section presents a brief overview of wavelet concepts, focusing mainly on the orthogonal wavelet case. It includes the following sections:

• “Wavelets: A New Tool for Signal Analysis”

• “Wavelet Decomposition: A Hierarchical Organization” on page 6-5

• “Finer and Coarser Resolutions” on page 6-6

• “Wavelet Shapes” on page 6-6

• “Wavelets and Associated Families” on page 6-7

• “Wavelet Transforms: Continuous and Discrete” on page 6-12

• “Local and Global Analysis” on page 6-14

• “Synthesis: an Inverse Transform” on page 6-15

• “Details and Approximations” on page 6-15

Wavelets: A New Tool for Signal AnalysisWavelet analysis consists of decomposing a signal or an image into a hierarchical set of approximations and details. The levels in the hierarchy often correspond to those in a dyadic scale.

From the signal analyst’s point of view, wavelet analysis is a decomposition of the signal on a family of analyzing signals, which is usually an “orthogonal function method.” From an algorithmic point of view, wavelet analysis offers a harmonious compromise between decomposition and smoothing techniques.

Wavelet Decomposition: A Hierarchical OrganizationUnlike conventional techniques, wavelet decomposition produces a family of hierarchically organized decompositions. The selection of a suitable level for the hierarchy will depend on the signal and experience. Often the level is chosen based on a desired low-pass cutoff frequency.

At each level j, we build the j-level approximation Aj, or approximation at level j, and a deviation signal called the j-level detail Dj, or detail at level j. We can consider the original signal as the approximation at level 0, denoted by A0. The words approximation and detail are justified by the fact that A1 is an approximation of A0 taking into account the low frequencies of A0, whereas the

Page 360: Wavelet ug

6 Advanced Concepts

6-6

detail D1 corresponds to the high frequency correction. Among the figures presented in the section “Reconstructing Approximations and Details” on page 1-23, one of them graphically represents this hierarchical decomposition.

One way of understanding this decomposition consists of using an optical comparison. Successive images A1, A2, A3 of a given object are built. We use the same type of photographic devices, but with increasingly poor resolution. The images are successive approximations; one detail is the discrepancy between two successive images. Image A2 is, therefore, the sum of image A4 and intermediate details D4, D3:

Finer and Coarser ResolutionsThe organizing parameter, the scale a, is related to level j, by . If we define resolution as 1/a, then the resolution increases as the scale decreases. The greater the resolution, the smaller and finer are the details that can be accessed.

From a technical point of view, the size of the revealed details for any j is proportional to the size of the domain in which the wavelet or analyzing

function of the variable x, is not too close to 0.

Wavelet ShapesOne-dimensional analysis is based on one scaling function φ and one wavelet ψ. Two-dimensional analysis (on a square or rectangular grid) is based on one scaling function and three wavelets.

Figure 6-1, Various One-Dimensional Wavelets, shows φ and ψ for each wavelet, except the Morlet wavelet and the Mexican hat for which φ does not exist. All the functions decay quickly to zero. The Haar wavelet is the only noncontinuous function with three points of discontinuity (0, 0.5, 1). The ψ

j 10 9 ... 2 1 0 -1 -2

Scale 1024 512 ... 4 2 1 1/2 1/4

Resolution 1/210 1/29 ... 1/4 1/2 1 2 4

A2 A3 D3 A4 D4 D3+ +=+=

a 2j=

ψ xa---

φ x1 x2,( )

Page 361: Wavelet ug

General Concepts

6-7

functions oscillate more than associated φ functions. coif2 exhibits some angular points, db6 and sym6 are quite smooth. The Morlet and Mexican hat wavelets are symmetrical.

Figure 6-1 Various One-Dimensional Wavelets

Wavelets and Associated FamiliesIn the one-dimensional context, we distinguish the wavelet ψ from the associated function φ, called the scaling function. Some properties of ψ and φ are:

• The integral of ψ is zero, , and ψ is used to define the details.

−4 −2 0 2

−0.5

0

0.5

Morlet wavelet function

−5 0 5

−0.2

0

0.2

0.4

0.6

0.8

Mexican hat wavelet function

−5 0 5

−0.5

0

0.5

1

Meyer scaling function

−5 0 5

−0.5

0

0.5

1

Meyer wavelet function

0 0.5 1

−1

−0.5

0

0.5

1

Haar scaling function

0 0.5 1

−1

−0.5

0

0.5

1

Haar wavelet function

0 5 10

−1

−0.5

0

0.5

1

db6 scaling function

0 5 10

−1

−0.5

0

0.5

1

db6 wavelet function

0 5 10−1

−0.5

0

0.5

1

1.5

coif2 scaling function

0 5 10−1

−0.5

0

0.5

1

1.5

coif2 wavelet function

0 5 10−1

−0.5

0

0.5

1

1.5sym6 scaling function

0 5 10−1

−0.5

0

0.5

1

1.5sym6 wavelet function

ψ x( ) xd∫ 0=( )

Page 362: Wavelet ug

6 Advanced Concepts

6-8

• The integral of φ is 1, , and φ is used to define the approximations.

The usual two-dimensional wavelets are defined as tensor products of one-dimensional wavelets: is the scaling function and

are the three wavelets.

Figure 6-2, Two-Dimensional coif2 Wavelet, shows the four functions associated with the two-dimensional coif2 wavelet.

Figure 6-2: Two-Dimensional coif2 Wavelet

φ x( ) xd∫ 1=( )

φ x y,( ) φ x( )φ y( )=ψ1 x y,( ) φ x( )ψ y( ),ψ2 x y,( ) ψ x( )φ y( ),ψ3 x y,( ) ψ x( )ψ y( )===

Page 363: Wavelet ug

General Concepts

6-9

To each of these functions, we associate its doubly indexed family, which is used to:

• Move the basic shape from one side to the other, translating it to position b (see Figure 6-3, on page 6-9).

• Keep the shape while changing the one-dimensional time scale a ( ) (see Figure 6-4, on page 6-10).

So a wavelet family member has to be thought as a function located at a position b, and having a scale a.

In one-dimensional situations, the family of translated and scaled wavelets associated with ψ is expressed as follows.

Figure 6-3: Translated Wavelets

Translation Change of scale Translation and change of scale

ψ(x-b)

a 0>

1a

-------ψ xa---

1a

-------ψ x b–a

------------

b = 8 b = 0 b = -8

db3(x + 8) db3(x) db3(x - 8)

Page 364: Wavelet ug

6 Advanced Concepts

6-10

Figure 6-4: Time Scaled One-Dimensional Wavelet

In a two-dimensional context, we have the translation by vector and a change of scale of parameter .Translation and change of scale become:

In most cases, we will limit our choice of a and b values by using only the following discrete set (coming back to the one-dimensional context):

Let us define:

We now have a hierarchical organization similar to the organization of a decomposition, this is represented in the example of the Figure 6-5, Wavelets Organization. Let k = 0 and leave the translations aside for the moment. The functions associated with j = 0, 1, 2, 3 for φ (expressed as φj,0) and with j = 1, 2, 3 for ψ (expressed as ψj,0) are displayed in Figure 6-5, on page 6-11 for the db3 wavelet.

a = 0.5 a = 1 a = 2

db3(x) db3(x/2 - 7)db3(2x + 7)

b1 b2( , )a1 a2( , )

1a1a2

-----------------ψ x1 b1–

a1------------------

x2 b2–

a2------------------ ,

where x x1 x2( , ) R2∈=( )

j k( , ) Z2∈ : a 2j,= b k2j ka= =

j k( , ) Z2∈ : ψj k, 2 j 2⁄– ψ 2 j– x k–( ) φj k, 2 j 2⁄– φ 2 j– x k–( )=,=

Page 365: Wavelet ug

General Concepts

6-11

Figure 6-5: Wavelets Organization

In Figure 6-5, Wavelets Organization, the four-level decomposition is shown, progressing from the top to the bottom. We find φ0,0; then 21/2φ1,0, 21/2ψ1,0; then 2φ2,0, 2ψ2,0; then 23/2φ3,0, 23/2ψ3,0. The wavelet is db3.

0 20 40

1

0

1

2phi(x)

0 20 40

1

0

1

2phi(x/2)

0 20 40

1

0

1

2phi(x/4)

0 20 40

1

0

1

2psi(x/2)

0 20 40

1

0

1

2psi(x/4)

0 20 40

1

0

1

2phi(x/8)

0 20 40

1

0

1

2psi(x/8)

Page 366: Wavelet ug

6 Advanced Concepts

6-12

Wavelet Transforms: Continuous and DiscreteThe wavelet transform of a signal s is the family C(a,b), which depends on two indices a and b. The set to which a and b belong is given below in the table. The studies focus on two transforms:

• Continuous transform

• Discrete transform.

From an intuitive point of view, the wavelet decomposition consists of calculating a “resemblance index” between the signal and the wavelet located at position b and of scale a. If the index is large, the resemblance is strong, otherwise it is slight. The indexes C(a,b) are called coefficients.

We define the coefficients in the following table. We have two types of analysis at our disposal.

Next we will illustrate the differences between the two transforms, for the analysis of a fractal signal (see Figure 6-6, on page 6-13).

Continuous Time SignalContinuous Analysis

Continuous Time SignalDiscrete Analysis

C a b,( ) s t( ) 1a

-------ψ t b–a

----------- td

R∫= C a b,( ) s t( ) 1

a-------ψ t b–

a-----------

tdR∫=

a R+ 0{ }–∈ b R∈, a 2j= b k2j

= j k( , ) Z2∈, ,

Page 367: Wavelet ug

General Concepts

6-13

Figure 6-6: Continuous Versus Discrete Transform

Using a redundant representation close to the so-called continuous analysis, instead of a nonredundant discrete time-scale representation, can be useful for analysis purposes. The nonredundant representation is associated with an orthonormal basis, whereas the redundant representation uses much more scale and position values than a basis. For a classical fractal signal, the redundant methods are quite accurate.

• Graphic representation of discrete analysis: (in the middle of the Figure 6-6, Continuous Versus Discrete Transform) time is on the abscissa and on the ordinate the scale a is dyadic: 21, 22, 23, 24 and 25 (from the bottom to the top), levels are 1, 2, 3, 4 and 5. Each coefficient of level k is repeated 2k times.

• Graphic representation of continuous analysis: (at the bottom of the Figure 6-6, Continuous Versus Discrete Transform) time is on the abscissa and on the ordinate the scale varies almost continuously between 21 and 25 by step 1 (from the bottom to the top). Keep in mind that when a scale is small, only small details are analyzed, as in a geographical map.

0 100 200 300 400 5000

0.01

0.02Analyzed signal.

Discrete Transform, absolute coefficients.

leve

l

100 200 300 400 500Continuous Transform, absolute coefficients.

time (or space) b

Sca

le

100 200 300 400 500

Page 368: Wavelet ug

6 Advanced Concepts

6-14

Local and Global AnalysisA small scale value permits us to perform a local analysis; a large scale value is used for a global analysis. Combining local and global is a useful feature of the method. Let us be a bit more precise about the local part and glance at the frequency domain counterpart.

Imagine that the analyzing function φ or ψ is zero outside of a domain U, which is contained in a disk of radius ρ: . The wavelet ψ is localized. The signal s and the function ψ are then compared in the disk, taking into account only the t values in the disk. The signal values, which are located outside of the domain U, do not influence the value of the coefficient

The same argument holds when ψ is translated to position b and the corresponding coefficient analyzes s around b. So this analysis is local.

The wavelets having a compact support are used in local analysis. This is the case for Haar and Daubechies wavelets, for example. The wavelets whose values are considered as very small outside a domain U can be used with caution, as if they were in fact actually zero outside U. Not every wavelet has a compact support. This is the case, for instance, of the Meyer wavelet.

The previous localization is temporal, and is useful in analyzing a temporal signal (or spatial signal if analyzing an image). The good spectral domain localization is a second type of a useful property. A result (linked to the Heisenberg uncertainty principle) links the dispersion of the signal f and the dispersion of its Fourier transform , and therefore of the dispersion of ψ and

. The product of these dispersions is always greater than a constant c (which does not depend on the signal, but only on the dimension of the space). So, it is impossible to reduce arbitrarily both time and frequency localization.

In the Fourier and spectral analysis, the basic function is . This function is not a time localized function. The support is R. Its Fourier transform is a generalized function concentrated at point .

The function f is very poorly localized in time, but is perfectly localized in frequency. The wavelets generate an interesting “compromise” on the supports, and this compromise differs from that of complex exponentials, sine, or cosine.

ψ u( ) = 0, u∀ U∉

s t( )ψ t( ) t and we get s t( )ψ t( ) tdR∫ s t( )ψ t( ) td

U∫=dR∫

f x( ) exp iωx( )=

f ω

f

Page 369: Wavelet ug

General Concepts

6-15

Synthesis: an Inverse TransformIn order to be efficient and useful, a method designed for analysis also has to be able to perform synthesis. The wavelet method achieves this.

The analysis starts from s and results in the coefficients C(a,b). The synthesis starts from the coefficients C(a,b) and reconstructs s. Synthesis is the reciprocal operation of analysis.

For signals of finite energy, there are two formulas to perform the inverse wavelet transform:

• Continuous synthesis:

where is a constant depending on ψ.

• Discrete synthesis:

Of course, the previous formulas need some hypotheses on the function. More precisely, see “What Functions Are Candidates to Be a Wavelet?” on page 6-54 for the continuous synthesis formula and “Why Does Such an Algorithm Exist?” on page 6-28 for the discrete one.

Details and ApproximationsThe equations for continuous and discrete synthesis are of considerable interest and can be read in order to define the detail at level j:

1 Let us fix j and sum on k. A detail is nothing more than the function

2 Now, let us sum on j. The signal is the sum of all the details:

s t( ) 1Kψ-------

R+∫ C a b,( ) 1a

-------ψ t b–a

----------- da db

a2------------------

R∫=

s t( ) C j k,( )ψj k, t( ).k Z∈∑

j Z∈∑=

ψ

Dj

Dj t( ) C j k( , )ψj k, t( ).k Z∈∑=

Page 370: Wavelet ug

6 Advanced Concepts

6-16

The details have just been defined. Take a reference level called J. There are two sorts of details. Those associated with indices correspond to the scales

which are the fine details. The others, which correspond to j > J, are the coarser details.

We group these latter details into

which defines what is called an approximation of the signal s. We have just created the details and an approximation. They are connected. The equality

signifies that s is the sum of its approximation AJ and of its fine details. From the previous formula, it is obvious that the approximations are related to one another by:

For an orthogonal analysis, in which the ψj,k is an orthonormal family,

• AJ is orthogonal to DJ, DJ-1, DJ-2, ...

• s is the sum of the two orthogonal signals: AJ and

• AJ is an approximation of s. The quality (in energy) of the approximation of sby AJ is:

s Djj Z∈∑=

j J≤a 2j 2J≤=

AJ Djj J>∑=

s AJ Djj J≤∑+=

AJ 1– AJ DJ+=

Djj J≤∑

Dj Dk for j k≠⊥

qualJAJ

2

s 2--------------=

qualJ 1– qualJDJ

2

s 2--------------- qualJ≥+=

Page 371: Wavelet ug

General Concepts

6-17

The following table contains definitions of details and approximations.

From a graphical point of view, when analyzing a signal, it is always valuable to represent the different signals (s, Aj, Dj) and coefficients (C(j,k)).

Let us consider the Figure 6-7, on page 6-18.

On the left side, s is the signal, a5, a4, a3, a2, and a1 are the approximations at level 5, 4, 3, 2, and 1. The best approximation is a1; the next one is a2, and so on. Noise oscillations are exhibited in a1, whereas a5 is smoother.

On the right side, cfs represents the coefficients (for more information, see “Wavelet Transforms: Continuous and Discrete” on page 6-12), s is the signal, d5, d4, d3, d2, and d1 are the details at level 5, 4, 3, 2, and 1.

The different signals that are presented exist in the same time grid. We can consider that the t index of detail D4(t) identifies the same temporal instant as that of the approximation A5(t) and that of the signal s(t). This identity is of considerable practical interest in understanding the composition of the signal, even if the wavelet sometimes introduces dephasing.

Definition of the detail at level j

The signal is the sum of its details

The approximation at level J

Link between AJ-1 and AJ AJ-1 = AJ + DJ

Several decompositions

Dj t( ) C j k( , )ψj k, t( )k Z∈∑=

s Djj Z∈∑=

AJ Djj J>∑=

s AJ Djj J≤∑+=

Page 372: Wavelet ug

6 Advanced Concepts

6-18

Figure 6-7: Approximations, Details, and Coefficients

200

400s

200

300

400

500

a4

200

300

400

500

a3

200

300

400

500

a2

1000 2000 3000 4000

200

300

400

500

a1

−20

0

20

40

d4

−100

1020

d3

−100

1020

d2

1000 2000 3000 4000−20

0

20

d1

200

300

400

500

a5

−20

0

20

d5

200

300

400

500

s

Signal and Approximation(s)

cfs

Signal and Detail(s)

12345

Page 373: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-19

The Fast Wavelet Transform (FWT) Algorithm In 1988, Mallat produced a fast wavelet decomposition and reconstruction algorithm [Mal89]. The Mallat algorithm for discrete wavelet transform (DWT) is, in fact, a classical scheme in the signal processing community, known as a two channel subband coder using conjugate quadrature filters or quadrature mirror filters (QMF).

• The decomposition algorithm starts with signal s, next calculates the coordinates of A1 and D1, and then those of A2 and D2, and so on.

• The reconstruction algorithm called the inverse discrete wavelet transform (IDWT), starts from the coordinates of AJ and DJ, next calculates the coordinates of AJ-1, and then using the coordinates of AJ-1 and DJ-1 calculates those of AJ-2, and so on.

This section addresses the following topics:

• “Filters Used to Calculate the DWT and IDWT”

• “Algorithms” on page 6-23

• “Why Does Such an Algorithm Exist?” on page 6-28

• “One-Dimensional Wavelet Capabilities” on page 6-32

• “Two-Dimensional Wavelet Capabilities” on page 6-33

Filters Used to Calculate the DWT and IDWTFor an orthogonal wavelet, in the multiresolution framework (see [Dau92] Chapter 5), we start with the scaling function φ and the wavelet function ψ. One of the fundamental relations is the twin-scale relation (dilation equation or refinement equation):

All the filters used in DWT and IDWT are intimately related to the sequence

12---φ x

2---

wnφ x n–( )n Z∈∑=

wn( )n Z∈

Page 374: Wavelet ug

6 Advanced Concepts

6-20

Clearly if φ is compactly supported, the sequence (wn) is finite and can be viewed as a filter. The filter W, which is called the scaling filter (nonnormalized), is:

• Finite Impulse Response (FIR)

• of length 2N

• of sum 1

• of norm

• a low-pass filter

For example, for the db3 scaling filter:

load db3 db3

db3 =0.2352 0.5706 0.3252 -0.0955 -0.0604 0.0249

sum(db3)ans =

1.0000

norm(db3)ans =

0.7071

From filter W, we define four FIR filters, of length 2N and of norm 1, organized as follows.

The four filters are computed using the following scheme.

Filters Low-pass High-pass

Decomposition Lo_D Hi_D

Reconstruction Lo_R Hi_R

12

-------

Page 375: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-21

where qmf is such that Hi_R and Lo_R are quadrature mirror filters (i.e., Hi_R(k) = (-1) k Lo_R(2N + 1 - k)) for k = 1, 2, ..., 2N.

Note that wrev flips the filter coefficients. So Hi_D an Lo_D are also quadrature mirror filters. The computation of these filters is performed using orthfilt. Next, we illustrate these properties with the db6 wavelet. The plots associated with the following commands are shown in the Figure 6-8, on page 6-22.

% Load scaling filter.load db6; w = db6; subplot(421); stem(w); title('Original scaling filter');

% Compute the four filters.[Lo_D,Hi_D,Lo_R,Hi_R] = orthfilt(w); subplot(423); stem(Lo_D); title('Decomposition low-pass filter Lo{\_}D'); subplot(424); stem(Hi_D); title('Decomposition high-pass filter Hi{\_}D'); subplot(425); stem(Lo_R); title('Reconstruction low-pass filter Lo{\_}R'); subplot(426); stem(Hi_R); title('Reconstruction high-pass filter Hi{\_}R');

% High and low frequency illustration.n = length(Hi_D);freqfft = (0:n-1)/n;nn = 1:n;N = 10*n;

Lo_R = norm(W)

Lo_D = wrev(Lo_R)

Hi_D = wrev(Hi_R)

W

W

Hi_R = qmf (Lo_R)

Page 376: Wavelet ug

6 Advanced Concepts

6-22

for k=1:Nlambda(k) = (k-1)/N;XLo_D(k) = exp(-2*pi*j*lambda(k)*(nn-1))*Lo_D';XHi_D(k) = exp(-2*pi*j*lambda(k)*(nn-1))*Hi_D';

endfftld = fft(Lo_D);ffthd = fft(Hi_D);subplot(427); plot(lambda,abs(XLo_D),freqfft,abs(fftld),'o'); title('Transfer modulus: lowpass (Lo{\_}D or Lo{\_}R') subplot(428); plot(lambda,abs(XHi_D),freqfft,abs(ffthd),'o'); title('Transfer modulus: highpass (Hi{\_}D or Hi{\_}R')

Figure 6-8: The Four Wavelet Filters for db6

0 5 10 15−1

−0.5

0

0.5

1Original scaling filter

0 5 10 15−1

−0.5

0

0.5

1Decomposition lowpass filter Lo_D

0 5 10 15−1

−0.5

0

0.5

1Decomposition highpass filter Hi_D

0 5 10 15−1

−0.5

0

0.5

1Reconstruction lowpass filter Lo_R

0 5 10 15−1

−0.5

0

0.5

1Reconstruction highpass filter Hi_R

0 0.5 10

0.5

1

1.5Transfer modulus: lowpass (Lo_D or Lo_R)

0 0.5 10

0.5

1

1.5Transfer modulus: highpass (Hi_D or Hi_R)

Page 377: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-23

Algorithms• Given a signal s of length N, the DWT consists of log2N stages at most.

Starting from s, the first step produces two sets of coefficients: approximation coefficients cA1, and detail coefficients cD1. These vectors are obtained by convolving s with the low-pass filter Lo_D for approximation, and with the high-pass filter Hi_D for detail, followed by dyadic decimation.

More precisely, the first step is:

The length of each filter is equal to 2N. If n = length(s), the signals F and G, are of length n + 2N - 1, and then the coefficients cA1 and cD1 are of length

The next step splits the approximation coefficients cA1 in two parts using the same scheme, replacing s by cA1 and producing cA2 and cD2, and so on.

s

Lo_D

Hi_D

high-pass filter

F

G

downsample

downsample approximation

cA1

cD1

2

detail

low-pass filter

2

where:

2

X Convolve with filter X.

Keep the even indexed elements(see dyaddown).

coefficients

coefficients

floorn 1–

2-------------

N+

Page 378: Wavelet ug

6 Advanced Concepts

6-24

So the wavelet decomposition of the signal s analyzed at level j has the following structure: [cAj, cDj, ..., cD1].

This structure contains for J = 3, the terminal nodes of the following tree.

• Conversely, starting from cAj and cDj, the IDWT reconstructs cAj-1, inverting the decomposition step by inserting zeros and convolving the results with the reconstruction filters.

One-Dimensional DWT

Decomposition Step

Lo_D

Hi_D

cAj

2

Initialization

Convolve with filter X.

Downsample.

cA0 = s.

where

2

2

X

cAj+1

cDj+1

level j+1level j

s

cD1cA1

cD2cA2

cD3cA3

Page 379: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-25

• For images, a similar algorithm is possible for two-dimensional wavelets and scaling functions obtained from one-dimensional wavelets by tensorial product.

This kind of two-dimensional DWT leads to a decomposition of approximation coefficients at level j in four components: the approximation at level j + 1 and the details in three orientations (horizontal, vertical, and diagonal).

The following charts describe the basic decomposition and reconstruction steps for images:

cAj-1

Lo_R

Hi_R

high-passupsample

upsample

cAj

cDj

2

level j

low-pass

where: 2

X Convolve with filter X.

Insert zeros at odd-indexed elements.

Take the central part of U with the

2

wkeep

wkeepconvenient length.

level j-1

One-Dimensional IDWT

Reconstruction Step

Page 380: Wavelet ug

6 Advanced Concepts

6-26

Two-Dimensional DWT

Decomposition Step

rows

Lo_D

Hi_D

rows

cAj

2 1

columns

Initialization

Downsample columns: keep the even indexed columns.

Downsample rows: keep the even indexed rows.

Convolve with filter X the rows of the entry.

Convolve with filter X the columns of the entry.

CA0 = s for the decomposition initialization.

Where:

2 1

21

21

21

21

2 1

21

X

columns

Hi_D

Lo_D

X

columns

columns

Hi_D

Lo_D

cAj+1

cDj+1

cDj+1

cDj+1

(h)

(v)

(d)

horizontal

vertical

diagonal

columns

rows

Page 381: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-27

So, for J = 2, the two-dimensional wavelet tree has the following form.

Two-Dimensional IDWTReconstruction Step

cAj

columns

Upsample columns: insert zeros at odd-indexed columns.

Upsample rows: insert zeros at odd-indexed rows.

Convolve with filter X the rows of the entry.

Convolve with filter X the columns of the entry.

Where:

21

21

21

21

2 1

21

X

columns

Hi_R

Lo_R

X

columns

columns

Hi_R

Lo_R

cAj+1

cDj+1

cDj+1

cDj+1

(h)

(v)

(d)

horizontal

vertical

diagonal

columns

rows

rows

Lo_R

Hi_R

rows

2 1

2 1

wkeep

cD(h)1 cD

(d)1 cD

(v)1

cA2 cD(h)2 cD

(d)2

cD(v)2

s

cA1

Page 382: Wavelet ug

6 Advanced Concepts

6-28

Finally, let us mention that, for biorthogonal wavelets, the same algorithms hold but the decomposition filters on one hand and the reconstruction filters on the other hand are obtained from two distinct scaling functions associated with two multiresolution analyses in duality.

In this case, the filters for decomposition and reconstruction are, in general, of different odd lengths. This situation occurs, for example, for “splines” biorthogonal wavelets used in the toolbox. By zero-padding, the four filters can be extended in such a way that they will have the same even length.

Why Does Such an Algorithm Exist?The previous paragraph describes algorithms designed for finite-length signals or images. To understand the rationale, we must consider infinite-length signals. The methods for the extension of a given finite-length signal are described in the section “Dealing with Border Distortion” on page 6-35.

Let us denote h = Lo_R and g = Hi_R and focus on the one-dimensional case.

We first justify how to go from level j to level j+1, for the approximation vector. This is the main step of the decomposition algorithm for the computation of the approximations. The details are calculated in the same way using the filter g instead of filter h.

Let be the coordinates of the vector Aj:

and the coordinates of the vector Aj+1:

is calculated using the formula:

This formula resembles a convolution formula.

The computation is very simple.

Akj( )( )k Z∈

Aj Akj( )φj k,

k∑=

Akj 1+( )

Aj 1+ Akj 1+( )φj 1+ k,

k∑=

Akj 1+( )

Akj 1+( ) hn 2k– An

j( )

n∑=

Page 383: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-29

Let us define

The sequence is the filtered output of the sequence by the filter .

We obtain:

We have to take the even index values of F. This is downsampling.

The sequence is the downsampled version of the sequence .

The initialization is carried out using , where s(k) is the signal value at time k.

There are several reasons for this surprising result, all of which are linked to the multiresolution situation and to a few of the properties of the functions φj,k and ψj,k.

Let us now describe some of them.

1 The family is formed of orthonormal functions. As a consequence for any j, the family is orthonormal.

2 The double indexed family is orthonormal.

3 For any j, the are orthogonal to .

4 Between two successive scales, we have a fundamental relation, called the twin-scale relation.

This relation introduces the algorithm’s h filter ( ). For more information, see the section “Filters Used to Calculate the DWT and IDWT” on page 6-19.

Twin-Scale Relation for φ

h k( ) h k–( )= , and Fkj 1+( ) hk n– An

j( )

n∑=

F j 1+( ) A j( ) h

Akj 1+( ) F2k

j 1+( )=

A j 1+( ) F j 1+( )

Ak0( ) s k( )=

φ0 k, k Z∈,( )φj k, k Z∈,( )

ψj k, j Z∈ k Z∈, ,( )

φj k, k Z∈,( ) ψj ′ k, j′ j≤ k Z∈, ,( )

φ1 0, hkφ0 k,k Z∈∑= φj 1+ 0, hkφj k,

k Z∈∑=

hn 2wn=

Page 384: Wavelet ug

6 Advanced Concepts

6-30

5 We check that:

a. The coordinate of on φj,k is and does not depend on j

b. The coordinate of on φj,k is equal to:

6 These relations supply the ingredients for the algorithm.

7 Up to now we used the filter h. The high-pass filter g is used in the twin scales relation linking the ψ and φ functions. Between two successive scales, we have the following twin-scale fundamental relation.

8 After the decomposition step, we justify now the reconstruction algorithm by building it. Let us simplify the notation. Starting from A1 and D1, let us study A0 = A1 + D1. The procedure is the same to calculate Aj = Aj+1 + Dj+1.

Let us define αn, δn, by:

Let us assess the coordinates as:

We will focus our study on the first sum ; the second sum

Twin-Scale Relation Between ψ and φ

φj 1+ 0, hk

φj 1+ n, φj 1+ n, φj k,,⟨ ⟩ hk 2n–=

ψ1 0, gkφ0 k,k Z∈∑= ψj 1+ 0, gkφj k,

k Z∈∑=

αk0

A1 αnφ1 n,n∑= D1 δnψ1 n,

n∑= A0 αk

0φ0 k,k∑=

αk0

αk0 A0 φ0 k,,⟨ ⟩ A1 D1+ φ0 k,,⟨ ⟩ A1 φ0 k,,⟨ ⟩ D1 φ0 k,,⟨ ⟩+= = =

αn φ1 n, φ0 k,,⟨ ⟩n∑ δn ψ1 n, φ0 k,,⟨ ⟩

n∑+=

αnhk 2n–

n∑ δngk 2n–

n∑+=

αnhk 2n–n∑

Page 385: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-31

is handled in a similar manner.

The calculations are easily organized if we note that (taking k = 0 in the previous formulas, makes things simpler):

If we transform the (αn) sequence into a new sequence defined by

..., α-1, 0, α0, 0, α1, 0, α2, 0, ... that is precisely

Then:

and by extension:

Since

the reconstruction steps are:

1 Replace the α and δ sequences by upsampled versions and inserting zeros

2 Filter by h and g respectively

3 Sum the obtained sequences

δngk 2n–n∑

αnh 2n–

n∑ … α 1– h2 α0h0 α1h 2– α2h 4– …+ + + + +=

… α 1– h2 0h1 α0h0 0h 1– α1h 2– 0h 3– α2h 4– …+ + + + + + + +=

αn( )

α2n αn α2n 1+, 0= =

αnh 2n–

n∑ αnh n–

n∑=

αnhk 2n–

n∑ αnhk n–

n∑=

αk0 αnhk n–

n∑ δngk n–

n∑+=

α δ

Page 386: Wavelet ug

6 Advanced Concepts

6-32

One-Dimensional Wavelet CapabilitiesThe basic one-dimensional objects are as follows.

The analysis-decomposition capabilities are as follows.

The synthesis-reconstruction capabilities are as follows.

Objects Description

Signal in original time s

Ak, 0 ≤ k ≤ j

Dk, 1 ≤ k ≤ j

Original signal

Approximation at level k

Detail at level k

Coefficients in scale-related time cAk, 1 ≤ k ≤ j

cDk, 1 ≤ k ≤ j

[cAj, cDj, ..., cD1]

Approximation coefficients at level k

Detail coefficients at level k

Wavelet decomposition at level j, j ≥ 1

Purpose Input Output M-file

Single-level decomposition s cA1, cD1 dwt

Single-level decomposition cAj cAj+1, cDj+1 dwt

Decomposition s [cAj, cDj, ..., cD1] wavedec

Purpose Input Output M-file

Single-level reconstruction cA1, cD1 s or A0 idwt

Single-level reconstruction cAj+1, cDj+1 cAj idwt

Full reconstruction [cAj, cDj, ..., cD1] s or A0 waverec

Selective reconstruction [cAj, cDj, ..., cD1] Al, Dm wrcoef

Page 387: Wavelet ug

The Fast Wavelet Transform (FWT) Algorithm

6-33

The decomposition structure utilities are as follows.

To illustrate the command line mode for one-dimensional capabilities, see the section “One-Dimensional Analysis Using the Command Line” on page 2-26.

Two-Dimensional Wavelet CapabilitiesThe basic two-dimensional objects are as follows.

Dk stands for , the horizontal, vertical and diagonal details at level k.

The same holds for cDk which stands for: .

The two-dimensional M-files are exactly the same as those for the one-dimensional case, but with a 2 appended on the end of the command.

Purpose Input Output M-file

Extraction of detail coefficients

[cAj, cDj, ..., cD1] cDk,

1 ≤ k ≤ j

detcoef

Extraction of approximation coefficients

[cAj, cDj, ..., cD1] cAk,

0≤ k ≤ j

appcoef

Recomposition of the decomposition structure

[cAj, cDj, ..., cD1] [cAk, cDk, ..., cD1]

1 ≤ k ≤ j

upwlev

Objects Description

Image in original resolution

s Original image

A0 Approximation at level 0

Ak, 1 ≤ k ≤ j Approximation at level k

Dk, 1 ≤ k ≤ j Details at level k

Coefficients in scale-related resolution

cAk, 1 ≤ k ≤ j Approximation coefficients at level k

cDk, 1 ≤ k ≤ j Detail coefficients at level k

[cAj, cDj, ..., cD1] Wavelet decomposition at level j

Dkh( ) Dk

v( ), Dk

d( ),[ ]

cDkh( ) cDk

v( ), cDk

d( ),[ ]

Page 388: Wavelet ug

6 Advanced Concepts

6-34

For example, idwt becomes idwt2. For more information, see “One-Dimensional Wavelet Capabilities” on page 6-32.

To illustrate the command line mode for two-dimensional capabilities, see the section “Two-Dimensional Analysis Using the Command Line” on page 2-59.

Page 389: Wavelet ug

Dealing with Border Distortion

6-35

Dealing with Border DistortionClassically, the DWT is defined for sequences with length of some power of two, and different ways of extending samples of other sizes are needed. Methods for extending the signal include: zero-padding, smooth padding, periodic extension, and boundary value replication (symmetrization).

The basic algorithm for the DWT is not limited to dyadic length and is based on a simple scheme: convolution and downsampling. As usual, when a convolution is performed on finite-length signals, border distortions arise.

Signal Extensions: Zero-Padding, Symmetrization, and Smooth PaddingTo deal with border distortions, the border should be treated differently from the other parts of the signal.

Various methods are available to deal with this problem, referred as “wavelets on the interval” (see [CohDJV93] in “References” on page 6-135). These interesting constructions are effective in theory but are not entirely satisfactory from a practical viewpoint.

Often it is preferable to use simple schemes based on signal extension on the boundaries. This involves the computation of a few extra coefficients at each stage of the decomposition process to get a perfect reconstruction. It should be noted that extension is needed at each stage of the decomposition process.

Details on the rationale of these schemes can be found in Chapter 8 of the book Wavelets and Filter Banks, by Strang and Nguyen (see [StrN96] in “References” on page 6-135).

The available signal extension modes are: (see dwtmode)

• Zero-padding ('zpd'): This method is used in the version of the DWT given in the previous sections and assumes that the signal is zero outside the original support.

The disadvantage of zero-padding is that discontinuities are artificially created at the border.

Page 390: Wavelet ug

6 Advanced Concepts

6-36

• Symmetrization ('sym'): This method assumes that signals or images can be recovered outside their original support by symmetric boundary value replication.

It is the default mode of the wavelet transform in the toolbox.

Symmetrization has the disadvantage of artificially creating discontinuities of the first derivative at the border, but this method works well in general for images.

• Smooth padding of order 1 ('spd' or 'sp1'): This method assumes that signals or images can be recovered outside their original support by a simple first-order derivative extrapolation: padding using a linear extension fit to the first two and last two values.

Smooth padding works well in general for smooth signals.

• Smooth padding of order 0 ('sp0'): This method assumes that signals or images can be recovered outside their original support by a simple constant extrapolation. For a signal extension is the repetition of the first value on the left and last value on the right.

• Periodic-padding (1) ('ppd'): This method assumes that signals or images can be recovered outside their original support by periodic extension.

The disadvantage of periodic padding is that discontinuities are artificially created at the border.

The DWT associated with these five modes is slightly redundant. But IDWT ensures a perfect reconstruction for any of the five previous modes whatever is the extension mode used for DWT.

• Periodic-padding (2) ('per'): If the signal length is odd, the signal is first extended by adding an extra-sample equal to the last value on the right. Then a minimal periodic extension is performed on each side. The same kind of rule exists for images. This extension mode is used for SWT (1-D & 2-D).

This last mode produces the smallest length wavelet decomposition. But the extension mode used for IDWT must be the same to ensure a perfect reconstruction.

Before looking at an illustrative example, let us compare some properties of the theoretical Discrete Wavelet Transform versus the actual DWT.

Page 391: Wavelet ug

Dealing with Border Distortion

6-37

The theoretical DWT is applied to signals that are defined on an infinite length time interval (Z). For an orthogonal wavelet, this transform has the following desirable properties:

1 Norm preservation.

Let cA and cD be the approximation and detail of the DWT coefficients of an infinite length signal X. Then the l2-norm is preserved:

2 Orthogonality.

Let A and D be the reconstructed approximation and detail. Then, A and D are orthogonal and:

3 Perfect reconstruction.

X = A + D

Since the DWT is applied to signals that are defined on a finite length time interval, extension is needed for the decomposition, and truncation is necessary for reconstruction.

To ensure the crucial property 3 (perfect reconstruction) for arbitrary choices of

• The signal length

• The wavelet

• The extension mode

the properties 1 and 2 can be lost. These properties hold true for an extended signal of length usually larger than the length of the original signal. So only the perfect reconstruction property is always preserved. Nevertheless if the DWT is performed using the periodic extension mode ('per') and if the length of the signal is divisible by 2J, where J is the maximum level decomposition, the properties 1, 2 and 3 remain true.

It is interesting to notice that if arbitrary extension is used, and decomposition performed using the convolution-downsampling scheme, perfect reconstruction

X 2 cA 2 cD 2+=

X 2 A 2 D 2+=

Page 392: Wavelet ug

6 Advanced Concepts

6-38

is recovered using idwt or idwt2. This point is illustrated in the following example.

% Set initial signal and get filters.x = sin(0.3*[1:451]); w = 'db9';[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters(w);% In fact using a slightly redundant scheme, any signal% extension strategy works well. % For example use random padding.

lx = length(x); lf = length(Lo_D);randn('seed',654);ex = [randn(1,lf) x randn(1,lf)];axis([1 lx+2*lf -2 3])subplot(211), plot(lf+1:lf+lx,x), title('Original signal')axis([1 lx+2*lf -2 3])subplot(212), plot(ex), title('Extended signal')axis([1 lx+2*lf -2 3])

% Decomposition.la = floor((lx+lf-1)/2);ar = wkeep(dyaddown(conv(ex,Lo_D)),la);

50 100 150 200 250 300 350 400 450−2

−1

0

1

2

3Original signal

50 100 150 200 250 300 350 400 450−2

−1

0

1

2

3Extended signal

Page 393: Wavelet ug

Dealing with Border Distortion

6-39

dr = wkeep(dyaddown(conv(ex,Hi_D)),la);% Reconstruction.xr = idwt(ar,dr,w,lx);

% Check perfect reconstruction.err0 = max(abs(x-xr))

err0 = 3.0464e-11

Now let us illustrate the differences between the first three methods both for 1-D and 2-D signals.

Zero-Padding.

Using the GUI we will examine the effects of zero-padding.

1 From the MATLAB prompt, type

dwtmode('zpd')

2 From the MATLAB prompt, type wavemenu.

The Wavelet Toolbox Main Menu appears.

3 Click the Wavelet 1-D menu item.The discrete wavelet analysis tool for one-dimensional signal data appears.

4 From the File menu, choose the Example Analysis option and select Basic Signals⇒ with db2 at level 5 --> Two nearby discontinuities.

5 Select Display Mode: Show and Scroll

The detail coefficients clearly show the signal end effects.

Page 394: Wavelet ug

6 Advanced Concepts

6-40

Symmetric Extension.

6 From the MATLAB prompt, type

dwtmode('sym')

7 Click the Wavelet 1-D menu item.

The discrete wavelet analysis tool for one-dimensional signal data appears.

8 From the File menu, choose the Example Analysis option and select Basic Signals⇒ with db2 at level 5 --> Two nearby discontinuities.

9 Select Display Mode: Show and Scroll

The detail coefficients show the signal end effects are present, but the discontinuities are well detected.

Smooth Padding.

10 From the MATLAB prompt, type

dwtmode('spd')

11 Click the Wavelet 1-D menu item.

The discrete wavelet analysis tool for one-dimensional signal data appears.

12 From the File menu, choose the Example Analysis option and select Basic Signals⇒ with db2 at level 5 --> Two nearby discontinuities.

Page 395: Wavelet ug

Dealing with Border Distortion

6-41

13 Select Display Mode: Show and Scroll

The detail coefficients show the signal end effects are not present, and the discontinuities are well detected.

Let us now consider an image example.

Original Image.

1 From the MATLAB prompt, type

load geometry;% X contains the loaded image and % map contains the loaded colormap. nbcol = size(map,1);colormap(pink(nbcol));image(wcodemat(X,nbcol));

Page 396: Wavelet ug

6 Advanced Concepts

6-42

Zero-Padding.

Now we set the extension mode to zero-padding and perform a decomposition of the image to level 3 using the sym4 wavelet. Then we reconstruct the approximation of level 3.

2 From the MATLAB prompt, type

lev = 3; wname = 'sym4';dwtmode('zpd')[c,s] = wavedec2(X,lev,wname);a = wrcoef2('a',c,s,wname,lev);image(wcodemat(a,nbcol));

Symmetric Extension.

Now we set the extension mode to symmetric extension and perform a decomposition of the image again to level 3 using the sym4 wavelet. Then we reconstruct the approximation of level 3.

3 From the MATLAB prompt, type

dwtmode('sym')[c,s] = wavedec2(X,lev,wname);a = wrcoef2('a',c,s,wname,lev);image(wcodemat(a,nbcol));

Page 397: Wavelet ug

Dealing with Border Distortion

6-43

Smooth Padding.

Finally we set the extension mode to smooth padding and perform a decomposition of the image again to level 3 using the sym4 wavelet. Then we reconstruct the approximation of level 3.

4 From the MATLAB prompt, type

dwtmode('spd')[c,s] = wavedec2(X,lev,wname);a = wrcoef2('a',c,s,wname,lev);image(wcodemat(a,nbcol));

Page 398: Wavelet ug

6 Advanced Concepts

6-44

Discrete Stationary Wavelet Transform (SWT)We know that the classical DWT suffers a drawback: the DWT is not a time- invariant transform.

This means that, even with periodic signal extension, the DWT of a translated version of a signal X is not, in general, the translated version of the DWT of X.How to restore the translation invariance, which is a desirable property lost by the classical DWT?

The idea is to average some slightly different DWT, called ε-decimated DWT, to define the stationary wavelet transform (SWT).

This property is useful for several applications such as breakdown points detection.

The main application of the SWT is de-noising. For more information on the rationale, see [CoiD95] in “References” on page 6-135. For examples, see “One-Dimensional Discrete Stationary Wavelet Analysis” on page 2-88 and “Two-Dimensional Discrete Stationary Wavelet Analysis” on page 2-103.

The principle is to average several de-noised signals. Each of them is obtained using the usual de-noising scheme (see “De-Noising” on page 6-84), but applied to the coefficients of an ε-decimated DWT.

There is a restriction: we define the SWT only for signals of length divisible by 2J, where J is the maximum decomposition level, and we use the DWT with periodic extension.

ε-decimated DWTWhat is an ε-decimated DWT?

There exist a lot of slightly different ways to handle the discrete wavelet transform. Let us recall that the DWT basic computational step is a convolution followed by a decimation. The decimation retain even indexed elements.

But the decimation could be carried out by choosing odd indexed elements instead of even indexed elements. This choice concerns every step of the decomposition process, so at every level we chose odd or even.

If we perform all the different possible decompositions of the original signal, we have 2J different decompositions, for a given maximum level J.

Page 399: Wavelet ug

Discrete Stationary Wavelet Transform (SWT)

6-45

Let us denote by εj = 1 or 0, the choice of odd or even indexed elements at step j, every decomposition is labelled by a sequence of 0’s and 1’s: ε = ε1,…,εJ. This transform is called the ε-decimated DWT.

You can obtain the basis vectors of the ε-decimated DWT from those of the standard DWT by applying a shift and corresponds to a special choice of the origin of the basis functions.

How to Calculate the ε-decimated DWT: SWTIt is possible to calculate all the ε-decimated DWT for a given signal of length N, by computing the approximation and detail coefficients for every possible sequence ε. Do this using iteratively, a slightly modified version of the basic step of the DWT of the form:

[A,D] = dwt(X,wname,'mode','per','shift',e);

The last two arguments specify the way to perform the decimation step. This is the classical one for e = 0, but for e = 1 the odd indexed elements are retained by the decimation.

Of course, this is not a good way to calculate all the ε-decimated DWT since many computations are performed many times. We shall now describe another way, which is the stationary wavelet transform (SWT).

The SWT algorithm is very simple and is close to the DWT one. More precisely, for level 1, all the ε-decimated DWT (which are only two at this level) for a given signal can be obtained by convolving the signal with the appropriate filters as in the DWT case but without downsampling. Then the approximation and detail coefficients at level 1 are both of size N, which is the signal length. This can be visualized in the following figure.

s

Lo_D

Hi_D

high-pass

approximation coefs

cA1

cD1

detail coefs

low-pass

where: X Convolve with filter X

Page 400: Wavelet ug

6 Advanced Concepts

6-46

The general step j convolves the approximation coefficients at level j-1, with upsampled versions of the appropriate original filters, to produce the approximation and detail coefficients at level j. This can be visualized in the following figure.

Next, we illustrate how to extract a given ε-decimated DWT from the approximation and detail coefficients structure of the SWT.

We decompose a sequence of height numbers with the SWT, at level J = 3, using an orthogonal wavelet.

The function swt calculates successively the following arrays, where A(j,ε1,…,εj) or D(j,ε1,…,εj) denotes an approximation or a detail coefficient at level j obtained for the ε-decimated DWT characterized by ε = [ε1,…,εj].

Step 0 (Original Data).

A(0) A(0) A(0) A(0) A(0) A(0) A(0) A(0)

One-Dimensional SWT

Decomposition step

Fj

Gj

cAj

Initialization

Convolve with filter X

cA0 = s

where X

cAj+1

cDj+1

level j+1level j

Upsample2

Fj

F0 = Lo_D

Fj+1

Gj

G0 = Hi_D

Gj+1

where:

2

2

Filter computation

Page 401: Wavelet ug

Discrete Stationary Wavelet Transform (SWT)

6-47

Step 1.

Step 2.

Step 3.

Let j denote the current level, where j is also the current step of the algorithm. Then we have the following abstract relations with εi = 0 or 1:

[tmpAPP,tmpDET] = dwt(A(j,ε1,…,εj),wname,'mode','per','shift',εj+1); A(j+1,ε1,…,εj,εj+1) = wshift('1D',tmpAPP,εj+1);D(j+1,ε1,…,εj,εj+1) = wshift('1D',tmpDET,εj+1);

where wshift performs a ε-circular shift of the input vector. Therefore, if εj+1 = 0, the wshift instruction is ineffective and can be suppressed.

Let ε = [ε1,…,εJ] with εi = 0 or 1. We have 2J = 23 = eight different ε-decimated DWTs at level 3. Choosing ε, we can retrieve the corresponding ε-decimated DWT from the SWT array.

D(1,0) D(1,1) D(1,0) D(1,1) D(1,0) D(1,1) D(1,0) D(1,1)

A(1,0) A(1,1) A(1,0) A(1,1) A(1,0) A(1,1) A(1,0) A(1,1)

D(1,0) D(1,1) D(1,0) D(1,1) D(1,0) D(1,1) D(1,0) D(1,1)

D(2,0,0) D(2,1,0) D(2,0,1) D(2,1,1) D(2,0,0) D(2,1,0) D(2,0,1) D(2,1,1)

A(2,0,0) A(2,1,0) A(2,0,1) A(2,1,1) A(2,0,0) A(2,1,0) A(2,0,1) A(2,1,1)

D(1,0) D(1,1) D(1,0) D(1,1) D(1,0) D(1,1) D(1,0) D(1,1)

D(2,0,0) D(2,1,0) D(2,0,1) D(2,1,1) D(2,0,0) D(2,1,0) D(2,0,1) D(2,1,1)

D(3,0,0,0) D(3,1,0,0) D(3,0,1,0) D(3,1,1,0) D(3,0,0,1) D(3,1,0,1) D(3,0,1,1) D(3,1,1,1)

A(3,0,0,0) A(3,1,0,0) A(3,0,1,0) A(3,1,1,0) A(3,0,0,1) A(3,1,0,1) A(3,0,1,1) A(3,1,1,1)

Page 402: Wavelet ug

6 Advanced Concepts

6-48

Now, consider the last step: J = 3, and let [Cε,Lε] denote the wavelet decomposition structure of an ε-decimated DWT for a given ε. Then, it can be retrieved from the SWT decomposition structure by selecting the appropriate coefficients as follows:

Cε =

Lε = [1,1,2,4,8]

For example, the ε-decimated DWT corresponding to ε = [ε1, ε2, ε3] = [1,0,1] is shown in bold in the sequence of arrays of the previous example.

This can be extended to the 2-D case. The algorithm for the stationary wavelet transform for images is visualized in the following figure.

A(3, ε1, ε2, ε3) D(3, ε1, ε2, ε3) D(2, ε1, ε2) D(2, ε1, ε2) D(1, ε1) D(1, ε1) D(1, ε1) D(1, ε1)

Page 403: Wavelet ug

Discrete Stationary Wavelet Transform (SWT)

6-49

Two-Dimensional SWT

Decomposition Step

rows

Fj

Gj

rows

cAj

columns

Convolve with filter X the rows of the entry

Convolve with filter X the columns of the entry

cA0 = s for the decomposition initialization

where

X

columns

Gj

Fj

X

columns

columns

Gj

Fj

cAj+1

cDj+1

cDj+1

cDj+1

(h)

(v)

(d)

horizontal

vertical

diagonalrows

columns

size(cAj) = size(cDj )(h)

= sNote = size(cDj )(v) = size(cDj )

(d)

Where s = size of the analyzed image

Initialization

Upsample2

Fj

F0 = Lo_D

Fj+1

Gj

G0 = Hi_D

Gj+1

where:

2

2

Filter Computation

Page 404: Wavelet ug

6 Advanced Concepts

6-50

Inverse Discrete Stationary Wavelet Transform (ISWT)Each ε-decimated DWT corresponding to a given ε can be inverted.

To reconstruct the original signal using a given ε-decimated DWT characterized by [ε1,…,εJ], we can use the abstract algorithm:

FOR j = J:-1:1A(j-1, ε1,…,εj-1) = ...idwt(A(j,ε1,…,εj),D(S,ε1,…,εj)],wname,'mode','per','shift',εj);

END

For each choice of ε = (ε1,…,εJ), we obtain the original signal A(0), starting from slightly different decompositions, and capturing in different ways the main features of the analyzed signal.

The idea of the inverse discrete stationary wavelet transform is to average the inverses obtained for every ε-decimated DWT. This can be done recursively, starting from level J down to level 1.

The ISWT is obtained with the following abstract algorithm:

FOR j = J:-1:1X0 = idwt(A(j,ε1,…,εj),D(j,ε1,…,εj)],wname, ...

'mode','per','shift',0);X1 = idwt(A(j,ε1,…,εj),D(j,ε1,…,εj)],wname, ...

'mode','per','shift',1);X1 = wshift('1D',X1,1);A(j-1, ε1,…,εj-1) = (X0+X1)/2;

END

Along the same lines, this can be extended to the 2-D case.

More about SWTSome useful references for the Stationary Wavelet Transform (SWT) are [CoiD95], [NasS95] and [PesKC96] (see “References” on page 6-135).

Page 405: Wavelet ug

Frequently Asked Questions

6-51

Frequently Asked Questions

Continuous or Discrete Analysis?When is continuous analysis more appropriate than discrete analysis? To answer this, consider the related questions: Do you need to know all values of a continuous decomposition to reconstruct the signal s exactly? Can you perform nonredundant analysis?

When the energy of the signal is finite, not all values of a decomposition are needed to exactly reconstruct the original signal, provided that you are using a wavelet that satisfies some admissibility condition (see [Dau92] pages 7, 24, and 27). Usual wavelets satisfy this condition. In which case, a continuous-time signal s is characterized by the knowledge of the discrete transform

.In such cases, discrete analysis is sufficient and continuous analysis is redundant. When the signal is recorded in continuous time or on a very fine time grid, both analyses are possible. Which should be used? It depends; each one has its own advantages:

• Discrete analysis ensures space-saving coding and is sufficient for exact reconstruction.

• Continuous analysis is often easier to interpret, since its redundancy tends to reinforce the traits and makes all information more visible. This is especially true of very subtle information. Thus, the analysis gains in “readability” and in ease of interpretation what it loses in terms of saving space.

Why Are Wavelets Useful for Space-Saving Coding?The family of functions (φ0,k;ψj,l) j ≤ 0, used for the analysis is an orthogonal basis, therefore leading to nonredundancy. The orthogonality properties are: as soon as , and as soon as

.

Let us remember that for one-dimensional signal, stands for

For biorthogonal wavelets, the idea is similar.

C j k,( ) j k( , ), Z2∈

k l,( ) Z2∈

φ0 k, ψj ′ k ′,⊥ j′ 0≤ ψj k, ψj ′ k ′,⊥j k( , ) j′ k′( , )≠

u v⊥

u x( )v x( ) xdR∫ 0=

Page 406: Wavelet ug

6 Advanced Concepts

6-52

What Is the Advantage Having Zero Average and Sometimes Several Vanishing Moments?

When the wavelet’s k + 1 moments are equal to zero ( for

) all the polynomial signals have zero wavelet

coefficients.

As a consequence, the details are also zero. This property ensures the suppression of signals that are polynomials of a degree lower or equal to k.

What About the Regularity of a Wavelet ψ?In theoretical and practical studies, the notion of regularity has been increasing in importance. Wavelets are tools used to study regularity and to conduct local studies. Deterministic fractal signals or Brownian motion trajectories are locally very irregular; for example, the latter are continuous signals, but their first derivative exists almost nowhere.

The definition of the concept of regularity is somewhat technical. To make things simple, we will define the regularity s of a signal f.

If the signal is s-time continuously differentiable at x0 and s is an integer ( ), then the regularity is s.

If the derivative of f of order m resembles locally around x0, then s = m + r with 0 < r < 1.

The regularity of f in a domain is that of its least regular point.

The greater s, the more regular the signal.

The regularity of certain wavelets is known. The following table gives some indications for Daubechies wavelets.

We have an asymptotic relation linking the size of the support of the Daubechies wavelets dbN and their regularity: when ,

length(support) = 2N, regularity .

ψ db1 = Haar db2 db3 db4 db5 db7 db10

Regularity discontinuous 0.5 0.91 1.27 1.59 2.15 2.90

tjψ t( ) tdR∫ 0=

j 0= … k, , s t( ) ajtj

0 j k≤ ≤∑=

0≥

x x0–r

N ∞→

s N5----≈

Page 407: Wavelet ug

Frequently Asked Questions

6-53

The functions are more regular at certain points than at others (see Figure 6-9, on page 6-53).

Figure 6-9: Zooming in on db3 Wavelet

Selecting a regularity and a wavelet for the regularity is useful in estimations of the local properties of functions or signals. This can be used, for example, to make sure that a signal has a constant regularity at all points. Work by Donoho, Johnstone, Kerkyacharian, and Picard on function estimation and nonlinear regression is currently underway to adapt the statistical estimators to unknown regularity. See also the remarks by I. Daubechies (see [Dau92] page 301).

From a practical viewpoint, these questions arise in the world of finance in dealing with monetary and stock markets where detailed studies of very fast transactions are required.

Are Wavelets Useful in Fields Other than Signal or Image Processing?

• From a theoretical viewpoint, wavelets are used to characterize large sets of mathematical functions and are used in the study of operators linked to partial differential equations.

• From a practical viewpoint, wavelets are used in several fields of numerical analysis, making certain complex calculations easier to handle or more precise.

Page 408: Wavelet ug

6 Advanced Concepts

6-54

What Functions Are Candidates to Be a Wavelet? If a function f is continuous, has null moments, decreases quickly towards 0 when x tends towards infinity, or is null outside a segment of R, it is a likely candidate to become a wavelet.

More precisely, the admissibility condition for is:

The family of shifts and dilations of allows all finite energy signals to be reconstructed using the details in all scales. This allows only continuous analysis.

In the toolbox, the ψ wavelet is usually associated with a scaling function φ. There are, however, some ψ wavelets for which we do not know how to associate a φ. In some cases we know how to prove that φ does not exist, for example, the Mexican hat wavelet.

Is It Easy to Build a New Wavelet?For a minimal requirement on the wavelet properties, it is easy to build a new wavelet, but not very interesting. But if more interesting properties (like the existence of φ for example) are needed, then building the wavelet is more difficult.

Very few wavelets have an explicit analytical expression. Notable exceptions are wavelets that are piecewise polynomials (Haar, Battle-Lemarié, see [Dau92] page 146), Morlet, or Mexican hat.

Wavelets, even db2, db3, ..., are defined by functional equations. The solution is numerical, and is accomplished using a fairly simple algorithm.

The basic property is the existence of a linear relation between the two functions φ(x/2) and φ(x). Another relation of the same type links ψ(x/2) to φ(x). These are the relations of the two scales, the twin-scale relations.

Indeed there are two sequences h and g of coefficients such that:

and

ψ L1 R( ) L2 R( )∩∈

ψ s( )2

s----------------- sd

R-∫ ψ s( )2

s----------------- sd

R+∫ Kψ +∞<= =

ψ

h l2 Z( )∈ g l2 Z( )∈,

Page 409: Wavelet ug

Frequently Asked Questions

6-55

By rewriting these formulas using Fourier transforms (expressed using a hat) we obtain:

There are functions for which the h has a finite impulse response (FIR): there is only a finite number of nonzero hn coefficients. The associated wavelets were built by I. Daubechies (see [Dau92] in “References” on page 6-135) and are used extensively in the toolbox. The reader can refer to page 164 and Chapter 10 of the book Wavelets and Filter Banks, by Strang and Nguyen (see [StrN96] in “References” on page 6-135).

What Is the Link Between Wavelet and Fourier Analysis?Wavelet analysis complements the Fourier analysis for which there are several MATLAB functions: fft, spa, etfe, spectrum, and sptool in the Signal Processing Toolbox.

Fourier analysis uses the basic functions sin(ωt), cos(ωt), and exp(iωt).

• In the frequency domain, these functions are perfectly localized. The functions are suited to the analysis and synthesis of signals with a simple spectrum, which is very well localized in frequency; for example, sin(ω1 t) + 0.5 sin(ω2 t) - cos(ω3 t).

• In the time domain, these functions are not localized. It is difficult for them to analyze or synthesize complex signals presenting fast local variations such as transients or abrupt changes: the Fourier coefficients for a frequency ω will depend on all values in the signal. To limit the difficulties involved, it is possible to “window” the signal using a regular function, which is zero or nearly zero outside a time segment [-m, m].

We then build “a well localized slice” as I. Daubechies calls it (see page 2 of [Dau92] listed in “References” on page 6-135). The windowed-Fourier analysis coefficients are the doubly indexed coefficients:

12---φ x

2---

1

2------- hnφ x n–( )

n Z∈∑=

12---ψ x

2---

1

2------- gnφ x n–( )

n Z∈∑=

φ 2ω( ) 1

2-------h ω( )φ ω( )= ψ 2ω( ) 1

2-------g ω( ) φ ω( )=

φ

Page 410: Wavelet ug

6 Advanced Concepts

6-56

The analogy of this formula with that of the wavelet coefficients is obvious:

The large values of a correspond to small values of ω.

The Fourier coefficient depends on the values of the signal s on the segment [t - m, t + m] with a constant width. If ψ, like g, is zero outside of [-m, m], the C(a,t) coefficients will depend on the values of the signal s on the segment [t - am, t + am] of width 2am, which varies as a function of a. This slight difference solves several difficulties, allowing a kind of time-windowed analysis, different at the various scales a.

The wavelets stay however competitive, even in contexts considered favorable for the Fourier technique. I. Daubechies (see [Dau92] page 3 to 6) gives an example of windowed-Fourier processing and complex Morlet wavelet

processing, with , of a signal composed mainly of the sum of two sines. This wavelet analysis gives good results.

How to Connect Scale to Frequency? A common question is, what is the relationship between scale and frequency?

The answer can only be given in a broad sense, and it’s better to speak about the pseudo-frequency corresponding to a scale.

A way to do it is to compute the center frequency Fc of the wavelet and to use the following relationship (see [Abr97] in “References” on page 6-135).

where

a is a scale.

is the sampling period.

Gs ω t( , ) s u( )g t u–( )e iωu– udR∫=

C a t( , ) s u( ) 1a

------- ψ t u–

a-----------

udR∫=

Gs ω t( , )

ψ t( ) Ce t– 2 α2⁄ eiπt e π2– α2 4⁄–( )= α 4=

Fa∆ Fc⋅

a--------------=

Page 411: Wavelet ug

Frequently Asked Questions

6-57

Fc is the center frequency of a wavelet in Hz.

Fa is the pseudo-frequency corresponding to the scale a, in Hz.

The idea is to associate with a given wavelet a purely periodic signal of frequency Fc. The frequency maximizing the fft of the wavelet modulus is Fc. The function centfrq can be used to compute the center frequency and it allows the plotting of the wavelet with the associated approximation based on the center frequency. The Figure 6-10, on page 6-58 shows some examples generated using the centfrq function.

• Four real wavelets: Daubechies wavelets of order 2 and 7, coiflet of order 1, and the Gaussian derivative of order 4.

• Two complex wavelets: the complex Gaussian derivative of order 6 and a Shannon complex wavelet.

As you can see, the center frequency-based approximation captures the main wavelet oscillations. So the center frequency is a convenient and simple characterization of the leading dominant frequency of the wavelet.

If we accept to associate the frequency Fc to the wavelet function, then when the wavelet is dilated by a factor a, this center frequency becomes Fc / a. Lastly, if the underlying sampling period is , it is natural to associate to the scale a the frequency:

The function scal2frq computes this correspondence.

Fa∆ Fc⋅

a--------------=

Page 412: Wavelet ug

6 Advanced Concepts

6-58

Figure 6-10: Center Frequencies for Real and Complex Wavelets

cgau6 shan1-0.5

coif1 gaus4

db2 db7

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1Wavelet shan1−0.5 (blue) and Center frequency based approximation

Rea

l par

ts

Period: 1.2903; Cent. Freq: 0.775

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1

Imag

inar

y pa

rts

Period: 1.2903; Cent. Freq: 0.775

0 0.5 1 1.5 2 2.5 3−1.5

−1

−0.5

0

0.5

1

1.5

2Wavelet db2 (blue) and Center frequency based approximation

Period: 1.5; Cent. Freq: 0.666670 2 4 6 8 10 12 14

−1.5

−1

−0.5

0

0.5

1

1.5Wavelet db7 (blue) and Center frequency based approximation

Period: 1.4444; Cent. Freq: 0.69231

0 1 2 3 4 5−2

−1.5

−1

−0.5

0

0.5

1

1.5

2

2.5Wavelet coif1 (blue) and Center frequency based approximation

Period: 1.25; Cent. Freq: 0.8−5 0 5

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

1.2Wavelet gaus4 (blue) and Center frequency based approximation

Period: 2; Cent. Freq: 0.5

−5 0 5−1

−0.5

0

0.5

1Wavelet cgau6 (blue) and Center frequency based approximation

Rea

l par

ts

Period: 1.6667; Cent. Freq: 0.6

−5 0 5−1

−0.5

0

0.5

1

Imag

inar

y pa

rts

Period: 1.6667; Cent. Freq: 0.6

Page 413: Wavelet ug

Frequently Asked Questions

6-59

To illustrate the behavior of this procedure, consider the following simple test. We generate sine functions of sensible frequencies F0. For each function, we shall try to detect this frequency by a wavelet decomposition followed by a translation of scale to frequency. More precisely, after a discrete wavelet decomposition, we identify the scale a* corresponding to the maximum value of the energy of the coefficients. The translated frequency F* is then given by:

scal2frq(a_star,'wname',sampling_period)

The F* values are close to the chosen F0. The plots at the end of the example, present the periods instead of the frequencies. If we change slightly the F0 values, the results remain satisfactory.

Example:

% Set sampling period and wavelet name.delta = 0.1; wname = 'coif3';

% Set scales. amax = 7;a = 2.^[1:amax];

% Compute associated pseudo-frequencies.f = scal2frq(a,wname,delta);

% Compute associated pseudo-periods.per = 1./f;

% Plot pseudo-periods versus scales.subplot(211), plot(a,per)title(['Wavelet: ',wname, ', Sampling period: ',num2str(delta)])xlabel('Scale')ylabel('Computed pseudo-period')

% For each scale 2^i:% - generate a sine function of period per(i);% - perform a wavelet decomposition;% - identify the highest energy level;% - compute the detected pseudo-period.for i = 1:amax

% Generate sine function of period% per(i) at sampling period delta.

Page 414: Wavelet ug

6 Advanced Concepts

6-60

t = 0:delta:100;x = sin((t.*2*pi)/per(i));

% Decompose x at level 9.[c,l] = wavedec(x,9,wname);

% Estimate standard deviation of detail coefficients.stdc = wnoisest(c,l,[1:amax]);% Compute identified period.[y,jmax] = max(stdc);idper(i) = per(jmax);

end

% Compare the detected and computed pseudo-periods.subplot(212), plot(per,idper,'o',per,per)title('Detected vs computed pseudo-period')xlabel('Computed pseudo-period')ylabel('Detected pseudo-period')

Figure 6-11: Detected Versus Computed Pseudo-Periods

20 40 60 80 100 120

5

10

15

Wavelet: coif3, Sampling period: 0.1

Scale

Com

pute

d ps

eudo

−per

iod

2 4 6 8 10 12 14 16 18

5

10

15

Detected vs computed pseudo−period

Computed pseudo−period

Det

ecte

d ps

eudo

−per

iod

Page 415: Wavelet ug

Wavelet Families: Additional Discussion

6-61

Wavelet Families: Additional DiscussionThere are different types of wavelet families whose qualities vary according to several criteria. The main criteria are:

• The support of ψ, (and φ, ): the speed of convergence to 0 of these functions ( or ) when the time t or the frequency goes to infinity, which quantifies both time and frequency localizations

• The symmetry, which is useful in avoiding dephasing in image processing

• The number of vanishing moments for ψ or for φ (if it exists), which is useful for compression purposes

• The regularity, which is useful for getting nice features, like smoothness of the reconstructed signal or image, and for the estimated function in nonlinear regression analysis

These are associated with two properties that allow fast algorithm and space-saving coding:

• The existence of a scaling function φ• The orthogonality or the biorthogonality of the resulting analysis

They may also be associated with these less important properties:

• The existence of an explicit expression

• The ease of tabulating

• The familiarity with use

Typing waveinfo in command line mode displays a survey of the main properties of all wavelet families available in the toolbox.

Note that the φ and ψ functions can be computed using wavefun; the filters are generated using wfilters. We provide definition equations for several wavelets. Some are given explicitly by their time definition, others by their frequency definition, and still others by their filter.

ψ φψ t( ) ψ ω( ) ω

Page 416: Wavelet ug

6 Advanced Concepts

6-62

The table below outlines the wavelet families included in the toolbox.

Daubechies Wavelets: dbNIn dbN, N is the order. Some authors use 2N instead of N. More about this family can be found in [Dau92] pages 115, 132, 194, 242. By typing waveinfo('db), at the MATLAB command prompt, you can obtain a survey of the main properties of this family.

Wavelet Family Short Name Wavelet Family Name

'haar' Haar wavelet.

'db' Daubechies wavelets.

'sym' Symlets.

'coif' Coiflets.

'bior' Biorthogonal wavelets.

'rbio' Reverse biorthogonal wavelets.

'meyr' Meyer wavelet.

'dmey' Discrete approximation of Meyer wavelet.

'gaus' Gaussian wavelets.

'mexh' Mexican hat wavelet.

'morl' Morlet wavelet.

'cgau' Complex Gaussian wavelets.

'shan' Shannon wavelets.

'fbsp' Frequency B-Spline wavelets.

'cmor' Complex Morlet wavelets.

Page 417: Wavelet ug

Wavelet Families: Additional Discussion

6-63

Figure 6-12: Daubechies Wavelets db4 on the Left and db8 on the Right

This family includes the Haar wavelet, written db1, the simplest wavelet imaginable and certainly the earliest. Using waveinfo('haar'), you can obtain a survey of the main properties of this wavelet.

Haar

dbNThese wavelets have no explicit expression except for db1, which is the Haar wavelet. However, the square modulus of the transfer function of h is explicit and fairly simple.

• Let , where denotes the binomial coefficients.

if

if

if

if

if

0 2 4 6−1

−0.5

0

0.5

1

Scaling function phi

0 2 4 6−1

−0.5

0

0.5

1

Wavelet function psi

0 1 2 3 4 5 6 7

−0.5

0

0.5

Decomposition low−pass filter

0 1 2 3 4 5 6 7

−0.5

0

0.5

Reconstruction low−pass filter0 1 2 3 4 5 6 7

−0.5

0

0.5

Decomposition high−pass filter

0 1 2 3 4 5 6 7

−0.5

0

0.5

Reconstruction high−pass filter

0 5 10

−1

−0.5

0

0.5

1

Scaling function phi

0 5 10

−1

−0.5

0

0.5

1

Wavelet function psi

0 2 4 6 8 10 12 14

−0.5

0

0.5

Decomposition low−pass filter

0 2 4 6 8 10 12 14

−0.5

0

0.5

Reconstruction low−pass filter0 2 4 6 8 10 12 14

−0.5

0

0.5

Decomposition high−pass filter

0 2 4 6 8 10 12 14

−0.5

0

0.5

Reconstruction high−pass filter

ψ x( ) 1= , x 0 0.5[,[∈

ψ x( ) 1,–= x 0.5 1[,[∈

ψ x( ) 0,= x 0 1[,[∉

φ x( ) 1,= x 0 1,[ ]∈

φ x( ) 0,= x 0 1,[ ]∉

P y( ) CkN 1 k+– yk

k 0=

N 1–

∑= CkN 1 k+–

Page 418: Wavelet ug

6 Advanced Concepts

6-64

Then:

• The support length of and is 2N - 1. The number of vanishing moments of is N.

• Most dbN are not symmetrical. For some, the asymmetry is very pronounced.

• The regularity increases with the order. When N becomes very large, and belong to where µ is approximately equal to 0.2. Certainly, this

asymptotic value is too pessimistic for small order N. Note that the functions are more regular at certain points than at others.

• The analysis is orthogonal.

Symlet Wavelets: symNIn symN, N is the order. Some authors use 2N instead of N. Symlets are only near symmetric; consequently some authors do not call them symlets. More about symlets can be found in [Dau92], pages 194, 254-257. By typing waveinfo('sym') at the MATLAB command prompt, you can obtain a survey of the main properties of this family.

Figure 6-13: Symlets sym4 on the Left and sym8 on the Right

m0 ω( ) 2 cos2 ω2----

N

P sin2 ω2----

=

where m0 ω( ) 12

------- hke i– kω

k 0=

2N 1–

∑=

ψ φψ

ψφ CµN

0 2 4 6

−1

−0.5

0

0.5

1

1.5

Scaling function phi

0 2 4 6

−1

−0.5

0

0.5

1

1.5

Wavelet function psi

0 1 2 3 4 5 6 7

−0.5

0

0.5

Decomposition low−pass filter

0 1 2 3 4 5 6 7

−0.5

0

0.5

Reconstruction low−pass filter0 1 2 3 4 5 6 7

−0.5

0

0.5

Decomposition high−pass filter

0 1 2 3 4 5 6 7

−0.5

0

0.5

Reconstruction high−pass filter

0 5 10

−0.5

0

0.5

1

Scaling function phi

0 5 10

−0.5

0

0.5

1

Wavelet function psi

0 2 4 6 8 10 12 14

−0.5

0

0.5

Decomposition low−pass filter

0 2 4 6 8 10 12 14

−0.5

0

0.5

Reconstruction low−pass filter0 2 4 6 8 10 12 14

−0.5

0

0.5

Decomposition high−pass filter

0 2 4 6 8 10 12 14

−0.5

0

0.5

Reconstruction high−pass filter

Page 419: Wavelet ug

Wavelet Families: Additional Discussion

6-65

Daubechies proposes modifications of her wavelets that increase their symmetry can be increased while retaining great simplicity.

The idea consists of reusing the function m0 introduced in the dbN, considering the as a function W of .

Then we can factor W in several different ways in the form of because the roots of W with modulus not equal to 1 go in pairs. If one of the root is z1, then is also a root.

• By selecting U such that the modulus of all its roots is strictly less than 1, we build Daubechies wavelets dbN. The U filter is a “minimum phase filter.”

• By making another choice, we obtain more symmetrical filters; these are symlets.

The symlets have other properties similar to those of the dbNs.

Coiflet Wavelets: coifNIn coifN, N is the order. Some authors use 2N instead of N. For the coiflet construction, see [Dau92] pages 258-259. By typing waveinfo('coif') at the MATLAB command prompt, you can obtain a survey of the main properties of this family.

Figure 6-14: Coiflets coif3 on the Left and coif5 on the Right

m0 ω( ) 2 z eiω=

W z( ) U z( )U 1z---

=

1

z1-------

0 5 10 15 20 25

−0.5

0

0.5

1

Scaling function phi

0 5 10 15 20 25

−0.5

0

0.5

1

Wavelet function psi

0 2 4 6 8 10121416182022242628

−0.5

0

0.5

Decomposition low−pass filter

0 2 4 6 8 10121416182022242628

−0.5

0

0.5

Reconstruction low−pass filter0 2 4 6 8 10121416182022242628

−0.5

0

0.5

Decomposition high−pass filter

0 2 4 6 8 10121416182022242628

−0.5

0

0.5

Reconstruction high−pass filter

0 5 10 15

−0.5

0

0.5

1

1.5Scaling function phi

0 5 10 15

−0.5

0

0.5

1

1.5Wavelet function psi

0 2 4 6 8 10 12 14 16

−0.5

0

0.5

Decomposition low−pass filter

0 2 4 6 8 10 12 14 16

−0.5

0

0.5

Reconstruction low−pass filter0 2 4 6 8 10 12 14 16

−0.5

0

0.5

Decomposition high−pass filter

0 2 4 6 8 10 12 14 16

−0.5

0

0.5

Reconstruction high−pass filter

Page 420: Wavelet ug

6 Advanced Concepts

6-66

Built by Daubechies at the request of Coifman, the function has 2N moments equal to 0 and, what is more unusual, the function has 2N-1 moments equal to 0. The two functions have a support of length 6N-1.

The coifN and are much more symmetrical than the dbNs. With respect to the support length, coifN has to be compared to db3N or sym3N. With respect to the number of vanishing moments of , coifN has to be compared to db2N or sym2N.

If s is a sufficiently regular continuous time signal, for large j the coefficient is approximated by .

If s is a polynomial of degree d, d ≤ N - 1, then the approximation becomes an equality. This property is used, connected with sampling problems, when calculating the difference between an expansion over the of a given signal and its sampled version.

Biorthogonal Wavelet Pairs: biorNr.NdMore about biorthogonal wavelets can be found in [Dau92] pages 259, 262-285 and in [Coh92]. By typing waveinfo('bior') at the MATLAB command prompt, you can obtain a survey of the main properties of this family, as well as information about Nr and Nd orders and associated filter lengths.

Figure 6-15: Biorthogonal Wavelets bior2.4 on the Left and bior4.4 on the Right

ψφ

ψ φ

ψ

s φ-j k,,⟨ ⟩ 2 j– 2⁄ s 2 j– k( )

φj k,

0 2 4 6 8

−1

0

1

2

Decomposition scaling function phi

0 2 4 6 8

−0.5

0

0.5

1

1.5Reconstruction scaling function phi

0 2 4 6 8

−1

0

1

2

Decomposition wavelet function psi

0 2 4 6 8

−0.5

0

0.5

1

1.5Reconstruction wavelet function psi

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Decomposition low−pass filter

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Reconstruction low−pass filter

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Decomposition high−pass filter

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Reconstruction high−pass filter

0 2 4 6 8

−1

0

1

Decomposition scaling function phi

0 2 4 6 8

−0.5

0

0.5

1

1.5

Reconstruction scaling function phi

0 2 4 6 8

−1

0

1

Decomposition wavelet function psi

0 2 4 6 8

−0.5

0

0.5

1

1.5

Reconstruction wavelet function psi0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Decomposition low−pass filter

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Reconstruction low−pass filter

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Decomposition high−pass filter

0 1 2 3 4 5 6 7 8 9

−0.50

0.5

Reconstruction high−pass filter

Page 421: Wavelet ug

Wavelet Families: Additional Discussion

6-67

The new family extends the wavelet family. It is well known in the subband filtering community that symmetry and exact reconstruction are incompatible (except for the Haar wavelet) if the same FIR filters are used for reconstruction and decomposition. Two wavelets, instead of just one, are introduced:

• One, , is used in the analysis, and the coefficients of a signal s are

• The other, , is used in the synthesis

In addition, the wavelets are related by duality in the following sense:

as soon as or and even

as soon as

It becomes apparent, as Cohen pointed out in his thesis, that “the useful properties for analysis (e.g., oscillations, zero moments) can be concentrated on the function whereas the interesting properties for synthesis (regularity) are assigned to the function. The separation of these two tasks proves very useful” (see [Coh92] page 110).

, can have very different regularity properties (see [Dau92] page 269).

The , , and functions are zero outside of a segment.

The calculation algorithms are maintained, and thus very simple.

The filters associated with m0 and can be symmetrical. The functions used in the calculations are easier to build numerically than those used in the usual wavelets.

ψ

cj k, s x( )ψj k, x( ) xd∫=

ψ

s cj k, ψj k,j k,

∑=

ψ and ψ

ψj k, x( )ψj ′ k ′, x( ) xd∫ 0= j j′≠ k k′≠

φ0 k, x( )φ0 k ′, x( ) xd∫ 0= k k′≠

ψψ

ψ ψ

ψ ψ φ φ

m0

Page 422: Wavelet ug

6 Advanced Concepts

6-68

Meyer Wavelet: meyrBoth ψ and φ are defined in the frequency domain, starting with an auxiliary function ν (see [Dau92] pages 117, 119, 137, 152). By typing waveinfo('meyr') at the MATLAB command prompt, you can obtain a survey of the main properties of this wavelet.

Figure 6-16: The Meyer Wavelet

The Meyer wavelet and scaling function are defined in the frequency domain:

• Wavelet function

and

where

• Scaling function

−5 0 5

−0.5

0

0.5

1

Meyer scaling function

−5 0 5

−0.5

0

0.5

1

Meyer wavelet function

ψ ω( ) 2π( ) 1– 2⁄ eiω 2⁄ π2---ν 3

2π------ ω 1–

sin= if 2π

3------ ω 4π

3------≤ ≤

ψ ω( ) 2π( ) 1– 2⁄ eiω 2⁄ π2---ν 3

4π------ ω 1–

cos= if 4π

3------ ω 8π

3------≤ ≤

ψ ω( ) 0 if= ω 2π3

------8π3

------,∉

ν a( ) a4 35 84a– 70a2 20a3–+( ),= a 0 1[ , ]∈

φ ω( ) 2π( ) 1– 2⁄= if ω 2π

3------≤

φ ω( ) 2π( ) 1– 2⁄=

π2---ν 3

2π------ ω 1–

cos if 2π

3------ ω 4π

3------≤ ≤

Page 423: Wavelet ug

Wavelet Families: Additional Discussion

6-69

By changing the auxiliary function, you get a family of different wavelets. For the required properties of the auxiliary function ν (see “References” on page 6-135 for more information). This wavelet ensures orthogonal analysis.

The function ψ does not have finite support, but ψ decreases to 0 when , faster than any inverse polynomial

such that

This property holds also for the derivatives:

The wavelet is infinitely differentiable.

Note Although the Meyer wavelet is not compactly supported, there exists a good approximation leading to FIR filters, and then allowing DWT. By typing waveinfo('dmey') at the MATLAB command prompt, you can obtain a survey of the main properties of this pseudo-wavelet.

Battle-Lemarie WaveletsSee [Dau92] pages 146-148, 151.

These wavelets are not included in the toolbox, but we use the spline functions in the biorthogonal family.

There are two forms of the wavelet: one does not ensure the analysis to be orthogonal, while the other does. For N=1, the scaling functions are linear splines. For N=2, the scaling functions are quadratic B-spline with finite support. More generally, for an N-degree B-splines:

with if N is odd, if N is even.

φ ω( ) 0= if ω 4π3

------>

x ∞→

n∀ Ν∈ Cn∃, ψ x( ) Cn 1 x 2+( )

n–≤

k N n N Ck n, , such that ψ k( )x Ck n, 1 x 2+( )

n–≤∃,∈∀,∈∀

φ ω( ) 2π( ) 1– 2⁄ e i– κω 2⁄ ω 2⁄( )sinω 2⁄

-------------------------N 1+

=

κ 0= κ 1=

Page 424: Wavelet ug

6 Advanced Concepts

6-70

This formula can be used to build the filters. The twin scale relation is:

• For an even N, φ is symmetrical around, x = 1/2; ψ is anti-symmetrical around x = 1/2. For an odd N, φ is symmetrical around x = 0; ψ is symmetrical around x = 1/2.

• The analysis becomes orthogonal if we transform the functions ψ and φ somewhat. For N=1, for instance, let:

• The supports of ψ and are not finite, but the decrease of the functions ψ and to 0 is exponential. The support of φ is compact. See [Dau92] p. 151.

• The ψ functions have derivatives up to order N-1.

Mexican Hat Wavelet: mexhSee [Dau92] page 75.

By typing waveinfo('mexh') at the MATLAB command prompt, you can obtain a survey of the main properties of this wavelet.

Figure 6-17: The Mexican Hat

φ x( ) 2 2M– Cj2M 1+ φ 2x M– 1 j+–( )

j 0=

2M 1+

∑= if N 2M=

φ x( ) 2 2M– 1– Cj2M 2+ φ 2x M– 1 j+–( )

j 0=

2M 2+

∑= if N 2M 1+=

φ⊥ ω( ) 31 2⁄ 2π( ) 1– 2⁄ 4sin2 ω 2⁄( )

ω2 1 2cos2 ω 2⁄( )+[ ]1 2⁄--------------------------------------------------------------=

φ⊥

φ⊥

−5 0 5

−0.2

0

0.2

0.4

0.6

0.8

Mexican hat wavelet function

Page 425: Wavelet ug

Wavelet Families: Additional Discussion

6-71

This function is proportional to the second derivative function of the Gaussian probability density function.

As the φ function does not exist, the analysis is not orthogonal.

Morlet Wavelet: morlSee [Dau92] page 76.

By typing waveinfo('morl') at the MATLAB command prompt you can obtain a survey of the main properties of this wavelet.

Figure 6-18: The Morlet Wavelet

The constant C is used for normalization in view of reconstruction.

The Morlet wavelet does not satisfy exactly the admissibility condition discussed earlier in “What Functions Are Candidates to Be a Wavelet?” on page 6-54.

ψ x( ) 23

-------π 1– 4⁄ 1 x2

–( )e x– 2 2⁄=

−4 −2 0 2

−0.5

0

0.5

Morlet wavelet function

ψ x( ) Ce x– 2 2⁄ cos 5x( )=

Page 426: Wavelet ug

6 Advanced Concepts

6-72

Other Real WaveletsSome other real wavelets are available in the toolbox.

Reverse Biorthogonal Wavelet Pairs: rbioNr.NdThis family is obtained from the biorthogonal wavelet pairs previously described.

You can obtain a survey of the main properties of this family by typing waveinfo('rbio') from the MATLAB command line.

Figure 6-19: Reverse Biorthogonal Wavelet rbio1.5

Gaussian Derivatives Family: gausThis family is built starting from the Gaussian function: by taking the derivative of f.

The integer is the parameter of this family and in the previous formula, is such that:

where is the derivative of f.

You can obtain a survey of the main properties of this family by typing waveinfo('gaus') from the MATLAB command line.

0 2 4 6 80

0.5

1Decomposition scaling function phi

0 2 4 6 8

0

0.5

1

Reconstruction scaling function phi

0 2 4 6 8−1

−0.5

0

0.5

1Decomposition wavelet function psi

0 2 4 6 8

−1

−0.5

0

0.5

1

Reconstruction wavelet function psi

0 1 2 3 4 5 6 7 8 9

−0.5

0

0.5

Decomposition low−pass filter

0 1 2 3 4 5 6 7 8 9

−0.5

0

0.5

Reconstruction low−pass filter

0 1 2 3 4 5 6 7 8 9

−0.5

0

0.5

Decomposition high−pass filter

0 1 2 3 4 5 6 7 8 9

−0.5

0

0.5

Reconstruction high−pass filter

f x( ) Cpe x2–=

pth

p Cp

f p( ) 21= f p( ) pth

Page 427: Wavelet ug

Wavelet Families: Additional Discussion

6-73

Figure 6-20: Gaussian Derivative Wavelet gaus8

FIR Based Approximation of the Meyer Wavelet: dmeySee [Abr97] page 268.

This wavelet is a FIR based approximation of the Meyer wavelet, allowing fast wavelet coefficients calculation using DWT.

You can obtain a survey of the main properties of this wavelet by typing waveinfo('dmey') from the MATLAB command line.

Figure 6-21: The FIR Based Approximation of the Meyer Wavelet

−5 −4 −3 −2 −1 0 1 2 3 4 5−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

Wavelet function psi

0 10 20 30 40 50 60−0.2

0

0.2

0.4

0.6

0.8

1

Scaling function phi

0 10 20 30 40 50 60

−0.5

0

0.5

1

Wavelet function psi

0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60

−0.5

0

0.5

Decomposition low−pass filter

0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60

−0.5

0

0.5

Reconstruction low−pass filter

0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60

−0.5

0

0.5

Decomposition high−pass filter

0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60

−0.5

0

0.5

Reconstruction high−pass filter

Page 428: Wavelet ug

6 Advanced Concepts

6-74

Complex WaveletsSome complex wavelet families are available in the toolbox.

Complex Gaussian Wavelets: cgauThis family is built starting from the complex Gaussian function:

by taking the derivative of . The integer is the parameter of this family and in the previous formula, is such that:

where is the derivative of f.

You can obtain a survey of the main properties of this family by typing waveinfo('cgau') from the MATLAB command line.

Figure 6-22: Complex Gaussian Wavelet cgau8

Complex Morlet Wavelets: cmorSee [Teo98] pages 62-65.

A complex Morlet wavelet is defined by:

f x( ) Cpe ix– ex2–

= pth f pCp

f p( ) 21= f p( ) pth

−5 0 5−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8Real part of function psi

−5 0 5

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

Imaginary part of function psi

−5 0 50

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Modulus of function psi

−5 0 5

−3

−2

−1

0

1

2

3

Angle of function psi

ψ x( ) πfb e2iπfcx e

x2

fb-----–

=

Page 429: Wavelet ug

Wavelet Families: Additional Discussion

6-75

depending on two parameters:

is a bandwidth parameter.

is a wavelet center frequency.

You can obtain a survey of the main properties of this family by typing waveinfo('cmor') from the MATLAB command line.

Figure 6-23: Complex Morlet Wavelet morl 1-1.5

Complex Frequency B-Spline Wavelets: fbspSee [Teo98] pages 62-65.

A complex Frequency B-Spline wavelet is defined by:

depending on three parameters:

is an integer order parameter ( ).

is a bandwidth parameter.

is a wavelet center frequency.

fb

fc

−8 −6 −4 −2 0 2 4 6 8−0.4

−0.3

−0.2

−0.1

0

0.1

0.2

0.3

0.4

Real part of function psi

−8 −6 −4 −2 0 2 4 6 8

−0.4

−0.3

−0.2

−0.1

0

0.1

0.2

0.3

0.4

Imaginary part of function psi

−8 −6 −4 −2 0 2 4 6 80

0.1

0.2

0.3

0.4

Modulus of function psi

−8 −6 −4 −2 0 2 4 6 8

−3

−2

−1

0

1

2

3

Angle of function psi

ψ x( ) fb sincfbx

m--------

m e

2iπfcx =

m m 1≥

fb

fc

Page 430: Wavelet ug

6 Advanced Concepts

6-76

You can obtain a survey of the main properties of this family by typing waveinfo('fbsp') from the MATLAB command line.

Figure 6-24: Complex Frequency B-Spline Wavelet fbsp 2-1-0.5

Complex Shannon Wavelets: shanSee [Teo98] pages 62-65.

This family is obtained from the frequency B-spline wavelets by setting m to 1.

A complex Shannon wavelet is defined by:

depending on two parameters:

is a bandwidth parameter.

is a wavelet center frequency.

−20 −10 0 10 20

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

Real part of function psi

−20 −10 0 10 20

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

Imaginary part of function psi

−20 −10 0 10 200

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Modulus of function psi

−20 −10 0 10 20

−3

−2

−1

0

1

2

3

Angle of function psi

ψ x( ) fb sinc fbx( ) e2iπfcx =

fb

fc

Page 431: Wavelet ug

Wavelet Families: Additional Discussion

6-77

You can obtain a survey of the main properties of this family by typing waveinfo('shan') from the MATLAB command line.

Figure 6-25: Complex Shannon Wavelet shan 1-0.5

−20 −10 0 10 20−0.6

−0.4

−0.2

0

0.2

0.4

0.6

Real part of function psi

−20 −10 0 10 20

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

Imaginary part of function psi

−20 −10 0 10 200

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Modulus of function psi

−20 −10 0 10 20

−3

−2

−1

0

1

2

3

Angle of function psi

Page 432: Wavelet ug

6 Advanced Concepts

6-78

Summary of Wavelet Families and Associated Properties (Part 1)

Property morl mexh meyr haar dbN symN coifN biorNr.Nd

Crude • •

Infinitely regular • • •

Arbitrary regularity • • • •

Compactly supported orthogonal

• • • •

Compactly supported biothogonal

Symmetry • • • • •

Asymmetry •

Near symmetry • •

Arbitrary number of vanishing moments

• • • •

Vanishing moments for φ •

Existence of φ • • • • • •

Orthogonal analysis • • • • •

Biorthogonal analysis • • • • • •

Exact reconstruction • • • • • • •

FIR filters • • • • •

Continuous transform • • • • • • • •

Discrete transform • • • • • •

Fast algorithm • • • • •

Explicit expression • • • For splines

Page 433: Wavelet ug

Wavelet Families: Additional Discussion

6-79

Summary of Wavelet Families and Associated Properties (Part 2)

Property rbioNr.Nd gaus dmey cgau cmor fbsp shan

Crude • • • • •

Infinitely regular • • • • •

Arbitrary regularity •

Compactly supported orthogonal

Compactly supported biothogonal •

Symmetry • • • • • • •

Asymmetry

Near symmetry

Arbitrary number of vanishing moments

Vanishing moments for φ

Existence of φ •

Orthogonal analysis

Biorthogonal analysis •

Exact reconstruction • • • • • •

FIR filters • •

Continuous transform • •

Discrete transform • •

Fast algorithm • •

Explicit expression For splines • • • • •

Complex valued • • • •

Complex continuous transform • • • •

FIR-based approximation •

Page 434: Wavelet ug

6 Advanced Concepts

6-80

Wavelet Applications: More DetailChapter 3, “Wavelet Applications” and Chapter 4, “Wavelets in Action: Examples and Case Studies” illustrate wavelet applications with examples and case studies. This section re-examines some of the applications with additional theory and more detail.

Suppressing SignalsAs shown in the section “Suppressing Signals” on page 3-15, by suppressing a part of a signal the remainder may be highlighted.

Let be a wavelet with at least k+1 vanishing moments:

for j = 0, ..., k,

If the signal s is a polynomial of degree k, then the coefficients C(a,b) = 0 for all a and all b. Such wavelets automatically suppress the polynomials. The degree of s can vary with time x, provided that it remains less than k.

If s is now a polynomial of degree k on segment , then C(a,b) = 0 as long

as the support of the function is included in . The suppression is

local. Effects will appear on the edges of the segment.

Likewise, let us suppose that, on to which 0 belongs, we have the

expansion . The s and g signals then have the same wavelet coefficients. This is the technical meaning of the phrase: “the wavelet suppresses a polynomial part of signal s.” The signal g is the “irregular” part of the signal s. The wavelet systematically suppresses the regular part and analyzes the irregular part. This effect is easily seen in detail D1 through D4 in Figure 4-2, on page 4-11 (see the curves d1, d2, d3, and d4). The wavelet suppresses the slow sine wave, which is locally assimilated to a polynomial.

Another way of suppressing a component of the signal is to modify and force certain coefficients C(a,b) to be equal to 0. Having selected a set E of indices, we stipulate that , C(a,b) = 0. We then synthesize the signal using the modified coefficients.

ψ

xjψ x( ) xdR∫ 0=

α β[ , ]1a

-------ψ x b–a

------------ α β[ , ]

α β[ , ]

s x( ) [s 0( ) xs′ 0( ) x2s 2( ) 0( ) … xks k( ) 0( )] g x( )+ + + + +=

ψ

a b( , )∀ E∈

Page 435: Wavelet ug

Wavelet Applications: More Detail

6-81

Let us illustrate with the following M-file, some features of wavelet processing using coefficients (resulting plots can be found in Figure 6-26, on page 6-82).

% Load original 1-D signal. load sumsin; s = sumsin;

% Set the wavelet name and perform the decomposition % of s at level 4, using coif3. w = 'coif3'; maxlev = 4; [c,l] = wavedec(s,maxlev,w); newc = c;

% Force to zero the detail coefficients at levels 3 and 4. newc = wthcoef('d',c,l,[3,4]);

% Force the detail coefficients at level 1 to zero on % original time interval [400:600] and shrink otherwise. % determine first and last index of % level 1 coefficients. k = maxlev+1; first = sum(l(1:k-1))+1; last = first+l(k)-1; indd1 = first:last;

% shrink by dividing by 3.newc(indd1) = c(indd1)/3;

% find at level 1 indices of coefficients % in the interval [400:600], % note that time t in original grid corresponds to time % t/2^k on the grid at level k. Here k=1. indd1 = first+400/2:first+600/2;

% force it to zero. newc(indd1) = zeros(size(indd1));

% Set to 4 a coefficient at level 2 corresponding roughly % to original time t = 500. k = maxlev; first = sum(l(1:k-1))+1; newc(first+500/2^2) = 4;% Synthesize modified decomposition structure. synth = waverec(newc,l,w);

Page 436: Wavelet ug

6 Advanced Concepts

6-82

Figure 6-26: Suppress or Modify Signal Components, Acting on Coefficients

Simple procedures to select the set of indices E are used for de-noising and compression purposes (see the sections “De-Noising” on page 6-84 and “Data Compression” on page 6-98).

0 200 400 600 800 10003

2

1

0

1

2

3

Original signal Original detail cfs from level 4 to level 1

Modified detail cfs from level 4 to level 1

0 200 400 600 800 10003

2

1

0

1

2

3Synthesized signal

Level 4Level 3

Level 2Level 1

Coefficientsforced to zero

One coefficientforced to 4

Coefficientsdivided by 3

Page 437: Wavelet ug

Wavelet Applications: More Detail

6-83

Splitting Signal ComponentsWavelet analysis is a linear technique: the wavelet coefficients of the linear combination of two signals are equal to the linear combination of their wavelet coefficients . The same holds true for the corresponding approximations and details, for example and

.

Noise ProcessingLet us first analyze noise as an ordinary signal. Then the probability characteristics: correlation function, spectrum, and distribution need to be studied.

In general, for a one-dimensional discrete-time signal, the high frequencies influence the details of the first levels (the small values of j), while the low frequencies influence the deepest levels (the large values of j) and the associated approximations.

If a signal comprised only of white noise is analyzed, (see for example Figure 4-3, on page 4-12), the details at the various levels decrease in amplitude as the level increases. The variance of the details also decreases as the level increases. The details and approximations are not white noise anymore, as color is introduced by the filters.

On the coefficients C(j,k), where j stands for the scale and k for the time, we can add often-satisfied properties for discrete time signals:

• If the analyzed signal s is stationary, zero mean, and a white noise, the coefficients are uncorrelated.

• If furthermore s is Gaussian, the coefficients are independent and Gaussian.

• If s is a colored, stationary, zero mean Gaussian sequence, then the coefficients remain Gaussian. For each scale level j, the sequence of coefficients is a colored stationary sequence. It could be interesting to know how to choose the wavelet that would de-correlate the coefficients. This problem has not yet been resolved. Furthermore, the wavelet (if indeed it exists) most probably depends on the color of the signal. For the wavelet to be calculated, the color must be known. In most instances, this is beyond our reach.

αs 1( ) βs 2( )+

αCj k,1( ) βCj k,

2( )+

αAj1( ) βAj

2( )+

αDj1( ) βDj

2( )+

Page 438: Wavelet ug

6 Advanced Concepts

6-84

• If s is a zero mean ARMA model stationary for each scale j, then is also a stationary, zero mean ARMA process whose characteristics depend on j.

• If s is a noise whose:

- Correlation function is known, we know how to calculate the correlations of C(j,k) and C(j,k′).

- Spectrum is known, we know how to calculate the spectrum of C(j,k), and the cross spectrum of two different levels j and j′.

These results are easily established, since they can be deduced from the fact that the C(a,b) coefficients are calculated primarily by convolving and s, and using conventional formulas. The quantity that comes into play is the self-reproduction function U(a,b), which is obtained by analyzing the wavelet as if it was a signal:

From the results for coefficients we deduce the properties of the details (and of the approximations), by using the formula:

where the C(j,k) coefficients are random variables and the functions are not. If the support of is finite, only a finite number of terms will be summed.

De-NoisingThis section discusses the problem of signal recovery from noisy data. This problem is easy to understand looking at the following simple example, where a slow sine is corrupted by a white noise.

C j k( , ) k Z∈,

ρ

ρk Z∈

ψ

ψ

U a b( , ) 1a

-------ψ x b–a

------------ ψ x( ) xd

R∫=

Dj n( ) C j k( , )ψj k, n( )k Z∈∑=

ψj k,ψ

Page 439: Wavelet ug

Wavelet Applications: More Detail

6-85

Figure 6-27: A Simple De-noising Example

The Basic One-Dimensional ModelThe underlying model for the noisy signal is basically of the following form:

where time n is equally spaced.

In the simplest model we suppose that e(n) is a Gaussian white noise N(0,1) and the noise level is supposed to be equal to 1.

The de-noising objective is to suppress the noise part of the signal s and to recover f.

0 100 200 300 400 500 600 700 800 900 1000−3

−2

−1

0

1

2

3Original signal

0 100 200 300 400 500 600 700 800 900 1000−3

−2

−1

0

1

2

3Noisy signal

0 100 200 300 400 500 600 700 800 900 1000−3

−2

−1

0

1

2

3De−noised signal

s n( ) f n( ) σe n( )+=

σ

Page 440: Wavelet ug

6 Advanced Concepts

6-86

The method is efficient for families of functions f that have only a few nonzero wavelet coefficients. These functions have a sparse wavelet representation. For example, a smooth function almost everywhere, with only a few abrupt changes, has such a property.

From a statistical viewpoint, the model is a regression model over time and the method can be viewed as a nonparametric estimation of the function f using orthogonal basis.

De-Noising Procedure PrinciplesThe general de-noising procedure involves three steps. The basic version of the procedure follows the steps described below.

1 Decompose

Choose a wavelet, choose a level N. Compute the wavelet decomposition of the signal s at level N.

2 Threshold detail coefficients

For each level from 1 to N, select a threshold and apply soft thresholding to the detail coefficients.

3 Reconstruct

Compute wavelet reconstruction using the original approximation coefficients of level N and the modified detail coefficients of levels from 1 to N.

Two points must be addressed: how to choose the threshold, and how to perform the thresholding.

Page 441: Wavelet ug

Wavelet Applications: More Detail

6-87

Soft or Hard Thresholding?Thresholding can be done using the function:

yt = wthresh(y,sorh,thr)

which returns soft or hard thresholding of input y, depending on the sorh option. Hard thresholding is the simplest method. Soft thresholding has nice mathematical properties and the corresponding theoretical results are available (For instance, see [Don95] in “References” on page 6-135).

Let us give a simple example.

y = linspace(-1,1,100); thr = 0.4; ythard = wthresh(y,'h',thr); ytsoft = wthresh(y,'s',thr);

Figure 6-28: Hard and Soft Thresholding of the Signal s = x

Comment: Let t denote the threshold. The hard threshold signal is x if |x| > t, and is 0 if |x| ≤ t. The soft threshold signal is sign(x)(|x| - t) if |x| > t and is 0 if |x| ≤ t.

Hard thresholding can be described as the usual process of setting to zero the elements whose absolute values are lower than the threshold. Soft thresholding is an extension of hard thresholding, first setting to zero the

−1 0 1−1

−0.5

0

0.5

1Original signal

−1 0 1−1

−0.5

0

0.5

1Hard thresholded signal

−1 0 1−1

−0.5

0

0.5

1Soft thresholded signal

Page 442: Wavelet ug

6 Advanced Concepts

6-88

elements whose absolute values are lower than the threshold, and then shrinking the nonzero coefficients towards 0 (see Figure 6-28 above).As can be seen in the comment of Figure 6-28, on page 6-87, the hard procedure creates discontinuities at x = ±t, while the soft procedure does not.

Threshold Selection RulesAccording to the basic noise model, four threshold selection rules are implemented in the M-file thselect. Each rule corresponds to a tptr option in the command:

thr = thselect(y,tptr)

which returns the threshold value.

• Option tptr = 'rigrsure' uses for the soft threshold estimator a threshold selection rule based on Stein’s Unbiased Estimate of Risk (quadratic loss function). You get an estimate of the risk for a particular threshold value t. Minimizing the risks in t gives a selection of the threshold value.

• Option tptr = 'sqtwolog' uses a fixed form threshold yielding minimax performance multiplied by a small factor proportional to log(length(s)).

• Option tptr = 'heursure' is a mixture of the two previous options. As a result, if the signal-to-noise ratio is very small, the SURE estimate is very noisy. So if such a situation is detected, the fixed form threshold is used.

• Option tptr = 'minimaxi' uses a fixed threshold chosen to yield minimax performance for mean square error against an ideal procedure. The minimax principle is used in statistics to design estimators. Since the de-noised signal can be assimilated to the estimator of the unknown regression function, the minimax estimator is the option that realizes the minimum, over a given set of functions, of the maximum mean square error.

Option Threshold Selection Rule

'rigrsure' Selection using principle of Stein’s Unbiased Risk Estimate (SURE)

'sqtwolog' Fixed form threshold equal to sqrt(2∗log(length(s)))

'heursure' Selection using a mixture of the first two options

'minimaxi' Selection using minimax principle

Page 443: Wavelet ug

Wavelet Applications: More Detail

6-89

Typically it is interesting to show how thselect works if y is a Gaussian white noise N(0,1) signal.

y = randn(1,1000);

thr = thselect(y,'rigrsure')thr =

2.0735

thr = thselect(y,'sqtwolog')thr =

3.7169

thr = thselect(y,'heursure')thr =

3.7169

thr = thselect(y,'minimaxi')thr =

2.2163

Because y is a standard Gaussian white noise, we expect that each method kills roughly all the coefficients and returns the result f(x) = 0. For Stein’s Unbiased Risk Estimate and minimax thresholds, roughly 3% of coefficients are saved. For other selection rules, all the coefficients are set to 0.

We know that the detail coefficients vector is the superposition of the coefficients of f and the coefficients of e, and that the decomposition of e leads to detail coefficients, which are standard Gaussian white noises.

So minimax and SURE threshold selection rules are more conservative and would be more convenient when small details of function f lie near the noise range. The two other rules remove the noise more efficiently. The option 'heursure' is a compromise. In this example, the fixed form threshold wins.

Recalling step 2 of the de-noise procedure, the function thselect performs a threshold selection, and then each level is thresholded. This second step can be done using wthcoef, directly handling the wavelet decomposition structure of the original signal s.

Page 444: Wavelet ug

6 Advanced Concepts

6-90

Dealing with Unscaled Noise and Non-White NoiseUsually in practice the basic model cannot be used directly. We examine here the options available to deal with model deviations in the main de-noising function wden.

The simplest use of wden is:

sd = wden(s,tptr,sorh,scal,n,wav)

which returns the de-noised version sd of the original signal s obtained using the tptr threshold selection rule. Other parameters needed are sorh, scal, n, and wav. The parameter sorh specifies the thresholding of details coefficients of the decomposition at level n of s by the wavelet called wav. The remaining parameter scal is to be specified. It corresponds to threshold’s rescaling methods.

• Option scal = 'one' corresponds to the basic model.

• In general, you can ignore the noise level and it must be estimated. The detail coefficients cD1 (the finest scale) are essentially noise coefficients with standard deviation equal to σ. The median absolute deviation of the coefficients is a robust estimate of σ. The use of a robust estimate is crucial for two reasons. The first one is that if level 1 coefficients contain f details, then these details are concentrated in a few coefficients if the function f is sufficiently regular. The second reason is to avoid signal end effects, which are pure artifacts due to computations on the edges.

Option scal = 'sln' handles threshold rescaling using a single estimation of level noise based on the first-level coefficients.

• When you suspect a non-white noise e, thresholds must be rescaled by a level-dependent estimation of the level noise. The same kind of strategy as in the previous option is used by estimating σlev level by level.

Option Corresponding Model

'one' Basic model

'sln' Basic model with unscaled noise

'mln' Basic model with non-white noise

Page 445: Wavelet ug

Wavelet Applications: More Detail

6-91

This estimation is implemented in M-file wnoisest, directly handling the wavelet decomposition structure of the original signal s.

Option scal = 'mln' handles threshold rescaling using a level-dependent estimation of the level noise.

For a more general procedure, the wdencmp function performs wavelet coefficients thresholding for both de-noising and compression purposes, while directly handling one-dimensional and two-dimensional data. It allows you to define your own thresholding strategy selecting in:

xd = wdencmp(opt,x,wav,n,thr,sorh,keepapp);

where

opt = 'gbl' and thr is a positive real number for uniform threshold

opt = 'lvd' and thr is a vector for level dependent threshold.

keepapp = 1 to keep approximation coefficients, as previously and

keepapp = 0 to allow approximation coefficients thresholding.

x is the signal to be de-noised and wav, n, sorh are the same as above.

De-Noising in ActionWe begin with examples of one-dimensional de-noising methods with the first example credited to Donoho and Johnstone. You can use the following M-file to get the first test function using wnoise.

% Set signal to noise ratio and set rand seed. sqrt_snr = 4; init = 2055615866;

% Generate original signal xref and a noisy version x adding % a standard Gaussian white noise. [xref,x] = wnoise(1,11,sqrt_snr,init);

% De-noise noisy signal using soft heuristic SURE thresholding % and scaled noise option, on detail coefficients obtained % from the decomposition of x, at level 3 by sym8 wavelet. xd = wden(x,'heursure','s','one',3,'sym8');

Page 446: Wavelet ug

6 Advanced Concepts

6-92

Figure 6-29: Blocks Signal De-noising

Since only a small number of large coefficients characterize the original signal, the method performs very well (see Figure 6-29 above). If you want to see more about how the thresholding works, use the GUI (see “De-Noising Signals” on page 3-18).

As a second example, let us try the method on the highly perturbed part of the electrical signal studied above.

According to this previous analysis, let us use db3 wavelet and decompose at level 3.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20Original signal

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20Noisy signal

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20De−noised signal − Signal to noise ratio = 4

Page 447: Wavelet ug

Wavelet Applications: More Detail

6-93

To deal with the composite noise nature, let us try a level-dependent noise size estimation.

% Load electrical signal and select part of it. load leleccum; indx = 2000:3450; x = leleccum(indx);

% Find first value in order to avoid edge effects. deb = x(1);

% De-noise signal using soft fixed form thresholding % and unknown noise option. xd = wden(x-deb,'sqtwolog','s','mln',3,'db3')+deb;

Figure 6-30: Electrical Signal De-noising

The result is quite good in spite of the time heterogeneity of the nature of the noise after and before the beginning of the sensor failure around time 2450.

2000 2500 3000 3500100

200

300

400

500

600Original electrical Signal

2000 2500 3000 3500100

200

300

400

500

600De−noised Signal

Page 448: Wavelet ug

6 Advanced Concepts

6-94

Extension to Image De-NoisingThe de-noising method described for the one-dimensional case applies also to images and applies well to geometrical images. A direct translation of the one-dimensional model is:

where e is a white Gaussian noise with unit variance.

The two-dimensional de-noising procedure has the same three steps and uses two-dimensional wavelet tools instead of one-dimensional ones. For the threshold selection, prod(size(s)) is used instead of length(s) if the fixed form threshold is used.

Note that except for the “automatic” one-dimensional de-noising case, de-noising and compression are performed using wdencmp. As an example, you can use the following M-file illustrating the de-noising of a real image.

% Load original image. load woman

% Generate noisy image.init = 2055615866; randn('seed',init); x = X + 15*randn(size(X));

% Find default values. In this case fixed form threshold% is used with estimation of level noise, thresholding% mode is soft and the approximation coefficients are % kept.[thr,sorh,keepapp] = ddencmp('den','wv',x);

% thr is equal to estimated_sigma*sqrt(log(prod(size(X))))thr

thr =

107.6428

% De-noise image using global thresholding option.xd = wdencmp('gbl',x,'sym4',2,thr,sorh,keepapp);

s i j,( ) f i j,( ) σe i j,( )+=

Page 449: Wavelet ug

Wavelet Applications: More Detail

6-95

% Plots.colormap(pink(255)), sm = size(map,1);subplot(221), image(wcodemat(X,sm)), title('Original Image')subplot(222), image(wcodemat(x,sm)), title('Noisy Image')subplot(223), image(wcodemat(xd,sm)), title('De-noised Image')

The result shown below is acceptable.

Figure 6-31: Image De-noising

One-Dimensional Variance Adaptive Thresholding of Wavelet CoefficientsLocal thresholding of wavelet coefficients, for one- or two-dimensional data, is a capability available from a lot of graphical interface tools throughout the MATLAB Wavelet Toolbox (see “Using Wavelets” on page 2-1).

The idea is to define level by level time-dependent thresholds, and then increase the capability of the de-noising strategies to handle nonstationary variance noise models.

More precisely, the model assumes (as previously) that the observation is equal to the interesting signal superimposed on a noise (see “De-Noising” on page 6-84).

Original Image

50 100 150 200 250

50

100

150

200

250

Noisy Image

50 100 150 200 250

50

100

150

200

250

De−noised Image

50 100 150 200 250

50

100

150

200

250

s n( ) f n( ) σe n( )+=

Page 450: Wavelet ug

6 Advanced Concepts

6-96

But the noise variance can vary with time. There are several different variance values on several time intervals. The values as well as the intervals are unknown.

Let us focus on the problem of estimating the change points or equivalently the intervals. The algorithm used is based on an original work of Marc Lavielle about detection of change points using dynamic programming (see [Lav99] in “References” on page 6-135).

Let us generate a signal from a fixed-design regression model with two noise variance change points located at positions 200 and 600.

% Generate blocks test signal.x = wnoise(1,10);

% Generate noisy blocks with change points.init = 2055615866; randn('seed',init);bb = randn(1,length(x));cp1 = 200; cp2 = 600;x = x + [bb(1:cp1),bb(cp1+1:cp2)/3,bb(cp2+1:end)];

The aim of this example is to recover the two change points from the signal x. In addition, this example illustrates how the GUI tools (see “Using Wavelets” on page 2-1) locate the change points for interval dependent thresholding.

Step 1. Recover a noisy signal by suppressing an approximation.

% Perform a single-level wavelet decomposition % of the signal using db3.wname = 'db3'; lev = 1;[c,l] = wavedec(x,lev,wname);

% Reconstruct detail at level 1.det = wrcoef('d',c,l,wname,1);

The reconstructed detail at level 1 recovered at this stage is almost signal free. It captures the main features of the noise from change points detection viewpoint if the interesting part of the signal has a sparse wavelet representation. To remove almost all the signal, we replace the biggest values by the mean.

Step 2. To remove almost all the signal, replace 2% of biggest values by the mean.

Page 451: Wavelet ug

Wavelet Applications: More Detail

6-97

x = sort(abs(det));v2p100 = x(fix(length(x)*0.98));ind = find(abs(det)>v2p100);det(ind) = mean(det);

Step 3. Use the wvarchg function to estimate the change points with the following default parameters:

• The minimum delay between two change points is d = 10.

• The maximum number of change points is 5.

[cp_est,kopt,t_est] = wvarchg(det)cp_est =

199 601

kopt =2

t_est =1024 0 0 0 0 0601 1024 0 0 0 0199 601 1024 0 0 0199 261 601 1024 0 0207 235 261 601 1024 0207 235 261 393 601 1024

Two change points and three intervals are proposed. Since the three interval variances for the noise are very different the optimization program detects easily the correct structure.

The estimated change points are close to the true change points: 200 and 600.

Step 4. (Optional) Replace the estimated change points.

For 2 ≤ i ≤ 6, t_est(i,1:i-1) contains the i-1 instants of the variance change points, and since kopt is the proposed number of change points; then:

cp_est = t_est(kopt+1,1:kopt);

You can replace the estimated change points by computing:

% cp_New = t_est(knew+1,1:knew); % where 2 ≤ knew ≤ 6

Page 452: Wavelet ug

6 Advanced Concepts

6-98

More About De-NoisingThe de-noising methods based on wavelet decomposition appear mainly initiated by Donoho and Johnstone in the USA, and Kerkyacharian and Picard in France. Meyer considers that this topic is one of the most significant applications of wavelets (cf. [Mey93] page 173). This chapter and the corresponding M-files follow the work of the above mentioned researchers. More details can be found in Donoho’s references in the section “References” on page 6-135 and in the section “More About the Thresholding Strategies” on page 6-113.

Data CompressionThe compression features of a given wavelet basis are primarily linked to the relative scarceness of the wavelet domain representation for the signal. The notion behind compression is based on the concept that the regular signal component can be accurately approximated using the following elements: a small number of approximation coefficients (at a suitably chosen level) and some of the detail coefficients.

Like de-noising, the compression procedure contains three steps:

1 Decompose

Choose a wavelet, choose a level N. Compute the wavelet decomposition of the signal s at level N.

2 Threshold detail coefficients

For each level from 1 to N, a threshold is selected and hard thresholding is applied to the detail coefficients.

3 Reconstruct

Compute wavelet reconstruction using the original approximation coefficients of level N and the modified detail coefficients of levels from 1 to N.

The difference of the de-noising procedure is found in step 2. There are two compression approaches available. The first consists of taking the wavelet expansion of the signal and keeping the largest absolute value coefficients. In this case, you can set a global threshold, a compression performance, or a relative square norm recovery performance.

Page 453: Wavelet ug

Wavelet Applications: More Detail

6-99

Thus, only a single parameter needs to be selected. The second approach consists of applying visually determined level-dependent thresholds.

Let us examine two real-life examples of compression using global thresholding, for a given and unoptimized wavelet choice, to produce a nearly complete square norm recovery for a signal (see Figure 6-32, on page 6-99) and for an image (see Figure 6-33, on page 6-100).

% Load electrical signal and select a part. load leleccum; indx = 2600:3100; x = leleccum(indx);

% Perform wavelet decomposition of the signal. n = 3; w = 'db3'; [c,l] = wavedec(x,n,w);

% Compress using a fixed threshold. thr = 35; keepapp = 1;[xd,cxd,lxd,perf0,perfl2] =

wdencmp('gbl',c,l,w,n,thr,'h',keepapp);

Figure 6-32: Signal Compression

2600 2650 2700 2750 2800 2850 2900 2950 3000 3050 3100150

200

250

300

350

400

450Original signal

2600 2650 2700 2750 2800 2850 2900 2950 3000 3050 3100150

200

250

300

350

400

450Compressed signal

2−norm rec.: 99.95 % −− zero cfs: 85.08

Page 454: Wavelet ug

6 Advanced Concepts

6-100

The result is quite satisfactory, not only because of the norm recovery criterion, but also on a visual perception point of view. The reconstruction uses only 15% of the coefficients.

% Load original image. load woman; x = X(100:200,100:200); nbc = size(map,1);

% Wavelet decomposition of x. n = 5; w = 'sym2'; [c,l] = wavedec2(x,n,w);

% Wavelet coefficients thresholding. thr = 20; keepapp =1;[xd,cxd,lxd,perf0,perfl2] =

wdencmp('gbl',c,l,w,n,thr,'h',keepapp);

Figure 6-33: Image Compression

If the wavelet representation is too dense, similar strategies can be used in the wavelet packet framework to obtain a sparser representation. You can then determine the best decomposition with respect to a suitably selected entropy-like criterion, which corresponds to the selected purpose (de-noising or compression).

Original image

20 40 60 80 100

20

40

60

80

100

2−norm rec.: 99.14 % −− nul cfs : 79.51

threshold = 20

20 40 60 80 100

20

40

60

80

100

Page 455: Wavelet ug

Wavelet Applications: More Detail

6-101

Compression ScoresWhen compressing using orthogonal wavelets, the Retained energy in percentage is defined by:

When compressing using biorthogonal wavelets, the previous definition is not convenient. We use instead the Energy ratio in percentage defined by:

and as a tuning parameter the Norm cfs recovery defined by:

The Number of zeros in percentage is defined by:

Function Estimation: Density and RegressionIn this section we present two problems of functional estimation:

• Density estimation

• Regression estimation

Note According to the classical statistical notations, in this section, denotes the estimator of the function g instead of the Fourier transform of g.

Density EstimationThe data are values (X(i), 1 ≤ i ≤ n) sampled from a distribution whose density is unknown. We are looking for an estimate of this density.

100*(vector-norm(coeffs of the current decomposition,2))2

(vector-norm(original signal,2))2--------------------------------------------------------------------------------------------------------------------------------------------------------------

100*(vector-norm(compressed signal,2))2

(vector-norm(original signal,2))2-----------------------------------------------------------------------------------------------------------------

100*(vector-norm(coeffs of the current decomposition,2))2

(vector-norm(coeffs of the original decomposition,2))2--------------------------------------------------------------------------------------------------------------------------------------------------------------

100*(number of zeros of the current decomposition)(number of coefficients)

----------------------------------------------------------------------------------------------------------------------------------------------

g

Page 456: Wavelet ug

6 Advanced Concepts

6-102

What Is Density.

The well known histogram creates the information on the density distribution of a set of measures. At the very beginning of the 19th century, Laplace, a French scientist, repeating sets of observations of the same quantity, was able to fit a simple function to the density distribution of the measures. This function is called now the Laplace-Gauss distribution.

Density Applications.

Density estimation is a core part of reliability studies. It permits the evaluation of the life-time probability distribution of a TV set produced by a factory, the computation of the instantaneous availability, and of other useful characteristics as the mean time to failure. A very similar situation occurs in survival analysis, when studying the residual life time of a medical treatment.

Density Estimators.

As in the regression context, the wavelets are useful in a nonparametric context, when very little information is available concerning the shape of the unknown density, or when you don’t want to tell the statistical estimator what you know about the shape.

Several alternative competitors exist. The orthogonal basis estimators are based on the same ideas as the wavelets. Other estimators rely on statistical window techniques such as kernel smoothing methods.

We have theorems proving that the wavelet-based estimators behave at least as well as the others, and sometimes better. When the density h(x) has irregularities, such as a breakdown point or a breakdown point of the derivative h’(x), the wavelet estimator is a good solution.

How to Perform Wavelet-Based Density Estimation.

The key idea is to reduce the density estimation problem to a fixed-design regression model. More precisely the main steps are:

1 Transform the sample X into (Xb, Yb) data where the Xb are equally spaced, using a binning procedure. For each bin i, Yb(i) = number of X(j) within bin i.

2 Perform a wavelet decomposition of Yb viewed as a signal, using fast algorithm. Thus, the underlying Xb data is 1, 2, ..., nb where nb is the number of bins.

Page 457: Wavelet ug

Wavelet Applications: More Detail

6-103

3 Threshold the wavelet coefficients according to one of the methods described for de-noising (see “De-Noising” on page 6-84).

4 Reconstruct an estimate h1 of the density function h from the thresholded wavelet coefficients using fast algorithm (see “The Fast Wavelet Transform (FWT) Algorithm” on page 6-19).

5 Post process the resulting function h1. Rescale the resulting function transforming 1, 2, ..., nb into Xb and interpolate h1 for each bin to calculate hest(X).

Steps 2 through 4 are standard wavelet-based steps. But the first step of this estimation scheme depends on nb (the number of bins), which can be viewed as a bandwidth parameter. In density estimation, nb is generally small with respect to the number of observations (equal to the length of X), since the binning step is a pre-smoother. A typical default value is nb = length(X) / 4.

For more information, you can refer for example to [AntP98], [HarKPT98], and [Ogd97] in “References” on page 6-135.

A More Technical Viewpoint.

Let us be a little more formal.

Let X1, X2, ... , Xn be a sequence of independent and identically distributed random variables, with a common density function .

This density h is unknown and we want to estimate it. We have very little information on h.

For technical reasons we suppose that is finite. This allows us to express h in the wavelet basis.

We know that in the basis of functions and with usual notations, J being an integer:

The estimator will use some wavelet coefficients. The rationale for the estimator is the following.

h h x( )=

h x( )2 xd∫

φ ψ

h aJ k, φJ k, dj k, ψj k,k∑

j -∞=

J

∑+k∑ AJ Dj

j -∞=

J

∑+= =

h h x( )=

Page 458: Wavelet ug

6 Advanced Concepts

6-104

To estimate h, it is sufficient to estimate the coordinates and the .

We shall do it now.

We know the definition of the coefficients:

and similarly

The expression of the has a very funny interpretation. Because h is a density is , the mean value of the random variable

.

Usually such an expectation is estimated very simply by the mean value:

Of course the same kind of formula holds true for the :

With a finite set of n observations, it is possible to estimate only a finite set of coefficients, those belonging to the levels from J-j0 up to J, and to some positions k.

Besides, several values of the are not significant and are to be set to 0.

The values , lower than a threshold t, are set to 0 in a very similar manner as the de-noising process and for almost the same reasons.

Inserting these expressions into the definition of h, we get an estimator:

aJ k, dj k,

aJ k, φJ k, x( ) h x( ) xd∫=

dj k, ψj k, x( )h x( ) xd∫=

aJ k,φJ k, x( )h x( ) xd∫ E φJ k, Xi( )( )

φJ k, Xi( )

aJ k,1n--- φJ k, Xi( )

i 1=

n

∑=

dj k,

dj k,1n--- ψj k, Xi( )

i 1=

n

∑=

dj k,

dj k,

h aJ k, φJ k, dj k, 1dj k, t>{ }

ψj k,k∑

j J j– 0=

J

∑+k∑=

Page 459: Wavelet ug

Wavelet Applications: More Detail

6-105

This kind of estimator avoids the oscillations that would occur if all the detail coefficients would have been kept.

From the computational viewpoint, it is difficult to use a quick algorithm because the Xi values are not equally spaced.

Note that this problem can be overcome.

Let’s introduce the normalized histogram of the values of X, having nb classes, where the centers of the bins are collected in a vector Xb, the frequencies of Xi within the bins are collected in a vector Yb and then:

on the r-th bin

We can write, using :

where is the length of each bin.

The signs occur because we lose some information when using histogram instead of the values Xi and when approximating the integral.

The last sign is very interesting. It means that is, up to the constant c, the wavelet coefficient of the function associated with the level j and the position k. The same result holds true for the .

So, the last sign of the previous equation shows that the coefficients appear also to be (up to an approximation) wavelet coefficients — those of the decomposition of the sequence . If some of the coefficients at level J are known or computed, the Mallat algorithm computes the others quickly and simply.

And now we are able to finish computing when the and the have been computed.

The trick is the transformation of irregularly spaced X values into equally spaced values by a process similar to the histogram computation, and that is called binning.

H

H x( ) Yb r( )n

---------------=

H

dj k,1n--- ψj k, Xi( ) 1

n--- Yb r( )ψj k, Xb r( )( )

r 1=

nb

∑ c ψj k, x( )H x( ) xd∫≈ ≈i 1=

n

∑=

1c---

≈ dj k,H

aJ k,

≈ dj k,

H

h dj k, aJ k,

Page 460: Wavelet ug

6 Advanced Concepts

6-106

You can see the different steps of the procedure using the Density Estimation Graphical User Interface, by typing

wavemenu

and clicking the Density Estimation 1-D option.

Regression Estimation

What Is Regression?

The regression problem belongs to the family of the most common practical questions. The goal is to get a model of the relationship between one variable Y and one or more variables X. The model gives the part of the variability of Y taken in account or explained by the variation of X. A function f represents the central part of the knowledge. The remaining part is dedicated to the residuals, which are similar to a noise. The model is Y = f(X)+e.

Regression Models.

The simplest case is the linear regression Y = aX+b+e where the function f is affine. A case a little more complicated occurs when the function belongs to a family of parametrized functions as f(X)= cos (w X), the value of w being unknown. The Statistics Toolbox provides tools for the study of such models. When f is totally unknown, the problem of the nonlinear regression is said to be a nonparametric problem and can be solved either by using usual statistical window techniques or by wavelet based methods.

Regression Applications.

These regression questions occurs in many domains. For example:

• Metallurgy, where you can try to explain the tensile strength by the carbon content

• Marketing, where the house price evolution is connected to an economical index

• Air-pollution studies, where you can explain the daily maximum of the ozone concentration by the daily maximum of the temperature

Two designs are distinguished: the fixed design and the stochastic design. The difference concerns the status of X.

Page 461: Wavelet ug

Wavelet Applications: More Detail

6-107

Fixed-Design Regression.

When the X values are chosen by the designer using a predefined scheme, as the days of the week, the age of the product, or the degree of humidity, the design is a fixed design. Usually in this case, the resulting X values are equally spaced. When X represents time, the regression problem can be viewed as a de-noising problem.

Stochastic Design Regression.

When the X values result from a measurement process or are randomly chosen, the design is stochastic. The values are often not regularly spaced. This framework is more general since it includes the analysis of the relationship between a variable Y and a general variable X, as well as the analysis of the evolution of Y as a function of time X when X is randomized.

How to Perform Wavelet-Based Regression Estimation?

The key idea is to reduce a general problem of regression to a fixed-design regression model. More precisely the main steps are:

1 Transform (X,Y) data into (Xb,Yb) data where the Xb are equally spaced, using a binning procedure. For each bin i:

with the convention .

2 Perform a wavelet decomposition of Yb viewed as a signal using fast algorithm. This last sentence means that the underlying Xb data is 1, 2, ..., nb where nb is the number of bins.

3 Threshold the wavelet coefficients according to one of the methods described for de-noising.

4 Reconstruct an estimate f1 of the function f from the thresholded wavelet coefficients using fast algorithm.

5 Post-process the resulting function f1. Rescale the resulting function f1 transforming 1, 2, ..., nb onto Xb and interpolate f1 for each bin in order to calculate fest(x).

Yb i )( ) sum Y j( ) such that X j( ) lies in bin i{ }number Y j( ) such that X j( ) lies in bin i{ }--------------------------------------------------------------------------------------------------------------------=

00--- 0=

Page 462: Wavelet ug

6 Advanced Concepts

6-108

Steps 2 through 4 are standard wavelet-based steps. But the first step of this estimation scheme depends on the number of bins, which can be viewed as a bandwidth parameter. Generally, the value of nb is not chosen too small with respect to the number of observations, since the binning step is a presmoother.

For more information, you can refer for example to [AntP98], [HarKPT98], and [Ogd97], see “References” on page 6-135.

A More Technical Viewpoint.

The regression problem goes along the same lines as the density estimation. The main differences concern, of course, the model.

There is another difference with the density step: we have here two variables X and Y instead of one in the density scheme.

The regression model is where is a sequence of independent and identically distributed (i.i.d.) random variables and where the

are randomly generated according to an unknown density h.

Also, let us assume that is a sequence of i.i.d. random variables.

The function f is unknown and we look for an estimator .

We introduce the function . So with the convention .

We could estimate g by a certain and, from the density part, an , and then

use . We choose to use the estimate of h given by the histogram suitably

normalized.

Let us bin the X-values into nb bins. The l-th bin-center is called Xb(l), the number of X-values belonging to this bin is n(l). Then, we define Yb(l) by the sum of the Y-values within the bin divided by n(l).

Let’s turn to the f estimator. We shall apply the technique used for the density function. The coefficients of f, are estimated by:

Yi f Xi( ) εi+= εi( )1 i n≤ ≤

Xi( )

X1 Y1,( ) … Xn Yn,( ), ,

f

g f h⋅= f gh---=

00--- 0=

g h

f g

h---=

dj k,1n--- Yiψj k, Xi( )

i 1=

n

∑=

Page 463: Wavelet ug

Wavelet Applications: More Detail

6-109

We get approximations of the coefficients by the following formula that can be written in a form proving that the approximated coefficients are also the wavelet decomposition coefficients of the sequence Yb:

The usual simple algorithms can be used.

You can see the different steps of the procedure using the Regression Estimation Graphical User Interface, by typing wavemenu, and clicking on the Regression Estimation 1-D option.

Available Methods for De-noising, Estimation and Compression Using GUI ToolsThis section presents the predefined strategies available using the de-noising, estimation and compression GUI tools.

One-Dimensional DWT and SWT De-noising Level-dependent or interval-dependent thresholding methods are available. Predefined thresholding strategies:

• Hard or soft (default) thresholding

• Scaled white noise, unscaled white noise (default) or non-white noise

• Thresholds values are:

- Donoho-Johnstone methods: Fixed-form (default), Heursure, Rigsure, Minimax

aJ k,1n--- YiφJ k, Xi( )

i 1=

n

∑=

dj k,1n--- Yb l( )ψj k, Xb l( )( )

l 1=

nb

∑≈

aJ k,1n--- Yb l( )φJ k, Xb l( )( )

l 1=

nb

∑≈

Page 464: Wavelet ug

6 Advanced Concepts

6-110

- Birgé-Massart method: Penalized high, Penalized medium, Penalized low.

The last three choices include a sparsity parameter a (a > 1).

Using this strategy the defaults are a = 6.25, 2 and 1.5, respectively and the thresholding mode is hard. Only scaled and unscaled white noise options are supported.

One-Dimensional DWT Compression

1 Level-dependent or interval-dependent hard thresholding methods are available. Predefined thresholding strategies are:

- Birgé-Massart method: Scarce high (default), Scarce medium, Scarce low.

This method includes a sparsity parameter a (1 < a < 5). Using this strategy the default is a = 1.5.

- Empirical methods

- Equal balance sparsity-norm

- Remove near 0

2 Global hard thresholding methods with GUI-driven choice are available. Predefined thresholding strategies are:

- Empirical methods

- Balance sparsity-norm (default = equal)

- Remove near 0

Two-Dimensional DWT and SWT De-noisingLevel-dependent and orientation-dependent (horizontal, vertical, and diagonal) thresholding methods are available. Predefined thresholding strategies are:

• Hard or soft (default) thresholding

• Scaled white noise, unscaled white noise (default) or non-white noise

• Thresholds values are:

- Donoho-Johnstone method: Fixed form (default)

- Birgé-Massart method: Penalized high, Penalized medium, Penalized low.

The last three choices include a sparsity parameter a (a > 1), see “One-Dimensional DWT and SWT De-noising” on page 6-109.

Page 465: Wavelet ug

Wavelet Applications: More Detail

6-111

- Empirical method: Balance sparsity-norm, default = sqrt

Two-Dimensional DWT CompressionLevel-dependent and orientation-dependent (horizontal, vertical, and diagonal) thresholding methods are available.

1 Level-dependent or interval-dependent hard thresholding methods are available. Predefined thresholding strategies are:

- Birgé-Massart method: Scarce high (default); Scarce medium, Scarce low.

This method includes a sparsity parameter a (1 < a < 5), the default is a = 1.5.

- Empirical methods

- Equal balance sparsity-norm

- Square root of the threshold associated with Equal balance sparsity-norm

- Remove near 0

2 Global hard thresholding methods with GUI-driven choice are available. Predefined thresholding strategies are:

- Empirical methods

- Balance sparsity-norm (default = equal); Balance sparsity-norm (sqrt)

- Remove near 0

One-Dimensional Wavelet Packet De-noisingGlobal thresholding methods with GUI-driven choice are available. Predefined thresholding strategies are:

• Hard or soft (default) thresholding

• Thresholds values:

- Donoho-Johnstone methods: Fixed form (unscaled noise) (default); Fixed form (scaled noise)

- Birgé-Massart method: Penalized high, Penalized medium, Penalized low.

This method includes a sparsity parameter a (a > 1); see “One-Dimensional DWT and SWT De-noising” on page 6-109.

Page 466: Wavelet ug

6 Advanced Concepts

6-112

One-Dimensional Wavelet Packet CompressionGlobal hard thresholding methods with GUI-driven choice are available. Predefined thresholding strategies are:

- Empirical methods

- Balance sparsity-norm (default = equal)

- Remove near 0

Two-Dimensional Wavelet Packet De-noisingGlobal thresholding methods with GUI-driven choice are available. Predefined thresholding strategies are:

• Hard or soft (default) thresholding

• Thresholds values:

- Donoho-Johnstone methods: Fixed form (unscaled noise) (default); Fixed form (scaled noise)

- Birgé-Massart method: Penalized high, Penalized medium, Penalized low.

The last three choices include a sparsity parameter a (a > 1); see “One-Dimensional DWT and SWT De-noising” on page 6-109.

- Empirical method: Balance sparsity-norm (sqrt).

Two-Dimensional Wavelet Packet CompressionGlobal thresholding methods with GUI-driven choice are available. Predefined thresholding strategies are:

- Empirical methods

- Balance sparsity-norm (default = equal), Balance sparsity-norm (sqrt)

- Remove near 0

One-Dimensional Regression EstimationA preliminary histogram estimator (binning) is used, and then the predefined thresholding strategies described in “One-Dimensional DWT and SWT De-noising” on page 6-109, are available.

Density EstimationA preliminary histogram estimator (binning) is used, and then the predefined thresholding strategies are:

Page 467: Wavelet ug

Wavelet Applications: More Detail

6-113

- Global threshold

- By level threshold 1, By level threshold 2, By level threshold 3.

The last choice includes a sparsity parameter a (a < 1), the default is 0.6.

More About the Thresholding StrategiesA lot of references are available for this topic of de-noising, estimation, and compression.

For example: [Ant94], [AntP98], [HalPKP97], [AntG99], [Ogd97], [HarKPT98], [DonJ94a&b], [DonJKP95], and [DonJKP96] (see “References” on page 6-135). A short description of the available methods previously mentioned follows.

Scarce High, Medium, and Low.

These strategies are based on an approximation result from Birgé and Massart (for more information, see [BirM97]) and are well suited for compression.

Three parameters characterize the strategy:

• J the level of the decomposition

• M a positive constant

• a a sparsity parameter (a > 1)

The strategy is such that:

• At level J the approximation is kept

• For level j from 1 to J, the nj largest coefficients are kept with

So the strategy leads to select the highest coefficients in absolute value at each level, the numbers of kept coefficients grow scarcely with J-j.

Typically, a = 1.5 for compression and a = 3 for de-noising.

A natural default value for M is the length of the coarsest approximation coefficients, since the previous formula for j = J+1, leads to M = nJ+1.

Let L denote the length of the coarsest approximation coefficients in the 1-D case and S the size of the coarsest approximation coefficients in the 2-D case.

njM

J 2 j–+( )a-----------------------------=

Page 468: Wavelet ug

6 Advanced Concepts

6-114

Three different choices for M are proposed:

• Scarce high:

- M = L in the 1-D case

- M = 4*prod(S) in the 2-D case

• Scarce medium:

- M = 1.5*L in the 1-D case

- M = 4*4*prod(S) / 3 in the 2-D case

• Scarce low:

- M = 2*L in the 1-D case

- M = 4*8*prod(S) / 3 in the 2-D case

The related M-files are wdcbm, wdcbm2, and wthrmngr (for more information, see the corresponding reference pages).

Penalized High, Medium, and Low.

These strategies are based on a recent de-noising result by Birgé and Massart, and can be viewed as a variant of the fixed form strategy (see the section “De-Noising” on page 6-84) of the wavelet shrinkage.

The threshold T applied to the detail coefficients for the wavelet case or the wavelet packet coefficients for a given fixed WP tree, is defined by:

with

where

• The sparsity parameter a > 1

• The coefficients c(k) are sorted in decreasing order of their absolute value

• v is the noise variance

Three different intervals of choices for the sparsity parameter a are proposed:

• Penalized high, 2.5 ≤ a < 10

T c t*( )=

t* argmin sum c2 k( ) k t<,{ }– 2vt a nt---

log+ t 1 … n, ,=;+=

Page 469: Wavelet ug

Wavelet Applications: More Detail

6-115

• Penalized medium, 1.5 < a < 2.5

• Penalized low, 1 < a < 2

The related M-files are wbmpen, wpbmpen, and wthrmngr (for more information, see the corresponding reference pages).

Remove Near 0.

Let c denote the detail coefficients at level 1 obtained from the decomposition of the signal or the image to be compressed, using db1. The threshold value is set to median(abs(c)) or to 0.05*max(abs(c)) if median(abs(c)) = 0.

The related M-files are ddencmp, and wthrmngr (for more information, see the corresponding reference pages).

Balance Sparsity-Norm.

Let c denote all the detail coefficients, two curves are built associating, for each possible threshold value t, two percentages:

• The 2-norm recovery in percentage

• The relative sparsity in percentage, obtained from the compressed signal by setting to 0 the coefficients less than t in absolute value

A default is provided for the 1-D case taking t such that the two percentages are equal. Another one is obtained for the 2-D case by taking the square root of the previous t.

The related M-file is wthrmngr (for more information, see the corresponding reference page).

Fixed Form.

This thresholding strategy comes from Donoho-Johnstone (see “References” on page 6-135 and the 'sqtwolog' option of the wden function in “De-Noising” on page 6-84), the universal threshold is of the following form:

• DWT or SWT 1-D, where n is the signal length and s is the noise standard deviation.

• DWT or SWT 2-D, where [n,m] is the image size

• WP 1-D,

• WP 2-D,

t s 2 n( )log=

t s 2 nm( )log=

t s 2 n n( ) 2( )log( )⁄log( )log=

t s 2 nm nm( ) 2( )log( )⁄log( )log=

Page 470: Wavelet ug

6 Advanced Concepts

6-116

The related M-files are ddencmp, thselect, wden, wdencmp, and wthrmngr (for more information, see the corresponding reference pages).

Heursure, Rigsure, and Minimax.

These methods are available for 1-D de-noising tools and come from Donoho-Johnstone (see “References” on page 6-135).

The related M-files are thselect, wden, wdencmp, and wthrmngr (for more information, see the corresponding reference pages).

Global, and By level 1, 2, 3.

These options are dedicated to the density estimation problem.

See [HalPKP97], [AntG99], [Ogd97], and [HarKPT98] in “References” on page 6-135 for more details.

Note that:

• c is all the detail coefficients of the binned data

• d(j) is the detail coefficients at level j

• n is the number of bins chosen for the preliminary estimator (binning)

Then, these options are defined as follow.

1 Global:

Threshold value is set to

2 By level 1:

Level dependent thresholds T(j) are defined by:

3 By level 2:

Level dependent thresholds T(j) are defined by:

4 By level 3:

Level dependent thresholds T(j) are defined by:

where a is a sparsity parameter ( is the default)

max c( ) n( )logn

-----------------×

0.4 max d j( )( )×

0.8 max d j( )( )×

a max d j( )( )×

0.2 a 1 a,≤< 0.6=

Page 471: Wavelet ug

Wavelet Packets

6-117

Wavelet PacketsThe wavelet packet method is a generalization of wavelet decomposition that offers a richer signal analysis.

Wavelet packet atoms are waveforms indexed by three naturally interpreted parameters: position, scale (as in wavelet decomposition), and frequency.

For a given orthogonal wavelet function, we generate a library of bases called wavelet packet bases. Each of these bases offers a particular way of coding signals, preserving global energy and reconstructing exact features. The wavelet packets can be used for numerous expansions of a given signal. We then select the most suitable decomposition of a given signal with respect to an entropy-based criterion.

There exist simple and efficient algorithms for both wavelet packet decomposition and optimal decomposition selection. We can then produce adaptive filtering algorithms with direct applications in optimal signal coding and data compression.

From Wavelets to Wavelet Packets: Decomposing the DetailsIn the orthogonal wavelet decomposition procedure, the generic step splits the approximation coefficients into two parts. After splitting we obtain a vector of approximation coefficients and a vector of detail coefficients, both at a coarser scale. The information lost between two successive approximations is captured in the detail coefficients. Then the next step consists of splitting the new approximation coefficient vector; successive details are never re-analyzed.

In the corresponding wavelet packet situation, each detail coefficient vector is also decomposed into two parts using the same approach as in approximation vector splitting. This offers the richest analysis: the complete binary tree is produced as shown in Figure 6-34, on page 6-118.

Page 472: Wavelet ug

6 Advanced Concepts

6-118

Figure 6-34: Wavelet Packet Decomposition Tree at Level 3

The idea of this decomposition is to start from a scale-oriented decomposition, and then to analyze the obtained signals on frequency subbands.

Wavelet Packets in Action: an IntroductionThe following simple examples illustrate certain differences between wavelet analysis and wavelet packet analysis.

Example 1: Analyzing a Sine FunctionThe signal to be analyzed, called sinper8, is a 256-length sampled sine function of period 8. The Haar wavelet is used to decompose the signal at level 7.

Figure 6-35, on page 6-120, contains the “time-frequency” plot (x-axis is time and y-axis is frequency, high to low from the top to the bottom) for the wavelet decomposition (on the left) and for the wavelet packet decomposition (on the right).

Wavelet decomposition localizes the period of the sine within the interval [8,16]. Wavelet packets provide a more precise estimation of the actual period.

How to Obtain and Explain These Graphs?

You can reproduce these graphs by typing at the MATLAB prompt:

wavemenu

S

A1 D1

AA2 DA2

AAA3 DAA3

AD2 DD2

ADA3 DDA3 AAD3 DAD3 ADD3 DDD3

Page 473: Wavelet ug

Wavelet Packets

6-119

Then click the Wavelet Packet 1-D option and select the Example Analysis using the sinper8 demo signal. For more information on using this GUI tool, see the section “One-Dimensional Wavelet Packet Analysis” on page 5-7.

The length of the WP tree leaves is 2; there are 128 leaves, labeled from (7,0) to (7,127) and indexed from 127 to 254.

The associated wavelet tree (click the Wavelet Tree button) is obviously simpler than the wavelet packet tree. There are eight leaves labeled: (7,0), (7,1), (6,1), . . . (2,1), (1,1).

The Colored Coefficients for Terminal Nodes graph deserves explanation. In principle the graphic displays eight stripes. When using Global + abs, only four seem to be present. In fact, the eight are drawn. As the values of several coefficients are close to 0, the stripes are merged and only four can be seen. The eight stripes are recovered when using the option By level + abs.

Getting back to the Colored Coefficients for Terminal Nodes graph of the initial tree, with cool colormap, two stripes are present. By zooming in, we determine their WP index or position:

• stripe 1: index 175 or position (7,48) and index 143 or position (7,16)

• stripe 2: index 207 or position (7,80) and index 239 or position (7,112)

Using the two sliders of the Decomposition Tree graphic, we can visualize the coefficients or the reconstructed signals corresponding to these four leaves.

Page 474: Wavelet ug

6 Advanced Concepts

6-120

Figure 6-35: Wavelets (Left) Versus Wavelet Packets (Right): a Sine Function

Wavelet frequency localization Wavelet packets frequency localization

Page 475: Wavelet ug

Wavelet Packets

6-121

Example 2: Analyzing a Chirp SignalThe signal to be analyzed is a chirp: an oscillatory signal with increasing modulation sin (250πt2) sampled 512 times on [0, 1]. For this “linear” chirp, the derivative of the phase is linear. On the left of Figure 6-36, a wavelet analysis does not easily detect this time-frequency property of the signal. But on the right of Figure 6-36, the linear slope for the greatest wavelet packet coefficients in absolute value is obvious. The same experiment can be done with a “quadratic” chirp of the form sin (kπt3) in which the greatest wavelet packet coefficients exhibit a quadratic time frequency pattern.

Figure 6-36: Wavelets (Left) Versus Wavelet Packets (Right): Damped Oscillations.

Page 476: Wavelet ug

6 Advanced Concepts

6-122

Building Wavelet PacketsThe computation scheme for wavelet packets generation is easy when using an orthogonal wavelet. We start with the two filters of length 2N, where h(n) and g(n), corresponding to the wavelet.

Now by induction let us define the following sequence of functions

(Wn(x), n = 0, 1, 2, ...)

by:

where W0(x) = φ(x) is the scaling function and W1(x) = ψ(x) is the wavelet function.

For example for the Haar wavelet we have:

and

The equations become:

and

W0(x) = φ(x) is the Haar scaling function and W1(x) = ψ(x) is the Haar wavelet, both supported in [0, 1]. Then we can obtain W2n by adding two 1/2-scaled

W2n x( ) 2 h k( )Wn 2x k–( )k 0=

2N 1–

∑=

W2n 1+ x( ) 2 g k( )Wn 2x k–( )k 0=

2N 1–

∑=

N 1 h 0( ), h 1( ) 12

-------= = =

g 0( ) g 1( )–12

-------= =

W2n x( ) Wn 2x( ) Wn 2x 1–( )+=

W2n 1+ x( ) Wn 2x( ) Wn 2x 1–( )–=

Page 477: Wavelet ug

Wavelet Packets

6-123

versions of Wn with distinct supports [0,1/2] and [1/2,1] and obtain W2n+1 by subtracting the same versions of Wn.

For n = 0 to 7, we have the W-functions shown below.

Figure 6-37: The Haar Wavelet Packets

This can be obtained using the following command:

[wfun,xgrid] = wpfun('db1',7,5);

which returns in wfun the approximate values of Wn for n = 0 to 7, computed on

a 1/25 grid of the support xgrid.

0 0.5 10

0.5

1

W00 0.5 1

−1.5

−1

−0.5

0

0.5

1

1.5

W10 0.5 1

−1.5

−1

−0.5

0

0.5

1

1.5

W20 0.5 1

−1.5

−1

−0.5

0

0.5

1

1.5

W3

0 0.5 1−1.5

−1

−0.5

0

0.5

1

1.5

W40 0.5 1

−1.5

−1

−0.5

0

0.5

1

1.5

W50 0.5 1

−1.5

−1

−0.5

0

0.5

1

1.5

W60 0.5 1

−1.5

−1

−0.5

0

0.5

1

1.5

W7

Page 478: Wavelet ug

6 Advanced Concepts

6-124

Starting from more regular original wavelets and using a similar construction, we obtain smoothed versions of this system of W-functions, all with support in the interval [0, 2N-1]. Figure 6-38, below, presents the system of W-functions for the original db2 wavelet.

Figure 6-38: The db2 Wavelet Packets

Wavelet Packet AtomsStarting from the functions and following the same line leading to orthogonal wavelets, we consider the three-indexed family of analyzing functions (the waveforms):

where and

0 1 2 3−0.5

0

0.5

1

1.5

W00 1 2 3

−1.5

−1

−0.5

0

0.5

1

1.5

2

W10 1 2 3

−2

−1

0

1

2

3

W20 1 2 3

−1.5

−1

−0.5

0

0.5

1

1.5

2

2.5

W3

0 1 2 3−2

−1

0

1

2

3

W40 1 2 3

−2

−1

0

1

2

3

W50 1 2 3

−2

−1

0

1

2

3

W60 1 2 3

−2

−1

0

1

2

3

W7

Wn x( ) n N∈,( )

Wj n k, , x( ) 2 j– 2⁄ Wn 2 j– x k–( )=

n N∈ j k( , ) Z2∈

Page 479: Wavelet ug

Wavelet Packets

6-125

As in the wavelet framework, k can be interpreted as a time-localization parameter and j as a scale parameter. So what is the interpretation of n?

The basic idea of the wavelet packets is that for fixed values of j and k, Wj,n,k analyzes the fluctuations of the signal roughly around the position , at the scale and at various frequencies for the different admissible values of the last parameter n.

In fact, examining carefully the wavelet packets displayed in Figure 6-37, on page 6-123 and Figure 6-38, on page 6-124, the naturally ordered Wn for n = 0, 1, ..., 7, does not match exactly the order defined by the number of oscillations. More precisely, counting the number of zero-crossings (up-crossings and down-crossings) for the db1 wavelet packets, we have the following.

So, to restore the property that the main frequency increases monotonically with the order, it is convenient to define the frequency order obtained from the natural one recursively.

As can be seen in the previous figures, Wr(n)(x) “oscillates” approximately n times.

To analyze a signal (the chirp of example 2 for instance), it is better to plot the wavelet packet coefficients following the Frequency order (on the right of the Figure 6-39) from the low frequencies at the bottom to the high frequencies at the top, rather than naturally ordered coefficients (on the left of Figure 6-39).

Natural order n 0 1 2 3 4 5 6 7

Number of zero-crossings for db1 Wn

2 3 5 4 9 8 6 7

Natural order n 0 1 2 3 4 5 6 7

Frequency order r(n) 0 1 3 2 6 7 5 4

2j k⋅2j

Page 480: Wavelet ug

6 Advanced Concepts

6-126

Figure 6-39: Natural and Frequency Ordered Wavelet Packets Coefficients

When plotting the coefficients, the various options related to the “Frequency” or “Natural” order choice are available using the GUI tools.

These options are also available from the command line mode when using the wpviewcf function.

Page 481: Wavelet ug

Wavelet Packets

6-127

Organizing the Wavelet PacketsThe set of functions: Wj,n = (Wj,n,k(x), ) is the (j,n) wavelet packet. For positive values of integers j and n, wavelet packets are organized in trees. The tree in Figure 6-40 is created to give a maximum level decomposition equal to 3. For each scale j, the possible values of parameter n are: 0, 1, ..., 2j -1.

Figure 6-40: Wavelet Packets Organized in a Tree, Scale j Defines Depth and Frequency n Defines Position in the Tree

The notation Wj,n, where j denotes scale parameter and n the frequency parameter, is consistent with the usual depth-position tree labeling.

We have , and .

It turns out that the library of wavelet packet bases contains the wavelet basis and also several other bases. Let us have a look at some of those bases. More precisely, let V0 denote the space (spanned by the family W0,0) in which the signal to be analyzed lies; then (Wd,1; d ≥ 1) is an orthogonal basis of V0.

For every strictly positive integer D, (WD,0, (Wd,1; 1 ≤ d ≤ D)) is an orthogonal basis of V0.

k Z∈

W0,0

W3,4

W2,2

W1,1

W3,3W3,2W3,1W3,0

W2,1W2,0

W1,0

W3,5

W2,3

W3,7W3,6

Scale

j = 0

j = 1

j = 2

j = 3

W0 0, φ x k–( ) k Z∈,( )= W1 1, ψ x2--- k–

k Z )∈,=

Page 482: Wavelet ug

6 Advanced Concepts

6-128

We also know that the family of functions {(Wj+1,2n),(Wj+1,2n+1)} is an orthogonal basis of the space spanned by Wj,n, which is split into two subspaces: Wj+1,2n spans the first subspace, and Wj+1,2n+1 the second one.

This last property gives a precise interpretation of splitting in the wavelet packet organization tree, because all the developed nodes are of the form shown in the figure below.

Figure 6-41: Wavelet Packet Tree: Split and Merge

It follows that the leaves of every connected binary subtree of the complete tree correspond to an orthogonal basis of the initial space.

For a finite energy signal belonging to V0, any wavelet packet basis will provide exact reconstruction and offer a specific way of coding the signal, using information allocation in frequency scale subbands.

Choosing the Optimal Decomposition Based on the organization of the wavelet packet library, it is natural to count the decompositions issued from a given orthogonal wavelet.

A signal of length N = 2L can be expanded in α different ways, where α is the number of binary subtrees of a complete binary tree of depth L. As a result,

(see [Mal98] page 323).

As this number may be very large, and since explicit enumeration is generally unmanageable, it is interesting to find an optimal decomposition with respect to a convenient criterion, computable by an efficient algorithm. We are looking for a minimum of the criterion.

Functions verifying an additivity-type property are well-suited for efficient searching of binary-tree structures and the fundamental splitting. Classical entropy-based criteria match these conditions and describe information- related properties for an accurate representation of a given signal. Entropy is

Wj,n

Wj+1,2n Wj+1,2n+1

α 2N 2⁄≥

Page 483: Wavelet ug

Wavelet Packets

6-129

a common concept in many fields, mainly in signal processing. Let us list four different entropy criteria (see [CoiW92]), many others are available and can be easily integrated (type help wentropy). In the following expressions s is the signal and (si) are the coefficients of s in an orthonormal basis.

The entropy E must be an additive cost function such that E(0) = 0 and

• The (nonnormalized) Shannon entropy

so

with the convention 0log(0) = 0

• The concentration in lp norm with 1 ≤ p

so

• The logarithm of the “energy” entropy

so

with the convention log(0) = 0.

• The threshold entropy

if and 0 elsewhere, so {i such that } is the number of time instants when the signal is greater than a threshold ε.

E s( ) E si( )i

∑=

E1 si( ) s– i2 si

2( )log=

E1 s( ) si2 si

2( )logi

∑–=

E2 si( ) sip

=

E2 s( ) sip s p

p=

i∑=

E3 si( ) si2( )log=

E3 s( ) si2( )log

i∑=

E4 si( ) 1= si ε> E4 s( ) #= si ε>

Page 484: Wavelet ug

6 Advanced Concepts

6-130

These entropy functions are available using the wentropy M-file.

Example 1: Compute Various Entropies.

1 Generate a signal of energy equal to 1.

s = ones(1,16)*0.25;

2 Compute the Shannon entropy of s.

e1 = wentropy(s,'shannon')e1 = 2.7726

3 Compute the l1.5 entropy of s, equivalent to norm(s,1.5)1.5.

e2 = wentropy(s,'norm',1.5)e2 = 2

4 Compute the “log energy” entropy of s.

e3 = wentropy(s,'log energy')e3 = -44.3614

5 Compute the threshold entropy of s, using a threshold value of 0.24.

e4 = wentropy(s,'threshold', 0.24)e4 = 16

Example 2: Minimum-Entropy Decomposition.

This simple example illustrates the use of entropy to determine whether a new splitting is of interest to obtain a minimum-entropy decomposition.

1 We start with a constant original signal. Two pieces of information are sufficient to define and to recover the signal (i.e., length and constant value).

w00 = ones(1,16)*0.25;

2 Compute entropy of original signal.

e00 = wentropy(w00,'shannon') e00 = 2.7726

3 Then split w00 using the haar wavelet.

[w10,w11] = dwt(w00,'db1');

Page 485: Wavelet ug

Wavelet Packets

6-131

4 Compute entropy of approximation at level 1

e10 = wentropy(w10,'shannon')e10 = 2.0794

The detail of level 1, w11, is zero; the entropy e11 is zero. Due to the additivity property the entropy of decomposition is given by e10+e11=2.0794. This has to be compared to the initial entropy e00=2.7726. We have e10 + e11 < e00, so the splitting is interesting.

5 Now split w10 (not w11 because the splitting of a null vector is without interest since the entropy is zero).

[w20,w21] = dwt(w10,'db1');

6 We have w20=0.5*ones(1,4) and w21 is zero. The entropy of the approximation level 2 is:

e20 = wentropy(w20,'shannon')e20 = 1.3863

Again we have e20 + 0 < e10, so splitting makes the entropy decrease.

7 Then

[w30,w31] = dwt(w20,'db1');e30 = wentropy(w30,'shannon')

e30 = 0.6931

[w40,w41] = dwt(w30,'db1')w40 = 1.0000w41 = 0

e40 = wentropy(w40,'shannon')e40 = 0

In the last splitting operation we find that only one piece of information is needed to reconstruct the original signal. The wavelet basis at level 4 is a best basis according to Shannon entropy (with null optimal entropy since e40+e41+e31+e21+e11 = 0).

Page 486: Wavelet ug

6 Advanced Concepts

6-132

8 Perform wavelet packets decomposition of the signal s defined in example 1.

t = wpdec(s,4,'haar','shannon');

The wavelet packet tree below shows the nodes labeled with original entropy numbers.

Figure 6-42: Entropy Values

9 Now compute the best tree.

bt = besttree(t);

The best tree is displayed in the figure below. In this case, the best tree corresponds to the wavelet tree. The nodes are labeled with optimal entropy.

Figure 6-43: Optimal Entropy Values

Page 487: Wavelet ug

Wavelet Packets

6-133

Some Interesting SubtreesUsing wavelet packets requires tree-related actions and labeling. The implementation of the user interface is built around this consideration. For more information on the technical details, see the reference pages.

The complete binary tree of depth D corresponding to a wavelet packet decomposition tree developed at level D is denoted by WPT.

We have the following interesting subtrees:

We deduce the following definitions of optimal decompositions, with respect to an entropy criterion E.

For any nonterminal node, we use the following basic step to find the optimal subtree with respect to a given entropy criterion E (where Eopt denotes the optimal entropy value).

Decomposition Tree Subtree Such That the Set of Leaves Is a Basis

Wavelet packets decomposition tree

Complete binary tree: WPT of depth D

Wavelet packets optimal decomposition tree

Binary subtree of WPT

Wavelet packets best-level tree

Complete binary subtree of WPT

Wavelet decomposition tree Left unilateral binary subtree of WPT of depth D

Wavelet best-basis tree Left unilateral binary subtree of WPT

Decompositions Optimal Decomposition

Best-Level Decomposition

Wavelet packet decompositions

Search among 2D trees Search among D trees

Wavelet decompositions Search among D trees Search among D trees

Page 488: Wavelet ug

6 Advanced Concepts

6-134

with the natural initial condition on the reference tree, Eopt(t) = E(t) for each terminal node t.

Wavelet Packets 2-D Decomposition StructureExactly as in the wavelet decomposition case, the preceding one-dimensional framework can be extended to image analysis. Minor direct modifications lead to quaternary tree-related definitions. An example is shown below for depth 2.

Figure 6-44: Quaternary Tree of Depth 2

Wavelet Packets for Compression and De-NoisingIn the wavelet packet framework, compression and de-noising ideas are identical to those developed in the wavelet framework. The only new feature is a more complete analysis that provides increased flexibility. A single decomposition using wavelet packets generates a large number of bases. You can then look for the best representation with respect to a design objective, using the function besttree with an entropy function. For more details, see “Using Wavelet Packets” on page 5-1.

Entropy Condition Action on Tree and on Entropy Labelling

E node( ) Eopt c( ) c child of node

∑≤ If node root≠( ), merge and set Eopt node( ) E node( )=

E node( ) Eopt c( ) c child of node

∑> Split and set Eopt node( ) Eopt c( ) c child of node

∑=

Page 489: Wavelet ug

References

6-135

References[Abr97] Abry, P. (1997), Ondelettes et turbulence. Multirésolutions, algorithmes de décomposition, invariance d’échelles, Diderot Editeur, Paris.

[Ant94] Antoniadis, A. (1994), “Smoothing noisy data with coiflets,” Statistica Sinica 4 (2), pp. 651–678.

[AntO95] Antoniadis, A.; G. Oppenheim, Eds.(1995), Wavelets and statistics, Lecture Notes in Statistics 103, Springer Verlag.

[AntP98] Antoniadis A.; D.T. Pham (1998), “Wavelet regression for random or irregular design,” Comp. Stat. and Data Analysis, 28, pp. 353–369.

[AntG99] Antoniadis, A.; G. Gregoire (1999), “Density and Hazard rate estimation for right-censored data using wavelet methods,” J. R. Statist. Soc. B, 61, 1, pp. 63–84.

[ArnABEM95] Arneodo, A.; F. Argoul, E. Bacry, J. Elezgaray, J.F. Muzy (1995), Ondelettes, multifractales et turbulence, Diderot Editeur, Paris.

[BirM97] Birgé, L.; P. Massart (1997), “From model selection to adaptive estimation,” in D. Pollard (ed), Festchrift for L. Le Cam, Springer, pp. 55–88.

[Bri95] Brislawn, C.M. (1995), “Fingerprints to digital,” Notices of the AMS. Vol. 42 pp. 1278–1283.

[Bur96] Burke Hubbard, B. (1996), The world accorging to wavelets, AK Peters, Wellesley. The French original version is entitled Ondes et Ondelettes. La saga d’un outil mathématique, Pour la Science, (1995).

[Chu92a] Chui, C.K. (1992a), Wavelets: a tutorial in theory and applications, Academic Press.

[Chu92b] Chui, C.K. (1992b), An introduction to wavelets, Academic Press.

[Coh92] Cohen, A. (1992), “Ondelettes, analyses multirésolution et traitement numérique du signal,” Ph. D. Thesis, University of Paris IX, Dauphine.

[Coh95] Cohen, A. (1995), Wavelets and multiscale signal processing, Chapman and Hall.

[CohDF92] Cohen, A.; I. Daubechies, J.C. Feauveau (1992), “Biorthogonal basis of compactly supported wavelets,” Comm. Pure Appli. Math. , vol. 45, pp. 485–560.

Page 490: Wavelet ug

6 Advanced Concepts

6-136

[CohDJV93] Cohen, A.; I. Daubechies, B. Jawerth, P. Vial (1993), “Multiresolution analysis, wavelets and fast wavelet transform on an interval,” CRAS Paris, Ser. A, t. 316, pp. 417–421.

[CoiD95] Coifman, R.R.; D.L. Donoho (1995), “Translation invariant de-noising,” Lecture Notes in Statistics, 103, pp. 125–150.

[CoiMW92] Coifman, R.R.; Y. Meyer, M.V. Wickerhauser (1992), “Wavelet analysis and signal processing,” in Wavelets and their applications, M.B. Ruskai et al. (Eds.), pp. 153–178, Jones and Bartlett.

[CoiW92] Coifman, R.R.; M.V Wickerhauser (1992), “Entropy-based algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

[Dau92] Daubechies, I. (1992), Ten lectures on wavelets, SIAM.

[DevJL92] DeVore, R.A.; B. Jawerth, B.J. Lucier (1992), “Image compression through wavelet transform coding,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 719–746.

[Don93] Donoho, D.L. (1993), “Progress in wavelet analysis and WVD: a ten minute tour,” in Progress in wavelet analysis and applications, Y. Meyer, S. Roques, pp. 109–128. Frontières Ed.

[Don95] Donoho, D.L. (1995), “De-Noising by soft-thresholding,” IEEE Trans. on Inf. Theory, vol. 41, 3, pp. 613–627.

[DonJ94a] Donoho, D.L.; I.M. Johnstone (1994),“Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

[DonJ94b] Donoho, D.L.; I.M. Johnstone (1994), “Ideal de-noising in an orthonormal basis chosen from a library of bases,” CRAS Paris, Ser I, t. 319, pp. 1317–1322.

[DonJKP95] Donoho, D.L.; I.M. Johnstone, G. Kerkyacharian, D. Picard (1995), “Wavelet shrinkage: asymptopia,” Jour. Roy. Stat. Soc., series B, vol. 57 no. 2, pp. 301–369.

[DonJKP96] Donoho, D.L.; I.M. Johnstone, G. Kerkyacharian, D. Picard (1996), “Density estimation by wavelet thesholding,” Annals of Stat., 24, pp. 508–539.

Page 491: Wavelet ug

References

6-137

[HalPKP97] Hall, P.; S. Penev, G. Kerkyacharian, D. Picard (1997), “Numerical performance of block thresholded wavelet estimators,” Stat. and Computing, 7, pp. 115–124.

[HarKPT98] Hardle, W.; G. Kerkyacharian, D. Picard, A. Tsybakov (1998), Wavelets, approximation and statistical applications, Lecture Notes in Statistics, 129, Springer Verlag.

[KahL95] Kahane, J.P.; P.G Lemarié (1995), Fourier series and wavelets, Gordon and Research Publishers, Studies in the Development of Modern Mathematics, vol 3.

[Kai94] Kaiser, G. (1994), A friendly guide to wavelets, Birkhauser.

[Lav99] Lavielle, M. (1999), “Detection of multiple changes in a sequence of dependent variables,” Stoch. Proc. and their Applications, 83, 2, pp. 79–102.

[Lem90] Lemarié, P.G., Ed, (1990), Les ondelettes en 1989, Lecture Notes in Mathematics, Springer Verlag.

[Mal89] Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

[Mal98] Mallat, S. (1998), A wavelet tour of signal processing, Academic Press.

[Mey90] Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)

[Mey93] Meyer, Y. (1993), Les ondelettes. Algorithmes et applications, Colin Ed., Paris, 2nd edition. (English translation: Wavelets: algorithms and applications, SIAM).

[MeyR93] Meyer, Y.; S. Roques, Eds. (1993), Progress in wavelet analysis and applications, Frontières Ed.

[MisMOP93a] Misiti, M.; Y. Misiti, G. Oppenheim, J.M. Poggi (1993a), “Analyse de signaux classiques par décomposition en ondelettes,” Revue de Statistique Appliquée, vol. XLI, no. 4, pp. 5–32.

[MisMOP93b] Misiti, M.; Y. Misiti, G. Oppenheim, J.M. Poggi (1993b), “Ondelettes en statistique et traitement du signal,” Revue de Statistique Appliquée, vol. XLI, no. 4, pp. 33–43.

Page 492: Wavelet ug

6 Advanced Concepts

6-138

[MisMOP94] Misiti, M.; Y. Misiti, G. Oppenheim, J.M. Poggi (1994), “Décomposition en ondelettes et méthodes comparatives: étude d'une courbe de charge électrique,” Revue de Statistique Appliquée, vol. XLII, no. 2, pp. 57–77.

[NasS95] Nason, G.P.; B.W. Silverman (1995), “The stationary wavelet transform and some statistical applications,” Lecture Notes in Statistics, 103, pp. 281–299.

[Ogd97] Ogden, R.T. (1997), Essential wavelets for statistical applications and data analysis, Birkhauser.

[PesKC96] Pesquet, J.C.; H. Krim, H. Carfatan (1996), “Time-invariant orthonormal wavelet representations,” IEEE Trans. Sign. Proc., vol. 44, 8, pp. 1964–1970.

[StrN96] Strang, G.; T. Nguyen (1996), Wavelets and filter banks, Wellesley- Cambridge Press.

[Teo98] Teolis, A. (1998), Computational signal processing with wavelets, Birkhauser.

[VetK95] Vetterli, M.; J. Kovacevic (1995), Wavelets and subband coding, Prentice Hall.

[Wic91] Wickerhauser, M.V. (1991), “INRIA lectures on wavelet packet algorithms,” Proceedings ondelettes et paquets d’ondes, 17–21 june, Rocquencourt France, pp. 31–99.

[Wic94] Wickerhauser, M.V. (1994), Adapted wavelet analysis from theory to software algorithms, A.K. Peters.

Page 493: Wavelet ug

7Adding Your Own Wavelets

Preparing to Add a New Wavelet Family . . . . . . . 7-3Choose the Wavelet Family Full Name . . . . . . . . . . 7-3Choose the Wavelet Family Short Name . . . . . . . . . 7-3Determine the Wavelet Type . . . . . . . . . . . . . . 7-4Define the Orders of Wavelets Within the Given Family . . . 7-4Build a MAT-File or M-File . . . . . . . . . . . . . . 7-5Define the Effective Support . . . . . . . . . . . . . . 7-7

Adding a New Wavelet Family . . . . . . . . . . . . 7-8Example 1 . . . . . . . . . . . . . . . . . . . . . 7-8Example 2 . . . . . . . . . . . . . . . . . . . . . 7-12

After Adding a New Wavelet Family . . . . . . . . . 7-16

Page 494: Wavelet ug

7 Adding Your Own Wavelets

7-2

The Wavelet Toolbox contains a lot of wavelet families, but by using the wavemngr function, you can add new wavelets to the existing ones to implement your favorite wavelet or try out one of your own design. The toolbox allows you to define new wavelets for use with both the command line functions and the graphical interface tools.

Caution This capability must be used carefully, because the toolbox does not check that your wavelet meets all the mathematical requisites.

The wavemngr function affords extensive wavelet management. However, this chapter focuses only on the addition of a wavelet family. For more complete information, see the wavemngr entry in the Reference Guide.

This chapter includes the following sections:

• “Preparing to Add a New Wavelet Family” on page 7-3

• “Adding a New Wavelet Family” on page 7-8

• “After Adding a New Wavelet Family” on page 7-16

Page 495: Wavelet ug

Preparing to Add a New Wavelet Family

7-3

Preparing to Add a New Wavelet FamilyThe wavemngr command permits you to add new wavelets and wavelet families to the predefined ones. However, before you can use the wavemngr command to add a new wavelet, you must:

1 Choose the full name of the wavelet family (fn).

2 Choose the short name of the wavelet family (fsn).

3 Determine the wavelet type (wt).

4 Define the orders of wavelets within the given family (nums).

5 Build a MAT-file or a M-file (file).

6 For wavelets without FIR filters: Define the effective support.

These steps are described below.

Choose the Wavelet Family Full NameThe full name of the wavelet family, fn, must be a string. Predefined wavelet family names are: Haar, Daubechies, Symlets, Coiflets, BiorSplines, ReverseBior, Meyer, DMeyer, Gaussian, Mexican_hat, Morlet, Complex Gaussian, Shannon, Frequency B-Spline, and Complex Morlet.

Choose the Wavelet Family Short NameThe short name of the wavelet family, fsn, must be a string of four characters or less. Predefined wavelet family short names are: haar, db, sym, coif, bior, rbio, meyr, dmey, gaus, mexh, morl, cgau, fbsp, and cmor.

Page 496: Wavelet ug

7 Adding Your Own Wavelets

7-4

Determine the Wavelet TypeWe distinguish five types of wavelets:

1 Orthogonal wavelets with FIR filters

These wavelets can be defined through the scaling filter w. Predefined families of such wavelets include: Haar, Daubechies, Coiflets, and Symlets.

2 Biorthogonal wavelets with FIR filters

These wavelets can be defined through the two scaling filters wr and wd, for reconstruction and decomposition respectively. The BiorSplines wavelet family is a predefined family of this type.

3 Orthogonal wavelets without FIR filter, but with scale function

These wavelets can be defined through the definition of the wavelet function and the scaling function. The Meyer wavelet family is a predefined family of this type.

4 Wavelets without FIR filter and without scale function

These wavelets can be defined through the definition of the wavelet function. Predefined families of such wavelets include: Morlet and Mexican_hat.

5 Complex wavelets without FIR filter and without scale function

These wavelets can be defined through the definition of the wavelet function. Predefined families of such wavelets include: Complex Gaussian and Shannon.

Define the Orders of Wavelets Within the Given FamilyIf a family contains many wavelets, the short name and the order are appended to form the wavelet name. Argument nums is a string containing the orders separated with blanks. This argument is not used for wavelet families that only have a single wavelet (Haar, Meyer and Morlet for example).

Page 497: Wavelet ug

Preparing to Add a New Wavelet Family

7-5

For example, for the first Daubechies wavelets,

fsn = 'db'nums = '1 2 3'

yield the three wavelets db1, db2 and db3.

For the first BiorSplines wavelets,

fsn = 'bior'nums = '1.1 1.3 1.5 2.2'

yield the four wavelets bior1.1, bior1.3, bior1.5, and bior2.2.

Build a MAT-File or M-FileThe wavemngr command requires a file argument, which is a string containing a MAT-file or M-file name.

If a family contains many wavelets, a M-file must be defined and must be of a specific form that depends on the wavelet type. The specific M-file formats are described in the remainder of this section.

If a family contains a single wavelet, then a MAT-file can be defined for wavelets of type 1. It must have the wavelet family short name (fsn) argument as its name and must contain a single variable whose name is fsn and whose value is the scaling filter. An M-file can also be defined as discussed below.

Type 1 (Orthogonal with FIR Filter)The syntax of the first line in the M-file must be:

function w = file(wname)

where the input argument wname is a string containing the wavelet name, and the output argument w is the corresponding scaling filter.

The filter w must be of even length otherwise it is zero-padded by the toolbox.

For predefined wavelets, the scaling filter is of sum 1. For a new wavelet, the normalization is free (except 0 of course) since the toolbox uses a suitably normalized version of this filter.

Examples of such M-files for predefined wavelets are: dbwavf.m for Daubechies, coifwavf.m for Coiflets, and symwavf.m for Symlets.

Page 498: Wavelet ug

7 Adding Your Own Wavelets

7-6

Type 2 (Biorthogonal with FIR Filter)The syntax of the first line in the M-file must be:

function [wr,wd] = file(wname)

where the input argument wname is a string containing the wavelet name and the output arguments wr and wd are the corresponding reconstruction and decomposition scaling filters, respectively.

The filters wr and wd must be of the same even length. In general, initial biorthogonal filters do not meet these requirements, so they are zero-padded by the toolbox.

For predefined wavelets, the scaling filters are of sum 1. For a new wavelet, the normalization is free (except 0 of course) since the toolbox uses a suitably normalized version of these filters.

The M-file biorwavf.m (for BiorSplines) is an example of an M-file for a type-2 predefined wavelet family.

Type 3 (Orthogonal with Scale Function)The syntax of the first line in the M-file must be:

function [phi,psi,t] = file(lb,ub,n,wname)

which returns values of the scaling function phi and of the wavelet function psi on t, a regular n-point grid of the interval [lb ub].

The argument wname is optional (see Note below).

The M-file meyer.m is an example of an M-file for a type-3 predefined wavelet family.

Type 4 or Type 5 (No FIR Filter; No Scale Function)The syntax of the first line in the M-file must be:

function [psi,t] = file(lb,ub,n,wname)

or

function [psi,t] = file(lb,ub,n,wname, “additional arguments”)

which returns values of the wavelet function psi on t, a regular n-point grid of the interval [lb ub].

Page 499: Wavelet ug

Preparing to Add a New Wavelet Family

7-7

The argument wname is optional (see Note below).

Examples of type-4 M-files for predefined wavelet families are mexihat.m (for Mexican_hat) and morlet.m (for Morlet).

Examples of type-5 M-files for predefined wavelet families are shanwavf.m (for Shannon) and cmorwavf.m (for Complex Morlet).

Note For the types 3, 4, and 5, the wname argument can be optional. It is only required if the new wavelet family contains more than one wavelet and if you plan to use this new family in the GUI mode. For the types 4 and 5, a complete example of using the “additional arguments” can be found looking at the reference page for the fbspwavf function.

Define the Effective SupportThis definition is required only for wavelets of type 3, 4, and 5, since they are not compactly supported.

Defining the effective support means specifying an upper and lower bound. For example, for some predefined wavelet families, we have the following.

Family Lower Bound (lb) Upper Bound (ub)

Meyer –8 8

Mexican_hat –5 5

Morlet –4 4

Page 500: Wavelet ug

7 Adding Your Own Wavelets

7-8

Adding a New Wavelet FamilyTo add a new wavelet, use the wavemngr command in one of two forms:

wavemngr('add',fn,fsn,wt,nums,file)

or

wavemngr('add',fn,fsn,wt,nums,file,b).

Here are a few examples to illustrate how you would use wavemngr to add some of the predefined wavelet families:

Example 1Let us take the example of Binlets proposed by Strang and Nguyen in the pages 216-217 of the book Wavelets and Filter Banks (See [StrN96] in “References” on page 6-135).

Note The M-files used in this example can be found in the wavedemo directory.

The full family name is: Binlets.

The short name of the wavelet family is: binl.

The wavelet type is: 2 (Biorthogonal with FIR filters).

Type Syntax

1 wavemngr('add','Ndaubechies','ndb',1,'1 2 3 4 5','dbwavf');

1 wavemngr('add','Ndaubechies','ndb',1,'1 2 3 4 5 **','dbwavf');

2 wavemngr('add','Nbiorwavf','nbio',2,'1.1 1.3','biorwavf');

3 wavemngr('add','Nmeyer','nmey',3,'','meyer',[-8,8]);

4 wavemngr('add','Nmorlet','nmor',4,'','morlet',[-4,4]).

Page 501: Wavelet ug

Adding a New Wavelet Family

7-9

The order of the wavelet within the family is: 7.9 (we just use one in this example).

The M-file used to generate the filters is binlwavf.m

Then to add the new wavelet, type:

% Add new family of biorthogonal wavelets. wavemngr('add','Binlets','binl',2,'7.9','binlwavf')

% List wavelets families. wavemngr('read')

ans =

=================================== Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor Binlets binl ===================================

Page 502: Wavelet ug

7 Adding Your Own Wavelets

7-10

If you want to get online information on this new family, you can build an associated help file which would look like:

function binlinfo%BINLINFO Information on biorthogonal wavelets (binlets).%% Biorthogonal Wavelets (Binlets)%% Family Binlets% Short name binl% Order Nr,Nd Nr = 7 , Nd = 9%% Orthogonal no% Biorthogonal yes% Compact support yes% DWT possible% CWT possible%% binl Nr.Nd ld lr % effective length effective length% of LoF_D of HiF_D% binl 7.9 7 9

The associated M-file to generate the filters (binlwavf.m) is:

function [Rf,Df] = binlwavf(wname)%BINLWAVF Biorthogonal wavelet filters (Binlets).% [RF,DF] = BINLWAVF(W) returns two scaling filters% associated with the biorthogonal wavelet specified% by the string W.% W = 'binlNr.Nd' where possible values for Nr and Nd are: Nr = 7 Nd = 9% The output arguments are filters:% RF is the reconstruction filter% DF is the decomposition filter

% Check arguments.if errargn('binlwavf',nargin,[0 1],nargout,[0:2]), error('*'); end

Page 503: Wavelet ug

Adding a New Wavelet Family

7-11

% suppress the following line for extensionNr = 7; Nd = 9;

% for possible extension% more wavelets in 'Binlets' family%----------------------------------if nargin==0 Nr = 7; Nd = 9;elseif isempty(wname) Nr = 7; Nd = 9;else if ischar(wname) lw = length(wname); ab = abs(wname); ind = find(ab==46 | 47<ab | ab<58); li = length(ind); err = 0; if li==0 err = 1; elseif ind(1)~=ind(li)-li+1 err = 1; end if err==0 , wname = str2num(wname(ind)); if isempty(wname) , err = 1; end end end if err==0 Nr = fix(wname); Nd = 10*(wname-Nr); else Nr = 0; Nd = 0; endend

% suppress the following lines for extension% and add a test for errors.%-------------------------------------------if Nr~=7 , Nr = 7; endif Nd~=9 , Nd = 9; end

Page 504: Wavelet ug

7 Adding Your Own Wavelets

7-12

if Nr == 7 if Nd == 9 Rf = [-1 0 9 16 9 0 -1]/32; Df = [ 1 0 -8 16 46 16 -8 0 1]/64; endend

Example 2In the following example, new compactly supported orthogonal wavelets are added to the toolbox. These wavelets, which are a slight generalization of the Daubechies wavelets, are based on the use of Bernstein polynomials and are due to Kateb and Lemarié in an unpublished work.

Note The M-files used in this example can be found in the wavedemo directory.

% List initial wavelets families. wavemngr('read')

ans ==================================== Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor ===================================

Page 505: Wavelet ug

Adding a New Wavelet Family

7-13

% List all wavelets. wavemngr('read',1)

ans =

=================================== Haar haar =================================== Daubechies db ------------------------------ db1 db2 db3 db4db5 db6 db7 db8db9 db10 db** =================================== Symlets sym ------------------------------ sym2 sym3 sym4 sym5 sym6 sym7 sym8 sym** =================================== Coiflets coif ------------------------------ coif1 coif2 coif3 coif4coif5 =================================== BiorSplines bior ------------------------------ bior1.1 bior1.3 bior1.5 bior2.2 bior2.4 bior2.6 bior2.8 bior3.1 bior3.3 bior3.5 bior3.7 bior3.9 bior4.4 bior5.5 bior6.8 =================================== ReverseBior rbio ------------------------------ rbio1.1 rbio1.3 rbio1.5 rbio2.2 rbio2.4 rbio2.6 rbio2.8 rbio3.1 rbio3.3 rbio3.5 rbio3.7 rbio3.9 rbio4.4 rbio5.5 rbio6.8 =================================== Meyer meyr ===================================

Page 506: Wavelet ug

7 Adding Your Own Wavelets

7-14

DMeyer dmey =================================== Gaussian gaus ------------------------------ gaus1 gaus2 gaus3 gaus4 gaus5 gaus6 gaus7 gaus8 gaus** =================================== Mexican_hat mexh =================================== Morlet morl =================================== Complex Gaussian cgau ------------------------------ cgau1 cgau2 cgau3 cgau4 cgau5 cgau** =================================== Shannon shan ------------------------------ shan1-1.5 shan1-1 shan1-0.5 shan1-0.1 shan2-3 shan** =================================== Frequency B-Spline fbsp ------------------------------ fbsp1-1-1.5 fbsp1-1-1 fbsp1-1-0.5 fbsp2-1-1fbsp2-1-0.5 fbsp2-1-0.1 fbsp** =================================== Complex Morlet cmor ------------------------------ cmor1-1.5 cmor1-1 cmor1-0.5 cmor1-1cmor1-0.5 cmor1-0.1 cmor** ===================================

% Add new family of orthogonal wavelets. % You must define: % % Family Name: Lemarie % Family Short Name: lem % Type of wavelet: 1 (orth) % Wavelets numbers: 1 2 3 4 5

Page 507: Wavelet ug

Adding a New Wavelet Family

7-15

% File driver: lemwavf % % The function lemwavf.m must be as follow: % function w = lemwavf(wname) % where the input argument wname is a string: % wname = 'lem1' or 'lem2' ... i.e., % wname = sh.name + number % and w the corresponding scaling filter. % The addition is obtained using:wavemngr('add','Lemarie','lem',1,'1 2 3 4 5','lemwavf');

% The ascii file 'wavelets.asc' is saved as % 'wavelets.prv', then it is modified and % the MAT file 'wavelets.inf' is generated.

% List wavelets families.wavemngr('read')

ans ==================================== Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor Lemarie lem ===================================

Page 508: Wavelet ug

7 Adding Your Own Wavelets

7-16

After Adding a New Wavelet FamilyWhen you use the wavemngr command to add a new wavelet, the toolbox creates three wavelet extension files in the current directory: the two ASCII files wavelets.asc and wavelets.prv, and the MAT-file wavelets.inf.

If you want to use your own extended wavelet families with the Wavelet Toolbox, you should:

1 Create a new directory specifically to hold the wavelet extension files.

2 Move the previously mentioned files into this new directory.

3 Prepend this directory to the MATLAB’s directory search path (see the reference entry for the path command).

4 Use this same directory for subsequent modifications. Allowing many wavelet extension files to proliferate in different directories may lead to unpredictable results.

5 Define an M-file called <fsn>info.m (For example, see dbinfo.m or morlinfo.m).

This file will be associated automatically with the Wavelet Family button in the Wavelet Display option of the graphical tools.

Page 509: Wavelet ug

8

Reference

Page 510: Wavelet ug

8 Reference

8-2

This chapter contains detailed descriptions of the functions in the Wavelet Toolbox. It begins with a listing of entries grouped by subject area and continues with the reference entries in alphabetical order.

Information is also available through the online help facility, help wavelet.

Functions by Category

Graphical User Interface Toolswavemenu Start graphical user interface tools.

Wavelets: Generalbiorfilt Biorthogonal wavelet filter set.centfrq Wavelet center frequency.dyaddown Dyadic downsampling.dyadup Dyadic upsampling.intwave Integrate wavelet function psi.orthfilt Orthogonal wavelet filter set.qmf Quadrature mirror filter.scal2frq Scale to frequency.wavefun Wavelet and scaling functions.wavefun2 Wavelet and scaling functions 2-D.wavemngr Wavelet manager. wfilters Wavelet filters.wmaxlev Maximum wavelet decomposition level.

Page 511: Wavelet ug

Functions by Category

8-3

Wavelet Familiesbiorwavf Biorthogonal spline wavelet filters.cgauwavf Complex Gaussian wavelet.cmorwavf Complex Morlet wavelet.coifwavf Coiflet wavelet filter.dbaux Daubechies wavelet filter computation.dbwavf Daubechies wavelet filter.fbspwavf Complex frequency B-Spline wavelet.gauswavf Gaussian wavelet.mexihat Mexican hat wavelet.meyer Meyer wavelet.meyeraux Meyer wavelet auxiliary function.morlet Morlet wavelet.rbiowavf Reverse biorthogonal spline wavelet filters.shanwavf Complex Shannon wavelet.symaux Symlet wavelet filter computation.symwavf Symlet wavelet filter.

Continuous Wavelet: One-Dimensionalcwt Real or complex continuous wavelet coefficients 1-D.

Page 512: Wavelet ug

8 Reference

8-4

Discrete Wavelets: One-Dimensionalappcoef Extract 1-D approximation coefficients.detcoef Extract 1-D detail coefficients.dwt Single-level discrete 1-D wavelet transform.dwtmode Discrete wavelet transform extension mode.idwt Single-level inverse discrete 1-D wavelet transform.upcoef Direct reconstruction from 1-D wavelet coefficients.upwlev Single-level reconstruction of 1-D wavelet

decomposition.wavedec Multilevel 1-D wavelet decomposition.waverec Multilevel 1-D wavelet reconstruction.wrcoef Reconstruct single branch from 1-D wavelet

coefficients.

Discrete Wavelets: Two-Dimensionalappcoef2 Extract 2-D approximation coefficients.detcoef2 Extract 2-D detail coefficients.dwt2 Single-level discrete 2-D wavelet transform.dwtmode Discrete wavelet transform extension mode.idwt2 Single-level inverse discrete 2-D wavelet transform.upcoef2 Direct reconstruction from 2-D wavelet coefficients.upwlev2 Single-level reconstruction of 2-D wavelet

decomposition.wavedec2 Multilevel 2-D wavelet decomposition.waverec2 Multilevel 2-D wavelet reconstruction.wrcoef2 Reconstruct single branch from 2-D wavelet

coefficients.

Page 513: Wavelet ug

Functions by Category

8-5

Wavelet Packet Algorithmsbestlevt Best level tree (wavelet packet).besttree Best tree (wavelet packet).entrupd Entropy update (wavelet packet).wentropy Entropy (wavelet packet).wp2wtree Extract wavelet tree from wavelet packet tree.wpcoef Wavelet packet coefficients.wpcutree Cut wavelet packet tree.wpdec Wavelet packet decomposition 1-D.wpdec2 Wavelet packet decomposition 2-D.wpfun Wavelet packet functions.wpjoin Recompose wavelet packet.wprcoef Reconstruct wavelet packet coefficients.wprec Wavelet packet reconstruction 1-D.wprec2 Wavelet packet reconstruction 2-D.wpsplt Split (decompose) wavelet packet.

Discrete Stationary Wavelet Transform Algorithmsiswt Inverse discrete stationary wavelet transform 1-D.iswt2 Inverse discrete stationary wavelet transform 2-D.swt Discrete stationary wavelet transform 1-D.swt2 Discrete stationary wavelet transform 2-D.

Page 514: Wavelet ug

8 Reference

8-6

De-Noising and Compression for Signals and Imagesddencmp Default values for de-noising or compression.thselect Threshold selection for de-noising.wbmpen Penalized threshold for wavelet 1-D or 2-D

de-noising.wdcbm Thresholds for wavelet 1-D using Birge-Massart

strategy.wdcbm2 Thresholds for wavelet 2-D using Birge-Massart

strategy.wden Automatic 1-D de-noising using wavelets.wdencmp De-noising or compression using wavelets.wnoise Generate noisy wavelet test data.wnoisest Estimate noise of 1-D wavelet coefficients.wpbmpen Penalized threshold for wavelet packet de-noising.wpdencmp De-noising or compression using wavelet packets.wpthcoef Wavelet packet coefficients thresholding.wthcoef Wavelet coefficient thresholding 1-D.wthcoef2 Wavelet coefficient thresholding 2-D.wthresh Perform soft or hard thresholding.wthrmngr Threshold settings manager.

Page 515: Wavelet ug

Functions by Category

8-7

Tree Management Utilitiesallnodes Tree nodes.depo2ind Node depth-position to node index.disp Display information of WPTREE object.drawtree Draw wavelet packet decomposition tree (GUI).dtree Constructor for the class DTREE.get Get tree object field contents.ind2depo Node index to node depth-position.isnode True for existing node.istnode Determine indices of terminal nodes.leaves Determine terminal nodes.

Page 516: Wavelet ug

8 Reference

8-8

nodeasc Node ascendants.nodedesc Node descendants.nodejoin Recompose node.nodepar Node parent.nodesplt Split (decompose) node.noleaves Determine nonterminal nodes.ntnode Number of terminal nodes.ntree Constructor for the class NTREE.plot Plot tree object.read Read values in tree object fields.readtree Read wavelet packet decomposition tree from a

figure.set Set tree object field contents.tnodes Determine terminal nodes.treedpth Tree depth.treeord Tree order.wptree Constructor for the class WPTREE.wpviewcf Plot wavelet packets colored coefficients.write Write values in tree object fields.wtbo Constructor for the class WTBO.wtreemgr NTREE object manager.

General Utilitieswcodemat Extended pseudocolor matrix scaling.wextend Extend a vector or a matrix.wkeep Keep part of a vector or a matrix.wrev Flip vector.

Tree Management Utilities

Page 517: Wavelet ug

Functions by Category

8-9

Otherwvarchg Find variance change points.

Wavelet Informationwaveinfo Information on wavelets.

Demoswavedemo Wavelet toolbox demos.

Obsolete Functionsdwtper Single-level discrete 1-D wavelet transform

(perodized).dwtper2 Single-level discrete 2-D wavelet transform

(perodized).idwtper Single-level inverse discrete 1-D wavelet transform

(perodized).idwtper2 Single-level inverse discrete 2-D wavelet transform

(perodized).maketree Make tree.plottree Plot tree.wdatamgr Manager for data structure.

Page 518: Wavelet ug

8 Reference

8-10

Alphabetical List of FunctionsFollowing are the function reference pages listed alphabetically.

Page 519: Wavelet ug

allnodes

8-11

8allnodesPurpose Tree nodes.

Syntax N = allnodes(T)N = allnodes(T,'deppos')

Description allnodes is a tree management utility that returns one of two node descriptions: either indices, or depths and positions.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

N = allnodes(T) returns the indices of all the nodes of the tree T in column vector N.

N = allnodes(T,'deppos') returns the depths and positions of all the nodes in matrix N. N(i,1) is the depth and N(i,2) the position of the node i.

Examples % Create initial tree. ord = 2;t = ntree(ord,3); % Binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 520: Wavelet ug

allnodes

8-12

% List t nodes (index).aln_ind = allnodes(t)aln_ind =

0 1 2 3 4 5 6 7 8

13 14

% List t nodes (Depth_Position). aln_depo = allnodes(t,'deppos')aln_depo =

0 01 01 12 02 12 22 33 03 13 63 7

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 521: Wavelet ug

appcoef

8-13

8appcoefPurpose Extract 1-D approximation coefficients.

Syntax A = appcoef(C,L,'wname',N)A = appcoef(C,L,'wname')A = appcoef(C,L,Lo_R,Hi_R)A = appcoef(C,L,Lo_R,Hi_R,N)

Description appcoef is a one-dimensional wavelet analysis function.

appcoef computes the approximation coefficients of a one-dimensional signal.

A = appcoef(C,L,’wname’,N) computes the approximation coefficients at level N using the wavelet decomposition structure [C,L] (see wavedec for more information).

’wname’ is a string containing the wavelet name. Level N must be an integer such that 0 ≤ N ≤ length(L)-2.

A = appcoef(C,L,’wname’) extracts the approximation coefficients at the last level: length(L)-2.

Instead of giving the wavelet name, you can give the filters.

For A = appcoef(C,L,Lo_R,Hi_R) or A = appcoef(C,L,Lo_R,Hi_R,N), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter (see wfilters for more information).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load a one-dimensional signal. load leleccum; s = leleccum(1:3920);

% Perform decomposition at level 3 of s using db1. [c,l] = wavedec(s,3,'db1');

% Extract approximation coefficients at level 3, from the % wavelet decomposition structure [c,l]. ca3 = appcoef(c,l,'db1',3);

Page 522: Wavelet ug

appcoef

8-14

% Using some plotting commands,% the following figure is generated.

Algorithm The input vectors C and L contain all the information about the signal decomposition.

Let NMAX = length(L)-2; then C = [A(NMAX) D(NMAX) ... D(1)] where A and the D are vectors.

If N = NMAX, then a simple extraction is done; otherwise, appcoef computes iteratively the approximation coefficients using the inverse wavelet transform.

See Also detcoef, wavedec

0 500 1000 1500 2000 2500 3000 3500 40000

200

400

600Original signal s.

0 5000

500

1000

1500

2000Approx. coef. level 3 : ca3

Page 523: Wavelet ug

appcoef2

8-15

8appcoef2Purpose Extract 2-D approximation coefficients.

Syntax A = appcoef2(C,S,'wname',N)A = appcoef2(C,S,'wname')A = appcoef2(C,S,Lo_R,Hi_R)A = appcoef2(C,S,Lo_R,Hi_R,N)

Description appcoef2 is a two-dimensional wavelet analysis function.

appcoef2 computes the approximation coefficients of a two-dimensional signal.

A = appcoef2(C,S,’wname’,N) computes the approximation coefficients at level N using the wavelet decomposition structure [C,S] (see wavedec2 for more information).

’wname’ is a string containing the wavelet name. Level N must be an integer such that 0 ≤ N ≤ size(S,1)-2.

A = appcoef2(C,S,’wname’) extracts the approximation coefficients at the last level: size(S,1)-2.

Instead of giving the wavelet name, you can give the filters.

For A = appcoef2(C,S,Lo_R,Hi_R) or A = appcoef2(C,S,Lo_R,Hi_R,N), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter (see wfilters for more information).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman;

% X contains the loaded image.

% Perform decomposition at level 2 % of X using db1. [c,s] = wavedec2(X,2,'db1'); sizex = size(X)sizex =

256 256

Page 524: Wavelet ug

appcoef2

8-16

sizec = size(c)

sizec = 1 65536val_s = s

val_s =64 6464 64

128 128256 256

% Extract approximation coefficients % at level 2. ca2 = appcoef2(c,s,'db1',2); sizeca2 = size(ca2)

sizeca2 =64 64

% Compute approximation coefficients % at level 1. ca1 = appcoef2(c,s,'db1',1); sizeca1 = size(ca1)

sizeca1 =128 128

Algorithm The algorithm is built on the same principle as appcoef.

See Also detcoef2, wavedec2

Page 525: Wavelet ug

bestlevt

8-17

8bestlevtPurpose Best level tree (wavelet packet).

Syntax T = bestlevt(T)[T,E] = bestlevt(T)

Description bestlevt is a one- or two-dimensional wavelet packet analysis function.

bestlevt computes the optimal complete subtree of an initial tree with respect to an entropy type criterion. The resulting complete tree may be of smaller depth than the initial one.

T = bestlevt(T) computes the modified wavelet packet tree T corresponding to the best level tree decomposition.

[T,E] = bestlevt(T) computes the best level tree T, and in addition, the best entropy value E.

The optimal entropy of the node, whose index is j-1, is E(j).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet, using default% entropy (shannon). wpt = wpdec(x,3,'db1');

% Decompose the packet [3 0].wpt = wpsplt(wpt,[3 0]);

Page 526: Wavelet ug

bestlevt

8-18

% Plot wavelet packet tree wpt. plot(wpt)

% Compute best level tree. blt = bestlevt(wpt);

% Plot best level tree blt. plot(blt)

Algorithm See besttree algorithm section. The only difference is that the optimal tree is searched among the complete subtrees of the initial tree, instead of among all the binary subtrees.

See Also besttree, wentropy, wpdec, wpdec2

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(4,0) (4,1)

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 527: Wavelet ug

besttree

8-19

8besttreePurpose Best tree (wavelet packet).

Syntax T = besttree(T)[T,E] = besttree(T)[T,E,N] = besttree(T)

Description besttree is a one- or two-dimensional wavelet packet analysis function that computes the optimal subtree of an initial tree with respect to an entropy type criterion. The resulting tree may be much smaller than the initial one.

Following the organization of the wavelet packets library, it is natural to count the decompositions issued from a given orthogonal wavelet.

A signal of length N = 2L can be expanded in α different ways, where α is the number of binary subtrees of a complete binary tree of depth L.

As a result, we can conclude that (for more information, see the Mallat’s book given in References at page 323).

This number may be very large, and since explicit enumeration is generally intractable, it is interesting to find an optimal decomposition with respect to a convenient criterion, computable by an efficient algorithm. We are looking for a minimum of the criterion.

T = besttree(T) computes the best tree T corresponding to the best entropy value.

[T,E] = besttree(T) computes the best tree T and, in addition, the best entropy value E.

The optimal entropy of the node, whose index is j-1, is E(j).

[T,E,N] = besttree(T) computes the best tree T, the best entropy value E and, in addition, the vector N containing the indices of the merged nodes.

α 2N 2⁄≥

Page 528: Wavelet ug

besttree

8-20

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal.load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet, using default% entropy (shannon). wpt = wpdec(x,3,'db1'); % Decompose the packet [3 0].wpt = wpsplt(wpt,[3 0]);

% Plot wavelet packet tree wpt. plot(wpt)

% Compute best tree.bt = besttree(wpt);

% Plot best tree bt. plot(bt)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(4,0) (4,1)

(0,0)

Page 529: Wavelet ug

besttree

8-21

Algorithm Consider the one-dimensional case. Starting with the root node, the best tree is calculated using the following scheme. A node N is split into two nodes N1 and N2 if and only if the sum of the entropy of N1 and N2 is lower than the entropy of N. This is a local criterion based only on the information available at the node N.

Several entropy type criteria can be used (see wentropy for more information). If the entropy function is an additive function along the wavelet packet coefficients, this algorithm leads to the best tree.

Starting from an initial tree T and using the merging side of this algorithm, we obtain the best tree among all the binary subtrees of T.

See Also bestlevt, wentropy, wpdec, wpdec2

References Coifman, R.R.; M.V. Wickerhauser (1992), “Entropy-based algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

Mallat, S. (1998), A wavelet tour of signal processing, Academic Press.

(1,0) (1,1)

(2,0) (2,1)

(3,0) (3,1) (3,2) (3,3)

(4,0) (4,1)

(0,0)

Page 530: Wavelet ug

biorfilt

8-22

8biorfiltPurpose Biorthogonal wavelet filter set.

Syntax [Lo_D,Hi_D,Lo_R,Hi_R] = biorfilt(DF,RF)[Lo_D1,Hi_D1,Lo_R1,Hi_R1,Lo_D2,Hi_D2,Lo_R2,Hi_R2] =

biorfilt(DF,RF,'8')

Description The biorfilt command returns either four or eight filters associated with biorthogonal wavelets.

[Lo_D,Hi_D,Lo_R,Hi_R] = biorfilt(DF,RF) computes four filters associated with the biorthogonal wavelet specified by decomposition filter DF and reconstruction filter RF. These filters are:

[Lo_D1,Hi_D1,Lo_R1,Hi_R1,Lo_D2,Hi_D2,Lo_R2,Hi_R2] = biorfilt(DF,RF,'8') returns eight filters, the first four associated with the decomposition wavelet, and the last four associated with the reconstruction wavelet.

It is well known in the subband filtering community that if the same FIR filters are used for reconstruction and decomposition, then symmetry and exact reconstruction are incompatible (except with the Haar wavelet). Therefore, with biorthogonal filters, two wavelets are introduced instead of just one:

One wavelet, , is used in the analysis, and the coefficients of a signal s are:

The other wavelet, ψ, is used in the synthesis:

Lo_D Decomposition low-pass filter

Hi_D Decomposition high-pass filter

Lo_R Reconstruction low-pass filter

Hi_R Reconstruction high-pass filter

ψ

cj k, s x( )ψj k, x( ) xd∫=

s cj k, ψj k,j k,∑=

Page 531: Wavelet ug

biorfilt

8-23

Furthermore, the two wavelets are related by duality in the following sense:

as soon as or and

as soon as .

It becomes apparent, as A. Cohen pointed out in his thesis (p. 110), that “the useful properties for analysis (e.g., oscillations, null moments) can be concentrated in the function; whereas, the interesting properties for synthesis (regularity) are assigned to the ψ function. The separation of these two tasks proves very useful.”

and ψ can have very different regularity properties, ψ being more regular than .

The , ψ, and φ functions are zero outside a segment.

Examples % Compute the four filters associated with spline biorthogonal % wavelet 3.5: bior3.5.

% Find the two scaling filters associated with bior3.5. [Rf,Df] = biorwavf('bior3.5'); % Compute the four filters needed. [Lo_D,Hi_D,Lo_R,Hi_R] = biorfilt(Df,Rf); subplot(221); stem(Lo_D); title('Dec. low-pass filter bior3.5'); subplot(222); stem(Hi_D); title('Dec. high-pass filter bior3.5'); subplot(223); stem(Lo_R); title('Rec. low-pass filter bior3.5'); subplot(224); stem(Hi_R); title('Rec. high-pass filter bior3.5');

ψj k, x( )ψj ′ k ′, x( ) xd∫ 0= j j′≠ k k′≠

φ0 k, x( )φ0 k ′, x( ) xd∫ 0= k k′≠

ψ

ψψ

ψ φ

Page 532: Wavelet ug

biorfilt

8-24

% Editing some graphical properties,% the following figure is generated.

% Orthogonality by dyadic translation is lost.nzer = [Lo_D 0 0]*[0 0 Lo_D]'nzer =

-0.6881nzer = [Hi_D 0 0]*[0 0 Hi_D]'nzer =

0.1875

% But using duality we have: zer = [Lo_D 0 0]*[0 0 Lo_R]'zer =

-2.7756e-17 zer = [Hi_D 0 0]*[0 0 Hi_R]'zer =

2.7756e-17

% But, perfect reconstruction via DWT is preserved.x = randn(1,500); [a,d] = dwt(x,Lo_D,Hi_D); xrec = idwt(a,d,Lo_R,Hi_R); err = norm(x-xrec)

0 5 10 15−1

−0.5

0

0.5

1Dec. low−pass filter bior3.5

0 5 10 15−1

−0.5

0

0.5

1Dec. high−pass filter bior3.5

0 5 10 15−1

−0.5

0

0.5

1Rec. low−pass filter bior3.5

0 5 10 15−1

−0.5

0

0.5

1Rec. high−pass filter bior3.5

Page 533: Wavelet ug

biorfilt

8-25

err =5.0218e-15

% High and low frequency illustration. fftld = fft(Lo_D); ffthd = fft(Hi_D); freq = [1:length(Lo_D)]/length(Lo_D); subplot(221); plot(freq,abs(fftld),freq,abs(ffthd)); title('Transfer modulus for dec. filters') fftlr = fft(Lo_R); ffthr = fft(Hi_R); freq = [1:length(Lo_R)]/length(Lo_R); subplot(222); plot(freq,abs(fftlr),freq,abs(ffthr)); title('Transfer modulus for rec. filters') subplot(223); plot(freq, abs(fftlr.*fftld + ffthd.*ffthr)); title('One biorthogonality condition') xlabel('|fft(Lo_R)fft(Lo_D) + fft(Hi_R)fft(Hi_D)| = 2')

% Editing some graphical properties,% the following figure is generated.

0.2 0.4 0.6 0.80

1

2

3Transfer modulus for dec. filters

0.2 0.4 0.6 0.80

1

2

3Transfer modulus for rec. filters

0.2 0.4 0.6 0.80

2

4One biorthogonality condition

|fft(Lo_R)fft(Lo_D) + fft(Hi_R)fft(Hi_D)| = 2

Page 534: Wavelet ug

biorfilt

8-26

Note For biorthogonal wavelets, the filters for decomposition and reconstruction are generally of different odd lengths. This situation occurs, for example, for “splines” biorthogonal wavelets used in the toolbox where the four filters are zero-padded to have the same even length.

See Also biorwavf, orthfilt

References Cohen, A. (1992), “Ondelettes, analyses multirésolution et traitement numérique du signal,” Ph. D. Thesis, University of Paris IX, DAUPHINE.

Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Page 535: Wavelet ug

biorwavf

8-27

8biorwavfPurpose Biorthogonal spline wavelet filters.

Syntax [RF,DF] = biorwavf(W)

Description [RF,DF] = biorwavf(W) returns two scaling filters associated with the biorthogonal wavelet specified by the string W.

W = 'biorNr.Nd' where possible values for Nr and Nd are:

The output arguments are filters.

• RF is the reconstruction filter.

• DF is the decomposition filter.

Examples % Set spline biorthogonal wavelet name. wname = 'bior2.2';

% Compute the two corresponding scaling filters.% rf is the reconstruction scaling filter.% df is the decomposition scaling filter. [rf,rd] = biorwavf(wname)

rf =0.2500 0.5000 0.2500

df =-0.1250 0.2500 0.7500 0.2500 -0.1250

See Also biorfilt, waveinfo

Nr = 1 Nd = 1 , 3 or 5

Nr = 2 Nd = 2 , 4 , 6 or 8

Nr = 3 Nd = 1 , 3 , 5 , 7 or 9

Nr = 4 Nd = 4

Nr = 5 Nd = 5

Nr = 6 Nd = 8

Page 536: Wavelet ug

centfrq

8-28

8centfrqPurpose Wavelet center frequency.

Syntax FREQ = centfrq('wname')FREQ = centfrq('wname',ITER)[FREQ,XVAL,RECFREQ] = centfrq('wname',ITER,'plot')

Description FREQ = centfrq('wname') returns the center frequency in herz of the wavelet function, 'wname' (see wavefun for more information).

For FREQ = centfrq('wname',ITER), ITER is the number of iterations performed by the function wavefun, which is used to compute the wavelet.

[FREQ,XVAL,RECFREQ] = centfrq('wname',ITER,'plot') returns, in addition, the associated center frequency based approximation RECFREQ on the 2ITER points grid XVAL and plots the wavelet function and RECFREQ.

Examples % Example 1: a real wavelet wname = 'db2';

% Compute the center frequency and display% the wavelet function and the associated % center frequency based approximation.iter = 8;cfreq = centfrq(wname,8,'plot')

cfreq = 0.6667

Page 537: Wavelet ug

centfrq

8-29

% Example 2: a complex wavelet wname = 'cgau6';

% Compute the center frequency and display % the wavelet function and the associated % center frequency based approximation.cfreq = centfrq(wname,8,'plot')

cfreq =

0.6000

0 0.5 1 1.5 2 2.5 3−1.5

−1

−0.5

0

0.5

1

1.5

2Wavelet db2 (in bold) and Center frequency based approximation

Period: 1.5; Cent. Freq: 0.66667

Page 538: Wavelet ug

centfrq

8-30

See Also scal2frq, wavefun

−5 0 5−1

−0.5

0

0.5

1

Imag

inar

y pa

rts

Period: 1.6667; Cent. Freq: 0.6

−5 0 5−1

−0.5

0

0.5

1Wavelet cgau6 (in bold) and Center frequency based approximation

Rea

l par

ts

Period: 1.6667; Cent. Freq: 0.6

Page 539: Wavelet ug

cgauwavf

8-31

8cgauwavfPurpose Complex Gaussian wavelets.

Syntax [PSI,X] = cgauwavf(LB,UB,N,P)

Description [PSI,X] = cgauwavf(LB,UB,N,P) returns values of the P-th derivative of the

complex Gaussian function on an N point regular grid for the

interval [LB,UB]. Cp is such that the 2-norm of the P-th derivative of F is equal to 1.

For P > 8, the Extended Symbolic Toolbox will be required.

Output arguments are the wavelet function PSI computed on the grid X.

[PSI,X] = cgauwavf(LB,UB,N) is equivalent to [PSI,X] = cgauwavf(LB,UB,N,1)

These wavelets have an effective support of [-5 5].

Examples % Set effective support and grid parameters.lb = -5; ub = 5; n = 1000;

% Compute complex Gaussian wavelet of order 4.[psi,x] = cgauwavf(lb,ub,n,4);

% Plot complex Gaussian wavelet of order 4.subplot(211)plot(x,real(psi)),title('Complex Gaussian wavelet of order 4')xlabel('Real part'), grid

F Cpe ix– e x2–=

Page 540: Wavelet ug

cgauwavf

8-32

subplot(212) plot(x,imag(psi)) xlabel('Imaginary part'), grid

See Also waveinfo

−5 0 5−1

−0.5

0

0.5

1Complex Gaussian wavelet of order 4

Real part

−5 0 5−1

−0.5

0

0.5

1

Imaginary part

Page 541: Wavelet ug

cmorwavf

8-33

8cmorwavfPurpose Complex Morlet wavelets.

Syntax [PSI,X] = cmorwavf(LB,UB,N,FB,FC)

Description [PSI,X] = cmorwavf(LB,UB,N,FB,FC) returns values of the complex Morlet wavelet defined by a positive bandwidth parameter FB, a wavelet center frequency FC and the expression:

PSI(X) = ((pi*FB)^(-0.5))*exp(2*i*pi*FC*X)*exp(-X^2/FB)

on an N point regular grid for the interval [LB,UB].

Output arguments are the wavelet function PSI computed on the grid X.

Examples % Set bandwidth and center frequency parameters.fb = 1; fc = 1.5;

% Set effective support and grid parameters.lb = -8; ub = 8; n = 1000;

% Compute complex Morlet wavelet cmor1-1.5.[psi,x] = cmorwavf(lb,ub,n,fb,fc);

% Plot complex Morlet wavelet.subplot(211)plot(x,real(psi)),title('Complex Morlet wavelet cmor1-1.5')xlabel('Real part'), grid

Page 542: Wavelet ug

cmorwavf

8-34

subplot(212)plot(x,imag(psi))xlabel('Imaginary part'), grid

See Also waveinfo

References Teolis, A. (1998), Computational signal processing with wavelets, Birkhauser, p. 65.

−8 −6 −4 −2 0 2 4 6 8−0.5

0

0.5Complex Morlet wavelet cmor1−1.5

Real part

−8 −6 −4 −2 0 2 4 6 8−0.5

0

0.5

Imaginary part

Page 543: Wavelet ug

coifwavf

8-35

8coifwavfPurpose Coiflet wavelet filter.

Syntax F = coifwavf(W)

Description F = coifwavf(W) returns the scaling filter associated with the Coiflet wavelet specified by the string W where W = 'coifN'. Possible values for N are: 1, 2, 3, 4, or 5.

Examples % Set coiflet wavelet name. wname = 'coif2';

% Compute the corresponding scaling filter. f = coifwavf(wname)

f =Columns 1 through 7 0.0116 -0.0293 -0.0476 0.2730 0.5747 0.2949 -0.0541

Columns 8 through 12-0.0420 0.0167 0.0040 -0.0013 -0.0005

See Also waveinfo

Page 544: Wavelet ug

cwt

8-36

8cwtPurpose Continuous 1-D wavelet coefficients.

Syntax COEFS = cwt(S,SCALES,'wname')COEFS = cwt(S,SCALES,'wname','plot')COEFS = cwt(S,SCALES,'wname',PLOTMODE)COEFS = cwt(S,SCALES,'wname',PLOTMODE,XLIM)

Description cwt is a one-dimensional wavelet analysis function.

COEFS = cwt(S,SCALES,’wname’) computes the continuous wavelet coefficients of the vector S at real, positive SCALES, using the wavelet whose name is ’wname’ (see waveinfo for more information).

The signal S is real, the wavelet can be real or complex.

COEFS = cwt(S,SCALES,’wname’,'plot') computes and, in addition, plots the continuous wavelet transform coefficients.

COEFS = cwt(S,SCALES,’wname’,PLOTMODE) computes and plots the continuous wavelet transform coefficients.

Coefficients are colored using PLOTMODE. Valid values for the string PLOTMODE are listed in the table below.

COEFS = cwt(...,'plot') is equivalent to COEFS = cwt(...,'absglb')

Note You can get 3-D plots (surfaces) using the same keywords listed above for the PLOTMODE parameter, preceded by '3D'. For example: COEFS = cwt(...,'3Dplot')or COEFS = cwt(...,'3Dlvl') ...

PLOTMODE Description

'lvl' Coloration made scale-by-scale

'glb' Coloration made considering all scales

'abslvl' or 'lvlabs'

Coloration made scale-by-scale using the absolute values of the coefficients

'absglb' or 'glbabs'

Coloration made considering all scales using the absolute values of the coefficients

Page 545: Wavelet ug

cwt

8-37

COEFS = cwt(S,SCALES,’wname’,PLOTMODE,XLIM) computes and plots the continuous wavelet transform coefficients.

Coefficients are colored using PLOTMODE and XLIM.

XLIM = [x1 x2] with 1 ≤ x1 < x2 ≤ length(S)

Let s be the signal and ψ the wavelet. The wavelet coefficient of s at scale a and position b is defined by:

Since s(t) is a discrete signal, we use a piecewise constant interpolation of the s(k) values, k = 1 to length(s).

For each given scale a within the vector SCALES, the wavelet coefficients Ca,b are computed for b = 1 to ls = length(s), and are stored in COEFS(i,:) if a = SCALES(i).

Output argument COEFS is a la-by-ls matrix where la is the length of SCALES. COEFS is a real or complex matrix depending on the wavelet type.

Examples of valid uses are:

t = linspace(-1,1,512);s = 1-abs(t);c = cwt(s,1:32,'cgau4');c = cwt(s,[64 32 16:-2:2],'morl');c = cwt(s,[3 18 12.9 7 1.5],'db2');c = cwt(s,1:64,'sym4','abslvl',[100 400]);

Examples This example demonstrates the difference between discrete and continuous wavelet transforms.

% Load a fractal signal. load vonkoch vonkoch=vonkoch(1:510); lv = length(vonkoch);

subplot(311), plot(vonkoch);title('Analyzed signal.'); set(gca,'Xlim',[0 510])

Ca b, s t( ) 1a

-------ψ t b–a

----------- td

R∫=

Page 546: Wavelet ug

cwt

8-38

% Perform discrete wavelet transform at level 5 by sym2. % Levels 1 to 5 correspond to scales 2, 4, 8, 16 and 32. [c,l] = wavedec(vonkoch,5,'sym2');

% Expand discrete wavelet coefficients for plot. % Levels 1 to 5 correspond to scales 2, 4, 8, 16 and 32. cfd = zeros(5,lv); for k = 1:5

d = detcoef(c,l,k); d = d(ones(1,2^k),:); cfd(k,:) = wkeep(d(:)',lv);

end

cfd = cfd(:); I = find(abs(cfd)<sqrt(eps)); cfd(I)=zeros(size(I)); cfd = reshape(cfd,5,lv);

% Plot discrete coefficients. subplot(312), colormap(pink(64)); img = image(flipud(wcodemat(cfd,64,'row'))); set(get(img,'parent'),'YtickLabel',[]); title('Discrete Transform, absolute coefficients.') ylabel('level')

% Perform continuous wavelet transform by sym2 at all integer % scales from 1 to 32. subplot(313)ccfs = cwt(vonkoch,1:32,'sym2','plot'); title('Continuous Transform, absolute coefficients.') colormap(pink(64)); ylabel('Scale')

Page 547: Wavelet ug

cwt

8-39

% Editing some graphical properties,% the following figure is generated.

Algorithm

if s(t) = s(k), for then

0 100 200 300 400 5000

0.01

0.02Analyzed signal.

Discrete Transform, absolute coefficients.

leve

l

100 200 300 400 500Continuous Transform, absolute coefficients.

time (or space) b

Sca

le

100 200 300 400 500

Ca b, s t( ) 1a

-------ψ t b–a

----------- td

R∫=

Ca b, sk

k 1+

∫ t( ) 1a

-------ψ t b–a

----------- td

k∑=

t k k 1+[ , ]∈

Ca b,1a

------- s k( ) ψ t b–a

-----------

k

k 1+

∫ tdk∑=

Ca b,1a

------- s k( ) ψ t b–a

----------- t d

∞–

k 1+

∫ ψ t b–a

----------- td

∞–

k

∫–

k∑=

Page 548: Wavelet ug

cwt

8-40

So at any scale a, the wavelet coefficients Ca,b for b = 1 to length(s) can be obtained by convolving the signal s and a dilated and translated version of the

integrals of the form (given by intwave), and taking the finite

difference using diff.

See Also wavedec, wavefun, waveinfo, wcodemat

ψ∞–

k

∫ t( ) td

Page 549: Wavelet ug

dbaux

8-41

8dbauxPurpose Daubechies wavelet filter computation.

Syntax W = dbaux(N,SUMW)W = dbaux(N)

Description W = dbaux(N,SUMW) is the order N Daubechies scaling filter such that sum(W) = SUMW. Possible values for N are: 1, 2, 3, ...

Note Instability may occur when N is too large.

W = dbaux(N) is equivalent to W = dbaux(N,1)

W = dbaux(N,0) is equivalent to W = dbaux(N,1)

Examples % P the “Lagrange à trous” filter for N=2 is explicit % and given by: P = [ -1/16 0 9/16 1 9/16 0 -1/16]

P =-0.0625 0 0.5625 1.0000 0.5625 0 -0.0625

% The db2 Daubechies scaling filter w, is a % solution of the equation: P = conv(wrev(w),w) * 2.%% This filter P is symmetric, easy to generate, and w is % a minimum phase solution of the previous equation, % based on the roots of P. rP = roots(P);

% Retaining only the root inside the unit circle (here it% is the sixth value of rP), and two roots located at -1, % we obtain the Daubechies wavelet of order 2:ww = poly([rP(6) -1 -1]); % filter constructionww = ww / sum(ww) % normalize sum

ww =0.3415 0.5915 0.1585 -0.0915

Page 550: Wavelet ug

dbaux

8-42

% Check that ww is correct and equal to % the db2 Daubechies scaling filter w. w = dbaux(2)

w =0.3415 0.5915 0.1585 -0.0915

Algorithm The algorithm used is based on a result obtained by Shensa (see “References”), showing a correspondence between the “Lagrange à trous” filters and the convolutional squares of the Daubechies wavelet filters.

The computation of the order N Daubechies scaling filter w proceeds in two steps: compute a “Lagrange à trous” filter P, and extract a square root. More precisely:

• P the associated “Lagrange à trous” filter is a symmetric filter of length 4N-1. P is defined by:

P = [a(N) 0 a(N-1) 0 ... 0 a(1) 1 a(1) 0 a(2) 0 ... 0 a(N)]

where

• Then, if w denotes dbN Daubechies scaling filter of sum , w is a square root of P:

P = conv(wrev(w),w) where w is a filter of length 2N.

The corresponding polynomial has N zeros located at -1 and N-1 zeros less than 1 in modulus.

Note that other methods can be used; see various solutions of the spectral factorization problem in Strang-Nguyen (p. 157).

a k( )

12--- i–

i N– 1+=i k≠

N

k i–( )

i N– 1+=i k≠

N

∏------------------------------------------ for k 1= …, N,=

2

Page 551: Wavelet ug

dbaux

8-43

Limitations The computation of the dbN Daubechies scaling filter requires the extraction of the roots of a polynomial of order 4N. Instability may occur when N is too large.

See Also dbwavf, wfilters

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Shensa, M.J. (1992), “The discrete wavelet transform: wedding the a trous and Mallat Algorithms,” IEEE Trans. on Signal Processing, vol. 40, 10, pp. 2464-2482.

Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

Page 552: Wavelet ug

dbwavf

8-44

8dbwavfPurpose Daubechies wavelet filter.

Syntax F = dbwavf(W)

Description F = dbwavf(W) returns the scaling filter associated with Daubechies wavelet specified by the string W where W = 'dbN'. Possible values for N are: 1, 2, 3, ..., 45.

Examples % Set Daubechies wavelet name. wname = 'db4';

% Compute the corresponding scaling filter. f = dbwavf(wname)

f =Columns 1 through 7 0.1629 0.5055 0.4461 -0.0198 -0.1323 0.0218 0.0233Column 8 -0.0075

See Also dbaux, waveinfo, wfilters

Page 553: Wavelet ug

ddencmp

8-45

8ddencmpPurpose Default values for de-noising or compression.

Syntax [THR,SORH,KEEPAPP,CRIT] = ddencmp(IN1,IN2,X)[THR,SORH,KEEPAPP] = ddencmp(IN1,'wv',X)[THR,SORH,KEEPAPP,CRIT] = ddencmp(IN1,'wp',X)

Description ddencmp is a de-noising and compression-oriented function.

ddencmp gives default values for all the general procedures related to de-noising and compression of one- or two-dimensional signals, using wavelets or wavelet packets.

[THR,SORH,KEEPAPP,CRIT] = ddencmp(IN1,IN2,X) returns default values for de-noising or compression, using wavelets or wavelet packets, of an input vector or matrix X, which can be a one- or two-dimensional signal. THR is the threshold, SORH is for soft or hard thresholding, KEEPAPP allows you to keep approximation coefficients, and CRIT (used only for wavelet packets) is the entropy name (see wentropy for more information).

IN1 is 'den' for de-noising or 'cmp' for compression.

IN2 is 'wv' for wavelet or 'wp' for wavelet packet.

For wavelets (three output arguments):

[THR,SORH,KEEPAPP] = ddencmp(IN1,'wv',X) returns default values for de-noising (if IN1 = 'den') or compression (if IN1 = 'cmp') of X. These values can be used for wdencmp.

For wavelet packets (four output arguments):

[THR,SORH,KEEPAPP,CRIT] = ddencmp(IN1,'wp',X) returns default values for de-noising (if IN1 = 'den') or compression (if IN1 = 'cmp') of X. These values can be used for wpdencmp.

Examples % The current extension mode is zero-padding (see dwtmode).

% Generate Gaussian white noise. init = 2055415866; randn('seed',init); x = randn(1,1000);

Page 554: Wavelet ug

ddencmp

8-46

% Find default values for wavelets (3 output arguments). % These values can be used for wdencmp with option 'gbl'.

% default for de-noising: % soft thresholding and approximation coefficients kept % thr = sqrt(2*log(n)) * s% where s is an estimate of level noise% and n is equal to prod(size(x)).[thr,sorh,keepapp] = ddencmp('den','wv',x)

thr =3.8593

sorh = skeepapp =

1

% default for compression: % hard thresholding and approximation coefficients kept % thr = median(abs(detail at level 1)) if nonzero % else thr = 0.05 * max(abs(detail at level 1)). [thr,sorh,keepapp] = ddencmp('cmp','wv',x)

thr =0.7003

sorh =hkeepapp =

1

% Find default values for wavelet packets (4 output arguments). % These values can be used for wpdencmp.

% default for de-noising: % soft thresholding and appr. cfs. kept % thr = sqrt(2*log(n*log(n)/log(2)))% the noise level is supposed to be equal to 1; % default entropy is 'sure' criterion. [thr,sorh,keepapp,crit] = ddencmp('den','wp',x)

Page 555: Wavelet ug

ddencmp

8-47

thr =4.2911

sorh = hkeepapp =

1crit = sure

% default for compression. % hard thresholding and approximation coefficients kept % thr = median(abs(detail at level 1)) % default entropy is 'threshold' criterion. [thr,sorh,keepapp,crit] = ddencmp('cmp','wp',x)

thr =0.7003

sorh = hkeepapp =

1crit = threshold

See Also wdencmp, wentropy, wpdencmp

References Donoho, D.L. (1995), “De-noising by soft-thresholding,” IEEE, Trans. on Inf. Theory, 41, 3, pp. 613–627.

Donoho, D.L.; I.M. Johnstone (1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

Donoho, D.L.; I.M. Johnstone (1994), “Ideal de-noising in an orthonormal basis chosen from a library of bases,” C.R.A.S. Paris, Ser. I, t. 319, pp. 1317–1322.

Page 556: Wavelet ug

depo2ind

8-48

8depo2indPurpose Node depth-position to node index.

Syntax N = depo2ind(ORD,[D P])

Description depo2ind is a tree-management utility.

For a tree of order ORD, N = depo2ind(ORD,[D P]) computes the indices N of the nodes whose depths and positions are encoded within [D,P].

The nodes are numbered from left to right and from top to bottom. The root index is 0.

D and P are column vectors. The values of depths D and positions P must be such that D ≥ 0 and 0 ≤ P ≤ ORDD-1.

Output indices N are such that 0 ≤ N < (ORDmax(D)-1) / (ORD-1).

Note that for a column vector X, we have depo2ind(O,X) = X.

Examples % Create initial tree. ord = 2; t = ntree(ord,3); % binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 557: Wavelet ug

depo2ind

8-49

% List t nodes (Depth_Position). aln_depo = allnodes(t,'deppos')aln_depo =

0 0 1 0 1 1 2 0 2 1 2 2 2 3 3 0 3 1 3 6 3 7

% Switch from Depth_Position to index.aln_ind = depo2ind(ord,aln_depo)aln_ind =

012345678

1314

See Also ind2depo

Page 558: Wavelet ug

detcoef

8-50

8detcoefPurpose Extract 1-D detail coefficients.

Syntax D = detcoef(C,L,N)D = detcoef(C,L)

Description detcoef is a one-dimensional wavelet analysis function.

D = detcoef(C,L,N) extracts the detail coefficients at level N from the wavelet decomposition structure [C,L]. See wavedec for more information on C and L.

Level N must be an integer such that 1 ≤ N ≤ NMAXwhere NMAX = length(L)-2.

D = detcoef(C,L) extracts the detail coefficients at last level NMAX.

If N is a vector of integers such that 1 ≤ N(j) ≤ NMAX:

DCELL = detcoef(C,L,N,'cells') returns a cell array where DCELL{j} contains the coefficients of detail N(j).

If length(N) > 1, DCELL = detcoef(C,L,N) is equivalent to DCELL = detcoef(C,L,N,'cells').

DCELL = detcoef(C,L,'cells') is equivalent to DCELL = detcoef(C,L,[1:NMAX])

[D1, ... ,Dp] = detcoef(C,L,[N(1), ... ,N(p)]) extracts the details coefficients at levels [N(1), ... ,N(p)].

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original one-dimensional signal. load leleccum; s = leleccum(1:3920);

% Perform decomposition at level 3 of s using db1. [c,l] = wavedec(s,3,'db1');

Page 559: Wavelet ug

detcoef

8-51

% Extract detail coefficients at levels % 1, 2 and 3, from wavelet decomposition % structure [c,l]. [cd1,cd2,cd3] = detcoef(c,l,[1 2 3]);

% Using some plotting commands,% the following figure is generated.

See Also appcoef, wavedec

500 1000 1500 2000 2500 3000 35000

500

1000Original signal s

0 500−100

0

100Detail coef. level 3 : cd3

0 500 1000−50

0

50Detail coef. level 2 : cd2

0 500 1000 1500 2000−50

0

50Detail coef. level 1 : cd1

Page 560: Wavelet ug

detcoef2

8-52

8detcoef2Purpose Extract 2-D detail coefficients.

Syntax D = detcoef2(O,C,S,N)

Description detcoef2 is a two-dimensional wavelet analysis function.

D = detcoef2(O,C,S,N) extracts from the wavelet decomposition structure [C,S] (see wavedec2 for more information), the horizontal, vertical or diagonal detail coefficients for O = 'h'(or 'v' or 'd', respectively), at level N.

N must be an integer such that 1 ≤ N ≤ size(S,1)-2.

See wavedec2 for more information on C and S.

[H,V,D] = detcoef2('all',C,S,N) returns the horizontal H, vertical V, and diagonal D detail coefficients at level N.

D = detcoef2('compact',C,S,N) returns the detail coefficients at level N, stored row-wise.

detcoef2('a',C,S,N) is equivalent to detcoef2('all',C,S,N).

detcoef2('c',C,S,N) is equivalent to detcoef2('compact',C,S,N).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman; % X contains the loaded image.

% Perform decomposition at level 2 % of X using db1.[c,s] = wavedec2(X,2,'db1');sizex = size(X)sizex =

256 256

sizec = size(c)sizec =

1 65536

Page 561: Wavelet ug

detcoef2

8-53

val_s = s val_s =

64 6464 64

128 128256 256

% Extract details coefficients at level 2 % in each orientation, from wavelet decomposition % structure [c,s]. [chd2,cvd2,cdd2] = detcoef2('all',c,s,2); sizecd2 = size(chd2)sizecd2 =

64 64

% Extract details coefficients at level 1 % in each orientation, from wavelet decomposition % structure [c,s]. [chd1,cvd1,cdd1] = detcoef2('all',c,s,1); sizecd1 = size(chd1)sizecd1 =

128 128

See Also appcoef2, wavedec2

Page 562: Wavelet ug

disp

8-54

8dispPurpose Display information of WPTREE object.

Syntax disp(T)

Description disp(T)displays the content of the WPTREE object T.

Examples % Compute a wavelet packets treex = rand(1,1000);t = wpdec(x,2,'db2');disp(t)

Wavelet Packet Object Structure ================================= size of initial data : [1 1000] order : 2 depth : 2 terminal nodes : [3 4 5 6]-------------------------------------------------- Wavelet Name : db2 Low Decomposition filter : [-0.1294 0.2241 0.8365 0.483] High Decomposition filter : [ -0.483 0.8365 -0.2241 -0.1294] Low Reconstruction filter : [ 0.483 0.8365 0.2241 -0.1294] High Reconstruction filter : [-0.1294 -0.2241 0.8365 -0.483]-------------------------------------------------- Entropy Name : shannon Entropy Parameter : 0--------------------------------------------------

See Also get, read, set, write

Page 563: Wavelet ug

drawtree

8-55

8drawtreePurpose Draw wavelet packet decomposition tree (GUI).

Syntax drawtree(T)drawtree(T,F)F = drawtree(T)

Description drawtree(T) draws the wavelet packet tree T, and F = drawtree(T) also returns the figure’s handle.

For an existing figure F produced by a previous call to the drawtree function, drawtree(T,F) draws the wavelet packet tree T in the figure whose handle is F. For more information see Chapter 5 of the User’s Guide, “Using Wavelet Packets” and Appendix B, “Wavelet Toolbox and Object Programming”.

Examples x = sin(8*pi*[0:0.005:1]);t = wpdec(x,3,'db2');fig = drawtree(t);

Page 564: Wavelet ug

drawtree

8-56

%---------------------------------------% Use command line function to modify t.%---------------------------------------t = wpjoin(t,2);drawtree(t,fig);

See Also readtree

Page 565: Wavelet ug

dtree

8-57

8dtreePurpose Constructor for the class DTREE.

Syntax T = dtree(ORD,D,X)T = dtree(ORD,D,X,U)[T,NB] = dtree(...)T = dtree('PropName1',PropValue1,'PropName2',PropValue2, ...)

Description T = dtree(ORD,D,X) returns a complete data tree (DTREE) object of order ORD and depth D. The data associated with the tree T is X.

With T = dtree(ORD,D,X,U) you can set a userdata field.

[T,NB] = dtree(...) returns also the number of terminal nodes (leaves) of T.

[T,NB] = dtree('PropName1',PropValue1,'PropName2',PropValue2,...) is the most general syntax to construct a DTREE object.

The valid choices for ’PropName’ are:

The split scheme field is an order ORD by 1 logical array. The root of the tree can be split and it has ORD children. If spsch(j) = 1, you can split the j-th child. Each node that you can split has the same property as the root node.

For more information on object fields, type: help dtree/get.

Class DTREE (Parent class: NTREE)

Fields:

'order' : Order of the tree.'depth' : Depth of the tree.'data' : Data associated to the tree.'spsch' : Split scheme for nodes.'ud' : Userdata field.

dtree : Parent object.allNI : All nodes information.terNI : Terminal nodes information.

Page 566: Wavelet ug

dtree

8-58

Examples % Create a data tree.x = [1:10];t = dtree(3,2,x);t = nodejoin(t,2);

See Also ntree, wtbo

Page 567: Wavelet ug

dwt

8-59

8dwtPurpose Single-level discrete 1-D wavelet transform.

Syntax [cA,cD] = dwt(X,'wname')[cA,cD] = dwt(X,'wname','mode',MODE)[cA,cD] = dwt(X,Lo_D,Hi_D)[cA,cD] = dwt(X,Lo_D,Hi_D,'mode',MODE)

Description The dwt command performs a single-level one-dimensional wavelet decomposition with respect to either a particular wavelet (’wname’, see wfilters for more information) or particular wavelet decomposition filters (Lo_D and Hi_D) that you specify.

[cA,cD] = dwt(X,’wname’) computes the approximation coefficients vector cA and detail coefficients vector cD, obtained by a wavelet decomposition of the vector X. The string 'wname' contains the wavelet name.

[cA,cD] = dwt(X,Lo_D,Hi_D) computes the wavelet decomposition as above, given these filters as input:

• Lo_D is the decomposition low-pass filter.

• Hi_D is the decomposition high-pass filter.

Lo_D and Hi_D must be the same length.

Let lx = the length of X and lf = the length of the filters Lo_D and Hi_D; then length(cA) = length(cD) = la where la = ceil(lx/2), if the DWT extension mode is set to periodization. For the other extension modes, la = floor(lx+lf-1)/2).

For more information about the different Discrete Wavelet Transform extension modes, see dwtmode.

[cA,cD] = dwt(...,'mode',MODE) computes the wavelet decomposition with the extension mode MODE that you specify. MODE is a string containing the desired extension mode.

Example:

[cA,cD] = dwt(x,'db1','mode','sym');

Page 568: Wavelet ug

dwt

8-60

Examples % The current extension mode is zero-padding (see dwtmode).

% Construct elementary original one-dimensional signal. randn('seed',531316785) s = 2 + kron(ones(1,8),[1 -1]) + ...

((1:16).^2)/32 + 0.2*randn(1,16);

% Perform single-level discrete wavelet transform of s by haar.[ca1,cd1] = dwt(s,'haar'); subplot(311); plot(s); title('Original signal'); subplot(323); plot(ca1); title('Approx. coef. for haar'); subplot(324); plot(cd1); title('Detail coef. for haar');

% For a given wavelet, compute the two associated decomposition % filters and compute approximation and detail coefficients % using directly the filters. [Lo_D,Hi_D] = wfilters('haar','d'); [ca1,cd1] = dwt(s,Lo_D,Hi_D);

% Perform single-level discrete wavelet transform of s by db2% and observe edge effects for last coefficients.% These extra coefficients are only used to ensure exact % global reconstruction.[ca2,cd2] = dwt(s,'db2');subplot(325); plot(ca2); title('Approx. coef. for db2'); subplot(326); plot(cd2); title('Detail coef. for db2');

Page 569: Wavelet ug

dwt

8-61

% Editing some graphical properties,% the following figure is generated.

Algorithm Starting from a signal s, two sets of coefficients are computed: approximation coefficients CA1, and detail coefficients CD1. These vectors are obtained by convolving s with the low-pass filter Lo_D for approximation and with the high-pass filter Hi_D for detail, followed by dyadic decimation.

More precisely, the first step is:

2 4 6 8 10 12 14 160

5

10Original signal

2 4 6 80

10

20Approx. coef. for haar

2 4 6 80

1

2Detail coef. for haar

2 4 6 80

10

20Approx. coef. for db2

2 4 6 8−5

0

5Detail coef. for db2

2

s

Lo_D

Hi_D

high-pass

F

G

downsample

downsample approximation coefs

cA1

cD1

2

detail coefs

low-pass

2

Where: X Convolve with filter X

Keep the even indexed elements(We call this operation downsampling)

Page 570: Wavelet ug

dwt

8-62

The length of each filter is equal to 2N. If n = length(s), the signals F and G are of length n + 2N - 1, and then the coefficients CA1 and CD1 are of length:

To deal with signal-end effects involved by a convolution-based algorithm, a global variable managed by dwtmode is used. This variable defines the kind of signal extension mode used. The possible options include zero-padding (used in the previous example) and symmetric extension, which is the default mode.

See Also dwtmode, idwt, wavedec, waveinfo

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)

floor n 1–2

------------- N+

Page 571: Wavelet ug

dwt2

8-63

8dwt2Purpose Single-level discrete 2-D wavelet transform.

Syntax [cA,cH,cV,cD] = dwt2(X,'wname')[cA,cH,cV,cD] = dwt2(X,Lo_D,Hi_D)

Description The dwt2 command performs a single-level two-dimensional wavelet decomposition with respect to either a particular wavelet (’wname’, see wfilters for more information) or particular wavelet decomposition filters (Lo_D and Hi_D) you specify.

[cA,cH,cV,cD] = dwt2(X,’wname’) computes the approximation coefficients matrix cA and details coefficients matrices cH, cV, and cD (horizontal, vertical, and diagonal, respectively), obtained by wavelet decomposition of the input matrix X. The 'wname' string contains the wavelet name.

[cA,cH,cV,cD] = dwt2(X,Lo_D,Hi_D) computes the two-dimensional wavelet decomposition as above, based on wavelet decomposition filters that you specify.

• Lo_D is the decomposition low-pass filter.

• Hi_D is the decomposition high-pass filter.

Lo_D and Hi_D must be the same length.

Let sx = size(X) and lf = the length of filters; then size(cA) = size(cH) = size(cV) = size(cD) = sa where sa = ceil(sx/2), if the DWT extension mode is set to periodization. For the other extension modes, sa = floor((sx+lf-1)/2).

For information about the different Discrete Wavelet Transform extension modes, see dwtmode.

[cA,cH,cV,cD] = dwt2(...,'mode',MODE) computes the wavelet decomposition with the extension mode MODE that you specify.

MODE is a string containing the desired extension mode.

Example of valid use is:

[cA,cH,cV,cD] = dwt2(x,'db1','mode','sym');

Page 572: Wavelet ug

dwt2

8-64

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image.load woman;

% X contains the loaded image. % map contains the loaded colormap. nbcol = size(map,1);

% Perform single-level decomposition % of X using db1. [cA1,cH1,cV1,cD1] = dwt2(X,'db1');

% Images coding. cod_X = wcodemat(X,nbcol); cod_cA1 = wcodemat(cA1,nbcol); cod_cH1 = wcodemat(cH1,nbcol); cod_cV1 = wcodemat(cV1,nbcol); cod_cD1 = wcodemat(cD1,nbcol); dec2d = [...

cod_cA1, cod_cH1; ... cod_cV1, cod_cD1 ... ];

% Using some plotting commands,% the following figure is generated.

Original image X.

50 100 150 200 250

50

100

150

200

250

One step decomposition

50 100 150 200 250

50

100

150

200

250

Page 573: Wavelet ug

dwt2

8-65

Algorithm For images, there exist an algorithm similar to the one-dimensional case for two-dimensional wavelets and scaling functions obtained from one- dimensional ones by tensorial product.

This kind of two-dimensional DWT leads to a decomposition of approximation coefficients at level j in four components: the approximation at level j + 1, and the details in three orientations (horizontal, vertical, and diagonal).

The following chart describes the basic decomposition steps for images:

Two-Dimensional DWT

Decomposition step

rows

Lo_D

Hi_D

rows

CAj

2 1

columns

Initialization

Downsample columns: keep the even indexed columns

Downsample rows: keep the even indexed rows

Convolve with filter X the rows of the entry

Convolve with filter X the columns of the entry

CA0 = s for the decomposition initialization

Where:

2 1

21

21

21

21

2 1

21

X

columns

Hi_D

Lo_D

X

columns

columns

Hi_D

Lo_D

CAj+1

CDj+1

CDj+1

CDj+1

(h)

(v)

(d)

horizontal

vertical

diagonal

columns

rows

Page 574: Wavelet ug

dwt2

8-66

Note To deal with signal-end effects involved by a convolution-based algorithm, a global variable managed by dwtmode is used. This variable defines the kind of signal extension mode used. The possible options include zero-padding (used in the previous example) and symmetric extension, which is the default mode.

See Also dwtmode, idwt2, wavedec2, waveinfo

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989),”A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)

Page 575: Wavelet ug

dwtmode

8-67

8dwtmodePurpose Discrete wavelet transform extension mode.

Syntax ST = dwtmodedwtmode('mode')

Description The dwtmode command sets the signal or image extension mode for discrete wavelet and wavelet packet transforms. The extension modes represent different ways of handling the problem of border distortion in signal and image analysis. For more information, see the section “Dealing with Border Distortion” in Chapter 6, “Advanced Concepts”, of the User’s Guide.

dwtmode or dwtmode('status') display the current mode.

ST = dwtmode or ST = dwtmode('status') display and returns in ST the current mode.

ST = dwtmode('status','nodisp') returns in ST the current mode and no text (status or warning) is displayed in the MATLAB command window.

dwtmode('mode') sets the DWT extension mode according to the value of ’mode’:

The DWT associated with these five modes is slightly redundant. But, the IDWT ensures a perfect reconstruction for any of the five previous modes whatever is the extension mode used for DWT.

dwtmode('per') sets the DWT mode to periodization.

'mode' DWT Extension Mode

'sym' Symmetric-padding (boundary value symmetric replication - default mode)

'zpd' Zero-padding

'spd' or 'sp1' Smooth-padding of order 1 (first derivative interpolation at the edges)

'sp0' Smooth-padding of order 0 (constant extension at the edges)

'ppd' Periodic-padding (periodic extension at the edges)

Page 576: Wavelet ug

dwtmode

8-68

This mode produces the smallest length wavelet decomposition. But, the extension mode used for IDWT must be the same to ensure a perfect reconstruction.

Using this mode, dwt and dwt2 produce the same results as the obsolete functions dwtper and dwtper2, respectively.

All functions and GUI tools involving the DWT (1-D & 2-D) or Wavelet Packet transform (1-D & 2-D) use the specified DWT extension mode.

dwtmode updates a global variable allowing the use of these six signal extensions. The extension mode should only be changed using this function. Avoid changing the global variable directly.

The default mode is loaded from the file DWTMODE.DEF (in the current path) if it exists. If not, the file DWTMODE.CFG (in the toolbox/wavelet/wavelet directory) is used.

dwtmode('save',MODE) saves MODE as the new default mode in the file DWTMODE.DEF (in the current directory). If a file with the same name already exists in the current directory, it is deleted before saving.

dwtmode('save') is equivalent to dwtmode('save',CURRENTMODE).

In these last two cases, the new default mode saved in the file DWTMODE.DEF will be active as default mode in the next MATLAB session.

Examples % If the DWT extension mode global variable does not% exist, default is Symmetrization.clear globaldwtmode ******************************************** DWT Extension Mode: Symmetrization ******************************************** % Display current DWT signal extension mode.dwtmode

******************************************** DWT Extension Mode: Symmetrization ********************************************

Page 577: Wavelet ug

dwtmode

8-69

% Change to Periodization extension mode.dwtmode('per')

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING: Change DWT Extension Mode !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ******************************************* DWT Extension Mode: Periodization *******************************************

% Display current DWT signal extension mode.dwtmode ******************************************* DWT Extension Mode: Periodization *******************************************

Note You should change the extension mode only by using dwtmode. Avoid changing the global variable directly.

See Also idwt, idwt2, dwt, dwt2, wextend

Page 578: Wavelet ug

dyaddown

8-70

8dyaddownPurpose Dyadic downsampling.

Syntax Y = dyaddown(X,EVENODD)Y = dyaddown(X)Y = dyaddown(X,EVENODD,'type')Y = dyaddown(X,'type',EVENODD)

Description Y = dyaddown(X,EVENODD) where X is a vector, returns a version of X that has been downsampled by 2. Whether Y contains the even- or odd-indexed samples of X depends on the value of positive integer EVENODD:

• If EVENODD is even, then Y(k) = X(2k).

• If EVENODD is odd, then Y(k) = X(2k+1).

Y = dyaddown(X) is equivalent to Y = dyaddown(X,0) (even-indexed samples).

Y = dyaddown(X,EVENODD,’type’) or Y = dyaddown(X,’type’,EVENODD), where X is a matrix, returns a version of X obtained by suppressing one out of two:

according to the parameter EVENODD, which is as above.

If you omit the EVENODD or ’type’ arguments, dyaddown defaults to EVENODD = 0 (even-indexed samples) and 'type' = 'c' (columns).

Y = dyaddown(X) is equivalent to Y = dyaddown(X,0,'c'). Y = dyaddown(X,’type’) is equivalent to Y = dyaddown(X,0,’type’). Y = dyaddown(X,EVENODD) is equivalent to Y = dyaddown(X,EVENODD,’c’).

Examples % For a vector.s = 1:10 s =

1 2 3 4 5 6 7 8 9 10

dse = dyaddown(s) % Downsample elements with even indices.dse =

2 4 6 8 10

Columns of X If 'type' = 'c'

Rows of X If 'type' = 'r'

Rows and columns of X If 'type' = 'm'

Page 579: Wavelet ug

dyaddown

8-71

% or equivalently dse = dyaddown(s,0)dse =

2 4 6 8 10

dso = dyaddown(s,1) % Downsample elements with odd indices.dso =

1 3 5 7 9

% For a matrix.s = (1:3)'*(1:4)s =

1 2 3 42 4 6 83 6 9 12

dec = dyaddown(s,0,'c') % Downsample columns with even indices.dec =

2 44 86 12

der = dyaddown(s,1,'r') % Downsample rows with odd indices.der = 1 2 3 43 6 9 12

dem = dyaddown(s,1,'m') % Downsample rows and columns % with odd indices.dem = 1 3 3 9

See Also dyadup

References Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

Page 580: Wavelet ug

dyadup

8-72

8dyadupPurpose Dyadic upsampling.

Syntax Y = dyadup(X,EVENODD)Y = dyadup(X)Y = dyadup(X,EVENODD,'type')Y = dyadup(X,'type',EVENODD)

Description dyadup implements a simple zero-padding scheme very useful in the wavelet reconstruction algorithm.

Y = dyadup(X,EVENODD) where X is a vector, returns an extended copy of vector X obtained by inserting zeros. Whether the zeros are inserted as even- or odd-indexed elements of Y depends on the value of positive integer EVENODD:

• If EVENODD is even, then Y(2k–1) = X(k), Y(2k) = 0.

• If EVENODD is odd, then Y(2k–1) = 0, Y(2k) = X(k).

Y = dyadup(X) is equivalent to Y = dyadup(X,1) (odd-indexed samples).

Y = dyadup(X,EVENODD,’type’) or Y = dyadup(X,’type’,EVENODD), where X is a matrix, returns extended copies of X obtained by inserting:

according to the parameter EVENODD, which is as above.

If you omit the EVENODD or ’type’ arguments, dyadup defaults to EVENODD = 1 (zeros in odd-indexed positions) and ’type’ = 'c' (insert columns).

Y = dyadup(X) is equivalent to Y = dyaddown(X,1,’c’).

Y = dyadup(X,’type’) is equivalent to Y = dyadup(X,1,’type’). Y = dyadup(X,EVENODD) is equivalent to Y = dyadup(X,EVENODD,’c’).

Columns in X If 'type' = 'c'

Rows in X If 'type' = 'r'

Rows and columns in X If 'type' = 'm'

Page 581: Wavelet ug

dyadup

8-73

Examples % For a vector.s = 1:5 s =

1 2 3 4 5

dse = dyadup(s) % Upsample elements at odd indices.dse =

0 1 0 2 0 3 0 4 0 5 0

% or equivalently dse = dyadup(s,1)dse =

0 1 0 2 0 3 0 4 0 5 0

dso = dyadup(s,0) % Upsample elements at even indices.dso =

1 0 2 0 3 0 4 0 5

% For a matrix.s = (1:2)'*(1:3)s =

1 2 32 4 6

der = dyadup(s,1,'r') % Upsample rows at even indices.der =

0 0 01 2 30 0 02 4 60 0 0

doc = dyadup(s,0,'c') % Upsample columns at odd indices.doc =

1 0 2 0 32 0 4 0 6

Page 582: Wavelet ug

dyadup

8-74

dem = dyadup(s,1,'m') % Upsample rows and columns % at even indices.dem = 0 0 0 0 0 0 0 0 1 0 2 0 3 0 0 0 0 0 0 0 0 0 2 0 4 0 6 0 0 0 0 0 0 0 0

% Using default values for dyadup and dyaddown, we have: % dyaddown(dyadup(s)) = s. s = 1:5s =

1 2 3 4 5

uds = dyaddown(dyadup(s))uds =

1 2 3 4 5

% In general reversed identity is false.

See Also dyaddown

References Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

Page 583: Wavelet ug

entrupd

8-75

8entrupdPurpose Entropy update (wavelet packet).

Syntax T = entrupd(T,ENT)T = entrupd(T,ENT,PAR)

Description entrupd is a one- or two-dimensional wavelet packet utility.

T = entrupd(T,ENT) or T = entrupd(T,ENT,PAR) returns for a given wavelet packet tree T, the updated tree using the entropy function ENT with the optional parameter PAR (see wentropy for more information).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 2 with db1 wavelet packets % using shannon entropy. t = wpdec(x,2,'db1','shannon');

% Read entropy of all the nodes. nodes = allnodes(t);ent = read(t,'ent',nodes);ent'ent =

1.0e+04 *-5.8615 -6.8204 -0.0350 -7.7901 -0.0497 -0.0205 -0.0138

% Update nodes entropy. t = entrupd(t,'threshold',0.5); nent = read(t,'ent');nent'nent =

937 488 320 241 175 170 163

See Also wentropy, wpdec, wpdec2

Page 584: Wavelet ug

fbspwavf

8-76

8fbspwavfPurpose Frequency B-Spline wavelets.

Syntax [PSI,X] = fbspwavf(LB,UB,N,M,FB,FC)

Description [PSI,X] = fbspwavf(LB,UB,N,M,FB,FC) returns values of the complex frequency B-Spline wavelet defined by the order parameter M (M is an integer such that 1 ≤ M), a bandwidth parameter FB, and a wavelet center frequency FC.

The function PSI is computed using the explicit expression:

PSI(X) = (FB^0.5)*((sinc(FB*X/M).^M).*exp(2*i*pi*FC*X))

on an N point regular grid in the interval [LB,UB].

FB and FC must be such that: FC > FB/2 > 0

Output arguments are the wavelet function PSI computed on the grid X.

Examples % Set order, bandwidth and center frequency parameters.m = 2; fb = 1; fc = 0.5;

% Set effective support and grid parameters.lb = -20; ub = 20; n = 1000;

% Compute complex Frequency B-Spline wavelet fbsp2-1-0.5.[psi,x] = fbspwavf(lb,ub,n,m,fb,fc);

Page 585: Wavelet ug

fbspwavf

8-77

% Plot complex Frequency B-Spline wavelet.subplot(211)plot(x,real(psi))title('Complex Frequency B-Spline wavelet fbsp2-1-0.5')xlabel('Real part'), gridsubplot(212)plot(x,imag(psi))xlabel('Imaginary part'), grid

See Also waveinfo

References Teolis, A. (1998), Computational signal processing with wavelets, Birkhauser, p. 63.

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1Complex Frequency B−Spline wavelet fbsp2−1−0.5

Real part

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1

Imaginary part

Page 586: Wavelet ug

gauswavf

8-78

8gauswavfPurpose Gaussian wavelets.

Syntax [PSI,X] = gauswavf(LB,UB,N,P)

Description [PSI,X] = gauswavf(LB,UB,N,P) returns values of the P-th derivative of the

Gaussian function on an N point regular grid for the interval

[LB,UB]. Cp is such that the 2-norm of the P-th derivative of F is equal to 1.

For P > 8, the Extended Symbolic Toolbox is required.

Output arguments are the wavelet function PSI computed on the grid X.

[PSI,X] = gauswavf(LB,UB,N) is equivalent to [PSI,X] = gauswavf(LB,UB,N,1)

These wavelets have an effective support of [-5 5].

Examples % Set effective support and grid parameters.lb = -5; ub = 5; n = 1000;

% Compute Gaussian wavelet of order 8.[psi,x] = gauswavf(lb,ub,n,8);

F Cpe x2–=

Page 587: Wavelet ug

gauswavf

8-79

% Plot Gaussian wavelet of order 8.plot(x,psi),title('Gaussian wavelet of order 8'), grid

See Also waveinfo

−5 0 5−1

−0.5

0

0.5

1

1.5Gaussian wavelet of order 8

Page 588: Wavelet ug

get

8-80

8getPurpose Get WPTREE object field contents.

Syntax [FieldValue1,FieldValue2, …] = get(T,'FieldName1','FieldName2', …)[FieldValue1,FieldValue2, …] = get(T)

Description [FieldValue1,FieldValue2, …] = get(T,'FieldName1','FieldName2', …) returns the content of the specified fields for the WPTREE object T.

For the fields that are objects or structures, you can get the subfield contents, giving the name of these subfields as 'FieldName' values. (See “Examples” below).

[FieldValue1,FieldValue2, …] = get(T) returns all the field contents of the tree T.

The valid choices for 'FieldName'are:

The fields of the wavelet information structure, 'wavInfo', are also valid for 'FieldName':

The fields of the entropy information structure, 'entInfo', are also valid for 'FieldName':

'dtree' : DTREE parent object'wavInfo' : Structure (wavelet information)

'wavName' : Wavelet name'Lo_D' : Low Decomposition filter'Hi_D' : High Decomposition filter'Lo_R' : Low Reconstruction filter'Hi_R' : High Reconstruction filter

'entInfo' : Structure (entropy information).

'entName' : Entropy name'entPar' : Entropy parameter

Page 589: Wavelet ug

get

8-81

Or fields of DTREE parent object:

Or fields of NTREE parent object:

Or fields of WTBO parent object:

Examples % Compute a wavelet packets treex = rand(1,1000);t = wpdec(x,2,'db2');o = get(t,'order');[o,tn] = get(t,'order','tn');[o,allNI,tn] = get(t,'order','allNI','tn');[o,wavInfo,allNI,tn] = get(t,'order','wavInfo','allNI','tn');[o,tn,Lo_D,EntName] = get(t,'order','tn','Lo_D','EntName');[wo,nt,dt] = get(t,'wtbo','ntree','dtree');

See Also disp, read, set, write

'ntree' : NTREE parent object'allNI' : All nodes information'terNI' : Terminal nodes information

'wtbo' : WTBO parent object'order' : Order of the tree'depth' : Depth of the tree'spsch' : Split scheme for nodes'tn' : Array of terminal nodes of the tree

'wtboInfo' : Object information'ud' : Userdata field

Page 590: Wavelet ug

idwt

8-82

8idwtPurpose Single-level inverse discrete 1-D wavelet transform.

Syntax X = idwt(cA,cD,'wname')X = idwt(cA,cD,Lo_R,Hi_R)X = idwt(cA,cD,'wname',L)X = idwt(cA,cD,Lo_R,Hi_R,L)X = idwt(...,'mode',MODE)

Description The idwt command performs a single-level one-dimensional wavelet reconstruction with respect to either a particular wavelet (’wname’, see wfilters for more information) or particular wavelet reconstruction filters (Lo_R and Hi_R) that you specify.

X = idwt(cA,cD,’wname') returns the single-level reconstructed approximation coefficients vector X based on approximation and detail coefficients vectors cA and cD, and using the wavelet ’wname'.

X = idwt(cA,cD,Lo_R,Hi_R) reconstructs as above using filters that you specify.

• Lo_R is the reconstruction low-pass filter.

• Hi_R is the reconstruction high-pass filter.

Lo_R and Hi_R must be the same length.

Let la be the length of cA (which also equals the length of cD) and lf the length of the filters Lo_R and Hi_R; then length(X) = LX where LX = 2*la if the DWT extension mode set to periodization. For the other extension modes LX = 2*la-lf+2.

For more information about the different Discrete Wavelet Transform extension modes, see dwtmode.

X = idwt(cA,cD,’wname',L) or X = idwt(cA,cD,Lo_R,Hi_R,L) returns the length-L central portion of the result obtained using idwt(cA,cD,’wname'). L must be less than LX.

X = idwt(...,’mode',MODE) computes the wavelet reconstruction using the specified extension mode MODE.

X = idwt(cA,[],...) returns the single-level reconstructed approximation coefficients vector X based on approximation coefficients vector cA.

Page 591: Wavelet ug

idwt

8-83

X = idwt([],cD,...) returns the single-level reconstructed detail coefficients vector X based on detail coefficients vector cD.

idwt is the inverse function of dwt in the sense that the abstract statement idwt(dwt(X,’wname’),’wname’) would give back X.

Examples % The current extension mode is zero-padding (see dwtmode).

% Construct elementary one-dimensional signal s.

randn('seed',531316785) s = 2 + kron(ones(1,8),[1 -1]) + ... ((1:16).^2)/32 + 0.2*randn(1,16);

% Perform single-level dwt of s using db2.

[ca1,cd1] = dwt(s,'db2'); subplot(221); plot(ca1); title('Approx. coef. for db2'); subplot(222); plot(cd1); title('Detail coef. for db2');

% Perform single-level inverse discrete wavelet transform, % illustrating that idwt is the inverse function of dwt.

ss = idwt(ca1,cd1,'db2'); err = norm(s-ss); % Check reconstruction. subplot(212); plot([s;ss]'); title('Original and reconstructed signals'); xlabel(['Error norm = ',num2str(err)])

% For a given wavelet, compute the two associated% reconstruction filters and inverse transform using % the filters directly.

[Lo_R,Hi_R] = wfilters('db2','r'); ss = idwt(ca1,cd1,Lo_R,Hi_R);

Page 592: Wavelet ug

idwt

8-84

% Using some plotting commands,% the following figure is generated.

Algorithm Starting from the approximation and detail coefficients at level j, cAj and cDj, the inverse discrete wavelet transform reconstructs cAj-1, inverting the decomposition step by inserting zeros and convolving the results with the reconstruction filters.

2 4 6 80

5

10

15Approx. coef. for db2

2 4 6 8−1

0

1

2Detail coef. for db2

2 4 6 8 10 12 14 160

5

10Original and reconstructed signals

Error norm = 1.435e−12

Page 593: Wavelet ug

idwt

8-85

See Also dwt, dwtmode, upwlev

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)

cAj-1

Lo_R

Hi_R

high-passupsample

upsamplecAj

cDj

2

level j

low-pass

Where: 2

X Convolve with filter X

Insert zeros at odd-indexed elements

Take the central part of U with the

2

wkeep

wkeepconvenient length

level j-1

One-Dimensional IDWT

Reconstruction step

Page 594: Wavelet ug

idwt2

8-86

8idwt2Purpose Single-level inverse discrete 2-D wavelet transform.

Syntax X = idwt2(cA,cH,cV,cD,'wname')X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R)X = idwt2(cA,cH,cV,cD,'wname',S)X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S)X = idwt2(...,'mode',MODE)

Description The idwt2 command performs a single-level two-dimensional wavelet reconstruction with respect to either a particular wavelet (’wname’, see wfilters for more information) or particular wavelet reconstruction filters (Lo_R and Hi_R) that you specify.

X = idwt2(cA,cH,cV,cD,’wname’) uses the wavelet ’wname' to compute the single-level reconstructed approximation coefficients matrix X, based on approximation matrix cA and details matrices cH,cV and cD (horizontal, vertical, and diagonal, respectively).

X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R) reconstructs as above, using filters that you specify.

• Lo_R is the reconstruction low-pass filter.

• Hi_R is the reconstruction high-pass filter.

Lo_R and Hi_R must be the same length.

Let sa = size(cA) = size(cH) = size(cV) = size(cD) and lf the length of the filters; then size(X) = SX, where SX = 2* SA, if the DWT extension mode is set to periodization. For the other extension modes, SX = 2*size(cA)-lf+2.

For more information about the different Discrete Wavelet Transform extension modes, see dwtmode.

X = idwt2(cA,cH,cV,cD,’wname’,S) and X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S) return the size-S central portion of the result obtained using the syntax idwt2(cA,cH,cV,cD,’wname'). S must be less than SX.

X = idwt2(...,'mode',MODE) computes the wavelet reconstruction using the extension mode MODE that you specify.

Page 595: Wavelet ug

idwt2

8-87

X = idwt2(cA,[],[],[],...) returns the single-level reconstructed approximation coefficients matrix X based on approximation coefficients matrix cA.

X = idwt2([],cH,[],[],...) returns the single-level reconstructed detail coefficients matrix X based on horizontal detail coefficients matrix cH.

The same result holds for X = idwt2([],[],cV,[],...) andX = idwt2([],[],[],cD,...), based on vertical and diagonal details.

More generally, X = idwt2(AA,HH,VV,DD,...) returns the single-level reconstructed matrix X where AA can be cA or [], and so on.

idwt2 is the inverse function of dwt2 in the sense that the abstract statement idwt2(dwt2(X,’wname’),’wname’) would give back X.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman;

% X contains the loaded image. sX = size(X);

% Perform single-level decomposition % of X using db4. [cA1,cH1,cV1,cD1] = dwt2(X,'db4');

% Invert directly decomposition of X % using coefficients at level 1. A0 = idwt2(cA1,cH1,cV1,cD1,'db4',sX);

% Check for perfect reconstruction. max(max(abs(X-A0)))ans =

3.4176e-10

Page 596: Wavelet ug

idwt2

8-88

Algorithm

See Also dwt2, dwtmode, upwlev2

Two-Dimensional IDWT

Reconstruction step

cAj

columns

Upsample columns: insert zeros at odd-indexed columns.

Upsample rows: insert zeros at odd-indexed rows.

Convolve with filter X the rows of the entry.

Convolve with filter X the columns of the entry.

Where:

21

21

21

21

2 1

21

X

columns

Hi_R

Lo_R

X

columns

columns

Hi_R

Lo_R

cAj+1

cDj+1

cDj+1

cDj+1

(h)

(v)

(d)

horizontal

vertical

diagonal

columns

rows

rows

Lo_R

Hi_R

rows

2 1

2 1

wkeep

Page 597: Wavelet ug

ind2depo

8-89

8ind2depoPurpose Node index to node depth-position.

Syntax [D,P] = ind2depo(ORD,N)

Description ind2depo is a tree-management utility.

For a tree of order ORD, [D,P] = ind2depo(ORD,N) computes the depths D and the positions P (at these depths D) for the nodes with indices N.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

N must be a column vector of integers (N ≥ 0).

Note that [D,P] = ind2depo(ORD,[D P]).

Examples % Create initial tree.ord = 2; t = ntree(ord,3); % Binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 598: Wavelet ug

ind2depo

8-90

% List t nodes (index).aln_ind = allnodes(t)

aln_ind =0 1 2 3 4 5 6 7 8

13 14

% Switch from index to Depth_Position. [depth,pos] = ind2depo(ord,aln_ind); aln_depo = [depth,pos]

aln_depo =0 0 1 0 1 1 2 0 2 1 2 2 2 3 3 0 3 1 3 6 3 7

See Also depo2ind

Page 599: Wavelet ug

intwave

8-91

8intwavePurpose Integrate wavelet function psi.

Syntax [INTEG,XVAL] = intwave('wname',PREC)[INTEG,XVAL] = intwave('wname',PREC,PFLAG)[INTEG,XVAL] = intwave('wname')

Description [INTEG,XVAL] = intwave(’wname’,PREC) computes the integral, INTEG, of the

wavelet function ψ (from to XVAL values): for x in XVAL.

The function ψ is approximated on the 2PREC points grid XVAL where PREC is a positive integer. ’wname’ is a string containing the name of the wavelet ψ (see wfilters for more information).

Output argument INTEG is a real or complex vector depending on the wavelet type.

For biorthogonal wavelets:

[INTDEC,XVAL,INTREC] = intwave('wname',PREC) computes the integrals, INTDEC and INTREC, of the wavelet decomposition function ψdec and the wavelet reconstruction function ψrec.

[INTEG,XVAL] = intwave(’wname’,PREC) is equivalent to [INTEG,XVAL] = intwave(’wname’,PREC,0).

[INTEG,XVAL] = intwave(’wname’) is equivalent to [INTEG,XVAL] = intwave(’wname’,8).

When used with three arguments intwave('wname',IN2,IN3), PREC = max(IN2,IN3) and plots are given.

When IN2 is equal to the special value 0, intwave(’wname’,0) is equivalent to intwave(’wname’,8,IN3).

intwave(’wname’) is equivalent to intwave(’wname’,8).

intwave is used only for continuous analysis (see cwt for more information).

∞– ψ y( ) yd∞–

x

Page 600: Wavelet ug

intwave

8-92

Examples % Set wavelet name. wname = 'db4';

% Plot wavelet function. [phi,psi,xval] = wavefun(wname,7);subplot(211); plot(xval,psi); title('Wavelet');

% Compute and plot wavelet integrals approximations % on a dyadic grid. [integ,xval] = intwave(wname,7); subplot(212); plot(xval,integ); title(['Wavelet integrals over [-Inf x] ' ...

'for each value of xval']);

Algorithm First, the wavelet function is approximated on a grid of 2PREC points using wavefun. A piecewise constant interpolation is used to compute the integrals using cumsum.

See Also wavefun

0 1 2 3 4 5 6 7−1

0

1

2Wavelet

0 1 2 3 4 5 6 7−0.4

−0.2

0

0.2

0.4Wavelet integrals over [−Inf x] for each value of xval

Page 601: Wavelet ug

isnode

8-93

8isnodePurpose True for existing node.

Syntax R = isnode(T,N)

Description isnode is a tree-management utility.

R = isnode(T,N) returns 1’s for nodes N, which exist in the tree T, and 0’s for others.

N can be a column vector containing the indices of nodes or a matrix, that contains the depths and positions of nodes.

In the last case, N(i,1) is the depth of i-th node and N(i,2) is the position of i-th node.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create initial tree. ord = 2; t = ntree(ord,3); % binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 602: Wavelet ug

isnode

8-94

% Change Node Label from Depth_Position to Index% (see the plot function).

% Check node index. isnode(t,[1;3;25])

ans =1 1 0

% Check node Depth_Position.isnode(t,[1 0;3 1;4 5])

ans =1 10

See Also istnode, wtreemgr

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 603: Wavelet ug

istnode

8-95

8istnodePurpose Determine indices of terminal nodes.

Syntax R = istnode(T,N)

Description istnode is a tree-management utility.

R = istnode(T,N) returns ranks (in left to right terminal nodes ordering) for terminal nodes N belonging to the tree T, and 0’s for others.

N can be a column vector containing the indices of nodes or a matrix that contains the depths and positions of nodes.

In the last case, N(i,1) is the depth of i-th node and N(i,2) is the position of i-th node.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create initial tree. ord = 2; t = ntree(ord,3); % binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

% Change Node Label from Depth_Position to Inde% (see the plot function)x.

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 604: Wavelet ug

istnode

8-96

% Find terminal nodes and return indices for terminal % nodes in the tree.istnode(t,[14])ans =

6

istnode(t,[15])ans =

0

istnode(t,[1;7;14;25])ans =

0 1 6 0

istnode(t,[1 0;3 1;4 5])ans =

020

See Also isnode, wtreemgr

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 605: Wavelet ug

iswt

8-97

8iswtPurpose Inverse discrete stationary wavelet transform 1-D.

Syntax X = iswt(SWC,'wname')X = iswt(SWA,SWD,'wname')X = iswt(SWC,Lo_R,Hi_R)X = iswt(SWA,SWD,Lo_R,Hi_R)

Description iswt performs a multilevel 1-D stationary wavelet reconstruction using either a specific orthogonal wavelet ('wname', see wfilters for more information) or specific reconstruction filters (Lo_R and Hi_R).

X = iswt(SWC,'wname') or X = iswt(SWA,SWD,'wname') or X = iswt(SWA(end,:),SWD,'wname') reconstructs the signal X based on the multilevel stationary wavelet decomposition structure SWC or [SWA,SWD] (see swt for more information).

X = iswt(SWC,Lo_R,Hi_R) or X = iswt(SWA,SWD,Lo_R,Hi_R) or X = iswt(SWA(end,:),SWD,Lo_R,Hi_R) reconstruct as above, using filters that you specify.

• Lo_R is the reconstruction low-pass filter.

• Hi_R is the reconstruction high-pass filter.

Lo_R and Hi_R must be the same length.

Examples % Load original 1D signal.load noisbloc; s = noisbloc; % Perform SWT decomposition at level 3 of s using db1.swc = swt(s,3,'db1');% Second usage.[swa,swd] = swt(s,3,'db1');

% Reconstruct s from the stationary wavelet% decomposition structure swc.a0 = iswt(swc,'db1');% Second usage.a0bis = iswt(swa,swd,'db1');

Page 606: Wavelet ug

iswt

8-98

% Check for perfect reconstruction.err = norm(s-a0)err = 9.6566e-014

errbis = norm(s-a0bis)errbis = 9.6566e-014

Algorithm See the section “Stationary Wavelet Transform” in Chapter 6, “Advanced Concepts”, of the User’s Guide.

See Also idwt, swt, waverec

References Nason, G.P.; B.W. Silverman (1995), “The stationary wavelet transform and some statistical applications,” Lecture Notes in Statistics, 103, pp. 281–299.

Coifman, R.R.; Donoho D.L. (1995), “Translation invariant de-noising,” Lecture Notes in Statistics, 103, pp 125–150.

Pesquet, J.C.; H. Krim, H. Carfatan (1996), “Time-invariant orthonormal wavelet representations,” IEEE Trans. Sign. Proc., vol. 44, 8, pp. 1964–1970.

Page 607: Wavelet ug

iswt2

8-99

8iswt2Purpose Inverse discrete stationary wavelet transform 2-D.

Syntax X = iswt2(SWC,'wname')X = iswt2(A,H,V,D,'wname')X = iswt2(SWC,Lo_R,Hi_R)X = iswt2(A,H,V,D,Lo_R,Hi_R)

Description iswt2 performs a multilevel 2-D stationary wavelet reconstruction using either a specific orthogonal wavelet ('wname', see wfilters for more information) or specific reconstruction filters (Lo_R and Hi_R).

X = iswt2(SWC,'wname') or X = iswt2(A,H,V,D,'wname') or X = iswt2(A(:,:,end),H,V,D,'wname') reconstructs the signal X, based on the multilevel stationary wavelet decomposition structure SWC or [A,H,V,D] (see swt2).

X = iswt2(SWC,Lo_R,Hi_R) or X = iswt2(A,H,V,D,Lo_R,Hi_R) or X = iswt2(A(:,:,end),H,V,D,Lo_R,Hi_R) reconstructs as above, using filters that you specify.

• Lo_R is the reconstruction low-pass filter.

• Hi_R is the reconstruction high-pass filter.

Lo_R and Hi_R must be the same length.

Examples % Load original image.load nbarb1; % Perform SWT decomposition% of X at level 3 using sym4.swc = swt2(X,3,'sym4');% Second usage.[ca,chd,cvd,cdd] = swt2(X,3,'sym4');

% Reconstruct s from the stationary wavelet% decomposition structure swc.a0 = iswt2(swc,'sym4');% Second usage.a0 = iswt2(ca,chd,cvd,cdd,'sym4');

Page 608: Wavelet ug

iswt2

8-100

% Check for perfect reconstruction.err = max(max(abs(X-a0)))ans = 2.3482e-010

errbis = max(max(abs(X-a0bis)))ans = 2.3482e-010

Algorithm See the section “Stationary Wavelet Transform” in Chapter 6, “Advanced Concepts”, of the User’s Guide.

See Also idwt2, swt2, waverec2

References Nason, G.P.; B.W. Silverman (1995), “The stationary wavelet transform and some statistical applications,” Lecture Notes in Statistics, 103, pp. 281–299.

Coifman, R.R.; Donoho D.L. (1995), “Translation invariant de-noising,” Lecture Notes in Statistics, 103, pp. 125–150.

Pesquet, J.C.; H. Krim, H. Carfatan (1996), “Time-invariant orthonormal wavelet representations,” IEEE Trans. Sign. Proc., vol. 44, 8, pp. 1964–1970.

Page 609: Wavelet ug

leaves

8-101

8leavesPurpose Determine terminal nodes.

Syntax N = leaves(T)N = leaves(T,'dp')[N,K] = leaves(T,'sort')[N,K] = leaves(T,'sortdp')

Description N = leaves(T) returns the indices of terminal nodes of the tree T where N is a column vector.

The nodes are ordered from left to right as in tree T.

[N,K] = leaves(T,'s') or [N,K] = leaves(T,'sort') returns sorted indices. M = N(K) are the indices reordered as in tree T, from left to right.

N = leaves(T,'dp') returns a matrix N, which contains the depths and positions of terminal nodes.

N(i,1) is the depth of i-th terminal node, and N(i,2) is the position of i-th terminal node.

[N,K] = leaves(T,'sortdp') or [N,K] = leaves(T,'sdp') returns sorted nodes.

Examples % Create initial tree.ord = 2; t = ntree(ord,3); % binary tree of depth 3.t=nodejoin(t,5);t=nodejoin(t,4);plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 610: Wavelet ug

leaves

8-102

% List terminal nodes (index).tnodes_ind = leaves(t)tnodes_ind = 7 8 4 5 13 14

% List terminal nodes (sorted on index).[tnodes_ind,Ind] = leaves(t,'sort')tnodes_ind = 4 5 7 8 13 14

Ind = 3 4 1 2 5 6

% List terminal nodes (Depth_Position).tnodes_depo = leaves(t,'dp')tnodes_depo = 3 0 3 1 2 1 2 2 3 6 3 7

% List terminal nodes (sorted on Depth_Position).[tnodes_depo,Ind] = leaves(t,'sortdp')

Page 611: Wavelet ug

leaves

8-103

tnodes_depo = 2 1 2 2 3 0 3 1 3 6 3 7

Ind = 3 4 1 2 5 6

See Also tnodes, noleaves

Page 612: Wavelet ug

mexihat

8-104

8mexihatPurpose Mexican hat wavelet.

Syntax [PSI,X] = mexihat(LB,UB,N)

Description [PSI,X] = mexihat(LB,UB,N) returns values of the Mexican hat wavelet on an N point regular grid, X, in the interval [LB,UB].

Output arguments are the wavelet function PSI computed on the grid X.

This wavelet has [-5 5] as effective support.

This function is proportional to the second derivative function of the Gaussian probability density function.

Examples % Set effective support and grid parameters. lb = -5; ub = 5; n = 1000;

% Compute and plot Mexican hat wavelet. [psi,x] = mexihat(lb,ub,n); plot(x,psi), title('Mexican hat wavelet')

See Also waveinfo

ψ x( ) 23

-------π 1– 4⁄ 1 x2

–( )e x2– 2⁄=

−5 0 5−0.4

−0.2

0

0.2

0.4

0.6

0.8

1Mexican hat wavelet

Page 613: Wavelet ug

meyer

8-105

8meyerPurpose Meyer wavelet.

Syntax [PHI,PSI,T] = meyer(LB,UB,N)[PHI,T] = meyer(LB,UB,N,'phi')[PSI,T] = meyer(LB,UB,N,'psi')

Description [PHI,PSI,T] = meyer(LB,UB,N) returns Meyer scaling and wavelet functions evaluated on an N point regular grid in the interval [LB,UB].

N must be a power of two.

Output arguments are the scaling function PHI and the wavelet function PSI computed on the grid T. These functions have [-8 8] as effective support.

If only one function is required, a fourth argument is allowed:

[PHI,T] = meyer(LB,UB,N,'phi')[PSI,T] = meyer(LB,UB,N,'psi')

When the fourth argument is used, but not equal to 'phi' or 'psi', outputs are the same as in the main option.

The Meyer wavelet and scaling function are defined in the frequency domain:

• Wavelet function

and

where

ψ ω( ) 2π( ) 1– 2⁄ eiω 2⁄ π2---ν 3

2π------ ω 1–

sin= if 2π

3------ ω 4π

3------≤ ≤

ψ ω( ) 2π( ) 1– 2⁄ eiω 2⁄ π2---ν 3

4π------ ω 1–

cos= if 4π

3------ ω 8π

3------≤ ≤

ψ ω( ) 0 if= ω 2π3

------8π3

------,∉

ν a( ) a4 35 84a– 70a2 20a3–+( ),= a 0 1[ , ]∈

Page 614: Wavelet ug

meyer

8-106

• Scaling function

By changing the auxiliary function (see meyeraux for more information), you get a family of different wavelets. For the required properties of the auxiliary function ν, see “References” in Chapter 6, “Advanced Concepts”, of the User’s Guide.

Examples % Set effective support and grid parameters. lb = -8; ub = 8; n = 1024;

% Compute and plot Meyer wavelet and scaling functions. [phi,psi,x] = meyer(lb,ub,n); subplot(211), plot(x,psi) title('Meyer wavelet') subplot(212), plot(x,phi) title('Meyer scaling function')

φ ω( ) 2π( ) 1– 2⁄= if ω 2π

3------≤

φ ω( ) 2π( ) 1– 2⁄=

π2---ν 3

2π------ ω 1–

cos if 2π

3------ ω 4π

3------≤ ≤

φ ω( ) 0= if ω 4π3

------>

−8 −6 −4 −2 0 2 4 6 8−1

0

1

2Meyer wavelet

−8 −6 −4 −2 0 2 4 6 8−0.5

0

0.5

1

1.5Meyer scaling function

Page 615: Wavelet ug

meyer

8-107

Algorithm Starting from an explicit form of the Fourier transform of φ, meyer computes the values of on a regular grid, and then the values of φ are computed using instdfft, the inverse nonstandard discrete FFT.

The procedure for ψ is along the same lines.

See Also meyeraux, wavefun, waveinfo

References Daubechies I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed. pp. 117–119, 137, 152.

φφ

Page 616: Wavelet ug

meyeraux

8-108

8meyerauxPurpose Meyer wavelet auxiliary function.

Syntax Y = meyeraux(X)

Description Y = meyeraux(X) returns values of the auxiliary function used for Meyer wavelet generation evaluated at the elements of the vector or matrix X.

The function is:

See Also meyer

35x4 84x5– 70x6 20x7

–+

Page 617: Wavelet ug

morlet

8-109

8morletPurpose Morlet wavelet.

Syntax [PSI,X] = morlet(LB,UB,N)

Description [PSI,X] = morlet(LB,UB,N) returns values of the Morlet wavelet on an N point regular grid in the interval [LB,UB].

Output arguments are the wavelet function PSI computed on the grid X, and the grid X.

This wavelet has [-4 4] as effective support.

Examples % Set effective support and grid parameters. lb = -4; ub = 4; n = 1000; % Compute and plot Morlet wavelet. [psi,x] = morlet(lb,ub,n); plot(x,psi), title('Morlet wavelet')

See Also waveinfo

ψ x( ) e x– 2 2⁄ 5x( )cos=

−4 −2 0 2 4−1

−0.5

0

0.5

1Morlet wavelet

Page 618: Wavelet ug

nodeasc

8-110

8nodeascPurpose Node ascendants.

Syntax A = nodeasc(T,N)A = nodeasc(T,N,'deppos')

Description nodeasc is a tree-management utility.

A = nodeasc(T,N) returns the indices of all the ascendants of the node N in the tree T where N can be the index node or the depth and position of the node. A is a column vector with A(1) = index of node N.

A = nodeasc(T,N,'deppos') is a matrix, which contains the depths and positions of all ascendants. A(i,1) is the depth of i-th ascendant and A(i,2) is the position of i-th ascendant.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create binary tree of depth 3.t = ntree(2,3); t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 619: Wavelet ug

nodeasc

8-111

% Change Node Label from Depth_Position to Index% (see the plot function).

nodeasc(t,[2 2])ans =

5 2 0

nodeasc(t,[2 2],'deppos')ans =

2 2 1 1 0 0

See Also nodedesc, nodepar, wtreemgr

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 620: Wavelet ug

nodedesc

8-112

8nodedescPurpose Node descendants.

Syntax D = nodedesc(T,N)D = nodedesc(T,N,'deppos')

Description nodedesc is a tree-management utility.

D = nodedesc(T,N) returns the indices of all the descendants of the node N in the tree T where N can be the index node or the depth and position of node. D is a column vector with D(1) = index of node N.

D = nodedesc(T,N,'deppos') is a matrix that contains the depths and positions of all descendants. D(i,1) is the depth of i-th descendant and D(i,2) is the position of i-th descendant.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create binary tree of depth 3. t = ntree(2,3); t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 621: Wavelet ug

nodedesc

8-113

% Change Node Label from Depth_Position to Index% (see the plot function).

% Node descendants. nodedesc(t,2)ans =

256

1314

nodedesc(t,2,'deppos')ans =

1 12 22 33 63 7

nodedesc(t,[1 1],'deppos')ans =

1 12 22 33 63 7

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 622: Wavelet ug

nodedesc

8-114

nodedesc(t,[1 1])ans =

256

1314

See Also nodeasc, nodepar, wtreemgr

Page 623: Wavelet ug

nodejoin

8-115

8nodejoinPurpose Recompose node.

Syntax T = nodejoin(T,N)T = nodejoin(T)

Description nodejoin is a tree-management utility.

T = nodejoin(T,N) returns the modified tree T corresponding to a recomposition of the node N.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

T = nodejoin(T) is equivalent to T = nodejoin(T,0).

Examples % Create binary tree of depth 3. t = ntree(2,3);

% Plot tree t. plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

% Merge nodes of indices 4 and 5.t = nodejoin(t,5);t = nodejoin(t,4);

(1) (2)

(3) (4) (5) (6)

(7) (8) (9) (10) (11) (12) (13) (14)

(0)

Page 624: Wavelet ug

nodejoin

8-116

% Plot new tree t. plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

See Also nodesplt

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 625: Wavelet ug

nodepar

8-117

8nodeparPurpose Node parent.

Syntax F = nodepar(T,N)F = nodepar(T,N,'deppos')

Description nodepar is a tree-management utility.

F = nodepar(T,N) returns the indices of the “parent(s)” of the nodes N in the tree T where N can be a column vector containing the indices of nodes or a matrix that contains the depths and positions of nodes. In the last case, N(i,1) is the depth of i-th node and N(i,2) is the position of i-th node.

F = nodepar(T,N,'deppos') is a matrix that contains the depths and positions of returned nodes. F(i,1) is the depth of i-th node and F(i,2) is the position of i-th node.

nodepar(T,0) or nodepar(T,[0,0]) returns -1.

nodepar(T,0,'deppos') or nodepar(T,[0,0],'deppos') returns [-1,0].

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create binary tree of depth 3. t = ntree(2,3); t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 626: Wavelet ug

nodepar

8-118

% Change Node Label from Depth_Position to Index% (see the plot function).

% Nodes parent.nodepar(t,[2 2],'deppos')

ans =1 1

nodepar(t,[1;7;14])

ans =036

See Also nodeasc, nodedesc, wtreemgr

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 627: Wavelet ug

nodesplt

8-119

8nodespltPurpose Split (decompose) node.

Syntax T = nodesplt(T,N)

Description nodesplt is a tree-management utility.

T = nodesplt(T,N) returns the modified tree T corresponding to the decomposition of the node N.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create binary tree (tree of order 2) of depth 3. t = ntree(2,3);

% Plot tree t. plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

% Split node of index 10. t = nodesplt(t,10);

(1) (2)

(3) (4) (5) (6)

(7) (8) (9) (10) (11) (12) (13) (14)

(0)

Page 628: Wavelet ug

nodesplt

8-120

% Plot new tree t. plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

See Also nodejoin

(1) (2)

(3) (4) (5) (6)

(7) (8) (9) (10) (11) (12) (13) (14)

(21) (22)

(0)

Page 629: Wavelet ug

noleaves

8-121

8noleavesPurpose Determine nonterminal nodes.

Syntax N = noleaves(T)N = noleaves(T,'dp')

Description N = noleaves(T) returns the indices of nonterminal nodes of the tree T (i.e., nodes that are not leaves). N is a column vector.

The nodes are ordered from left to right as in tree T.

N = noleaves(T,'dp') returns a matrix N, which contains the depths and positions of nonterminal nodes.

N(i,1) is the depth of i-th nonterminal node andN(i,2) is the position of i-th nonterminal node.

Examples % Create initial tree.ord = 2; t = ntree(ord,3); % binary tree of depth 3.t=nodejoin(t,5);t=nodejoin(t,4);plot(t)

% Change Node Label from Depth_Position to Index% (see the plot function).

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 630: Wavelet ug

noleaves

8-122

% List nonterminal nodes (index).ntnodes_ind = noleaves(t)

ntnodes_ind = 0 1 2 3 6

% List nonterminal nodes (Depth_Position).ntnodes_depo = noleaves(t,'dp')

ntnodes_depo = 0 0 1 0 1 1 2 0 2 3

See Also leaves

Page 631: Wavelet ug

ntnode

8-123

8ntnodePurpose Number of terminal nodes.

Syntax NB = ntnode(T)

Description ntnode is a tree-management utility.

NB = ntnode(T) returns the number of terminal nodes in the tree T.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples % Create binary tree (tree of order 2) of depth 3.t = ntree(2,3);

% Plot tree t. plot(t)

% Number of terminal nodes. ntnode(t)

ans =8

See Also wtreemgr

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 632: Wavelet ug

ntree

8-124

8ntreePurpose Constructor for the class NTREE.

Syntax T = ntree(ORD,D)T = ntreeT = ntree(ORD)T = ntree(ORD,D,S,U)T = ntree('PropName1',PropValue1,'PropName2',PropValue2, ...)

Description T = ntree(ORD,D) returns an NTREE object, which is a complete tree of order ORD and depth D.

T = ntree is equivalent to T = ntree(2,0)

T = ntree(ORD) is equivalent to T = ntree(ORD,0)

With T = ntree(ORD,D,S) you can set a "split scheme" for nodes. The split scheme field S, is a logical array of size ORD by 1.

The root of the tree can be split and it has ORD children. You can split the j-th child if S(j) = 1.

Each node that you can split has the same property as the root node.

With T = ntree(ORD,D,S,U) you can, in addition, set a userdata field.

Inputs can be given in another way:

T = ntree('order',ORD,'depth',D,'spsch',S,'ud',U). For "missing" inputs the defaults are: ORD = 2 , D = 0 , S = ones([1:ORD]) , U = {}.

[T,NB] = ntree( ... ) returns also the number of terminal nodes (leaves) of T.

For more information on object fields, type: help ntree/get.

Page 633: Wavelet ug

ntree

8-125

Class NTREE (Parent class: WTBO)

Fields:

Examples % Create binary tree (tree of order 2) of depth 3.t2 = ntree(2,3);

% Plot tree t2.plot(t2)

% Create a quadtree (tree of order 4) of depth 2.t4 = ntree(4,2,[1 1 0 1]);

% Plot tree t4.plot(t4)

wtbo : Parent object.order : Tree order.depth : Tree depth.spsch : Split scheme for nodestn : Column vector with terminal node indices.

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

Page 634: Wavelet ug

ntree

8-126

% Split and merge some nodes using the gui% generated by plot (see the plot function).% The figure becomes:

See Also wtbo

(0,0)

(1,0) (1,1) (1,2) (1,3)

(2,0) (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,12)(2,13)(2,14)(2,15)

(0,0)

(1,0) (1,1) (1,2) (1,3)

(2,0) (2,1) (2,2) (2,3) (2,12) (2,13) (2,14) (2,15)

(3,12) (3,13) (3,14) (3,15)

Page 635: Wavelet ug

orthfilt

8-127

8orthfiltPurpose Orthogonal wavelet filter set.

Syntax [Lo_D,Hi_D,Lo_R,Hi_R] = orthfilt(W)

Description [Lo_D,Hi_D,Lo_R,Hi_R] = orthfilt(W) computes the four filters associated with the scaling filter W corresponding to a wavelet:

For an orthogonal wavelet, in the multiresolution framework, we start with the scaling function φ and the wavelet function ψ. One of the fundamental relations is the twin-scale relation:

All the filters used in dwt and idwt are intimately related to the sequence . Clearly if φ is compactly supported, the sequence (wn) is finite and

can be viewed as a FIR filter. The scaling filter W is:

• A low-pass FIR filter

• Of length 2N

• Of sum 1

• Of norm

For example, for the db3 scaling filter:

load db3 db3db3 =

0.2352 0.5706 0.3252 -0.0955 -0.0604 0.0249

sum(db3)ans =

1.000

Lo_D Decomposition low-pass filter

Hi_D Decomposition high-pass filter

Lo_R Reconstruction low-pass filter

Hi_R Reconstruction high-pass filter

12---φ x

2---

wnφ x n–( )n Z∈∑=

wn( )n Z∈

12

-------

Page 636: Wavelet ug

orthfilt

8-128

norm(db3)ans =

0.7071

From filter W, we define four FIR filters, of length 2N and norm 1, organized as follows:

The four filters are computed using the following scheme:

where qmf is such that Hi_R and Lo_R are quadrature mirror filters (i.e., Hi_R(k) = (-1)k Lo_R(2N + 1 - k), for k = 1, 2, … , 2N), and where wrev flips the filter coefficients. So Hi_D and Lo_D are also quadrature mirror filters. The computation of these filters is performed using orthfilt.

Examples % Load scaling filter. load db8; w = db8; subplot(421); stem(w); title('Original scaling filter');

% Compute the four filters. [Lo_D,Hi_D,Lo_R,Hi_R] = orthfilt(w); subplot(423); stem(Lo_D); title('Decomposition low-pass filter'); subplot(424); stem(Hi_D); title('Decomposition high-pass filter');

Filters Low-Pass High-Pass

Decomposition Lo_D Hi_D

Reconstruction Lo_R Hi_R

Lo_R = W

norm(W)

Hi_R = qmf(Lo_R) Hi_D = wrev(Hi_R)

W

Lo_D = wrev(Lo_R)

Page 637: Wavelet ug

orthfilt

8-129

subplot(425); stem(Lo_R); title('Reconstruction low-pass filter'); subplot(426); stem(Hi_R); title('Reconstruction high-pass filter');

% Check for orthonormality. df = [Lo_D;Hi_D];rf = [Lo_R;Hi_R];id = df*df'

id =1.0000 0

0 1.0000

id = rf*rf'

id =1.0000 0

0 1.0000

% Check for orthogonality by dyadic translation, for example:df = [Lo_D 0 0;Hi_D 0 0]; dft = [0 0 Lo_D; 0 0 Hi_D]; zer = df*dft'

zer =

1.0e-12 *-0.1883 0.0000-0.0000 -0.1883

% High- and low-frequency illustration. fftld = fft(Lo_D); ffthd = fft(Hi_D); freq = [1:length(Lo_D)]/length(Lo_D); subplot(427); plot(freq,abs(fftld)); title('Transfer modulus: low-pass');subplot(428); plot(freq,abs(ffthd)); title('Transfer modulus: high-pass')

Page 638: Wavelet ug

orthfilt

8-130

% Editing some graphical properties,% the following figure is generated.

See Also biorfilt, qmf, wfilters

References Daubechies I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed. pp. 117–119, 137, 152.

0 5 10 15 20−1

0

1Original scaling filter

0 5 10 15 20−1

0

1Decomposition lowpass filter

0 5 10 15 20−1

0

1Decomposition highpass filter

0 5 10 15 20−1

0

1Reconstruction lowpass filter

0 5 10 15 20−1

0

1Reconstruction highpass filter

0.2 0.4 0.6 0.8 10

1

2Transfer modulus : lowpass

0.2 0.4 0.6 0.8 10

1

2Transfer modulus : highpass

Page 639: Wavelet ug

plot

8-131

8plotPurpose Plot tree.

Syntax plot(T) plot(T,FIG) FIG = plot(T) NEWT = plot(T,'read',FIG) NEWT = plot(DUMMY,'read',FIG)

Description plot is a graphical tree-management utility.

plot(T) plots the tree T.

The figure that contains the tree is a GUI tool. It lets you change the Node Label to Depth_Position or Index, and Node Action to Split-Merge or Visualize.

The default values are Depth_Position and Visualize.

You can click the nodes to execute the current Node Action.

plot(T,FIG) plots the tree T in the figure whose handle is FIG. This figure was already used to plot a tree, for example using the command:

FIG = plot(T)

After some split or merge actions, you can get the new tree using its parent figure handle. The following syntax let you perform this functionality:

NEWT = plot(T,'read',FIG)

In fact, the first argument is dummy. The most general syntax is:

NEWT = plot(DUMMY,'read',FIG)

where DUMMY is any object parented by an NTREE object. More generally, DUMMY can be any object constructor name returning an NTREE parented object. For example:

NEWT = plot(ntree,'read',FIG) NEWT = plot(dtree,'read',FIG) NEWT = plot(wptree,'read',FIG)

Page 640: Wavelet ug

plot

8-132

Examples % Create a wavelet packets tree (1-D)load noisblocx = noisbloc;t = wpdec(x,2,'db2');

% Plot tree t.plot(t)

% Change Node Label from Depth_Position to Index.

Page 641: Wavelet ug

plot

8-133

% Click the node (3). You get the following figure.

Page 642: Wavelet ug

plot

8-134

% Change Node Action from Visualize to Split_Merge.

% Merge the node (2) and split the node (3). % Change Node Action from Split_Merge to Visualize.% Click the node (7). You obtain the following figure,% which represents the wavelet decomposition at level 3.

Page 643: Wavelet ug

plot

8-135

% Create a wavelet packets tree (2-D)load woman2t = wpdec2(X,1,'sym4');

% Plot tree t.plot(t)

% Change Node Label from Depth_Position to Index.% Click the node (1). You get the following figure.

Page 644: Wavelet ug

qmf

8-136

8qmfPurpose Quadrature mirror filter.

Syntax Y = qmf(X,P)Y = qmf(X)

Description Y = qmf(X,P) changes the signs of the even index entries of the reversed vector filter coefficients X if P is even. If P is odd the same holds for odd index entries. Y = qmf(X) is equivalent to Y = qmf(X,0).

Let x be a finite energy signal. Two filters F0 and F1 are quadrature mirror filters (QMF) if, for any x:

where y0 is a decimated version of the signal x filtered with F0 so y0 is defined by x0 = F0(x) and y0(n) = x0(2n), and similarly, y1 is defined by x1 = F1(x) and y1(n) = x1(2n). This property ensures a perfect reconstruction of the associated two-channel filter banks scheme (See Strang-Nguyen p. 103).

For example, if F0 is a Daubechies scaling filter and F1 = qmf(F0), then the transfer functions F0(z) and F1(z) of the filters F0 and F1 satisfy the condition (see the example for db10):

Examples % Load scaling filter associated with an orthogonal wavelet. load db10; subplot(321); stem(db10); title('db10 low-pass filter');

% Compute the quadrature mirror filter. qmfdb10 = qmf(db10); subplot(322); stem(qmfdb10); title('QMF db10 filter');

% Check for frequency condition (necessary for orthogonality):% abs(fft(filter))^2 + abs(fft(qmf(filter))^2 = 1 at each % frequency. m = fft(db10); mt = fft(qmfdb10); freq = [1:length(db10)]/length(db10);

y02 y1

2+ x 2

=

F0 z( ) 2 F1 z( ) 2+ 1=

Page 645: Wavelet ug

qmf

8-137

subplot(323); plot(freq,abs(m)); title('Transfer modulus of db10')subplot(324); plot(freq,abs(mt)); title('Transfer modulus of QMF db10')subplot(325); plot(freq,abs(m).^2 + abs(mt).^2); title('Check QMF condition for db10 and QMF db10') xlabel(' abs(fft(db10))^2 + abs(fft(qmf(db10))^2 = 1')

% Editing some graphical properties,% the following figure is generated.

% Check for orthonormality. df = [db10;qmfdb10]*sqrt(2); id = df*df'

id =1.0000 0.0000 0.0000 1.0000

References Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

0 10 20−0.5

0

0.5db10 low−pass filter

0 10 20−0.5

0

0.5QMF db10 filter

0 0.5 10

0.5

1Transfer modulus of db10

0 0.5 10

0.5

1Transfer modulus of QMF db10

0.2 0.4 0.6 0.80

1

2Check QMF condition for db10 and QMF db10

abs(fft(db10))^2 + abs(fft(qmf(db10))^2 = 1

Page 646: Wavelet ug

rbiowavf

8-138

8rbiowavfPurpose Reverse biorthogonal spline wavelet filters.

Syntax [RF,DF]= rbiowavf(W)

Description [RF,DF] = rbiowavf(W) returns two scaling filters associated with the biorthogonal wavelet specified by the string W.

W = 'rbioNr.Nd' where possible values for Nr and Nd are:

The output arguments are filters.

• RF is the reconstruction filter.

• DF is the decomposition filter.

Examples % Set reverse biorthogonal spline wavelet name. wname = 'rbio2.2'; % Compute the two corresponding scaling filters,% rf is the reconstruction scaling filter and% df is the decomposition scaling filter.[rf,df] = rbiowavf(wname)

rf =

-0.1250 0.2500 0.7500 0.2500 -0.1250

df =

0.2500 0.5000 0.2500

See Also biorfilt, waveinfo

Nr = 1 Nd = 1 , 3 or 5

Nr = 2 Nd = 2 , 4 , 6 or 8

Nr = 3 Nd = 1 , 3 , 5 , 7 or 9

Nr = 4 Nd = 4

Nr = 5 Nd = 5

Nr = 6 Nd = 8

Page 647: Wavelet ug

read

8-139

8readPurpose Read values in WPTREE object fields.

Syntax VARARGOUT = read(T,VARARGIN)

Description VARARGOUT = read(T,VARARGIN) is the most general syntax to read one or more property values from the fields of a WPTREE object .

The different ways to call the read function are:

PropValue = read(T,'PropName') or

PropValue = read(T,'PropName','PropParam')

or any combination of the previous syntaxes:

[PropValue1,PropValue2, …] = read(T,'PropName1','PropParam1','PropName2','PropParam2', …)

where 'PropParam' is optional.

The valid choices for 'PropName' and 'PropParam' are listed in the table below.

PropName PropParam

'ent', 'ento' or 'sizes' (see wptree)

Without 'PropParam' or with 'PropParam' = Vector of node indices, PropValue contains the entropy (or optimal entropy, or size) of the tree nodes in ascending node index order.

'cfs' With 'PropParam' = One terminal node index.cfs = read(T,'cfs',NODE) is equivalent tocfs = read(T,'data',NODE) and returns the coefficients of the terminal node NODE.

'entName', 'entPar' 'wavName' (see wptree) or 'allcfs',

Without 'PropParam'.cfs = read(T,'allcfs') is equivalent tocfs = read(T,'data'). PropValue contains the desired information in ascending node index order of the tree nodes.

Page 648: Wavelet ug

read

8-140

Examples % Create a wavelet packet tree.x = rand(1,512);t = wpdec(x,3,'db3');t = wpjoin(t,[4;5]);plot(t);

% Click the node (3,0), (see the plot function).

'wfilters' (see wfilters)

Without 'PropParam' or with 'PropParam' = 'd','r','l','h'.

'data' Without 'PropParam' or with'PropParam' = One terminal node index or 'PropParam' = Column vector of terminal node indices.In this last case, PropValue is a cell array. Without 'PropParam', PropValue contains the coefficients of the tree nodes in ascending node index order.

PropName PropParam

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

20 40 600.8

1

1.2

1.4

1.6

1.8

2data for node: (7) or (3,0).

Page 649: Wavelet ug

read

8-141

% Read values.

sAll = read(t,'sizes');sNod = read(t,'sizes',[0,4,5]); eAll = read(t,'ent');eNod = read(t,'ent',[0,4,5]); dAll = read(t,'data');dNod = read(t,'data',[4;5]);[lo_D,hi_D,lo_R,hi_R] = read(t,'wfilters');[lo_D,lo_R,hi_D,hi_R] = read(t,'wfilters','l','wfilters','h');[ent,ento,cfs4,cfs5] = read(t,'ent','ento','cfs',4,'cfs',5);

See Also disp, get, set, wptree, write

Page 650: Wavelet ug

readtree

8-142

8readtreePurpose Read wavelet packet decomposition tree from a figure.

Syntax T = readtree(F)

Description T = readtree(F) reads the wavelet packet decomposition tree from the figure whose handle is F.

For more information see Chapter 5 of the User’s Guide, “Using Wavelet Packets” and Appendix B, “Wavelet Toolbox and Object Programming”.

Examples % Create a wavelet packet tree.x = sin(8*pi*[0:0.005:1]);t = wpdec(x,3,'db2');

% Display the generated tree in a Wavelet Pachet 1-D GUI window.fig = drawtree(t);

%-------------------------------------% Use the GUI to split or merge Nodes.%-------------------------------------

Page 651: Wavelet ug

readtree

8-143

t = readtree(fig);plot(t)

% Click the node (3,0), (see the plot function).

See Also drawtree

(0,0)

(1,0) (1,1)

(2,0) (2,1)

(3,0) (3,1) (3,2) (3,3)

5 10 15 20 25−3

−2

−1

0

1

2

3data for node: (7) or (3,0).

Page 652: Wavelet ug

scal2frq

8-144

8scal2frqPurpose Scale to frequency.

Syntax F = scal2frq(A,'wname',DELTA)

Description F = scal2frq(A,'wname',DELTA) returns the pseudo-frequencies corresponding to the scales given by A, the wavelet function 'wname' (see wavefun for more information) and the sampling period DELTA.

scal2frq(A,'wname') is equivalent to scal2frq(A,'wname',1).

One of the most frequently asked question is, “How does one map a scale, for a given wavelet and a sampling period, to a kind of frequency?”.

The answer can only be given in a broad sense and it’s better to speak about the pseudo-frequency corresponding to a scale.

A way to do it is to compute the center frequency, Fc, of the wavelet and to use the following relationship.

where

a is a scale.

is the sampling period.

Fc is the center frequency of a wavelet in Hz.

Fa is the pseudo-frequency corresponding to the scale a, in Hz.

The idea is to associate with a given wavelet a purely periodic signal of frequency Fc. The frequency maximizing the fft of the wavelet modulus is Fc. The function centfrq can be used to compute the center frequency and it allows the plotting of the wavelet with the associated approximation based on the center frequency. The figure on the next page shows some examples generated using the centfrq function.

• Four real wavelets: Daubechies wavelets of order 2 and 7, coiflet of order 1, and the Gaussian derivative of order 4.

• Two complex wavelets: the complex Gaussian derivative of order 6 and a Shannon complex wavelet.

Fa∆ Fc⋅

a--------------=

Page 653: Wavelet ug

scal2frq

8-145

Center Frequencies for Real and Complex Wavelets

cgau6 shan1-0.5

coif1 gaus4

db2 db7

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1Wavelet shan1−0.5 (blue) and Center frequency based approximation

Rea

l par

ts

Period: 1.2903; Cent. Freq: 0.775

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1

Imag

inar

y pa

rts

Period: 1.2903; Cent. Freq: 0.775

0 0.5 1 1.5 2 2.5 3−1.5

−1

−0.5

0

0.5

1

1.5

2Wavelet db2 (blue) and Center frequency based approximation

Period: 1.5; Cent. Freq: 0.666670 2 4 6 8 10 12 14

−1.5

−1

−0.5

0

0.5

1

1.5Wavelet db7 (blue) and Center frequency based approximation

Period: 1.4444; Cent. Freq: 0.69231

0 1 2 3 4 5−2

−1.5

−1

−0.5

0

0.5

1

1.5

2

2.5Wavelet coif1 (blue) and Center frequency based approximation

Period: 1.25; Cent. Freq: 0.8−5 0 5

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

1.2Wavelet gaus4 (blue) and Center frequency based approximation

Period: 2; Cent. Freq: 0.5

−5 0 5−1

−0.5

0

0.5

1Wavelet cgau6 (blue) and Center frequency based approximation

Rea

l par

ts

Period: 1.6667; Cent. Freq: 0.6

−5 0 5−1

−0.5

0

0.5

1

Imag

inar

y pa

rts

Period: 1.6667; Cent. Freq: 0.6

Page 654: Wavelet ug

scal2frq

8-146

As you can see, the center frequency based approximation captures the main wavelet oscillations. So the center frequency is a convenient and simple characterization of the leading dominant frequency of the wavelet.

If we accept to associate the frequency Fc to the wavelet function then, when the wavelet is dilated by a factor a, this center frequency becomes Fc / a. Lastly, if the underlying sampling period is , it is natural to associate to the scale a the frequency:

The function scal2frq computes this correspondence.

To illustrate the behavior of this procedure, let us consider the following simple test. We generate sine functions of sensible frequencies F0. For each function, we shall try to detect this frequency by a wavelet decomposition followed by a translation of scale to frequency. More precisely, after a discrete wavelet decomposition, we identify the scale a* corresponding to the maximum value of the energy of the coefficients. The translated frequency F* is then given by:

scal2frq(a_star,'wname',sampling_period)

The F* values are close to the chosen F0. The plots at the end of example 2, presents the periods instead of frequencies. If we change slightly the F0 values, the results remain satisfactory.

Examples Example 1:

% Set sampling period and wavelet name.delta = 0.1; wname = 'coif3';

% Define scales.amax = 7; a = 2.^[1:amax];

% Compute associated pseudo-frequencies.f = scal2frq(a,wname,delta);

% Compute associated pseudo-periods.per = 1./f;

Fa∆ Fc⋅

a--------------=

Page 655: Wavelet ug

scal2frq

8-147

% Display information.disp(' Scale Frequency Period')disp([a' f' per'])

Scale Frequency Period

2.0000 3.5294 0.2833 4.0000 1.7647 0.5667 8.0000 0.8824 1.1333 16.0000 0.4412 2.2667 32.0000 0.2206 4.5333 64.0000 0.1103 9.0667 128.0000 0.0551 18.1333

Example 2:

% Set sampling period and wavelet name.delta = 0.1; wname = 'coif3';

% Define scales. amax = 7;a = 2.^[1:amax];

% Compute associated pseudo-frequencies.f = scal2frq(a,wname,delta);

% Compute associated pseudo-periods.per = 1./f;

% Plot pseudo-periods versus scales.subplot(211), plot(a,per)title(['Wavelet: ',wname, ', Sampling period: ',num2str(delta)])xlabel('Scale')ylabel('Computed pseudo-period')

% For each scale 2^i:% - generate a sine function of period per(i);% - perform a wavelet decomposition;% - identify the highest energy level;% - compute the detected pseudo-period.

Page 656: Wavelet ug

scal2frq

8-148

for i = 1:amax% Generate sine function of period% per(i) at sampling period delta.t = 0:delta:100;x = sin((t.*2*pi)/per(i));% Decompose x at level 9.[c,l] = wavedec(x,9,wname);

% Estimate standard deviation of detail coefficients.stdc = wnoisest(c,l,[1:amax]);% Compute identified period.[y,jmax] = max(stdc);idper(i) = per(jmax);

end

% Compare the detected and computed pseudo-periods.subplot(212), plot(per,idper,'o',per,per)title('Detected vs computed pseudo-period')xlabel('Computed pseudo-period')ylabel('Detected pseudo-period')

20 40 60 80 100 120

5

10

15

Wavelet: coif3, Sampling period: 0.1

Scale

Com

pute

d ps

eudo

−pe

riod

2 4 6 8 10 12 14 16 18

5

10

15

Detected vs computed pseudo−period

Computed pseudo−period

Det

ecte

d ps

eudo

−pe

riod

Page 657: Wavelet ug

scal2frq

8-149

Example 3:

This example demonstrates that, starting from the periodic function x(t) = cos(5t), the scal2frq function translates the scale corresponding to the maximum value of the CWT coefficients to a pseudo-frequency (0.795), which is near to the true frequency (5/(2*pi) =~ 0.796).

% Set wavelet name, interval and number of samples.wname = 'db10';A = -64; B = 64; P = 224;

% Compute the sampling period and the sampled function,% and the true frequency.delta = (B-A)/(P-1);t = linspace(A,B,P);omega = 5; x = cos(omega*t);freq = omega/(2*pi);

% Set scales and use scal2frq to compute the array% of pseudo-frequencies.scales = [0.25:0.25:3.75];TAB_PF = scal2frq(scales,wname,delta);

% Compute the nearest pseudo-frequency% and the corresponding scale.[dummy,ind] = min(abs(TAB_PF-freq));freq_APP = TAB_PF(ind);scale_APP = scales(ind);

% Continuous analysis and plot.str1 = ['224 samples of x = cos(5t) on [-64,64] - ' ... 'True frequency = 5/(2*pi) =~ ' num2str(freq,3)];str2 = ['Array of pseudo-frequencies and scales: '];str3 = [num2str([TAB_PF',scales'],3)];str4 = ['Pseudo-frequency = ' num2str(freq_APP,3)];str5 = ['Corresponding scale = ' num2str(scale_APP,3)];figure; cwt(x,scales,wname,'plot'); ax = gca; colorbaraxTITL = get(ax,'title');axXLAB = get(ax,'xlabel');set(axTITL,'String',str1)set(axXLAB,'String',[str4,' - ' str5])

Page 658: Wavelet ug

scal2frq

8-150

clc ; disp(strvcat(' ',str1,' ',str2,str3,' ',str4,str5))

224 samples of x = cos(5t) on [-64,64] - True frequency = 5/(2*pi) =~ 0.796

Array of pseudo-frequencies and scales: 4.77 0.25 2.38 0.5 1.59 0.75 1.19 1 0.954 1.25 0.795 1.5 0.681 1.75 0.596 2. . . .0.341 3.5 0.318 3.75 Pseudo-frequency = 0.795 Corresponding scale = 1.5

20

40

60

80

100

120

224 samples of x = cos(5t) on [−64,64] − True frequency = 5/(2*pi) =~ 0.796

Pseudo−frequency = 0.795 − Corresponding scale = 1.5

scal

es a

20 40 60 80 100 120 140 160 180 200 220

0.25

0.5

0.75

1

1.25

1.5

1.75

2

2.25

2.5

2.75

3

3.25

3.5

3.75

Page 659: Wavelet ug

scal2frq

8-151

Example 4:

This example demonstrates that, starting from the periodic function x(t) = 5*sin(5t)+3*sin(2t)+2*sin(t), the scal2frq function translates the scales corresponding to the maximum values of the CWT coefficients to pseudo-frequencies ([0.796 0.318 0.159]), which are near to the true frequencies ([5 2 1] / (2*pi) =~ [0.796 0.318 0.159]).

% Set wavelet name,interval and number of samples.wname = 'morl';A = 0; B = 64; P = 500;

% Compute the sampling period and the sampled function,% and the true frequencies.t = linspace(A,B,P);delta = (B-A)/(P-1);tab_OMEGA = [5,2,1];tab_FREQ = tab_OMEGA/(2*pi);tab_COEFS = [5,3,2];x = zeros(1,P);for k = 1:3; x = x+tab_COEFS(k)*sin(tab_OMEGA(k)*t);end

% Set scales and use scal2frq to compute the array% of pseudo-frequencies.scales = [1:1:60];tab_PF = scal2frq(scales,wname,delta);

% Compute the nearest pseudo-frequencies% and the corresponding scales.for k=1:3 [dummy,ind] = min(abs(tab_PF-tab_FREQ(k))); PF_app(k) = tab_PF(ind); SC_app(k) = scales(ind);end

% Continuous analysis and plot. str1 = strvcat( ... '500 samples of x = 5*sin(5t)+3*sin(2t)+2*sin(t) on [0,64]',... ['True frequencies (in Hz): [5 2 1]/(2*pi) =~ [' ...

Page 660: Wavelet ug

scal2frq

8-152

num2str(tab_FREQ,3) ']' ] ... );str2 = ['Array of pseudo-frequencies and scales: '];str3 = [num2str([tab_PF',scales'],3)];str4 = ['Pseudo-frequencies = ' num2str(PF_app,3)];str5 = ['Corresponding scales = ' num2str(SC_app,3)];figure; cwt(x,scales,wname,'plot'); ax = gca; colorbaraxTITL = get(ax,'title');axXLAB = get(ax,'xlabel');set(axTITL,'String',str1)set(axXLAB,'String',strvcat(str4, str5))clc; disp(strvcat(' ',str1,' ',str2,str3,' ',str4,str5)) 500 samples of x = 5*sin(5t)+3*sin(2t)+2*sin(t) on [0,64] True frequencies (in Hz): [5 2 1]/(2*pi) =~ [0.796 0.318 0.159] Array of pseudo-frequencies and scales: 6.33 1 3.17 2 2.11 3 1.58 4 1.27 5 1.06 6 0.905 7 0.792 8 0.704 9 0.633 10

. . . .

. . . .

0.122 52 0.12 53 0.117 54 0.115 55 0.113 56 0.111 57 0.109 58 0.107 59 0.106 60

Page 661: Wavelet ug

scal2frq

8-153

Pseudo-frequencies = 0.792 0.317 0.158 Corresponding scales = 8 20 40

See Also centfrq

References Abry, P. (1997), Ondelettes et turbulence. Multirésolutions, algorithmes de décomposition, invariance d’échelles, Diderot Editeur, Paris.

20

40

60

80

100

120

500 samples of x = 5*sin(5t)+3*sin(2t)+2*sin(t) on [0,64] True frequencies: [5 2 1]/(2*pi) =~ [0.796 0.318 0.159]

Pseudo−frequencies = 0.792 0.317 0.158Corresponding scales = 8 20 40

scal

es a

50 100 150 200 250 300 350 400 450 500 1

4

7

10

13

16

19

22

25

28

31

34

37

40

43

46

49

52

55

58

Page 662: Wavelet ug

set

8-154

8setPurpose Set WPTREE object field content.

Syntax T = set(T,'FieldName1',FieldValue1,'FieldName2',FieldValue2, ...)

Description T = set(T,'FieldName1',FieldValue1,'FieldName2',FieldValue2, ...) sets the content of the specified fields for the WPTREE object T.

For the fields that are objects or structures, you can set the subfield contents, giving the name of these subfields as 'FieldName' values.

The valid choices for 'FieldName'are:

The fields of the wavelet information structure, 'wavInfo', are also valid for 'FieldName':

The fields of the entropy information structure, 'entInfo', are also valid for 'FieldName':

Or fields of DTREE parent object:

'dtree' : DTREE parent object.'wavInfo' : Structure (wavelet information).

'wavName' : Wavelet name.'Lo_D' : Low Decomposition filter.'Hi_D' : High Decomposition filter.'Lo_R' : Low Reconstruction filter.'Hi_R' : High Reconstruction filter.

'entInfo' : Structure (entropy information).

'entName' : Entropy name.'entPar' : Entropy parameter.

'ntree' : NTREE parent object.'allNI' : All nodes information.'terNI' : Terminal nodes information.

Page 663: Wavelet ug

set

8-155

Or fields of NTREE parent object:

Or fields of WTBO parent object:

Caution The set function should only be used to set the field 'ud'.

See Also disp, get, read, write

'wtbo' : WTBO parent object.'order' : Order of the tree.'depth' : Depth of the tree.'spsch' : Split scheme for nodes.'tn' : Array of terminal nodes of the tree.

'wtboInfo' : Object information.'ud' : Userdata field.

Page 664: Wavelet ug

shanwavf

8-156

8shanwavfPurpose Shannon wavelets.

Syntax [PSI,X] = shanwavf(LB,UB,N,FB,FC)

Description [PSI,X] = shanwavf(LB,UB,N,FB,FC) returns values of the complex Shannon wavelet defined by a bandwidth parameter FB, a wavelet center frequency FC and the expression:

PSI(X) = (FB^0.5)*(sinc(FB*X).*exp(2*i*pi*FC*X))

on an N point regular grid in the interval [LB,UB].

FB and FC must be such that: FC > FB/2 > 0

Output arguments are the wavelet function PSI computed on the grid X.

Examples % Set bandwidth and center frequency parameters.fb = 1; fc = 1.5;

% Set effective support and grid parameters.lb = -20; ub = 20; n = 1000; % Compute complex Shannon wavelet shan1-1.5.[psi,x] = shanwavf(lb,ub,n,fb,fc);

% Plot complex Shannon wavelet.subplot(211)plot(x,real(psi)),title('Complex Shannon wavelet shan1-1.5')xlabel('Real part'), grid

Page 665: Wavelet ug

shanwavf

8-157

subplot(212)plot(x,imag(psi))xlabel('Imaginary part'), grid

See Also waveinfo

References Teolis, A. (1998), Computational signal processing with wavelets, Birkhauser, p. 62.

−20 −15 −10 −5 0 5 10 15 20−0.5

0

0.5

1

1.5Complex Shannon wavelet shan1−1.5

Real part

−20 −15 −10 −5 0 5 10 15 20−1

−0.5

0

0.5

1

Imaginary part

Page 666: Wavelet ug

swt

8-158

8swtPurpose Discrete stationary wavelet transform 1-D.

Syntax SWC = swt(X,N,'wname')SWC = swt(X,N,Lo_D,Hi_D)[SWA,SWD] = swt(X,N,'wname')[SWA,SWD] = swt(X,N,Lo_D,Hi_D)

Description swt performs a multilevel 1-D stationary wavelet decomposition using either a specific orthogonal wavelet ('wname' see wfilters for more information) or specific orthogonal wavelet decomposition filters.

SWC = swt(X,N,'wname') computes the stationary wavelet decomposition of the signal X at level N, using 'wname'.

N must be a strictly positive integer (see wmaxlev for more information) and

length(X) must be a multiple of 2N .

SWC = swt(X,N,Lo_D,Hi_D), computes the stationary wavelet decomposition as above, given these filters as input:

• Lo_D is the decomposition low-pass filter.

• Hi_D is the decomposition high-pass filter.

Lo_D and Hi_D must be the same length.

The output matrix SWC contains the vectors of coefficients stored row-wise:

for 1 ≤ i ≤ N, the output matrix SWC(i,:) contains the detail coefficients of level i and SWC(N+1,:) contains the approximation coefficients of level N.

[SWA,SWD] = swt(…) computes approximations, SWA, and details, SWD, stationary wavelet coefficients.

The vectors of coefficients are stored row-wise:

for 1 ≤ i ≤ N, the output matrix SWA(i,:) contains the approximation coefficients of level i and the output matrix SWD(i,:) contains the detail coefficients of level i.

Examples % Load original 1D signal.load noisbloc; s = noisbloc;

Page 667: Wavelet ug

swt

8-159

% Perform SWT decomposition at level 3 of s using db1.[swa,swd] = swt(s,3,'db1');

% Plots of SWT coefficients of approximations and details% at levels 3 to 1.

% Using some plotting commands,% the following figure is generated.

Algorithm Given a signal s of length N, the first step of the SWT produces, starting from s, two sets of coefficients: approximation coefficients cA1 and detail coefficients cD1. These vectors are obtained by convolving s with the low-pass filter Lo_D for approximation, and with the high-pass filter Hi_D for detail.

200 400 600 800 1000

0

10

20Original signal s.

200 400 600 800 1000

0

10

20Original signal s.

200 400 600 800 1000

0

20

40

200 400 600 800 1000

−10

0

10

200 400 600 800 1000−10

0102030

200 400 600 800 1000

−10

0

10

200 400 600 800 1000

0

10

20

SWT Coefs: approx. at levels 3, 2 and 1200 400 600 800 1000

−5

0

5

SWT Coefs: detail at levels 3, 2 and 1

Page 668: Wavelet ug

swt

8-160

More precisely, the first step is:

Note cA1 and cD1 are of length N instead of N/2 as in the DWT case.

The next step splits the approximation coefficients cA1 in two parts using the same scheme. But, with modified filters obtained by upsampling the filters used for the previous step and replacing s by cA1. Then, the SWT produces cA2 and cD2. More generally:

s

Lo_D

Hi_D

high-pass

approximation coefs

cA1

cD1

detail coefs

low-pass

where: X Convolve with filter X

One-Dimensional SWTDecomposition step

Fj

Gj

cAj

Initialization

Convolve with filter X

cA0 = s

where: X

cAj+1

cDj+1

level j+1level j

Upsample2

Fj

Initialization F0 = Lo_D

Fj+1

Gj

Initialization G0 = Hi_D

Gj+1

where:

2

2

Page 669: Wavelet ug

swt

8-161

See Also dwt, wavedec

References Nason, G.P.; B.W. Silverman (1995), “The stationary wavelet transform and some statistical applications,” Lecture Notes in Statistics, 103, pp. 281–299.

Coifman, R.R.; Donoho D.L. (1995), “Translation invariant de-noising,” Lecture Notes in Statistics, 103, pp. 125–150.

Pesquet, J.C.; H. Krim, H. Carfatan (1996), “Time-invariant orthonormal wavelet representations,” IEEE Trans. Sign. Proc., vol. 44, 8, pp. 1964–1970.

Page 670: Wavelet ug

swt2

8-162

8swt2Purpose Discrete stationary wavelet transform 2-D.

Syntax SWC = swt2(X,N,'wname')[A,H,V,D] = swt2(X,N,'wname')SWC = swt2(X,N,Lo_D,Hi_D)[A,H,V,D] = swt2(X,N,Lo_D,Hi_D)

Description swt2 performs a multilevel 2-D stationary wavelet decomposition using either a specific orthogonal wavelet ('wname' see wfilters for more information) or specific orthogonal wavelet decomposition filters.

SWC = swt2(X,N,'wname') or [A,H,V,D] = swt2(X,N,'wname') compute the stationary wavelet decomposition of the matrix X at level N, using 'wname'.

N must be a strictly positive integer (see wmaxlev for more information), and 2N

must divide size(X,1) and size(X,2).

Outputs [A,H,V,D] are 3-D arrays, which contain the coefficients:

for 1 ≤ i ≤ N, the output matrix A(:,:,i) contains the coefficients of approximation of level i.The output matrices H(:,:,i), V(:,:,i) and D(:,:,i) contain the coefficients of details of level i (Horizontal, Vertical and Diagonal):SWC = [H(:,:,1:N) ; V(:,:,1:N) ; D(:,:,1:N) ; A(:,:,N)]

SWC = swt2(X,N,Lo_D,Hi_D) or [A,H,V,D] = swt2(X,N,Lo_D,Hi_D), computes the stationary wavelet decomposition as above, given these filters as input:

• Lo_D is the decomposition low-pass filter.

• Hi_D is the decomposition high-pass filter.

Lo_D and Hi_D must be the same length.

Page 671: Wavelet ug

swt2

8-163

Examples % Load original image.load nbarb1;

% Image coding.nbcol = size(map,1);cod_X = wcodemat(X,nbcol);

% Visualize the original image.subplot(221)image(cod_X)title('Original image');colormap(map)

% Perform SWT decomposition% of X at level 3 using sym4.[ca,chd,cvd,cdd] = swt2(X,3,'sym4');

% Visualize the decomposition.

for k = 1:3 % Images coding for level k. cod_ca = wcodemat(ca(:,:,k),nbcol); cod_chd = wcodemat(chd(:,:,k),nbcol); cod_cvd = wcodemat(cvd(:,:,k),nbcol); cod_cdd = wcodemat(cdd(:,:,k),nbcol); decl = [cod_ca,cod_chd;cod_cvd,cod_cdd];

% Visualize the coefficients of the decomposition % at level k. subplot(2,2,k+1) image(decl) title(['SWT dec.: approx. ', ... 'and det. coefs (lev. ',num2str(k),')']); colormap(map)end

Page 672: Wavelet ug

swt2

8-164

% Editing some graphical properties,% the following figure is generated.

Algorithm For images, an algorithm similar to the one-dimensional case is possible for two-dimensional wavelets and scaling functions obtained from one-dimensional ones by tensor product.

This kind of two-dimensional SWT leads to a decomposition of approximation coefficients at level j in four components: the approximation at level j+1, and the details in three orientations (horizontal, vertical, and diagonal).

The following chart describes the basic decomposition step for images:

Original image

20 40 60 80 100 120

20

40

60

80

100

120

SWT dec.: approx. and det. coefs (lev. 1)

50 100 150 200 250

50

100

150

200

250

SWT dec.: approx. and det. coefs (lev. 2)

50 100 150 200 250

50

100

150

200

250

SWT dec.: approx. and det. coefs (lev. 3)

50 100 150 200 250

50

100

150

200

250

Page 673: Wavelet ug

swt2

8-165

Two-Dimensional SWT

Decomposition step

rows

Fj

Gj

rows

cAj

columns

Initialization

Convolve with filter X the rows of the entry

Convolve with filter X the columns of the entry

cA0 = s for the decomposition initialization

where

X

columns

Gj

Fj

X

columns

columns

Gj

Fj

cAj+1

cDj+1

cDj+1

cDj+1

(h)

(v)

(d)

horizontal

vertical

diagonal

rows

columns

Upsample2

Fj

Initialization F0 = Lo_D

Fj+1

Gj

Initialization G0 = Hi_D

Gj+1

where:

2

2

size(cAj) = size(cDj )(h)

= sNote = size(cDj )(v) = size(cDj )

(d)

Where s = size of the analyzed image

Page 674: Wavelet ug

swt2

8-166

See Also dwt2, wavedec2

References Nason, G.P.; B.W. Silverman (1995), “The stationary wavelet transform and some statistical applications,” Lecture Notes in Statistics, 103, pp. 281–299.

Coifman, R.R.; Donoho D.L. (1995), “Translation invariant de-noising,” Lecture Notes in Statistics, 103, pp. 125–150.

Pesquet, J.C.; H. Krim, H. Carfatan (1996), “Time-invariant orthonormal wavelet representations,” IEEE Trans. Sign. Proc., vol. 44, 8, pp. 1964–1970.

Page 675: Wavelet ug

symaux

8-167

8symauxPurpose Symlet wavelet filter computation.

Syntax W = SYMAUX(N,SUMW)W = SYMAUX(N)

Description Symlets are the "least asymmetric" Daubechies’ wavelets.

W = SYMAUX(N,SUMW) is the order N Symlet scaling filter such that SUM(W) = SUMW. Possible values for N are: 1, 2, 3, …

Note Instability may occur when N is too large.

W = SYMAUX(N) is equivalent to W = SYMAUX(N,1)

W = SYMAUX(N,0) is equivalent to W = SYMAUX(N,1)

Examples % Generate wdb4 the order 4 Daubechies scaling filter.wdb4 = dbaux(4)

wdb4 =

Columns 1 through 7

0.1629 0.5055 0.4461 -0.0198 -0.1323 0.0218 0.0233

Column 8

-0.0075

% wdb4 is a solution of the equation: P = conv(wrev(w),w)*2,% where P is the "Lagrange à trous" filter for N=4.% wdb4 is a minimum phase solution of the previous equation,% based on the roots of P (see dbaux).P = conv(wrev(wdb4),wdb4)*2;

Page 676: Wavelet ug

symaux

8-168

% Generate wsym4 the order 4 symlet scaling filter.% The Symlets are the "least asymmetric" Daubechies' % wavelets obtained from another choice between the roots of P.wsym4 = symaux(4)

wsym4 =

Columns 1 through 7

0.0228 -0.0089 -0.0702 0.2106 0.5683 0.3519 -0.0210

Column 8

-0.0536

% Compute conv(wrev(wsym4),wsym4) * 2 and check that wsym4% is another solution of the equation P = conv(wrev(w),w)*2.Psym = conv(wrev(wsym4),wsym4)*2;err = norm(P-Psym)

err =

7.4988e-016

See Also symwavf, wfilters

Page 677: Wavelet ug

symwavf

8-169

8symwavfPurpose Symlet wavelet filter.

Syntax F = symwavf(W)

Description F = symwavf(W) returns the scaling filter associated with the symlet wavelet specified by the string W where W = ’symN’. Possible values for N are: 2, 3, …, 45.

Examples % Compute the scaling filter corresponding to wavelet sym4. w = symwavf('sym4')

w =Columns 1 through 7

0.0228 -0.0089 -0.0702 0.2106 0.5683 0.3519 -0.0210Column 8

-0.0536

See Also symaux, waveinfo

Page 678: Wavelet ug

thselect

8-170

8thselectPurpose Threshold selection for de-noising.

Syntax THR = thselect(X,TPTR)

Description thselect is a one-dimensional de-noising oriented function.

THR = thselect(X,TPTR) returns threshold X-adapted value using selection rule defined by string TPTR.

Available selection rules are:

TPTR = 'rigrsure', adaptive threshold selection using principle of Stein’s Unbiased Risk Estimate.

TPTR = 'heursure', heuristic variant of the first option.

TPTR = 'sqtwolog', threshold is sqrt(2*log(length(X))).

TPTR = 'minimaxi', minimax thresholding.

Threshold selection rules are based on the underlying model y = f(t) + e where e is a white noise N(0,1). Dealing with unscaled or nonwhite noise can be handled using rescaling output threshold THR (see SCAL parameter in wden for more information).

Available options are:

• tptr = 'rigrsure' uses for the soft threshold estimator a threshold selection rule based on Stein’s Unbiased Estimate of Risk (quadratic loss function). One gets an estimate of the risk for a particular threshold value t. Minimizing the risks in t gives a selection of the threshold value.

• tptr = 'sqtwolog' uses a fixed-form threshold yielding minimax performance multiplied by a small factor proportional to log(length(X)).

• tptr = 'heursure' is a mixture of the two previous options. As a result, if the signal to noise ratio is very small, the SURE estimate is very noisy. If such a situation is detected, the fixed form threshold is used.

• tptr = 'minimaxi' uses a fixed threshold chosen to yield minimax performance for mean square error against an ideal procedure. The minimax principle is used in statistics in order to design estimators. Since the de-noised signal can be assimilated to the estimator of the unknown regression function, the minimax estimator is the one that realizes the

Page 679: Wavelet ug

thselect

8-171

minimum of the maximum mean square error obtained for the worst function in a given set.

Examples % The current extension mode is zero-padding (see dwtmode).

% Generate Gaussian white noise.init = 2055415866; randn('seed',init); x = randn(1,1000);

% Find threshold for each selection rule. % Adaptive threshold using SURE. thr = thselect(x,'rigrsure') thr =

1.8065

% Fixed form threshold. thr = thselect(x,'sqtwolog') thr =

3.7169

% Heuristic variant of the first option. thr = thselect(x,'heursure') thr =

3.7169

% Minimax threshold. thr = thselect(x,'minimaxi') thr =

2.2163

See Also wden

References Donoho, D.L. (1993), “Progress in wavelet analysis and WVD: a ten minute tour,” in Progress in wavelet analysis and applications, Y. Meyer, S. Roques, pp. 109–128. Frontières Ed. Donoho, D.L.; I.M. Johnstone (1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.Donoho, D.L. (1995), “De-noising by soft-thresholding,” IEEE Trans. on Inf. Theory, 41, 3, pp. 613–627.

Page 680: Wavelet ug

tnodes

8-172

8tnodesPurpose Determine terminal nodes.

Syntax N = tnodes(T)N = tnodes(T,'deppos')[N,K] = tnodes(T)[N,K] = tnodes(T,'deppos')

Description tnodes is a tree-management utility.

N = tnodes(T) returns the indices of terminal nodes of the tree T. N is a column vector.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

N = tnodes(T,'deppos') returns a matrix N, which contains the depths and positions of terminal nodes.

N(i,1) is the depth of i-th terminal node. N(i,2) is the position of i-th terminal node.

For [N,K] = tnodes(T) or [N,K] = tnodes(T,'deppos'), M = N(K) are the indices reordered as in tree T, from left to right.

Examples % Create initial tree. ord = 2; t = ntree(ord,3); % Binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

(0,0)

Page 681: Wavelet ug

tnodes

8-173

% Change Node Label from Depth_Position to Index% (see the plot function).

% List terminal nodes (index). tnodes(t)

ans =45781314

% List terminal nodes (Depth_Position). tnodes(t,'deppos')ans =

2 1 2 2 3 0 3 1 3 6 3 7

See Also leaves, noleaves, wtreemgr

(1) (2)

(3) (4) (5) (6)

(7) (8) (13) (14)

(0)

Page 682: Wavelet ug

treedpth

8-174

8treedpthPurpose Tree depth.

Syntax D = treedpth(T)

Description treedpth is a tree-management utility.

D = treedpth(T) returns the depth D of the tree T.

Examples % Create binary tree (tree of order 2) of depth 3. t = ntree(2,3);

% Plot tree t. plot(t)

% Tree depth. treedpth(t)

ans =3

See Also wtreemgr

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 683: Wavelet ug

treeord

8-175

8treeordPurpose Tree order.

Syntax ORD = treeord(T)

Description treeord is a tree-management utility.

ORD = treeord(T) returns the order ORD of the tree T.

Examples % Create binary tree (tree of order 2) of depth 3. t = ntree(2,3);

% Plot tree t. plot(t)

% Tree order. treeord(t)

ans =2

See Also wtreemgr

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 684: Wavelet ug

upcoef

8-176

8upcoefPurpose Direct reconstruction from 1-D wavelet coefficients.

Syntax Y = upcoef(O,X,'wname',N)Y = upcoef(O,X,'wname',N,L)Y = upcoef(O,X,Lo_R,Hi_R,N)Y = upcoef(O,X,Lo_R,Hi_R,N,L)Y = upcoef(O,X,'wname')Y = upcoef(O,X,Lo_R,Hi_R)

Description upcoef is a one-dimensional wavelet analysis function.

Y = upcoef(O,X,’wname’,N) computes the N-step reconstructed coefficients of vector X.

’wname’ is a string containing the wavelet name. See wfilters for more information.

N must be a strictly positive integer.

If O = 'a', approximation coefficients are reconstructed.

If O = 'd', detail coefficients are reconstructed.

Y = upcoef(O,X,’wname’,N,L) computes the N-step reconstructed coefficients of vector X and takes the length-L central portion of the result.

Instead of giving the wavelet name, you can give the filters.

For Y = upcoef(O,X,Lo_R,Hi_R,N) or Y = upcoef(O,X,Lo_R,Hi_R,N,L), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

Y = upcoef(O,X,’wname’) is equivalent to Y = upcoef(O,X,’wname’,1).

Y = upcoef(O,X,Lo_R,Hi_R) is equivalent to Y = upcoef(O,X,Lo_R,Hi_R,1).

Examples % The current extension mode is zero-padding (see dwtmode).

% Approximation signals, obtained from a single coefficient % at levels 1 to 6. cfs = [1]; % Decomposition reduced a single coefficient. essup = 10; % Essential support of the scaling filter db6. figure(1)

Page 685: Wavelet ug

upcoef

8-177

for i=1:6 % Reconstruct at the top level an approximation % which is equal to zero except at level i where only % one coefficient is equal to 1. rec = upcoef('a',cfs,'db6',i);

% essup is the essential support of the % reconstructed signal.

% rec(j) is very small when j is >= essup. ax = subplot(6,1,i),h = plot(rec(1:essup)); set(ax,'xlim',[1 325]); essup = essup*2;

end subplot(611) title(['Approximation signals, obtained from a single ' ...

'coefficient at levels 1 to 6'])

% Editing some graphical properties,% the following figure is generated.

Page 686: Wavelet ug

upcoef

8-178

% The same can be done for details. % Details signals, obtained from a single coefficient % at levels 1 to 6.

cfs = [1]; mi = 12; ma = 30; % Essential support of

% the wavelet filter db6. rec = upcoef('d',cfs,'db6',1); figure(2) subplot(611), plot(rec(3:12)) for i=2:6

% Reconstruct at top level a single detail % coefficient at level i. rec = upcoef('d',cfs,'db6',i); subplot(6,1,i), plot(rec(mi*2^(i-2):ma*2^(i-2)))

end subplot(611) title(['Detail signals obtained from a single ' ...

50 100 150 200 250 300−1

01

Approximation signals, obtained from a single coefficient at levels 1 to 6

50 100 150 200 250 300−1

01

50 100 150 200 250 300−0.5

00.5

50 100 150 200 250 300−0.5

00.5

50 100 150 200 250 300−0.2

00.2

50 100 150 200 250 300−0.2

00.2

Page 687: Wavelet ug

upcoef

8-179

'coefficient at levels 1 to 6'])% Editing some graphical properties,% the following figure is generated.

Algorithm upcoef is equivalent to an N time repeated use of the inverse wavelet transform.

See Also idwt

1 2 3 4 5 6 7 8 9−1

01

Detail signals obtained from a single coefficient at levels 1 to 6

2 4 6 8 10 12 14 16 18−1

01

5 10 15 20 25 30 35−0.5

00.5

10 20 30 40 50 60 70−0.5

00.5

20 40 60 80 100 120 140−0.2

00.2

50 100 150 200 250−0.2

00.2

Page 688: Wavelet ug

upcoef2

8-180

8upcoef2Purpose Direct reconstruction from 2-D wavelet coefficients.

Syntax Y = upcoef2(O,X,'wname',N,S)Y = upcoef2(O,X,Lo_R,Hi_R,N,S)Y = upcoef2(O,X,'wname',N)Y = upcoef2(O,X,Lo_R,Hi_R,N)Y = upcoef2(O,X,'wname')Y = upcoef2(O,X,Lo_R,Hi_R)

Description upcoef2 is a two-dimensional wavelet analysis function.

Y = upcoef2(O,X,’wname’,N,S) computes the N-step reconstructed coefficients of matrix X and takes the central part of size S. ’wname’ is a string containing the name of the wavelet. See wfilters for more information.

If O = ’a’, approximation coefficients are reconstructed; otherwise if O = 'h' ('v' or 'd', respectively), horizontal (vertical or diagonal, respectively) detail coefficients are reconstructed. N must be a strictly positive integer.

Instead of giving the wavelet name, you can give the filters.

For Y = upcoef2(O,X,Lo_R,Hi_R,N,S), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

Y = upcoef2(O,X,’wname’,N) or Y = upcoef2(O,X,Lo_R,Hi_R,N) returns the computed result without any truncation.

Y = upcoef2(O,X,’wname’) is equivalent to Y = upcoef2(O,X,’wname’,1).

Y = upcoef2(O,X,Lo_R,Hi_R) is equivalent to Y = upcoef2(O,X,Lo_R,Hi_R,1).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman; % X contains the loaded image.

% Perform decomposition at level 2 % of X using db4. [c,s] = wavedec2(X,2,'db4');

Page 689: Wavelet ug

upcoef2

8-181

% Reconstruct approximation and details % at level 1, from coefficients. % This can be done using wrcoef2, or % equivalently using: % % Step 1: Extract coefficients from the % decomposition structure [c,s]. % % Step 2: Reconstruct using upcoef2.

siz = s(size(s,1),:);

ca1 = appcoef2(c,s,'db4',1); a1 = upcoef2('a',ca1,'db4',1,siz);

chd1 = detcoef2('h',c,s,1); hd1 = upcoef2('h',chd1,'db4',1,siz);

cvd1 = detcoef2('v',c,s,1); vd1 = upcoef2('v',cvd1,'db4',1,siz);

cdd1 = detcoef2('d',c,s,1); dd1 = upcoef2('d',cdd1,'db4',1,siz);

Algorithm See upcoef.

See Also idwt2

Page 690: Wavelet ug

upwlev

8-182

8upwlevPurpose Single-level reconstruction of 1-D wavelet decomposition.

Syntax [NC,NL,cA] = upwlev(C,L,'wname')[NC,NL,cA] = upwlev(C,L,Lo_R,Hi_R)

Description upwlev is a one-dimensional wavelet analysis function.

[NC,NL,cA] = upwlev(C,L,’wname’) performs the single-level reconstruction of the wavelet decomposition structure [C,L] giving the new one [NC,NL], and extracts the last approximation coefficients vector cA.

[C,L] is a decomposition at level n = length(L)-2, so [NC,NL] is the same decomposition at level n-1 and cA is the approximation coefficients vector at level n.

’wname’ is a string containing the wavelet name, C is the original wavelet decomposition vector, and L the corresponding bookkeeping vector (for detailed storage information, see wavedec).

Instead of giving the wavelet name, you can give the filters.

For [NC,NL,cA] = upwlev(C,L,Lo_R,Hi_R), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original one-dimensional signal.load sumsin; s = sumsin;

% Perform decomposition at level 3 of s using db1. [c,l] = wavedec(s,3,'db1'); subplot(311); plot(s); title('Original signal s.'); subplot(312); plot(c); title('Wavelet decomposition structure, level 3') xlabel(['Coefs for approx. at level 3 ' ... 'and for det. at levels 3, 2 and 1'])

Page 691: Wavelet ug

upwlev

8-183

% One step reconstruction of the wavelet decomposition % structure at level 3 [c,l], so the new structure [nc,nl] % is the wavelet decomposition structure at level 2. [nc,nl] = upwlev(c,l,'db1'); subplot(313); plot(nc); title('Wavelet decomposition structure, level 2') xlabel(['Coefs for approx. at level 2 ' ...

'and for det. at levels 2 and 1'])

% Editing some graphical properties,% the following figure is generated.

See Also idwt, upcoef, wavedec

0 200 400 600 800 1000−5

0

5Original signal s.

0 200 400 600 800 1000−10

0

10Wavelet decomposition structure, level 3

Coefs for approx. at level 3 and for det. at levels 3, 2 and 1

0 200 400 600 800 1000−5

0

5Wavelet decomposition structure, level 2

Coefs for approx. at level 2 and for det. at levels 2 and 1

Page 692: Wavelet ug

upwlev2

8-184

8upwlev2Purpose Single-level reconstruction of 2-D wavelet decomposition.

Syntax [NC,NS,cA] = upwlev2(C,S,'wname')[NC,NS,cA] = upwlev2(C,S,Lo_R,Hi_R)

Description upwlev2 is a two-dimensional wavelet analysis function.

[NC,NS,cA] = upwlev2(C,S,’wname’) performs the single-level reconstruction of wavelet decomposition structure [C,S] giving the new one [NC,NS], and extracts the last approximation coefficients matrix cA.

[C,S] is a decomposition at level n = size(S,1)-2, so [NC,NS] is the same decomposition at level n-1 and cA is the approximation matrix at level n.

’wname’ is a string containing the wavelet name, C is the original wavelet decomposition vector, and S the corresponding bookkeeping matrix (for detailed storage information, see wavedec2).

Instead of giving the wavelet name, you can give the filters.

For [NC,NS,cA] = upwlev2(C,S,Lo_R,Hi_R), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman; % X contains the loaded image.

% Perform decomposition at level 2 % of X using db1. [c,s] = wavedec2(X,2,'db1');sc = size(c)

sc =1 65536

val_s = s

Page 693: Wavelet ug

upwlev2

8-185

val_s =64 64 64 64 128 128 256 256

% One step reconstruction of wavelet % decomposition structure [c,s]. [nc,ns] = upwlev2(c,s,'db1');snc = size(nc)

snc =1 65536

val_ns = ns

val_ns =128 128 128 128 256 256

See Also idwt2, upcoef2, wavedec2

Page 694: Wavelet ug

wavedec

8-186

8wavedecPurpose Multilevel 1-D wavelet decomposition.

Syntax [C,L] = wavedec(X,N,'wname')[C,L] = wavedec(X,N,Lo_D,Hi_D)

Description wavedec performs a multilevel one-dimensional wavelet analysis using either a specific wavelet (’wname’) or a specific wavelet decomposition filters (Lo_D and Hi_D, see wfilters).

[C,L] = wavedec(X,N,’wname’) returns the wavelet decomposition of the signal X at level N, using ’wname’. N must be a strictly positive integer (see wmaxlev for more information). The output decomposition structure contains the wavelet decomposition vector C and the bookkeeping vector L. The structure is organized as in this level-3 decomposition example:

[C,L] = wavedec(X,N,Lo_D,Hi_D) returns the decomposition structure as above, given the low- and high-pass decomposition filters you specify.

X

cA1 cD1

cA2 cD2

cA3 cD3

C:

L:

Decomposition:

cD1cD2cA3 cD3

cA3length of

cD3length of

cD2

length of length ofX

length ofcD1

Page 695: Wavelet ug

wavedec

8-187

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original one-dimensional signal. load sumsin; s = sumsin; % Perform decomposition at level 3 of s using db1. [c,l] = wavedec(s,3,'db1');

% Using some plotting commands,% the following figure is generated.

Algorithm Given a signal s of length N, the DWT consists of log2 N stages at most. The first step produces, starting from s, two sets of coefficients: approximation coefficients CA1, and detail coefficients CD1. These vectors are obtained by convolving s with the low-pass filter Lo_D for approximation, and with the high-pass filter Hi_D for detail, followed by dyadic decimation (downsampling).

100 200 300 400 500 600 700 800 900

−2

−1

0

1

2

Original signal s.

100 200 300 400 500 600 700 800 900

−4

−2

0

2

4

Wavelet decomposition structure

Coefs for approx. at level 3 and for det. at levels 3, 2 and 1

Page 696: Wavelet ug

wavedec

8-188

More precisely, the first step is:

The length of each filter is equal to 2N. If n = length(s), the signals F and G are of length n + 2N - 1 and the coefficients cA1 and cD1 are of length:

The next step splits the approximation coefficients cA1 in two parts using the same scheme, replacing s by cA1, and producing cA2 and cD2, and so on.

s

Lo_D

Hi_D

high-pass

F

G

downsample

downsample approximation coefs

cA1

cD1

2

detail coefs

low-pass

2

where:

2

X Convolve with filter X

Keep the even indexed elements(We call this operation downsampling.)

floorn 1–

2-------------

N+

One-Dimensional DWTDecomposition step

Lo_D

Hi_D

cAj

2

Initialization

Convolve with filter X

Downsample

cA0 = s

where:

2

2

X

cAj+1

cDj+1

level j+1level j

Page 697: Wavelet ug

wavedec

8-189

The wavelet decomposition of the signal s analyzed at level j has the following structure: [cAj, cDj, ..., cD1].

This structure contains, for J = 3, the terminal nodes of the following tree:

See Also dwt, waveinfo, wfilters, wmaxlev

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp 674–693.

Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)

s

cD1

cD2

cD3cA3

cA1

cA2

Page 698: Wavelet ug

wavedec2

8-190

8wavedec2Purpose Multilevel 2-D wavelet decomposition.

Syntax [C,S] = wavedec2(X,N,'wname')[C,S] = wavedec2(X,N,Lo_D,Hi_D)

Description wavedec2 is a two-dimensional wavelet analysis function.

[C,S] = wavedec2(X,N,’wname’) returns the wavelet decomposition of the matrix X at level N, using the wavelet named in string ’wname’ (see wfilters for more information).

Outputs are the decomposition vector C and the corresponding bookkeeping matrix S.

N must be a strictly positive integer (see wmaxlev for more information).

Instead of giving the wavelet name, you can give the filters.

For [C,S] = wavedec2(X,N,Lo_D,Hi_D), Lo_D is the decomposition low-pass filter and Hi_D is the decomposition high-pass filter.

Vector C is organized as:

C = [ A(N) | H(N) | V(N) | D(N) | ...

H(N-1) | V(N-1) | D(N-1) | ... | H(1) | V(1) | D(1) ].

where A, H, V, D, are row vectors such that:

A = approximation coefficients

H = horizontal detail coefficients

V = vertical detail coefficients

D = diagonal detail coefficients

each vector is the vector column-wise storage of a matrix.

Matrix S is such that:

S(1,:) = size of approximation coefficients(N)

S(i,:) = size of detail coefficients(N-i+2) for i = 2, ...N+1 and S(N+2,:) = size(X).

Page 699: Wavelet ug

wavedec2

8-191

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman; % X contains the loaded image.

% Perform decomposition at level 2 % of X using db1. [c,s] = wavedec2(X,2,'db1');

% Decomposition structure organization. sizex = size(X)

sizex =256 256

sizec = size(c)

sizec =1 65536val_s = s

cAn

coefs (3n+1 sections)

cHn cVn cDn cHn–1 cVn–1 cDn–1 cH1 cV1 cD1...

32 32

...

32 32

256 256

sizes (n+2-by-2)

512 512 X

Page 700: Wavelet ug

wavedec2

8-192

val_s =64 64 64 64 128 128 256 256

Algorithm For images, an algorithm similar to the one-dimensional case is possible for two-dimensional wavelets and scaling functions obtained from one-dimensional ones by tensor product.

This kind of two-dimensional DWT leads to a decomposition of approximation coefficients at level j in four components: the approximation at level j+1, and the details in three orientations (horizontal, vertical, and diagonal).

The following chart describes the basic decomposition step for images:

Two-Dimensional DWT

Decomposition step

rows

Lo_D

Hi_D

rows

cAj

2 1

columns

Initialization

Downsample columns: keep the even indexed columns

Downsample rows: keep the even indexed rows

Convolve with filter X the rows of the entry

Convolve with filter X the columns of the entry

cA0 = s for the decomposition initialization

where

2 1

21

21

21

21

2 1

21

X

columns

Hi_D

Lo_D

X

columns

columns

Hi_D

Lo_D

cAj+1

cDj+1

cDj+1

cDj+1

(h)

(v)

(d)

horizontal

vertical

diagonal

rows

columns

Page 701: Wavelet ug

wavedec2

8-193

So, for J=2, the two-dimensional wavelet tree has the form:

See Also dwt, waveinfo, wfilters, wmaxlev

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

Meyer, Y. (1990), Ondelettes et opérateurs, Tome 1, Hermann Ed. (English translation: Wavelets and operators, Cambridge Univ. Press. 1993.)

cA2

cD h1 cD d

1 cD v1

cD h2 cD d

2 cD v2

s

cA1

Page 702: Wavelet ug

wavedemo

8-194

8wavedemoPurpose Wavelet Toolbox demos.

Syntax wavedemo

Description wavedemo brings up a GUI that allows you to choose between several Wavelet Toolbox demos.

Page 703: Wavelet ug

wavefun

8-195

8wavefunPurpose Wavelet and scaling functions.

Syntax [PHI,PSI,XVAL] = wavefun('wname',ITER)[PHI1,PSI1,PHI2,PSI2,XVAL] = wavefun('wname',ITER)[PSI,XVAL] = wavefun('wname',ITER)[...] = wavefun('wname',A,B)

Description The function wavefun returns approximations of the wavelet function 'wname' and the associated scaling function, if it exists. The positive integer ITER determines the number of iterations computed; thus, the refinement of the approximations.

For an orthogonal wavelet:

[PHI,PSI,XVAL] = wavefun('wname',ITER) returns the scaling and wavelet functions on the points grid XVAL.

For a biorthogonal wavelet:

[PHI1,PSI1,PHI2,PSI2,XVAL] = wavefun('wname',ITER) returns the scaling and wavelet functions both for decomposition (PHI1,PSI1) and for reconstruction (PHI2,PSI2).

For a Meyer wavelet:

[PHI,PSI,XVAL] = wavefun('wname',ITER)

For a wavelet without scaling function (e.g., Morlet, Mexican Hat, Gaussian derivatives wavelets or complex wavelets):

[PSI,XVAL] = wavefun('wname',ITER)

[...] = wavefun('wname',A,B), where A and B are positive integers, is equivalent to [...] = wavefun('wname',max(A,B)), and draws plots.

When A is set equal to the special value 0,

[...] = wavefun('wname',0) is equivalent to

[...] = wavefun('wname',8,0).

[...] = wavefun('wname') is equivalent to

[...] = wavefun('wname',8).

The output arguments are optional.

Page 704: Wavelet ug

wavefun

8-196

Examples On the following graph, 10 piecewise linear approximations of the sym4 wavelet obtained after each iteration of the cascade algorithm are shown.

% Set number of iterations and wavelet name. iter = 10;wav = 'sym4';

% Compute approximations of the wavelet function using the% cascade algorithm. for i = 1:iter

[phi,psi,xval] = wavefun(wav,i); plot(xval,psi); hold on

endtitle(['Approximations of the wavelet ',wav, ...

' for 1 to ',num2str(iter),' iterations']); hold off

Algorithm For compactly supported wavelets defined by filters, in general no closed form analytic formula exists.

0 1 2 3 4 5 6 7−1.5

−1

−0.5

0

0.5

1

1.5

2Approximations of the wavelet sym4 for 1 to 10 iterations

Page 705: Wavelet ug

wavefun

8-197

The algorithm used is the cascade algorithm. It uses the single-level inverse wavelet transform repeatedly.

Let us begin with the scaling function φ.

Since φ is also equal to , (according to the notation used in Chapter 6, “Advanced Concepts”, of the User’s Guide), this function is characterized by the following coefficients in the orthogonal framework:

<φ, > = 1 only if n = 0 and equal to 0 otherwise

<φ, > = 0 for positive j, and all k.

This expansion can be viewed as a wavelet decomposition structure. Detail coefficients are all zeros and approximation coefficients are all zeros except one equal to 1.

Then we use the reconstruction algorithm to approximate the function over a dyadic grid, according to the following result:

For any dyadic rational of the form x = n2-j in which the function is continuous and where j is sufficiently large, we have pointwise convergence and

where C is a constant, and α is a positive constant depending on the wavelet regularity.

Then using a good approximation of φ on dyadic rationals, we can use piecewise constant or piecewise linear interpolations η on dyadic intervals, for which uniform convergence occurs with similar exponential rate:

So using a J-step reconstruction scheme, we obtain an approximation that converges exponentially towards φ when J goes to infinity.

Approximations are computed over a grid of dyadic rationals covering the support of the function to be approximated.

φ0 0,

φ0 n,

ψ j– k,

φ

φ x( ) 2

j2---

– φ φ,j– n2j J–,

⟨ ⟩ C.2 jα–≤

φ η– ∞ C.2 jα–≤

Page 706: Wavelet ug

wavefun

8-198

Since a scaled version of the wavelet function ψ can also be expanded on the , the same scheme can be used, after a single-level reconstruction

starting with the appropriate wavelet decomposition structure. Approximation coefficients are all zeros and detail coefficients are all zeros except one equal to 1.

For biorthogonal wavelets, the same ideas can be applied on each of the two multiresolution schemes in duality.

Note This algorithm may diverge if the function to be approximated is not continuous on dyadic rationals.

See Also intwave, waveinfo, wfilters

References Daubechies, I., Ten lectures on wavelets, CBMS, SIAM, 1992, pp. 202–213.

Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

φ 1 n,–( )n

Page 707: Wavelet ug

wavefun2

8-199

8wavefun2Purpose Wavelet and scaling functions 2-D.

Syntax [S,W1,W2,W3,XYVAL] = wavefun2('wname',ITER)[S,W1,W2,W3,XYVAL] = wavefun2('wname',A,B)

Description For an orthogonal wavelet 'wname', wavefun2 returns the scaling function and the three wavelet functions resulting from the tensor products of the one-dimensional scaling and wavelet functions.

If [PHI,PSI,XVAL] = wavefun('wname',ITER), the scaling function S is the tensor product of PHI and PSI.

The wavelet functions W1, W2 and W3 are the tensor products (PHI,PSI), (PSI,PHI) and (PSI,PSI), respectively.

The two-dimensional variable XYVAL is a 2ITER x 2ITER points grid obtained from the tensor product (XVAL,XVAL).

The positive integer ITER determines the number of iterations computed and thus, the refinement of the approximations.

[S,W1,W2,W3,XYVAL] = wavefun2('wname',A,B), where A and B are positive integers, is equivalent to [S,W1,W2,W3,XYVAL] = wavefun2('wname',max(A,B)). The resulting functions are plotted.

When A is set equal to the special value 0,

[S,W1,W2,W3,XYVAL] = wavefun2('wname',0) is equivalent to [S,W1,W2,W3,XYVAL] = wavefun2('wname',4,0).

[S,W1,W2,W3,XYVAL] = wavefun2('wname') is equivalent to [S,W1,W2,W3,XYVAL] = wavefun2('wname',4).

The output arguments are optional.

Note The wavefun2 function can only be used with an orthogonal wavelet.

Examples On the following graph, a linear approximation of the sym4 wavelet obtained using the cascade algorithm is shown.

Page 708: Wavelet ug

wavefun2

8-200

% Set number of iterations and wavelet name. iter = 4;wav = 'sym4';

% Compute approximations of the wavelet and scale functions using% the cascade algorithm and plot.[s,w1,w2,w3,xyval] = wavefun2(wav,iter,0);

Algorithm See wavefun for more information.

See Also intwave, wavefun, waveinfo, wfilters

References Daubechies, I., Ten lectures on wavelets, CBMS, SIAM, 1992, pp. 202–213.

Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

Page 709: Wavelet ug

waveinfo

8-201

8waveinfoPurpose Information on wavelets.

Syntax waveinfowaveinfo('wname')

Description waveinfo provides information on all wavelets within the toolbox.

waveinfo(’wname’) provides information on the wavelet family whose short name is specified by the string ’wname’. Available family short names are listed in the table below.

The family short names can also be user-defined ones (see wavemngr for more information).

waveinfo('wsys') provides information on wavelet packets.

Wavelet family short name Wavelet family name

'haar' Haar wavelet.

'db' Daubechies wavelets.

'sym' Symlets.

'coif' Coiflets.

'bior' Biorthogonal wavelets.

'rbio' Reverse biorthogonal wavelets.

'meyr' Meyer wavelet.

'dmey' Discrete approximation of Meyer wavelet.

'gaus' Gaussian wavelets.

'mexh' Mexican hat wavelet.

'morl' Morlet wavelet.

'cgau' Complex Gaussian wavelets.

'shan' Shannon wavelets.

'fbsp' Frequency B-Spline wavelets.

'cmor' Complex Morlet wavelets.

Page 710: Wavelet ug

waveinfo

8-202

Examples waveinfo('db')

DBINFO Information on Daubechies wavelets. Daubechies Wavelets General characteristics: Compactly supported wavelets with extremal phase and highest number of vanishing moments for a given support width. Associated scaling filters are minimum-phase filters.

Family Daubechies Short name db Order N N strictly positive integer Examples db1 or haar, db4, db15

Orthogonal yes Biorthogonal yes Compact support yes DWT possible CWT possible

Support width 2N-1 Filters length 2N Regularity about 0.2 N for large N Symmetry far from Number of vanishing moments for psi N

Reference: I. Daubechies, Ten lectures on wavelets CBMS, SIAM, 61, 1994, 194-202.

See Also wavemngr

Page 711: Wavelet ug

wavemenu

8-203

8wavemenuPurpose Start graphical user interface tools.

Syntax wavemenu

Description wavemenu brings up a menu for accessing the various graphical tools provided in the Wavelet Toolbox. For instructions on using these tools see the corresponding chapters in the “MATLAB Wavelet Toolbox” User’s Guide.

The title of each mentioned chapter is given in the following table.

Tools Chapter

Wavelet 1-D and Wavelet 2-D Chapter 2

Wavelet Packet 1-D and Wavelet Packet 2-D Chapter 5

Continuous Wavelet 1-D Chapter 2

Complex Continuous Wavelet 1-D Chapter 2

Wavelet Display and Wavelet Packet Display Chapter 1

SWT De-noising 1-D and SWT De-noising 2-D Chapter 2

Density Estimation1-D Chapter 2

Regression Estimation1-D Chapter 2

Wavelet Coefficients Selection 1-D Chapter 2

Wavelet Coefficients Selection 2-D Chapter 2

Signal Extension and Image Extension Chapter 2

Chapter Title

Chapter 1 “Wavelets: A New Tool for Signal Analysis”

Chapter 2 “Using Wavelets”

Chapter 5 “Using Wavelet Packets”

Page 712: Wavelet ug

wavemenu

8-204

Examples wavemenu

Page 713: Wavelet ug

wavemngr

8-205

8wavemngrPurpose Wavelet manager.

Syntax wavemngr('add',FN,FSN,WT,NUMS,FILE)wavemngr('add',FN,FSN,WT,NUMS,FILE,B)wavemngr('del',N)wavemngr('restore')wavemngr('restore',IN2)OUT1 = wavemngr('read')OUT1 = wavemngr('read',IN2)OUT1 = wavemngr('read_asc')

Description wavemngr is a type of wavelets manager. It allows you to add, delete, restore or read wavelets.

wavemngr('add',FN,FSN,WT,NUMS,FILE) or wavemngr('add',FN,FSN,WT,NUMS,FILE,B) or wavemngr('add',FN,FSN,WT,{NUMS,TYPNUMS},FILE) or wavemngr('add',FN,FSN,WT,{NUMS,TYPNUMS},FILE,B), add a new wavelet family to the toolbox.

FN = Family Name (string)

FSN = Family Short Name (string of length equal or less than four characters)

WT defines the wavelet type:

WT = 1, for orthogonal wavelets

WT = 2, for biorthogonal wavelets

WT = 3, for wavelet with scaling function

WT = 4, for wavelet without scaling function

WT = 5, for complex wavelet without scaling function

If the family contains a single wavelet, NUMS = ’ ’.

Examples:

If the wavelet is member of a finite family of wavelets, NUMS is a string containing a blank separated list of items representing wavelet parameters.

mexh

morl

Page 714: Wavelet ug

wavemngr

8-206

Example:

If the wavelet is part of an infinite family of wavelets, NUMS is a string containing a blank separated list of items representing wavelet parameters, terminated by the special sequence **.

Examples:

In these last two cases, TYPNUMS specifies the wavelet parameter input format: ’integer’ or ’real’ or ’string’; the default value is ’integer’.

Examples:

FILE = MAT-file or M-file name (string). See usage in the “Examples” section.

B = [lb ub] specifies lower and upper bounds of effective support for wavelets of type = 3, 4 or 5.

This option is fully documented in Chapter 7 of the User’s Guide, “Adding Your Own Wavelets”.

wavemngr('del',N), deletes a wavelet or a wavelet family. N is the Family Short Name or the Wavelet Name (in the family). N is a string.

wavemngr('restore') or wavemngr('restore',IN2), restore previous or initial wavelets. If nargin = 1, the previous wavelets.asc ASCII-file is restored; otherwise the initial wavelets.asc ASCII-file is restored. Here IN2 is a dummy argument.

OUT1 = wavemngr('read') returns all wavelet family names.

OUT1 = wavemngr('read',IN2) returns all wavelet names, IN2 is a dummy argument.

bior : NUMS = '1.1 1.3 ... 4.4 5.5 6.8'

db : NUMS = '1 2 3 4 5 6 7 8 9 10 **'shan : NUMS = '1-1.5 1-1 1-0.5 1-0.1 2-3 **'

db : TYPNUMS = 'integer'bior : TYPNUMS = 'real'shan : TYPNUMS = 'string'

Page 715: Wavelet ug

wavemngr

8-207

OUT1 = wavemngr('read_asc') reads wavelets.asc ASCII-file and returns all wavelets information.

Examples % List initial wavelets families. wavemngr('read')

ans ==================================== Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor ===================================% List all wavelets. wavemngr('read',1)

ans =

=================================== Haar haar =================================== Daubechies db ------------------------------ db1 db2 db3 db4 db5 db6 db7 db8 db9 db10 db**

Page 716: Wavelet ug

wavemngr

8-208

=================================== Symlets sym ------------------------------ sym2 sym3 sym4 sym5 sym6 sym7 sym8 sym** =================================== Coiflets coif ------------------------------ coif1 coif2 coif3 coif4 coif5 =================================== BiorSplines bior ------------------------------ bior1.1 bior1.3 bior1.5 bior2.2 bior2.4 bior2.6 bior2.8 bior3.1 bior3.3 bior3.5 bior3.7 bior3.9 bior4.4 bior5.5 bior6.8 =================================== ReverseBior rbio ------------------------------ rbio1.1 rbio1.3 rbio1.5 rbio2.2 rbio2.4 rbio2.6 rbio2.8 rbio3.1 rbio3.3 rbio3.5 rbio3.7 rbio3.9 rbio4.4 rbio5.5 rbio6.8 =================================== Meyer meyr =================================== DMeyer dmey =================================== Gaussian gaus ------------------------------ gaus1 gaus2 gaus3 gaus4 gaus5 gaus6 gaus7 gaus8 gaus** =================================== Mexican_hat mexh =================================== Morlet morl

Page 717: Wavelet ug

wavemngr

8-209

=================================== Complex Gaussian cgau ------------------------------ cgau1 cgau2 cgau3 cgau4 cgau5 cgau** =================================== Shannon shan ------------------------------ shan1-1.5 shan1-1 shan1-0.5 shan1-0.1 shan2-3 shan** =================================== Frequency B-Spline fbsp ------------------------------ fbsp1-1-1.5 fbsp1-1-1 fbsp1-1-0.5 fbsp2-1-1fbsp2-1-0.5 fbsp2-1-0.1 fbsp** =================================== Complex Morlet cmor ------------------------------ cmor1-1.5 cmor1-1 cmor1-0.5 cmor1-1 cmor1-0.5 cmor1-0.1 cmor** ===================================

In the following example, new compactly supported orthogonal wavelets are added to the toolbox. These wavelets, which are a slight generalization of the Daubechies wavelets, are based on the use of Bernstein polynomials and are due to Kateb and Lemarié in an unpublished work.

Note The M-files used in this example can be found in the wavedemo directory.

% Add new family of orthogonal wavelets. % You must define: % % Family Name: Lemarie % Family Short Name: lem % Type of wavelet: 1 (orth) % Wavelets numbers: 1 2 3 4 5 % File driver: lemwavf

Page 718: Wavelet ug

wavemngr

8-210

% % The function lemwavf.m must be as follows: % function w = lemwavf(wname) % where the input argument wname is a string: % wname = 'lem1' or 'lem2' ... i.e., % wname = sh.name + number % and w the corresponding scaling filter. % The addition is obtained using:

wavemngr('add','Lemarie','lem',1,'1 2 3 4 5','lemwavf');

% The ascii file 'wavelets.asc' is saved as % 'wavelets.prv', then it is modified and % the MAT file 'wavelets.inf' is generated.

% List wavelets families.wavemngr('read')

ans ====================================Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor Lemarie lem ===================================% Remove the added family. wavemngr('del','Lemarie');

Page 719: Wavelet ug

wavemngr

8-211

% List wavelets families. wavemngr('read')

ans ==================================== Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor ===================================% Restore the previous ascii file % 'wavelets.prv', then build % the MAT-file 'wavelets.inf'. wavemngr('restore');

% List restored wavelets. wavemngr('read',1)

ans ==================================== Haar haar =================================== Daubechies db ------------------------------ db1 db2 db3 db4 db5 db6 db7 db8 db9 db10 db**

Page 720: Wavelet ug

wavemngr

8-212

=================================== Symlets sym ------------------------------ sym2 sym3 sym4 sym5 sym6 sym7 sym8 sym** =================================== Coiflets coif ------------------------------ coif1 coif2 coif3 coif4 coif5 =================================== BiorSplines bior ------------------------------ bior1.1 bior1.3 bior1.5 bior2.2 bior2.4 bior2.6 bior2.8 bior3.1 bior3.3 bior3.5 bior3.7 bior3.9 bior4.4 bior5.5 bior6.8 =================================== ReverseBior rbio ------------------------------ rbio1.1 rbio1.3 rbio1.5 rbio2.2 rbio2.4 rbio2.6 rbio2.8 rbio3.1 rbio3.3 rbio3.5 rbio3.7 rbio3.9 rbio4.4 rbio5.5 rbio6.8 =================================== Meyer meyr =================================== DMeyer dmey =================================== Gaussian gaus ------------------------------ gaus1 gaus2 gaus3 gaus4 gaus5 gaus6 gaus7 gaus8 gaus** =================================== Mexican_hat mexh =================================== Morlet morl

Page 721: Wavelet ug

wavemngr

8-213

=================================== Complex Gaussian cgau ------------------------------ cgau1 cgau2 cgau3 cgau4 cgau5 cgau** =================================== Shannon shan ------------------------------ shan1-1.5 shan1-1 shan1-0.5 shan1-0.1 shan2-3 shan** =================================== Frequency B-Spline fbsp ------------------------------ fbsp1-1-1.5 fbsp1-1-1 fbsp1-1-0.5 fbsp2-1-1fbsp2-1-0.5 fbsp2-1-0.1 fbsp** =================================== Complex Morlet cmor ------------------------------ cmor1-1.5 cmor1-1 cmor1-0.5 cmor1-1 cmor1-0.5 cmor1-0.1 cmor** =================================== Lemarie lem ------------------------------ lem1 lem2 lem3 lem4 lem5 ===================================% Restore initial wavelets. % % Restore the initial ascii file % 'wavelets.ini' and initial % MAT-file 'wavelets.bin'. wavemngr('restore',0);

% List wavelets families. wavemngr('read')

Page 722: Wavelet ug

wavemngr

8-214

ans ==================================== Haar haar Daubechies db Symlets sym Coiflets coif BiorSplines bior ReverseBior rbio Meyer meyr DMeyer dmey Gaussian gaus Mexican_hat mexh Morlet morl Complex Gaussian cgau Shannon shan Frequency B-Spline fbsp Complex Morlet cmor ===================================% Add new family of orthogonal wavelets.wavemngr('add','Lemarie','lem',1,'1 2 3','lemwavf');

% All command line capabilities are available for % the new wavelets. % % Example 1: compute the four associated filters. [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('lem3');

% Example 2: compute scale and wavelet functions. [phi,psi,xval] = wavefun('lem3');

% Add a new family of orthogonal wavelets: special form % for the GUI mode. % % The M-file lemwavf allows you to compute the filter for % any order. If you want to get a popup of the form% 1 2 3 **, associated with the family, then wavelets are % appended for GUI mode using:

wavemngr('restore',0); wavemngr('add','Lemarie','lem',1,'1 2 3 **','lemwavf');

Page 723: Wavelet ug

wavemngr

8-215

% After this sequence, all GUI capabilities are available for % the new wavelets. % Note that the last command allows a short cut in the % order definition only if possible orders are integers.

Caution wavemngr works on the current directory. If you add a new wavelet family, it is available in this directory only. Refer to Chapter 7 of the User’s Guide, “Adding Your Own Wavelets”.

Limitations wavemngr allows you to add a new wavelet. You must verify that it is truly a wavelet. No check is performed either about this point or about the type of the new wavelet.

Page 724: Wavelet ug

waverec

8-216

8waverecPurpose Multilevel 1-D wavelet reconstruction.

Syntax X = waverec(C,L,'wname')X = waverec(C,L,Lo_R,Hi_R)

Description waverec performs a multilevel one-dimensional wavelet reconstruction using either a specific wavelet (’wname’, see wfilters) or specific reconstruction filters (Lo_R and Hi_R). waverec is the inverse function of wavedec in the sense that the abstract statement waverec(wavedec(X,N,’wname’),’wname’) returns X.

X = waverec(C,L,’wname’) reconstructs the signal X based on the multilevel wavelet decomposition structure [C,L] and wavelet ’wname’. (For information about the decomposition structure, see wavedec.)

X = waverec(C,L,Lo_R,Hi_R) reconstructs the signal X as above, using the reconstruction filters you specify. Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

Note that X = waverec(C,L,’wname’) is equivalent to X = appcoef(C,L,’wname’,0).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original one-dimensional signal. load leleccum; s = leleccum(1:3920); ls = length(s);

% Perform decomposition of signal at level 3 using db5. [c,l] = wavedec(s,3,'db5');

% Reconstruct s from the wavelet decomposition structure [c,l]. a0 = waverec(c,l,'db5');

% Check for perfect reconstruction. err = norm(s-a0)err =

3.2079e-09

See Also appcoef, idwt, wavedec

Page 725: Wavelet ug

waverec2

8-217

8waverec2Purpose Multilevel 2-D wavelet reconstruction.

Syntax X = waverec2(C,S,'wname')X = waverec2(C,S,Lo_R,Hi_R)

Description waverec2 is a two-dimensional wavelet analysis function.

X = waverec2(C,S,’wname’) performs a multilevel wavelet reconstruction of the matrix X based on the wavelet decomposition structure [C,S] (for detailed storage information, see wavedec2). ’wname’ is a string containing the name of the wavelet (see wfilters for more information).

Instead of giving the wavelet name, you can give the filters. For X = waverec2(C,S,Lo_R,Hi_R), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

waverec2 is the inverse function of wavedec2 in the sense that the abstract statement waverec2(wavedec2(X,N,’wname’),’wname’) would give back X.

Remarks Note that X = waverec2(C,S,’wname’) is equivalent to X = appcoef2(C,S,’wname’,0).

Examples % The current extension mode is zero-padding (see dwtmode).% Load original image. load woman; % X contains the loaded image.

% Perform decomposition at level 2 % of X using sym4. [c,s] = wavedec2(X,2,'sym4');

% Reconstruct X from the wavelet % decomposition structure [c,s]. a0 = waverec2(c,s,'sym4');

% Check for perfect reconstruction. max(max(abs(X-a0)))ans =

2.5565e-10

See Also appcoef2, idwt2, wavedec2

Page 726: Wavelet ug

wbmpen

8-218

8wbmpenPurpose Penalized threshold for wavelet 1-D or 2-D de-noising.

Syntax THR = wbmpen(C,L,SIGMA,ALPHA)

Description THR = wbmpen(C,L,SIGMA,ALPHA) returns global threshold THR for de-noising. THR is obtained by a wavelet coefficients selection rule using a penalization method provided by Birge-Massart.

[C,L] is the wavelet decomposition structure of the signal or image to be de-noised.

SIGMA is the standard deviation of the zero mean Gaussian white noise in de-noising model (see wnoisest for more information).

ALPHA is a tuning parameter for the penalty term. It must be a real number greater than 1. The sparsity of the wavelet representation of the de-noised signal or image grows with ALPHA. Typically ALPHA = 2.

THR minimizes the penalized criterion given by:

let t* be the minimizer of

crit(t) = -sum(c(k)^2,k<=t) + 2*SIGMA^2*t*(ALPHA + log(n/t))

where c(k) are the wavelet coefficients sorted in decreasing order of their absolute value and n is the number of coefficients; then THR = c(t*) .

wbmpen(C,L,SIGMA,ALPHA,ARG) computes the global threshold and, in addition, plots three curves:

• 2*SIGMA^2*t*(ALPHA + log(n/t))• sum(c(k)^2,k<=t)

• crit(t).

Examples % Example 1: Signal de-noising.% Load noisy bumps signal.load noisbump; x = noisbump;

% Perform a wavelet decomposition of the signal% at level 5 using sym6.wname = 'sym6'; lev = 5;[c,l] = wavedec(x,lev,wname);

Page 727: Wavelet ug

wbmpen

8-219

% Estimate the noise standard deviation from the% detail coefficients at level 1, using wnoisest.sigma = wnoisest(c,l,1);

% Use wbmpen for selecting global threshold % for signal de-noising, using the tuning parameter.alpha = 2;thr = wbmpen(c,l,sigma,alpha)thr =

2.7681

% Use wdencmp for de-noising the signal using the above% threshold with soft thresholding and approximation kept.keepapp = 1;xd = wdencmp('gbl',c,l,wname,lev,thr,'s',keepapp);

% Plot original and de-noised signals.figure(1)subplot(211), plot(x), title('Original signal')subplot(212), plot(xd), title('De-noised signal')

200 400 600 800 1000

0

5

10

15

Original signal

200 400 600 800 10000

5

10

De−noised signal

Page 728: Wavelet ug

wbmpen

8-220

% Example 2: Image de-noising.% Load original image.load noiswom; nbc = size(map,1);

% Perform a wavelet decomposition of the image% at level 3 using coif2.wname = 'coif2'; lev = 3;[c,s] = wavedec2(X,lev,wname);

% Estimate the noise standard deviation from the% detail coefficients at level 1.det1 = detcoef2('compact',c,s,1);sigma = median(abs(det1))/0.6745;

% Use wbmpen for selecting global threshold % for image de-noising.alpha = 1.2;thr = wbmpen(c,l,sigma,alpha)

thr =

36.0621

% Use wdencmp for de-noising the image using the above% thresholds with soft thresholding and approximation kept.keepapp = 1;xd = wdencmp('gbl',c,s,wname,lev,thr,'s',keepapp);

% Plot original and de-noised images.figure(2)colormap(pink(nbc));subplot(221), image(wcodemat(X,nbc))title('Original image')

Page 729: Wavelet ug

wbmpen

8-221

subplot(222), image(wcodemat(xd,nbc))title('De-noised image')

See Also wden, wdencmp, wpbmpen, wpdencmp

Original image

20 40 60 80

20

40

60

80

De−noised image

20 40 60 80

20

40

60

80

Page 730: Wavelet ug

wcodemat

8-222

8wcodematPurpose Extended pseudocolor matrix scaling.

Syntax Y = wcodemat(X,NBCODES,OPT,ABSOL) Y = wcodemat(X,NBCODES,OPT) Y = wcodemat(X,NBCODES) Y = wcodemat(X)

Description wcodemat is a general utility.

Y = wcodemat(X,NBCODES,OPT,ABSOL) returns a coded version of input matrix X if ABSOL = 0, or ABS(X) if ABSOL is nonzero, using the first NBCODES integers. Coding can be done row-wise (OPT = 'row' or 'r'), columnwise (OPT = 'col' or 'c'), or globally (OPT = 'mat' or 'm').

Coding uses a regular grid between the minimum and the maximum values of each row (column or matrix, respectively).

Y = wcodemat(X,NBCODES,OPT) is equivalent to Y = wcodemat(X,NBCODES,OPT,1).

Y = wcodemat(X,NBCODES) is equivalent to Y = wcodemat(X,NBCODES,'mat',1).

Y = wcodemat(X) is equivalent to Y = wcodemat(X,16,'mat',1).

Page 731: Wavelet ug

wdcbm

8-223

8wdcbmPurpose Thresholds for wavelet 1-D using Birge-Massart strategy.

Syntax [THR,NKEEP] = wdcbm(C,L,ALPHA)[THR,NKEEP] = wdcbm(C,L,ALPHA,M)

Description [THR,NKEEP] = wdcbm(C,L,ALPHA,M) returns level-dependent thresholds THR and numbers of coefficients to be kept NKEEP, for de-noising or compression. THR is obtained using a wavelet coefficients selection rule based on the Birge-Massart strategy.

[C,L] is the wavelet decomposition structure of the signal to be de-noised or compressed, at level j = length(L)-2.ALPHA and M must be real numbers greater than 1.

THR is a vector of length j, THR(i) contains the threshold for level i.

NKEEP is a vector of length j, NKEEP(i) contains the number of coefficients to be kept at level i.

j, M and ALPHA define the strategy:

• At level j+1 (and coarser levels), everything is kept.

• For level i from 1 to j, the ni largest coefficients are kept with ni = M (j+2-i)ALPHA.

Typically ALPHA = 1.5 for compression and ALPHA = 3 for de-noising.

A default value for M is M = L(1), the number of the coarsest approximation coefficients, since the previous formula leads for i = j+1, to nj+1 = M = L(1). Recommended values for M are from L(1) to 2*L(1).

wdcbm(C,L,ALPHA) is equivalent to wdcbm(C,L,ALPHA,L(1)).

Examples % Load electrical signal and select a part of it.load leleccum; indx = 2600:3100; x = leleccum(indx);

% Perform a wavelet decomposition of the signal% at level 5 using db3.wname = 'db3'; lev = 5;[c,l] = wavedec(x,lev,wname);

Page 732: Wavelet ug

wdcbm

8-224

% Use wdcbm for selecting level dependent thresholds % for signal compression using the adviced parameters.alpha = 1.5; m = l(1);[thr,nkeep] = wdcbm(c,l,alpha,m)

thr = 19.5569 17.1415 20.2599 42.8959 15.0049

nkeep = 1 2 3 4 7

% Use wdencmp for compressing the signal using the above% thresholds with hard thresholding.[xd,cxd,lxd,perf0,perfl2] = ... wdencmp('lvd',c,l,wname,lev,thr,'h');

% Plot original and compressed signals.subplot(211), plot(indx,x), title('Original signal');subplot(212), plot(indx,xd), title('Compressed signal');xlab1 = ['2-norm rec.: ',num2str(perfl2)];xlab2 = [' % -- zero cfs: ',num2str(perf0), ' %'];xlabel([xlab1 xlab2]);

2600 2700 2800 2900 3000 3100100

200

300

400

500Original signal

2600 2700 2800 2900 3000 3100100

200

300

400

500Compressed signal

2−norm rec.: 99.9549 % −− zero cfs: 92.9524 %

Page 733: Wavelet ug

wdcbm

8-225

See Also wden, wdencmp, wpdencmp

References Birgé, L.; P. Massart (1997), “From model selection to adaptive estimation,” in D. Pollard (ed), Festchrift for L. Le Cam, Springer, pp. 55–88.

Page 734: Wavelet ug

wdcbm2

8-226

8wdcbm2Purpose Thresholds for wavelet 2-D using Birge-Massart strategy.

Syntax [THR,NKEEP] = wdcbm2(C,S,ALPHA)[THR,NKEEP] = wdcbm2(C,S,ALPHA,M)

Description [THR,NKEEP] = wdcbm2(C,S,ALPHA,M) returns level-dependent thresholds THR and numbers of coefficients to be kept NKEEP, for de-noising or compression. THR is obtained using a wavelet coefficients selection rule based on the Birge-Massart strategy.

[C,S] is the wavelet decomposition structure of the image to be de-noised or compressed, at level j = size(S,1)-2.

ALPHA and M must be real numbers greater than 1.

THR is a matrix 3 by j, THR(:,i) contains the level dependent thresholds in the three orientations: horizontal, diagonal and vertical, for level i.

NKEEP is a vector of length j, NKEEP(i) contains the number of coefficients to be kept at level i.

j, M and ALPHA define the strategy:

• At level j+1 (and coarser levels), everything is kept.

• For level i from 1 to j, the ni largest coefficients are kept with ni = M (j+2-i)ALPHA.

Typically ALPHA = 1.5 for compression and ALPHA = 3 for de-noising.

A default value for M is M = prod(S(1,:)), the length of the coarsest approximation coefficients, since the previous formula leads for i = j+1, to nj+1 = M = prod(S(1,:)).

Recommended values for M are from prod(S(1,:)) to 6*prod(S(1,:)).

wdcbm2(C,S,ALPHA) is equivalent to wdcbm2(C,S,ALPHA,prod(S(1,:))).

Examples % Load original image.load detfingr; nbc = size(map,1);

% Perform a wavelet decomposition of the image% at level 3 using sym4.

Page 735: Wavelet ug

wdcbm2

8-227

wname = 'sym4'; lev = 3;[c,s] = wavedec2(X,lev,wname);

% Use wdcbm2 for selecting level dependent thresholds % for image compression using the adviced parameters.alpha = 1.5; m = 2.7*prod(s(1,:));[thr,nkeep] = wdcbm2(c,s,alpha,m)

thr = 21.4814 46.8354 40.7907 21.4814 46.8354 40.7907 21.4814 46.8354 40.7907

nkeep = 624 961 1765

% Use wdencmp for compressing the image using the above% thresholds with hard thresholding.[xd,cxd,sxd,perf0,perfl2] = ... wdencmp('lvd',c,s,wname,lev,thr,'h');

% Plot original and compressed images.colormap(pink(nbc));subplot(221), image(wcodemat(X,nbc)),title('Original image')subplot(222), image(wcodemat(xd,nbc)),title('Compressed image')xlab1 = ['2-norm rec.: ',num2str(perfl2)];xlab2 = [' % -- zero cfs: ',num2str(perf0), ' %'];xlabel([xlab1 xlab2]);

Page 736: Wavelet ug

wdcbm2

8-228

See Also wdencmp, wpdencmp

References Birgé, L.; P. Massart (1997). “From model selection to adaptive estimation,” in D. Pollard (ed), Festchrift for L. Le Cam, Springer, pp. 55–88.

Original image

50 100 150 200 250

50

100

150

200

250

Compressed image

2−norm rec.: 98.0065 % −− zero cfs: 94.4950 100 150 200 250

50

100

150

200

250

Page 737: Wavelet ug

wden

8-229

8wdenPurpose Automatic 1-D de-noising using wavelets.

Syntax [XD,CXD,LXD] = wden(X,TPTR,SORH,SCAL,N,'wname')[XD,CXD,LXD] = wden(C,L,TPTR,SORH,SCAL,N,'wname')

Description wden is a one-dimensional de-noising function.

wden performs an automatic de-noising process of a one-dimensional signal using wavelets.

[XD,CXD,LXD] = wden(X,TPTR,SORH,SCAL,N,’wname’) returns a de-noised version XD of input signal X obtained by thresholding the wavelet coefficients.

Additional output arguments [CXD,LXD] are the wavelet decomposition structure (see wavedec for more information) of the de-noised signal XD.

TPTR string contains the threshold selection rule:

'rigrsure' use the principle of Stein’s Unbiased Risk

'heursure' is an heuristic variant of the first option

'sqtwolog' for universal threshold

'minimaxi' for minimax thresholding (see thselect for more information)

SORH ('s' or 'h') is for soft or hard thresholding (see wthresh for more information).

SCAL defines multiplicative threshold rescaling:

'one' for no rescaling

'sln' for rescaling using a single estimation of level noise based on first-level coefficients

'mln' for rescaling done using level-dependent estimation of level noise

Wavelet decomposition is performed at level N and ’wname’ is a string containing the name of the desired orthogonal wavelet (see wmaxlev and wfilters for more information).

[XD,CXD,LXD] = wden(C,L,TPTR,SORH,SCAL,N,’wname’) returns the same output arguments, using the same options as above, but obtained directly from

2 .( )log

Page 738: Wavelet ug

wden

8-230

the input wavelet decomposition structure [C,L] of the signal to be de-noised, at level N and using ’wname’ orthogonal wavelet.

The underlying model for the noisy signal is basically of the following form:

where time n is equally spaced.

In the simplest model, suppose that e(n) is a Gaussian white noise N(0,1) and the noise level a is supposed to be equal to 1.

The de-noising objective is to suppress the noise part of the signal s and to recover f.

The de-noising procedure proceeds in three steps:

1 Decomposition. Choose a wavelet, and choose a level N. Compute the wavelet decomposition of the signal s at level N.

2 Detail coefficients thresholding. For each level from 1 to N, select a threshold and apply soft thresholding to the detail coefficients.

3 Reconstruction. Compute wavelet reconstruction based on the original approximation coefficients of level N and the modified detail coefficients of levels from 1 to N.

More details about threshold selection rules can be found in the “De-noising” section of Chapter 6, “Advanced Concepts”, in the User’s Guide, and in the help of the thselect function. Let us point out that:

• The detail coefficients vector is the superposition of the coefficients of f and the coefficients of e, and that the decomposition of e leads to detail coefficients that are standard Gaussian white noises.

• Minimax and SURE threshold selection rules are more conservative and are more convenient when small details of function f lie in the noise range. The two other rules remove the noise more efficiently. The option 'heursure' is a compromise.

In practice, the basic model cannot be used directly. This section examines the options available, to deal with model deviations. The remaining parameter scal has to be specified. It corresponds to threshold rescaling methods.

• Option scal = 'one' corresponds to the basic model.

s n( ) f n( ) σe n( )+=

σ

Page 739: Wavelet ug

wden

8-231

• In general, you can ignore the noise level that must be estimated. The detail coefficients CD1 (the finest scale) are essentially noise coefficients with standard deviation equal to . The median absolute deviation of the coefficients is a robust estimate of . The use of a robust estimate is crucial for two reasons. The first is that if level 1 coefficients contain f details, these details are concentrated in few coefficients. The second reason is to avoid signal end effects, which are pure artifacts due to computations on the edges.

Option scal = 'sln' handles threshold rescaling using a single estimation of level noise based on the first-level coefficients.

• When you suspect a nonwhite noise e, thresholds must be rescaled by a level dependent estimation of the level noise. The same kind of strategy is used by estimating level by level. This estimation is implemented in M-file wnoisest, which handles the wavelet decomposition structure of the original signal s directly.

Option scal = 'mln' handles threshold rescaling using a level-dependent es-timation of the level noise.

Examples % The current extension mode is zero-padding (see dwtmode).

% Set signal to noise ratio and set rand seed. snr = 3; init = 2055615866;

% Generate original signal and a noisy version adding % a standard Gaussian white noise. [xref,x] = wnoise(3,11,snr,init);

% De-noise noisy signal using soft heuristic SURE thresholding % and scaled noise option, on detail coefficients obtained % from the decomposition of x, at level 5 by sym8 wavelet. lev = 5;xd = wden(x,'heursure','s','one',lev,'sym8');

% Plot signals. subplot(611), plot(xref), axis([1 2048 -10 10]); title('Original signal'); subplot(612), plot(x), axis([1 2048 -10 10]); title(['Noisy signal - Signal to noise ratio = ',... num2str(fix(snr))]);

σσ

σlev

Page 740: Wavelet ug

wden

8-232

subplot(613), plot(xd), axis([1 2048 -10 10]); title('De-noised signal - heuristic SURE');

% De-noise noisy signal using soft SURE thresholding xd = wden(x,'heursure','s','one',lev,'sym8');

% Plot signal. subplot(614), plot(xd), axis([1 2048 -10 10]); title('De-noised signal - SURE');

% De-noise noisy signal using fixed form threshold with % a single level estimation of noise standard deviation. xd = wden(x,'sqtwolog','s','sln',lev,'sym8');

% Plot signal. subplot(615), plot(xd), axis([1 2048 -10 10]); title('De-noised signal - Fixed form threshold');

% De-noise noisy signal using minimax threshold with % a multiple level estimation of noise standard deviation. xd = wden(x,'minimaxi','s','sln',lev,'sym8');

% Plot signal. subplot(616), plot(xd), axis([1 2048 -10 10]); title('De-noised signal - Minimax');

% If many trials are necessary, it is better to perform % decomposition once and threshold it many times: % decomposition. [c,l] = wavedec(x,lev,'sym8'); % threshold the decomposition structure [c,l].xd = wden(c,l,'minimaxi','s','sln',lev,'sym8');

% Editing some graphical properties,% the following figure is generated.

Page 741: Wavelet ug

wden

8-233

See Also thselect, wavedec, wdencmp, wfilters, wthresh

References Antoniadis, A.; G. Oppenheim, Eds. (1995), Wavelets and statistics, 103, Lecture Notes in Statistics, Springer Verlag.

Donoho, D.L. (1993), “Progress in wavelet analysis and WVD: a ten minute tour,” in Progress in wavelet analysis and applications, Y. Meyer, S. Roques, pp. 109–128. Frontières Ed.

Donoho, D.L.; I.M. Johnstone (1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

Donoho, D.L. (1995), “De-noising by soft-thresholding,” IEEE Trans. on Inf. Theory, 41, 3, pp. 613–627.

Donoho, D.L.; I.M. Johnstone, G. Kerkyacharian, D. Picard (1995), “Wavelet shrinkage: asymptotia,” Jour. Roy. Stat. Soc., series B, vol. 57, no. 2, pp. 301–369.

−100

10Original signal

−100

10Noisy signal − Signal to noise ratio = 3

−100

10De−noised signal − heuristic SURE

−100

10De−noised signal − SURE

−100

10De−noised signal − Fixed form threshold

500 1000 1500 2000−10

010

De−noised signal − Minimax

Page 742: Wavelet ug

wdencmp

8-234

8wdencmpPurpose De-noising or compression using wavelets.

Syntax [XC,CXC,LXC,PERF0,PERFL2] = wdencmp('gbl',X,'wname',N,THR,SORH,KEEPAPP)

[XC,CXC,LXC,PERF0,PERFL2] = wdencmp('lvd',X,'wname',N,THR,SORH)[XC,CXC,LXC,PERF0,PERFL2] = wdencmp('lvd',C,L,'wname',N,THR,SORH)

Description wdencmp is a one- or two-dimensional de-noising and compression-oriented function.

wdencmp performs a de-noising or compression process of a signal or an image, using wavelets.

[XC,CXC,LXC,PERF0,PERFL2] = wdencmp('gbl',X,’wname’,N,THR,SORH, KEEPAPP) returns a de-noised or compressed version XC of input signal X (one- or two-dimensional) obtained by wavelet coefficients thresholding using global positive threshold THR.

Additional output arguments [CXC,LXC] are the wavelet decomposition structure of XC (see wavedec or wavedec2 for more information). PERF0 and PERFL2 are L2-norm recovery and compression score in percentage.

PERFL2 = 100 ∗ (vector-norm of CXC / vector-norm of C)2 if [C,L] denotes the wavelet decomposition structure of X.

If X is a one-dimensional signal and ’wname’ an orthogonal wavelet, PERFL2 is reduced to

Wavelet decomposition is performed at level N and ’wname’ is a string containing wavelet name (see wmaxlev and wfilters for more information). SORH ('s' or 'h') is for soft or hard thresholding (see wthresh for more information). If KEEPAPP = 1, approximation coefficients cannot be thresholded, otherwise it is possible.

wdencmp('gbl',C,L,’wname’,N,THR,SORH,KEEPAPP) has the same output arguments, using the same options as above, but obtained directly from the input wavelet decomposition structure [C,L] of the signal to be de-noised or compressed, at level N and using ’wname’ wavelet.

100 XC 2

X 2--------------------------

Page 743: Wavelet ug

wdencmp

8-235

For the one-dimensional case and 'lvd' option: [XC,CXC,LXC,PERF0,PERFL2] = wdencmp('lvd',X,’wname’,N,THR,SORH)or [XC,CXC,LXC,PERF0,PERFL2] = wdencmp('lvd',C,L,’wname’,N,THR,SORH)

have the same output arguments, using the same options as above, but allowing level-dependent thresholds contained in vector THR (THR must be of length N). In addition, the approximation is kept. Note that, with respect to wden (automatic de-noising), wdencmp allows more flexibility and you can implement your own de-noising strategy.

For the two-dimensional case and 'lvd' option:[XC,CXC,LXC,PERF0,PERFL2] = wdencmp('lvd',X,’wname’,N,THR,SORH) or [XC,CXC,LXC,PERF0,PERFL2] = wdencmp('lvd',C,L,’wname’,N,THR,SORH)

THR must be a matrix 3 by N containing the level-dependent thresholds in the three orientations; horizontal, diagonal, and vertical.

Ideas for de-noising can be found in Chapter 2, “Using Wavelets,” and in the “Description” section of the wden function.

The compression features of a given wavelet basis are primarily linked to the relative scarceness of the wavelet domain representation for the signal. The notion behind compression is based on the concept that the regular signal component can be accurately approximated using a small number of approximation coefficients (at a suitably selected level) and some of the detail coefficients.

Like de-noising, the compression procedure contains three steps:

1 Decomposition.

2 Detail coefficient thresholding. For each level from 1 to N, a threshold is selected and hard thresholding is applied to the detail coefficients.

3 Reconstruction.

The difference with the de-noising procedure is found in step 2.

Page 744: Wavelet ug

wdencmp

8-236

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load sinsin % X contains the loaded image.

% Generate noisy image. init=2055615866; randn('seed',init); x = X + 18*randn(size(X));

% Use wdencmp for image de-noising. % find default values (see ddencmp). [thr,sorh,keepapp] = ddencmp('den','wv',x);% de-noise image using global thresholding option. xd = wdencmp('gbl',x,'sym4',2,thr,sorh,keepapp);

% Using some plotting commands,% the following figure is generated.

Original Image

20 40 60 80 100 120

20

40

60

80

100

120

Noisy Image

20 40 60 80 100 120

20

40

60

80

100

120

De−noised Image

20 40 60 80 100 120

20

40

60

80

100

120

Page 745: Wavelet ug

wdencmp

8-237

% Load electrical signal and select a part. load leleccum; indx = 2600:3100; x = leleccum(indx);

% Use wdencmp for signal compression. % Compress using a fixed threshold. thr=35;[xd,cxd,lxd,perf0,perfl2] = ... wdencmp('gbl',x,'db3',3,thr,'h',1);

% Using some plotting commands,% the following figure is generated.

% Use wdencmp for signal de-noising. % Find default values (see ddencmp). [thr,sorh,keepapp] = ddencmp('den','wv',x);

% De-noise signal using global thresholding option. xd = wdencmp('gbl',x,'db3',2,thr,sorh,keepapp);

% Using some plotting commands,

2600 2700 2800 2900 3000 3100100

200

300

400

500Original signal

2600 2700 2800 2900 3000 3100100

200

300

400

500Compressed signal

2_norm rec.: 99.95 % −− zero cfs: 85.08 %

Page 746: Wavelet ug

wdencmp

8-238

% the following figure is generated.

% Load original image. load woman; % X contains the loaded image.

x=X(100:200,100:200); nbc = size(map,1);

% Use wdencmp for image compression. % Wavelet decomposition of x. n = 5; w = 'sym2'; [c,l] = wavedec2(x,n,w);

% Wavelet coefficients thresholding. thr=20;[xd,cxd,lxd,perf0,perfl2] = ... wdencmp('gbl',c,l,w,n,thr,'h',1);

2600 2700 2800 2900 3000 3100100

200

300

400

500Original signal

2600 2700 2800 2900 3000 3100100

200

300

400

500De−noised signal

Page 747: Wavelet ug

wdencmp

8-239

% Using some plotting commands,% the following figure is generated.

% In addition the first option allows level and orientation-% dependent thresholds. In this case the approximation is kept. % The level-dependent thresholds in the three orientations % horizontal, diagonal and vertical are as follows: thr_h = [17 18]; % Horizontal thresholds. thr_d = [19 20]; % Diagonal thresholds. thr_v = [21 22]; % Vertical thresholds.

thr = [thr_h ; thr_d ; thr_v]

thr =17 1819 2021 22

[xd,cxd,lxd,perf0,perfl2] = ... wdencmp('lvd',x,'sym8',2,thr,'h');

See Also ddencmp, wavedec, wavedec2, wdcbm, wdcbm2, wden, wbmpen, wpdencmp, wthresh

References DeVore, R.A.; B. Jawerth, B.J. Lucier (1992), “Image compression through wavelet transform coding,” IEEE Trans. on Inf. Theory, vol. 38, No 2, pp. 719–746.

Original image

20 40 60 80 100

20

40

60

80

100

threshold = 20

2_norm rec.: 99.14 % −− nul cfs : 79.51 %20 40 60 80 100

20

40

60

80

100

Page 748: Wavelet ug

wdencmp

8-240

Donoho, D.L. (1993), “Progress in wavelet analysis and WVD: a ten minute tour,” in Progress in wavelet analysis and applications, Y. Meyer, S. Roques, pp. 109-128. Frontières Ed.

Donoho, D.L.; I.M. Johnstone(1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

Donoho, D.L.; I.M. Johnstone, G. Kerkyacharian, D. Picard (1995), “Wavelet shrinkage: asymptopia,” Jour. Roy. Stat. Soc., series B, vol. 57 no. 2, pp. 301–369.

Donoho, D.L.; I.M. Johnstone, “Ideal de-noising in an orthonormal basis chosen from a library of bases,” C.R.A.S. Paris, t. 319, Ser. I, pp. 1317–1322.

Donoho, D.L. (1995), “De-noising by soft-thresholding,” IEEE Trans. on Inf. Theory, 41, 3, pp. 613–627.

Page 749: Wavelet ug

wentropy

8-241

8wentropyPurpose Entropy (wavelet packet).

Syntax E = wentropy(X,T,P)E = wentropy(X,T)

Description E = wentropy(X,T,P) returns the entropy E of the vector or matrix input X. In both cases, output E is a real number. T is a string containing the type of entropy:

T = 'shannon', 'threshold', 'norm', 'log energy', 'sure', 'user'

P is an optional parameter depending on the value of T:

If T = 'shannon' or 'log energy', P is not used.

If T = 'threshold' or 'sure', P is the threshold and must be a positive number.

If T = 'norm', P is the power and must be such that 1 ≤ P.

If T = 'user', P is a string containing the M-file name of your own entropy function, with a single input X.

E = wentropy(X,T) is equivalent to E = wentropy(X,T,0).

Functionals verifying an additive-type property are well suited for efficient searching of binary-tree structures and the fundamental splitting property of the wavelet packets decomposition. Classical entropy-based criteria match these conditions and describe information-related properties for an accurate representation of a given signal. Entropy is a common concept in many fields, mainly in signal processing. The following example lists different entropy criteria, many others are available and can be easily integrated. In the following expressions, s is the signal and (si)i the coefficients of s in an orthonormal basis.

The entropy E must be an additive cost function such that E(0) = 0 and

• The (nonnormalized) Shannon entropy.

E s( ) E si( )i

∑=

Page 750: Wavelet ug

wentropy

8-242

so

with the convention 0log(0) = 0.

• The concentration in lp norm entropy with 1 ≤ p.

E2(si) = |si|p

so

• The “log energy” entropy.

so

with the convention log(0) = 0.

• The threshold entropy.

E4(si) = 1 if |si| > p and 0 elsewhere so E4(s) = #{i such that |si| > p} is the number of time instants when the signal is greater than a threshold p.

• The “SURE” entropy.

E5(s) = n-#{i such that

For more information, see the section entitled “Using wavelet packets for compression and de-noising” in Chapter 6, “Advanced Concepts”, of the User’s Guide.

E1 si( ) si2 si

2( )log=

E1 s( ) si2 si

2( )logi

∑–=

E2 s( ) sip

i∑ s p

p= =

E3 si( ) si2( )log=

E3 s( ) si2( )log

i∑=

si p } min si2 p2,( )

i∑+≤

Page 751: Wavelet ug

wentropy

8-243

Examples % The current extension mode is zero-padding (see dwtmode).

% Generate initial signal. x = randn(1,200);

% Compute Shannon entropy of x. e = wentropy(x,'shannon')

e =-142.7607

% Compute log energy entropy of x. e = wentropy(x,'log energy')e =

-281.8975

% Compute threshold entropy of x % with threshold equal to 0.2. e = wentropy(x,'threshold',0.2)e =

162

% Compute Sure entropy of x % with threshold equal to 3. e = wentropy(x,'sure',3)e = -0.6575

% Compute norm entropy of x with power equal to 1.1. e = wentropy(x,'norm',1.1)e = 160.1583

% Compute user entropy of x with a user defined % function: userent for example. % This function must be an M-file, with first line % of the following form: % % function e = userent(x) %

Page 752: Wavelet ug

wentropy

8-244

% where x is a vector and e is a real number. % Then a new entropy is defined and can be used typing: % % e = wentropy(x,'user','userent')

References Coifman, R.R.; M.V. Wickerhauser (1992), “Entropy-based Algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

Donoho, D.L.; I.M. Johnstone, “Ideal de-noising in an orthonormal basis chosen from a library of bases,” C.R.A.S. Paris, Ser. I, t. 319, pp. 1317–1322.

Page 753: Wavelet ug

wextend

8-245

8wextendPurpose Extend a vector or a matrix.

Syntax Y = wextend(TYPE,MODE,X,L,LOC)Y = wextend(TYPE,MODE,X,L)

Description The valid extension types (TYPE) are listed in the table below.

The valid extension modes (MODE) are listed in the table below.

TYPE Description

1, '1', '1d' or '1D' 1-D extension

2, '2', '2d' or '2D’ 2-D extension

'ar' or 'addrow' Add rows

'ac' or 'addcol' Add columns

MODE Description

'zpd' Zero extension

'sp0' Smooth extension of order 0

'spd' (or'sp1') Smooth extension of order 1

'sym' Symmetric extension

'ppd' Periodized extension (1)

'per' Periodized extension (2):If the signal length is odd, wextend adds an extra-sample, equal to the last value, on the right and performs extension using the 'ppd' mode. Otherwise, 'per' reduces to 'ppd'. The same kind of rule stands for images.

Page 754: Wavelet ug

wextend

8-246

• With TYPE = {1, '1', '1d' or '1D'}:

LOC = ’l’ (or ’u’) for left (or up) extension.

LOC = ’r’ (or ’d’) for right (or down) extension.

LOC = ’b’ for extension on both sides.

LOC = ’n’ null extension.

The default is LOC = ’b’.

L is the length of the extension.

• With TYPE = {'ar', 'addrow’}:

LOC is a 1D extension location.

The default is LOC = ’b’.

L is the number of rows to add.

• With TYPE = {'ac', 'addcol'}:

LOC is a 1D extension location.

The default is LOC = ’b’.

L is the number of columns to add.

• With TYPE = {2, '2', '2d' or ’2D’}:

LOC = [LOCROW,LOCCOL] where LOCROW and LOCCOL are 1D extension locations or ’n’ (none).

The default is LOC = ’bb’.

L = [LROW,LCOL] where LROW is the number of rows to add and LCOL is the number of columns to add.

Examples % Original signal.x = [1 2 3]

x =

1 2 3

% 1-D extension length.l = 2;

% Zero-padding extensions 1-D.xextzpd1 = wextend('1','zpd',x,l)

Page 755: Wavelet ug

wextend

8-247

xextzpd1 =

0 0 1 2 3 0 0

xextzpd2 = wextend('1D','zpd',x,l,'b')

xextzpd2 =

0 0 1 2 3 0 0

% Symmetric extension 1-D.xextsym = wextend('1D','sym',x,l)

xextsym =

2 1 1 2 3 3 2

% Periodic extension 1-D.xextper = wextend('1D','per',x,l)

xextper =

3 3 1 2 3 3 1 2

% Original image.X = [1 2 3;4 5 6]

X = 1 2 3 4 5 6

% 2-D extension length.l = 2;

% Zero-padding extension 2-D.Xextzpd = wextend(2,'zpd',X,l)

Page 756: Wavelet ug

wextend

8-248

Xextzpd = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

% Symmetric extension 2-D.Xextsym = wextend('2D','sym',X,l)

Xextsym = 5 4 4 5 6 6 5 2 1 1 2 3 3 2 2 1 1 2 3 3 2 5 4 4 5 6 6 5 5 4 4 5 6 6 5 2 1 1 2 3 3 2

Page 757: Wavelet ug

wfilters

8-249

8wfiltersPurpose Wavelet filters.

Syntax [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('wname')[F1,F2] = wfilters('wname','type')

Description [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters(’wname’) computes four filters associated with the orthogonal or biorthogonal wavelet named in the string ’wname’.

The four output filters are:

• Lo_D, the decomposition low-pass filter

• Hi_D, the decomposition high-pass filter

• Lo_R, the reconstruction low-pass filter

• Hi_R, the reconstruction high-pass filter

Available orthogonal or biorthogonal wavelet names ’wname’ are listed in the table below.

Wavelet Families Wavelets

Daubechies 'db1' or 'haar', 'db2', ... ,'db10', ... , 'db45'

Coiflets 'coif1', ... , 'coif5'

Symlets 'sym2', ... , 'sym8', ... ,'sym45'

Discrete Meyer 'dmey'

Biorthogonal 'bior1.1', 'bior1.3', 'bior1.5''bior2.2', 'bior2.4', 'bior2.6', 'bior2.8''bior3.1', 'bior3.3', 'bior3.5', 'bior3.7''bior3.9', 'bior4.4', 'bior5.5', 'bior6.8'

Reverse Biorthogonal 'rbio1.1', 'rbio1.3', 'rbio1.5''rbio2.2', 'rbio2.4', 'rbio2.6', 'rbio2.8''rbio3.1', 'rbio3.3', 'rbio3.5', 'rbio3.7''rbio3.9', 'rbio4.4', 'rbio5.5', 'rbio6.8'

Page 758: Wavelet ug

wfilters

8-250

[F1,F2] = wfilters(’wname’,’type’) returns the following filters:

Examples % Set wavelet name. wname = 'db5';

% Compute the four filters associated with wavelet name given % by the input string wname. [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters(wname); subplot(221); stem(Lo_D); title('Decomposition low-pass filter'); subplot(222); stem(Hi_D); title('Decomposition high-pass filter'); subplot(223); stem(Lo_R); title('Reconstruction low-pass filter'); subplot(224); stem(Hi_R); title('Reconstruction high-pass filter'); xlabel('The four filters for db5')

% Editing some graphical properties,% the following figure is generated.

Lo_D and Hi_D (Decomposition filters) If ’type’ = 'd'

Lo_R and Hi_R (Reconstruction filters) If ’type’ = 'r'

Lo_D and Lo_R (Low-pass filters) If ’type’ = 'l'

Hi_D and Hi_R (High-pass filters) If ’type’ = 'h'

Page 759: Wavelet ug

wfilters

8-251

See Also biorfilt, orthfilt, waveinfo

References Daubechies, I. (1992), Ten lectures on wavelets, CBMS-NSF conference series in applied mathematics. SIAM Ed.

Mallat, S. (1989), “A theory for multiresolution signal decomposition: the wavelet representation,” IEEE Pattern Anal. and Machine Intell., vol. 11, no. 7, pp. 674–693.

0 5 10−1

−0.5

0

0.5

1Decomposition low−pass filter

0 5 10−1

−0.5

0

0.5

1Decomposition high−pass filter

0 5 10−1

−0.5

0

0.5

1Reconstruction low−pass filter

0 5 10−1

−0.5

0

0.5

1Reconstruction high−pass filter

The four filters for coif5

Page 760: Wavelet ug

wkeep

8-252

8wkeepPurpose Keep part of a vector or a matrix.

Syntax Y = wkeep(X,L,OPT)Y = wkeep(X,L)

Description wkeep is a general utility.

For a vector, Y = wkeep(X,L,OPT) extracts the vector Y from the vector X. The length of Y is L.

If OPT = 'c' ('l', 'r', respectively), Y is the central (left, right, respectively) part of X.

Y = wkeep(X,L,FIRST) returns the vector X(FIRST:FIRST+L-1).

Y = wkeep(X,L) is equivalent to Y = wkeep(X,L,'c').

For a matrix, Y = wkeep(X,S) extracts the central part of the matrix X. The size of Y is S.

Y = wkeep(X,S,[FIRSTR FIRSTC]) extracts the submatrix of matrix X, of size S and starting from X(FIRSTR,FIRSTC).

Examples % For a vector. x = 1:10;y = wkeep(x,6,'c')y =

3 4 5 6 7 8

y = wkeep(x,6)y =

3 4 5 6 7 8

y = wkeep(x,7,'c')y =

2 3 4 5 6 7 8y = wkeep(x,6,'l')y =

1 2 3 4 5 6

Page 761: Wavelet ug

wkeep

8-253

y = wkeep(x,6,'r')y =

5 6 7 8 9 10

% For a matrix. x = magic(5)x =

17 24 1 8 15 23 5 7 14 16 4 6 13 20 22

10 12 19 21 3 11 18 25 2 9

y = wkeep(x,[3 2])y =

5 76 13

12 19

Page 762: Wavelet ug

wmaxlev

8-254

8wmaxlevPurpose Maximum wavelet decomposition level.

Syntax L = wmaxlev(S,'wname')

Description wmaxlev is a one- or two-dimensional wavelet or wavelet packets oriented function.

wmaxlev can help you avoid unreasonable maximum level values. L = wmaxlev(S,’wname’) returns the maximum level decomposition of signal or image of size S using the wavelet named in the string ’wname’ (see wfilters for more information).

wmaxlev gives the maximum allowed level decomposition, but in general, a smaller value is taken.

Usual values are 5 for the one-dimensional case, and 3 for the two-dimensional case.

Examples % For a 1-D signal. s = 2^10; w = 'db1';

% Compute maximum level decomposition. % The rule is the last level for which at least % one coefficient is correct. l = wmaxlev(s,w)

l =10

% Change wavelet. w = 'db7';

% Compute maximum level decomposition. l = wmaxlev(s,w)

l =6

Page 763: Wavelet ug

wmaxlev

8-255

% For a 2-D signal. s = [2^9 2^7]; w = 'db1';

% Compute maximum level decomposition. l = wmaxlev(s,w)

l =7

% which is the same as: l = wmaxlev(min(s),w)

l =7

% Change wavelet. w = 'db7';

% Compute maximum level decomposition. l = wmaxlev(s,w)

l =3

See Also wavedec, wavedec2, wpdec, wpdec2

Page 764: Wavelet ug

wnoise

8-256

8wnoisePurpose Generate noisy wavelet test data.

Syntax X = wnoise(FUN,N)[X,XN] = wnoise(FUN,N,SQRT_SNR)[X,XN] = wnoise(FUN,N,SQRT_SNR,INIT)

Description X = wnoise(FUN,N) returns values of the test signal given by FUN, on a 2N grid of [0,1].

[X,XN] = wnoise(FUN,N,SQRT_SNR) returns a test vector X as above, rescaled such that std(X) = SQRT_SNR. The returned vector XN contains the same test vector corrupted by additive Gaussian white noise N(0,1). Then, XN has a signal-to-noise ratio of SNR = (SQRT_SNR)2.

[X,XN] = wnoise(FUN,N,SQRT_SNR,INIT) returns previous vectors X and XN, but the generator seed is set to INIT value.

The six functions below are due to Donoho and Johnstone (See “References”).

Examples % Generate 2^10 samples of 'Heavy sine' (item 3). x = wnoise(3,10);

% Generate 2^10 samples of 'Doppler' (item 4) and of% noisy 'Doppler' with a square root of signal-to-noise% ratio equal to 7. [x,noisyx] = wnoise(4,10,7);

% To introduce your own rand seed, a fourth % argument is allowed: init = 2055415866; [x,noisyx] = wnoise(4,10,7,init);

FUN = 1 or 'blocks'

FUN = 2 or 'bumps'

FUN = 3 or 'heavy sine'

FUN = 4 or 'doppler'

FUN = 5 or 'quadchirp'

FUN = 6 or 'mishmash'

Page 765: Wavelet ug

wnoise

8-257

% Plot all the test functions. ind = linspace(0,1,2^10); for i = 1:6

x = wnoise(i,10); subplot(6,1,i), plot(ind,x)

end

% Editing some graphical properties,% the following figure is generated.

See Also wden

References Donoho, D.L.; I.M. Johnstone (1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

Donoho, D.L.; I.M. Johnstone (1995), “Adapting to unknown smoothness via wavelet shrinkage via wavelet shrinkage,” JASA, vol 90, 432, pp. 1200–1224.

0 0.2 0.4 0.6 0.8 1−10

010

0 0.2 0.4 0.6 0.8 105

10

0 0.2 0.4 0.6 0.8 1−10

010

0 0.2 0.4 0.6 0.8 1−0.5

00.5

0 0.2 0.4 0.6 0.8 1−1

01

0 0.2 0.4 0.6 0.8 1−5

05

Page 766: Wavelet ug

wnoisest

8-258

8wnoisestPurpose Estimate noise of 1-D wavelet coefficients.

Syntax STDC = wnoisest(C,L,S)

Description STDC = wnoisest(C,L,S) returns estimates of the detail coefficients’ standard deviation for levels contained in the input vector S. [C,L] is the input wavelet decomposition structure (see wavedec for more information).

If C is a one dimensional cell array, STDC = wnoisest(C) returns a vector such that STDC(k) is an estimate of the standard deviation of C{k}.

If C is a numeric array, STDC = wnoisest(C) returns a vector such that STDC(k) is an estimate of the standard deviation of C(k,:).

The estimator used is Median Absolute Deviation / 0.6745, well suited for zero mean Gaussian white noise in the de-noising one-dimensional model (see thselect for more information).

Examples % The current extension mode is zero-padding (see dwtmode).

% Generate Gaussian white noise. init = 2055415866; randn('seed',init); x = randn(1,1000);

% Decompose x at level 2 using db3 wavelet. [c,l] = wavedec(x,2,'db3');

% Estimate standard deviation of coefficients % at each level 1 and 2. % Since x is a Gaussian white noise with unit % variance, estimates must be close to 1. wnoisest(c,l,1:2)

ans =1.0111 1.0763

Page 767: Wavelet ug

wnoisest

8-259

% Now suppose that x contains 10 outliers. ind = 50:50:500;x(ind) = 100 * ones(size(ind));

% Decompose x at level 1 using db3 wavelet. [ca,cd] = dwt(x,'db3');

% Ordinary estimate of cd standard deviation % overestimates noise level. std(cd)

ans =8.0206

% Robust estimate of cd standard deviation % remains close to 1 the noise level. median(abs(cd))/0.6745

ans =1.0540

Limitations This procedure is well suited for Gaussian white noise.

See Also thselect, wavedec, wden

References Donoho, D.L.; I.M. Johnstone (1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

Donoho, D.L.; I.M. Johnstone (1995), “Adapting to unknown smoothness via wavelet shrinkage via wavelet shrinkage,” JASA, vol 90, 432, pp. 1200–1224.

Page 768: Wavelet ug

wp2wtree

8-260

8wp2wtreePurpose Extract wavelet tree from wavelet packet tree.

Syntax T = wp2wtree(T)

Description wp2wtree is a one- or two-dimensional wavelet packet analysis function.

T = wp2wtree(T) computes the modified wavelet packet tree T corresponding to the wavelet decomposition tree.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet packets % using shannon entropy. wpt = wpdec(x,3,'db1');

% Plot wavelet packet tree wpt. plot(wpt)

% Compute wavelet tree. wt = wp2wtree(wpt);

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 769: Wavelet ug

wp2wtree

8-261

% Plot wavelet tree wt. plot(wt)

See Also wpdec, wpdec2

(1,0) (1,1)

(2,0) (2,1)

(3,0) (3,1)

(0,0)

Page 770: Wavelet ug

wpbmpen

8-262

8wpbmpenPurpose Penalized threshold for wavelet packet de-noising.

Syntax THR = wpbmpen(T,SIGMA,ALPHA)THR = wpbmpen(T,SIGMA,ALPHA,ARG)

Description THR = wpbmpen(T,SIGMA,ALPHA) returns a global threshold THR for de-noising. THR is obtained by a wavelet packet coefficients selection rule using a penalization method provided by Birge-Massart.

T is a wavelet packet tree corresponding to the wavelet packet decomposition of the signal or image to be de-noised.

SIGMA is the standard deviation of the zero mean Gaussian white noise in the de-noising model (see wnoisest for more information).

ALPHA is a tuning parameter for the penalty term. It must be a real number greater than 1. The sparsity of the wavelet packet representation of the de-noised signal or image grows with ALPHA. Typically ALPHA = 2.

THR minimizes the penalized criterion given by:

let t* be the minimizer of

crit(t) = -sum(c(k)^2,k<=t) + 2*SIGMA^2*t*(ALPHA + log(n/t))

where c(k) are the wavelet packet coefficients sorted in decreasing order of their absolute value and n is the number of coefficients, then THR = c(t*) .

wpbmpen(T,SIGMA,ALPHA,ARG) computes the global threshold and, in addition, plots three curves:

• 2*SIGMA^2*t*(ALPHA + log(n/t))

• sum(c(k)^2,k<=t)

• crit(t).

Examples % Example 1: Signal de-noising.% Load noisy chirp signal.load noischir; x = noischir;

Page 771: Wavelet ug

wpbmpen

8-263

% Perform a wavelet packet decomposition of the signal% at level 5 using sym6.wname = 'sym6'; lev = 5;tree = wpdec(x,lev,wname);

% Estimate the noise standard deviation from the% detail coefficients at level 1,% corresponding to the node index 2.det1 = wpcoef(tree,2);sigma = median(abs(det1))/0.6745;

% Use wpbmpen for selecting global threshold % for signal de-noising, using the recommended parameter.alpha = 2;thr = wpbmpen(tree,sigma,alpha)

thr =

4.5740

% Use wpdencmp for de-noising the signal using the above% threshold with soft thresholding and keeping the approximation.keepapp = 1;xd = wpdencmp(tree,'s','nobest',thr,keepapp);

% Plot original and de-noised signals.figure(1)subplot(211), plot(x),title('Original signal')

Page 772: Wavelet ug

wpbmpen

8-264

subplot(212), plot(xd)title('De-noised signal')

% Example 2: Image de-noising.% Load original image.load noiswom; nbc = size(map,1);

% Perform a wavelet packet decomposition of the image% at level 3 using coif2.wname = 'coif2'; lev = 3;tree = wpdec2(X,lev,wname); % Estimate the noise standard deviation from the% detail coefficients at level 1.det1 = [wpcoef(tree,2) wpcoef(tree,3) wpcoef(tree,4)];sigma = median(abs(det1(:)))/0.6745;

% Use wpbmpen for selecting global threshold % for image de-noising.alpha = 1.1;

200 400 600 800 1000

−5

0

5

Original signal

200 400 600 800 1000

−5

0

5

De−noised signal

Page 773: Wavelet ug

wpbmpen

8-265

thr = wpbmpen(tree,sigma,alpha)

thr =

38.5125

% Use wpdencmp for de-noising the image using the above% thresholds with soft thresholding and keeping the approximation.keepapp = 1;xd = wpdencmp(tree,'s','nobest',thr,keepapp);

% Plot original and de-noised images.figure(2)colormap(pink(nbc));subplot(221), image(wcodemat(X,nbc))title('Original image')subplot(222), image(wcodemat(xd,nbc))title('De-noised image')

See Also wbmpen, wden, wdencmp, wpdencmp

Original image

20 40 60 80

20

40

60

80

De−noised image

20 40 60 80

20

40

60

80

Page 774: Wavelet ug

wpcoef

8-266

8wpcoefPurpose Wavelet packet coefficients.

Syntax X = wpcoef(T,N)X = wpcoef(T)

Description wpcoef is a one- or two-dimensional wavelet packet analysis function.

X = wpcoef(T,N) returns the coefficients associated with the node N of the wavelet packet tree T. If N doesn’t exist, X = [ ];

X = wpcoef(T) is equivalent to X = wpcoef(T,0).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

figure(1); subplot(211); plot(x); title('Original signal');

% Decompose x at depth 3 with db1 wavelet packets % using Shannon entropy. wpt = wpdec(x,3,'db1');

% Plot wavelet packet tree wpt. plot(wpt)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 775: Wavelet ug

wpcoef

8-267

% Read packet (2,1) coefficients. cfs = wpcoef(wpt,[2 1]);

figure(1); subplot(212); plot(cfs); title('Packet (2,1) coefficients');

See Also wpdec, wpdec2

200 400 600 800 1000−10

−5

0

5

10Original signal

50 100 150 200 250−5

0

5Packet (2,1) coefficients

Page 776: Wavelet ug

wpcutree

8-268

8wpcutreePurpose Cut wavelet packet tree.

Syntax T = wpcutree(T,L)[T,RN] = wpcutree(T,L)

Description wpcutree is a one- or two-dimensional wavelet packet analysis function.

T = wpcutree(T,L) cuts the tree T at level L.

[T,RN] = wpcutree(T,L) returns the same arguments as above and, in addition, the vector RN contains the indices of the reconstructed nodes.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet packets% using Shannon entropy.wpt = wpdec(x,3,'db1');

% Plot wavelet packet tree wpt. plot(wpt)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 777: Wavelet ug

wpcutree

8-269

% Cut wavelet packet tree at level 2. nwpt = wpcutree(wpt,2);

% Plot new wavelet packet tree nwpt. plot(nwpt)

See Also wpdec, wpdec2

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(0,0)

Page 778: Wavelet ug

wpdec

8-270

8wpdecPurpose Wavelet packet decomposition 1-D.

Syntax T = wpdec(X,N,'wname',E,P)T = wpdec(X,N,'wname')

Description wpdec is a one-dimensional wavelet packet analysis function.

T = wpdec(X,N,'wname',E,P) returns a wavelet packet tree T corresponding to the wavelet packet decomposition of the vector X at level N, with a particular wavelet (’wname’, see wfilters for more information).

E is a string containing the type of entropy (see wentropy for more information):

E = 'shannon', 'threshold', 'norm', 'log energy', 'sure', 'user'

P is an optional parameter:

'shannon' or 'log energy': P is not used

'threshold' or 'sure': P is the threshold (0 ≤ P)

'norm': P is a power (1 ≤ P)

'user': P is a string containing the name of a user-defined function.

T = wpdec(X,N,'wname') is equivalent to T = wpdec(X,N,'wname','shannon').

The wavelet packet method is a generalization of wavelet decomposition that offers a richer signal analysis. Wavelet packet atoms are waveforms indexed by three naturally interpreted parameters: position and scale as in wavelet decomposition, and frequency.

For a given orthogonal wavelet function, a library of wavelet packets bases is generated. Each of these bases offers a particular way of coding signals, preserving global energy and reconstructing exact features. The wavelet packets can then be used for numerous expansions of a given signal.

Simple and efficient algorithms exist for both wavelet packets decomposition and optimal decomposition selection. Adaptive filtering algorithms with direct applications in optimal signal coding and data compression can then be produced.

Page 779: Wavelet ug

wpdec

8-271

In the orthogonal wavelet decomposition procedure, the generic step splits the approximation coefficients into two parts. After splitting we obtain a vector of approximation coefficients and a vector of detail coefficients, both at a coarser scale. The information lost between two successive approximations is captured in the detail coefficients. The next step consists in splitting the new approximation coefficient vector; successive details are never re-analyzed.

In the corresponding wavelet packets situation, each detail coefficient vector is also decomposed into two parts using the same approach as in approximation vector splitting. This offers the richest analysis: the complete binary tree is produced in the one-dimensional case or a quaternary tree in the two-dimensional case.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet packets% using Shannon entropy. wpt = wpdec(x,3,'db1','shannon');

% The result is the wavelet packet tree wpt.

% Plot wavelet packet tree (binary tree, or tree of order 2).plot(wpt)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 780: Wavelet ug

wpdec

8-272

Algorithm The algorithm used for the wavelet packets decomposition follows the same line as the wavelet decomposition process (see dwt and wavedec for more information).

See Also wavedec, waveinfo, wentropy, wpdec, wprec

References Coifman, R.R.; M.V. Wickerhauser, (1992), “Entropy-based Algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

Meyer, Y. (1993), Les ondelettes. Algorithmes et applications, Colin Ed., Paris, 2nd edition. (English translation: Wavelets: Algorithms and Applications, SIAM).

Wickerhauser, M.V. (1991), “INRIA lectures on wavelet packet algorithms,” Proceedings ondelettes et paquets d’ondes 17–21 June, Rocquencourt France, pp. 31–99.

Wickerhauser, M.V. (1994), Adapted wavelet analysis from theory to software algorithms, A.K. Peters.

Page 781: Wavelet ug

wpdec2

8-273

8wpdec2Purpose Wavelet packet decomposition 2-D.

Syntax T = wpdec2(X,N,'wname',E,P)T = wpdec2(X,N,'wname')

Description wpdec2 is a two-dimensional wavelet packet analysis function.

T = wpdec2(X,N,'wname',E,P) returns a wavelet packet tree T corresponding to the wavelet packet decomposition of the matrix X, at level N, with a particular wavelet (’wname’, see wfilters for more information).

E is a string containing the type of entropy (see wentropy for more information):

E = 'shannon', 'threshold', 'norm', 'log energy', 'sure', 'user'

P is an optional parameter:

'shannon' or 'log energy': P is not used

'threshold' or 'sure': P is the threshold (0 ≤ P)

'norm': P is a power (1 ≤ P)

'user': P is a string containing the name of a user-defined function.

T = wpdec2(X,N,'wname') is equivalent to

T = wpdec2(X,N,'wname','shannon').

See wpdec for a more complete description of the wavelet packet decomposition.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load image. load tire % X contains the loaded image.

% For an image the decomposition is performed using: t = wpdec2(X,2,'db1'); % The default entropy is shannon.

Page 782: Wavelet ug

wpdec2

8-274

% Plot wavelet packet tree % (quarternary tree, or tree of order 4). plot(t)

Algorithm The algorithm used for the wavelet packets decomposition follows the same line as the wavelet decomposition process (see dwt2 and wavedec2 for more information).

See Also wavedec2, waveinfo, wentropy, wpdec, wprec2

References Coifman, R.R.; M.V. Wickerhauser (1992), “Entropy-based algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

Meyer, Y. (1993), Les ondelettes. Algorithmes et applications, Colin Ed., Paris, 2nd edition. (English translation: Wavelets: Algorithms and Applications, SIAM).

Wickerhauser, M.V. (1991), “INRIA lectures on wavelet packet algorithms,” Proceedings ondelettes et paquets d’ondes 17–21 June Rocquencourt France, pp. 31–99.

Wickerhauser, M.V. (1994), Adapted wavelet analysis from theory to software Algorithms, A.K. Peters.

(1,0) (1,1) (1,2) (1,3)

(2,0) (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8) (2,9) (2,10) (2,11) (2,12) (2,13) (2,14) (2,15)

(0,0)

Page 783: Wavelet ug

wpdencmp

8-275

8wpdencmpPurpose De-noising or compression using wavelet packets.

Syntax [XD,TREED,PERF0,PERFL2] = wpdencmp(X,SORH,N,'wname',CRIT,PAR,KEEPAPP)

[XD,TREED,PERF0,PERFL2] = wpdencmp(TREE,SORH,CRIT,PAR,KEEPAPP)

Description wpdencmp is a one- or two-dimensional de-noising and compression oriented function.

wpdencmp performs a de-noising or compression process of a signal or an image, using wavelet packet. The ideas and the procedures for de-noising and compression using wavelet packet decomposition are the same as those used in the wavelets framework (see wden and wdencmp for more information).

[XD,TREED,PERF0,PERFL2] = wpdencmp(X,SORH,N,’wname’,CRIT,PAR,KEEPAPP) returns a de-noised or compressed version XD of input signal X (one- or two-dimensional) obtained by wavelet packets coefficients thresholding.

The additional output argument TREED is the wavelet packet best tree decomposition (see besttree for more information) of XD. PERFL2 and PERF0 are L2 energy recovery and compression scores in percentages.

PERFL2 = 100 * (vector-norm of WP-cfs of XD / vector-norm of WP-cfs of X)2.

If X is a one-dimensional signal and ’wname’ an orthogonal wavelet, PERFL2 is reduced to:

SORH ('s' or 'h') is for soft or hard thresholding (see wthresh for more information).

Wavelet packet decomposition is performed at level N and ’wname’ is a string containing the wavelet name. Best decomposition is performed using entropy criterion defined by string CRIT and parameter PAR (see wentropy for more information). Threshold parameter is also PAR. If KEEPAPP = 1, approximation coefficients cannot be thresholded; otherwise, they can be.

100 XD 2

X 2---------------------------

Page 784: Wavelet ug

wpdencmp

8-276

[XD,TREED,PERF0,PERFL2] = wpdencmp(TREE,SORH,CRIT,PAR,KEEPAPP) has the same output arguments, using the same options as above, but obtained directly from the input wavelet packet tree decomposition TREE (see wpdec for more information) of the signal to be de-noised or compressed.

In addition if CRIT = 'nobest' no optimization is done and the current decomposition is thresholded.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load original signal. load sumlichr; x = sumlichr;

% Use wpdencmp for signal compression. % Find default values (see ddencmp). [thr,sorh,keepapp,crit] = ddencmp('cmp','wp',x)

thr =0.5193

sorh =h

keepapp =1

crit =threshold

% De-noise signal using global thresholding with % threshold best basis.

Page 785: Wavelet ug

wpdencmp

8-277

[xc,treed,datad,perf0,perfl2] = ... wpdencmp(x,sorh,3,'db2',crit,thr,keepapp);

% Using some plotting commands,% the following figure is generated.

% Load original image. load sinsin

% Generate noisy image. init = 2055615866; randn('seed',init); x = X/18 + randn(size(X));

% Use wpdencmp for image de-noising. % Find default values (see ddencmp).[thr,sorh,keepapp,crit] = ddencmp('den','wp',x)

thr =4.9685

100 200 300 400 500

−2

−1

0

1

2

Original signal

100 200 300 400 500

−2

−1

0

1

2

Compressed Signal using Wavelet Packets

2_norm rec.: 97.52 % −− zero cfs: 53.98 %

Page 786: Wavelet ug

wpdencmp

8-278

sorh =hkeepapp =

1

crit =sure% De-noise image using global thresholding with % SURE best basis. xd = wpdencmp(x,sorh,3,'sym4',crit,thr,keepapp);

% Using some plotting commands,% the following figure is generated.

% Generate heavy sine and a noisy version of it.[xref,x] = wnoise(5,11,7,init);

Original Image

20 40 60 80100120

20

40

60

80

100

120

Noisy Image

20 40 60 80100120

20

40

60

80

100

120

De−noised Image

20 40 60 80100120

20

40

60

80

100

120

Page 787: Wavelet ug

wpdencmp

8-279

% Use wpdencmp for signal de-noising. n = length(x); thr = sqrt(2*log(n*log(n)/log(2))); xwpd = wpdencmp(x,'s',4,'sym4','sure',thr,1);

% Compare with wavelet-based de-noising result. xwd = wden(x,'rigrsure','s','one',4,'sym4');

% Using some plotting commands,% the following figure is generated.

See Also besttree, ddencmp, wdencmp, wentropy, wpbmpen, wpdec, wpdec2, wthresh

References Antoniadis, A.; G. Oppenheim, Eds. (1995), Wavelets and statistics, Lecture Notes in Statistics, 103, Springer Verlag.

Coifman, R.R.; M.V. Wickerhauser (1992), “Entropy-based algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

500 1000 1500 2000

−100

10

Original signal

500 1000 1500 2000

−100

10

Noisy Signal

500 1000 1500 2000

−100

10

De−noised Signal using Wavelet Packets

500 1000 1500 2000

−100

10

De−noised Signal using Wavelets

Page 788: Wavelet ug

wpdencmp

8-280

DeVore, R.A.; B. Jawerth, B.J. Lucier (1992), “Image compression through wavelet transform coding,” IEEE Trans. on Inf. Theory, vol. 38, No 2, pp. 719–746.

Donoho, D.L. (1993), “Progress in wavelet analysis and WVD: a ten minute tour,” in Progress in wavelet analysis and applications, Y. Meyer, S. Roques, pp. 109–128. Frontières Ed.

Donoho, D.L.; I.M. Johnstone (1994), “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol 81, pp. 425–455.

Donoho, D.L.; I.M. Johnstone, G. Kerkyacharian, D. Picard (1995), “Wavelet shrinkage: asymptopia,” Jour. Roy. Stat. Soc., series B, vol. 57 no. 2, pp. 301–369.

Page 789: Wavelet ug

wpfun

8-281

8wpfunPurpose Wavelet packet functions.

Syntax [WPWS,X] = wpfun('wname',NUM,PREC)[WPWS,X] = wpfun('wname',NUM)

Description wpfun is a wavelet packet analysis function.

[WPWS,X] = wpfun(’wname’,NUM,PREC) computes the wavelet packets for a wavelet ’wname’ (see wfilters for more information), on dyadic intervals of length 2-PREC.

PREC must be a positive integer. Output matrix WPWS contains the W functions of index from 0 to NUM, stored row-wise as [W0; W1; ... ; WNUM]. Output vector X is the corresponding common X-grid vector.

[WPWS,X] = wpfun(’wname’,NUM) is equivalent to [WPWS,X] = wpfun(’wname’,NUM,7).

The computation scheme for wavelet packets generation is easy when using an orthogonal wavelet. We start with the two filters of length 2N, denoted h(n) and g(n), corresponding to the wavelet.

Now by induction let us define the following sequence of functions (Wn(x) , n = 0,1,2,...) by:

where W0(x) = (x) is the scaling function and W1(x) = (x) is the wavelet function.

For example for the Haar wavelet we have:

W2n x( ) 2 h k( )k 0= … 2N 1–, ,

∑ Wn 2x k–( )=

W2n x( ) 2 h k( )k 0= … 2N 1–, ,

∑ Wn 2x k–( )=

φ ψ

N 1 h 0( ), h 1( ) 12

-------= = =

Page 790: Wavelet ug

wpfun

8-282

and

The equations become:

W0(x) = (x) is the haar scaling function and W1(x) = (x) is the haar wavelet, both supported in [0,1].

Then we can obtain W2n by adding two 1/2-scaled versions of Wn with distinct supports [0,1/2] and [1/2,1], and obtain W2n+1 by subtracting the same versions of Wn.

Starting from more regular original wavelets, using a similar construction, we obtain smoothed versions of this system of W-functions, all with support in the interval [0, 2N-1].

Examples % Compute the db2 Wn functions for n = 0 to 7, generating % the db2 wavelet packets. [wp,x] = wpfun('db2',7);

% Using some plotting commands,% the following figure is generated.

g 0( ) g 1( )–12

-------= =

W2n x( ) Wn 2x( ) Wn 2x 1–( ) and W2n 1+ x( ) Wn 2x( ) Wn 2x 1–( )–=( )+=

φ ψ

Page 791: Wavelet ug

wpfun

8-283

See Also wavefun, waveinfo

References Coifman, R.R.; M.V. Wickerhauser (1992), “Entropy-based Algorithms for best basis selection,” IEEE Trans. on Inf. Theory, vol. 38, 2, pp. 713–718.

Meyer, Y. (1993), Les ondelettes. Algorithmes et applications, Colin Ed., Paris, 2nd edition. (English translation: Wavelets: Algorithms and applications, SIAM).

Wickerhauser, M.V. (1991), “INRIA lectures on wavelet packet algorithms,” Proceedings ondelettes et paquets d’ondes 17–21 June Rocquencourt France, pp. 31–99.

Wickerhauser, M.V. (1994), Adapted wavelet analysis from theory to software algorithms, A.K. Peters.

0 2 4−0.5

0

0.5

1

1.5

W00 2 4

−2

−1

0

1

2

W10 2 4

−2

−1

0

1

2

3

W20 2 4

−2

−1

0

1

2

3

W3

0 2 4−2

−1

0

1

2

3

W40 2 4

−2

−1

0

1

2

3

W50 2 4

−2

−1

0

1

2

3

W60 2 4

−2

−1

0

1

2

3

W7

Page 792: Wavelet ug

wpjoin

8-284

8wpjoinPurpose Recompose wavelet packet.

Syntax T = wpjoin(T,N)[T,X] = wpjoin(T,N)T = wpjoin(T)[T,X] = wpjoin(T)

Description wpjoin is a one- or two-dimensional wavelet packet analysis function.

wpjoin updates the wavelet packet tree after the recomposition of a node.

The nodes are numbered from left to right and from top to bottom. The root index is 0.

T = wpjoin(T,N) returns the modified wavelet packet tree T corresponding to a recomposition of the node N.

[T,X] = wpjoin(T,N) also returns the coefficients of the node.

T = wpjoin(T) is equivalent to T = wpjoin(T,0).

[T,X] = wpjoin(T) is equivalent to [T,X] = wpjoin(T,0).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet packets. wpt = wpdec(x,3,'db1');

Page 793: Wavelet ug

wpjoin

8-285

% Plot wavelet packet tree wpt. plot(wpt)

% Recompose packet (1,1) or 2 wpt = wpjoin(wpt,[1 1]);

% Plot wavelet packet tree wpt. plot(wpt)

See Also wpdec, wpdec2, wpsplt

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

(1,0) (1,1)

(2,0) (2,1)

(3,0) (3,1) (3,2) (3,3)

(0,0)

Page 794: Wavelet ug

wprcoef

8-286

8wprcoefPurpose Reconstruct wavelet packet coefficients.

Syntax X = wprcoef(T,N)

Description wprcoef is a one- or two-dimensional wavelet packet analysis function.

X = wprcoef(T,N) computes reconstructed coefficients of the node N of the wavelet packet tree T.

X = wprcoef(T) is equivalent to X = wprcoef(T,0).

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

figure(1); subplot(211); plot(x); title('Original signal');

% Decompose x at depth 3 with db1 wavelet packets % using Shannon entropy. t = wpdec(x,3,'db1','shannon');

% Plot wavelet packet tree. plot(t)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

Page 795: Wavelet ug

wprcoef

8-287

% Reconstruct packet (2,1). rcfs = wprcoef(t,[2 1]);

figure(1); subplot(212); plot(rcfs); title('Reconstructed packet (2,1)');

See Also wpdec, wpdec2, wprec, wprec2

200 400 600 800 1000−10

−5

0

5

10Original signal

200 400 600 800 1000−4

−2

0

2

4Reconstructed packet (2,1)

Page 796: Wavelet ug

wprec

8-288

8wprecPurpose Wavelet packet reconstruction 1-D.

Syntax X = wprec(T)

Description wprec is a one-dimensional wavelet packet analysis function.

X = wprec(T) returns the reconstructed vector X corresponding to a wavelet packet tree T.

wprec is the inverse function of wpdec in the sense that the abstract statement wprec(wpdec(X,’wname’)) would give back X.

See Also wpdec, wpdec2, wpjoin, wprec2, wpsplt

Page 797: Wavelet ug

wprec2

8-289

8wprec2Purpose Wavelet packet reconstruction 2-D.

Syntax X = wprec2(T)

Description wprec2 is a two-dimensional wavelet packet analysis function.

X = wprec2(T) returns the reconstructed matrix X corresponding to a wavelet packet tree T.

wprec2 is the inverse function of wpdec2 in the sense that the abstract statement wprec2(wpdec2(X,’wname’)) would give back X.

See Also wpdec, wpdec2, wpjoin, wprec, wpsplt

Page 798: Wavelet ug

wpsplt

8-290

8wpspltPurpose Split (decompose) wavelet packet.

Syntax T = wpsplt(T,N)[T,cA,cD] = wpsplt(T,N)[T,cA,cH,cV,cD] = wpsplt(T,N)

Description wpsplt is a one- or two-dimensional wavelet packet analysis function.

wpsplt updates the wavelet packet tree after the decomposition of a node.

T = wpsplt(T,N) returns the modified wavelet packet tree T corresponding to the decomposition of the node N.

For a one-dimensional decomposition:

[T,cA,cD] = wpsplt(T,N) with cA = approximation and cD = detail of node N.

For a two-dimensional decomposition:

[T,cA,cH,cV,cD] = wpsplt(T,N) with cA = approximation and cH,cV,c = horizontal, vertical and diagonal details of node N.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load signal. load noisdopp; x = noisdopp;

% Decompose x at depth 3 with db1 wavelet packets. wpt = wpdec(x,3,'db1');

Page 799: Wavelet ug

wpsplt

8-291

% Plot wavelet packet tree wpt. plot(wpt)

% Decompose packet (3,0).wpt = wpsplt(wpt,[3 0]); % or equivalently wpsplt(wpt,7).

% Plot wavelet packet tree wpt. plot(wpt)

See Also wavedec, wavedec2, wpdec, wpdec2, wpjoin

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

(4,0) (4,1)

(0,0)

Page 800: Wavelet ug

wpthcoef

8-292

8wpthcoefPurpose Wavelet packet coefficients thresholding.

Syntax T = wpthcoef(T,KEEPAPP,SORH,THR)

Description wpthcoef is a one- or two-dimensional de-noising and compression utility.

NT = wpthcoef(T,KEEPAPP,SORH,THR) returns a new wavelet packet tree NT obtained from the wavelet packet tree T by coefficients thresholding.

If KEEPAPP = 1, approximation coefficients are not thresholded; otherwise, they can be thresholded.

If SORH = 's', soft thresholding is applied, if SORH = 'h', hard thresholding is applied (see wthresh for more information).

THR is the threshold value.

See Also wpdec, wpdec2, wpdencmp, wthresh

Page 801: Wavelet ug

wptree

8-293

8wptreePurpose Constructor for the class WPTREE.

Syntax T = wptree(ORDER,DEPTH,X,WNAME,ENT_TYPE,ENT_PAR)T = wptree(ORDER,DEPTH,X,WNAME)T = wptree( ... ,USERDATA)

Description T = wptree(ORDER,DEPTH,X,WNAME,ENT_TYPE,PARAMETER) returns a complete wavelet packet tree T.

ORDER is an integer, which must be equal to 2 or 4.

If ORDER = 2, T is a WPTREE object corresponding to a wavelet packet decomposition of the vector (signal) X, at level DEPTH with a particular wavelet WNAME.

If ORDER = 4, T is a WPTREE object corresponding to a wavelet packet decomposition of the matrix (image) X, at level DEPTH with a particular wavelet WNAME.

ENT_TYPE is a string containing the entropy type and ENT_PAR is an optional parameter used for entropy computation ( see wentropy, wpdec or wpdec2 for more information).

T = wptree(ORDER,DEPTH,X,WNAME) is equivalent to T = wptree(ORDER,DEPTH,X,WNAME,'shannon')

With T = wptree(ORDER,DEPTH,X,WNAME,ENT_TYPE,ENT_PAR,USERDATA) you may set a userdata field.

The function wptree returns a WPTREE object.

For more information on object fields, see the get function or type:

help wptree/get.

Class WPTREE (Parent class: DTREE)

Fields:

'dtree' : DTREE parent object.'wavInfo' : Structure (wavelet information).'entInfo' : Structure (entropy information).

Page 802: Wavelet ug

wptree

8-294

The wavelet information structure, 'wavInfo', contains:

The entropy information structure, 'entInfo', contains:

Fields from the DTREE parent object:

'allNI' is an array of size nbnode by 5, which contains:

Each line is built based on the following scheme:

Examples % Create a wavelet packet tree.x = rand(1,512);t = wptree(2,3,x,'db3');t = wpjoin(t,[4;5]);

% Plot tree t4.plot(t);

'wavName : Wavelet name.'Lo_D' : Low Decomposition filter.'Hi_D' : High Decomposition filter.'Lo_R' : Low Reconstruction filter.'Hi_R' : High Reconstruction filter.

'entName' : Entropy name.'entPar' : Entropy parameter.

'allNI' : All nodes information.

ind : index.size : Size of data.ent : Entropy.ento : Optimal entropy.

ind size ent ento

Page 803: Wavelet ug

wptree

8-295

% Click the node (3,0), (see the plot function).

See Also dtree, ntree

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

20 40 600.6

0.8

1

1.2

1.4

1.6

1.8

2

2.2data for node: (7) or (3,0).

Page 804: Wavelet ug

wpviewcf

8-296

8wpviewcfPurpose Plot wavelet packets colored coefficients.

Syntax wpviewcf(T,CMODE)wpviewcf(T,CMODE,NBCOL)

Description wpviewcf(T,CMODE) plots the colored coefficients for the terminal nodes of the tree T.

T is a wavelet packet tree and CMODE is an integer, which represents the color mode. The color modes are listed in the table below.

wpviewcf(T,CMODE,NBCOL) uses NBCOL colors.

Color Mode Description

1 Frequency order – Global coloration – Absolute values

2 Frequency order – By level – Absolute values

3 Frequency order – Global coloration – Values

4 Frequency order – By level coloration – Values

5 Natural order – Global coloration – Absolute values

6 Natural order – By level – Absolute values

7 Natural order – Global coloration – Values

8 Natural order – By level coloration – Values

Page 805: Wavelet ug

wpviewcf

8-297

Examples % Create a wavelet packet tree.x = sin(8*pi*[0:0.005:1]);t = wpdec(x,4,'db1');

% Plot tree t.% Click the node (3,0), (see the plot function)plot(t);

% Plot the colored wavelet packet coefficients.wpviewcf(t,1);

See Also wpdec

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7)

5 10 15 20 25−3

−2

−1

0

1

2

3data for node: (7) or (3,0).

Frequency Order : Global + abs

50 100 150 200

11

12

14

13

9

10

8

7

Page 806: Wavelet ug

wrcoef

8-298

8wrcoefPurpose Reconstruct single branch from 1-D wavelet coefficients.

Syntax X = wrcoef('type',C,L,'wname',N)X = wrcoef('type',C,L,Lo_R,Hi_R,N)X = wrcoef('type',C,L,'wname')X = wrcoef('type',C,L,Lo_R,Hi_R)

Description wrcoef reconstructs the coefficients of a one-dimensional signal, given a wavelet decomposition structure (C and L) and either a specified wavelet (’wname’, see wfilters for more information) or specified reconstruction filters (Lo_R and Hi_R).

X = wrcoef(’type’,C,L,’wname’,N) computes the vector of reconstructed coefficients, based on the wavelet decomposition structure [C,L] (see wavedec for more information), at level N. ’wname’ is a string containing the wavelet name.

Argument ’type’ determines whether approximation (’type’ = 'a') or detail (’type’ = 'd') coefficients are reconstructed. When ’type’ = 'a', N is allowed to be 0; otherwise, a strictly positive number N is required. Level N must be an integer such that N ≤ length(L)-2.

X = wrcoef(’type’,C,L,Lo_R,Hi_R,N) computes coefficients as above, given the reconstruction filters you specify.

X = wrcoef(’type’,C,L,’wname’) and X = wrcoef(’type’,C,L,Lo_R,Hi_R) reconstruct coefficients of maximum level N = length(L)-2.

Page 807: Wavelet ug

wrcoef

8-299

Examples % The current extension mode is zero-padding (see dwtmode).

% Load a one-dimensional signal. load sumsin; s = sumsin;

% Perform decomposition at level 5 of s using sym4. [c,l] = wavedec(s,5,'sym4');

% Reconstruct approximation at level 5, % from the wavelet decomposition structure [c,l].a5 = wrcoef('a',c,l,'sym4',5);

% Using some plotting commands,% the following figure is generated.

See Also appcoef, detcoef, wavedec

0 200 400 600 800 1000−4

−2

0

2

4Original signal s.

0 200 400 600 800 1000−2

−1

0

1

2Reconstructed approximation at level 5 : a5

Page 808: Wavelet ug

wrcoef2

8-300

8wrcoef2Purpose Reconstruct single branch from 2-D wavelet coefficients.

Syntax X = wrcoef2('type',C,S,'wname',N)X = wrcoef2('type',C,S,Lo_R,Hi_R,N)X = wrcoef2('type',C,S,'wname')X = wrcoef2('type',C,S,Lo_R,Hi_R)

Description wrcoef2 is a two-dimensional wavelet analysis function. wrcoef2 reconstructs the coefficients of an image.

X = wrcoef2(’type’,C,S,’wname’,N) computes the matrix of reconstructed coefficients of level N, based on the wavelet decomposition structure [C,S] (see wavedec2 for more information).

’wname’ is a string containing the name of the wavelet (see wfilters for more information). If ’type’ = 'a', approximation coefficients are reconstructed; otherwise if ’type’ = 'h' ('v' or 'd', respectively), horizontal (vertical or diagonal, respectively) detail coefficients are reconstructed.

Level N must be an integer such that: 0 ≤ N ≤ size(S,1)-2 if ’type’ = 'a' and such that 1 ≤ N ≤ size(S,1)-2 if ’type’ = 'h', 'v' or ’d’.

Instead of giving the wavelet name, you can give the filters.

For X = wrcoef2(’type’,C,S,Lo_R,Hi_R,N), Lo_R is the reconstruction low-pass filter and Hi_R is the reconstruction high-pass filter.

X = wrcoef2(’type’,C,S,’wname’) or X = wrcoef2(’type’,C,S,Lo_R,Hi_R) reconstruct coefficients of maximum level N = size(S,1)-2.

Examples % The current extension mode is zero-padding (see dwtmode).

% Load an image. load woman;% X contains the loaded image.

% Perform decomposition at level 2 % of X using sym5. [c,s] = wavedec2(X,2,'sym5');

Page 809: Wavelet ug

wrcoef2

8-301

% Reconstruct approximations at % levels 1 and 2, from the wavelet % decomposition structure [c,s]. a1 = wrcoef2('a',c,s,'sym5',1); a2 = wrcoef2('a',c,s,'sym5',2);

% Reconstruct details at level 2, % from the wavelet decomposition % structure [c,s]. % 'h' is for horizontal, % 'v' is for vertical, % 'd' is for diagonal. hd2 = wrcoef2('h',c,s,'sym5',2); vd2 = wrcoef2('v',c,s,'sym5',2); dd2 = wrcoef2('d',c,s,'sym5',2);

% All these images are of same size sX. sX = size(X)

sX =256 256

sa1 = size(a1)

sa1 =256 256

shd2 = size(hd2)

shd2 =256 256

See Also appcoef2, detcoef2, wavedec2

Page 810: Wavelet ug

wrev

8-302

8wrevPurpose Flip vector.

Syntax Y = wrev(X)

Description wrev is a general utility.

Y = wrev(X) reverses the vector X.

Examples % Set simple vector. v = [1 2 3];

% Reverse v.wrev(v)

ans =3 2 1

% Reverse v transpose. wrev(v')

ans =3 2 1

See Also fliplr, flipud

Page 811: Wavelet ug

write

8-303

8writePurpose Write values in WPTREE object fields.

Syntax T = write(T,'cfs',NODE,COEFS)T = write(T,'cfs',N1,CFS1,'cfs',N2,CFS2, ...)

Description T = write(T,'cfs',NODE,COEFS) writes coefficients for the terminal node NODE.

T = write(T,'cfs',N1,CFS1,'cfs',N2,CFS2, ...) writes coefficients CFS1, CFS2, ... for the terminal nodes N1, N2, ...

Caution The coefficients values must have the suitable size. You can use S = read(T,'sizes',NODE) or S = read(T,'sizes',[N1;N2; ...]) in order to get those sizes.

Examples % Create a wavelet packet tree.load noisdopp; x = noisdopp;t = wpdec(x,3,'db3');t = wpjoin(t,[4;5]);

% Plot tree t and click the node (0,0) (see the plot function).plot(t);

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

200 400 600 800 1000−10

−8

−6

−4

−2

0

2

4

6

8

10data for node: (0) or (0,0).

Page 812: Wavelet ug

write

8-304

% Write values.sNod = read(t,'sizes',[4,5,7]); cfs4 = zeros(sNod(1,:));cfs5 = zeros(sNod(2,:));cfs7 = zeros(sNod(3,:));t = write(t,'cfs',4,cfs4,'cfs',5,cfs5,'cfs',7,cfs7);

% Plot tree t and click the node (0,0) (see the plot function).plot(t)

See Also disp, get, read, set

(0,0)

(1,0) (1,1)

(2,0) (2,1) (2,2) (2,3)

(3,0) (3,1) (3,6) (3,7)

200 400 600 800 1000−4

−3

−2

−1

0

1

2

3

4

5data for node: (0) or (0,0).

Page 813: Wavelet ug

wtbo

8-305

8wtboPurpose Constructor for the class WTBO.

Syntax OBJ = wtboOBJ = wtbo(USERDATA)

Description OBJ = wtbo returns a WTBO object. Any object in the Wavelet Toolbox is parented by a WTBO object.

With OBJ = wtbo(USERDATA) you can set a userdata field.

Class WTBO (Parent class: none)

Fields:

wtboInfo : Object information (not used in the current version of the toolbox).

ud : Userdata field.

Page 814: Wavelet ug

wthcoef

8-306

8wthcoefPurpose Wavelet coefficient thresholding 1-D.

Syntax NC = wthcoef('d',C,L,N,P) NC = wthcoef('d',C,L,N)NC = wthcoef('a',C,L) NC = wthcoef('t',C,L,N,T,SORH)

Description wthcoef is a one-dimensional de-noising and compression oriented function.

NC = wthcoef('d',C,L,N,P) returns coefficients obtained from the wavelet decomposition structure [C,L] (see wavedec for more information), by rate compression defined in vectors N and P. N contains the detail levels to be compressed and P the corresponding percentages of lower coefficients to be set to zero. N and P must be of same length. Vector N must be such that 1 ≤ N(i) ≤ length(L)-2.

NC = wthcoef('d',C,L,N) returns coefficients obtained from [C,L] by setting all the coefficients of detail levels defined in N to zero.

NC = wthcoef('a',C,L) returns coefficients obtained by setting approximation coefficients to zero.

NC = wthcoef('t',C,L,N,T,SORH) returns coefficients obtained from the wavelet decomposition structure [C,L] by soft (if SORH='s') or hard (if SORH='h') thresholding (see wthresh for more information) defined in vectors N and T. N contains the detail levels to be thresholded and T the corresponding thresholds. N and T must be of the same length.

[NC,L] is the modified wavelet decomposition structure.

See Also wavedec, wthresh

Page 815: Wavelet ug

wthcoef2

8-307

8wthcoef2Purpose Wavelet coefficient thresholding 2-D.

Syntax NC = wthcoef2('type',C,S,N,T,SORH) NC = wthcoef2('type',C,S,N)NC = wthcoef2('a',C,S) NC = wthcoef2('t',C,S,N,T,SORH)

Description wthcoef2 is a two-dimensional de-noising and compression oriented function.

For ’type’ = 'h' ( ’v' or 'd'), NC = wthcoef2(’type’,C,S,N,T,SORH) returns the horizontal (vertical or diagonal, respectively) coefficients obtained from the wavelet decomposition structure [C,S] (see wavedec2 for more information), by soft (if SORH='s') or hard (if SORH='h') thresholding defined in vectors N and T. N contains the detail levels to be thresholded and T the corresponding thresholds. N and T must be of the same length. The vector N must be such that 1 ≤ N(i) ≤ size(S,1)-2.

For ’type’ = 'h' ('v' or 'd'), NC = wthcoef2(’type’,C,S,N) returns the horizontal (vertical or diagonal, respectively) coefficients obtained from [C,S] by setting all the coefficients of detail levels defined in N to zero.

NC = wthcoef2('a',C,S) returns the coefficients obtained by setting approximation coefficients to zero.

NC = wthcoef2('t',C,S,N,T,SORH) returns the detail coefficients obtained from the wavelet decomposition structure [C,S] by soft (if SORH='s') or hard (if SORH='h') thresholding (see wthresh for more information) defined in vectors N and T. N contains the detail levels to be thresholded and T the corresponding thresholds which are applied in the three detail orientations. N and T must be of the same length.

[NC,S] is the modified wavelet decomposition structure.

See Also wavedec2, wthresh

Page 816: Wavelet ug

wthresh

8-308

8wthreshPurpose Perform soft or hard thresholding.

Syntax Y = wthresh(X,SORH,T)

Description Y = wthresh(X,SORH,T) returns the soft (if SORH = 's') or hard (if SORH = 'h') T-thresholding of the input vector or matrix X. T is the threshold value.

Y = wthresh(X,'s',T) returns , soft thresholding is wavelet shrinkage ( (x)+ = 0 if x < 0; (x)+ = x, if x ≥ 0 ).

Y = wthresh(X,'h',T) returns , hard thresholding is cruder.

Examples % Generate signal and set threshold. y = linspace(-1,1,100); thr = 0.4;

% Perform hard thresholding. ythard = wthresh(y,'h',thr);

% Perform soft thresholding. ytsoft = wthresh(y,'s',thr);

% Using some plotting commands,% the following figure is generated.

See Also wden, wdencmp, wpdencmp

Y sign X( ) X T–( )+⋅=

Y X.1 X T>( )=

−1 0 1−1

−0.5

0

0.5

1Original signal

−1 0 1−1

−0.5

0

0.5

1Hard thresholded signal

−1 0 1−1

−0.5

0

0.5

1Soft thresholded signal

Page 817: Wavelet ug

wthrmngr

8-309

8wthrmngrPurpose Threshold settings manager.

Syntax THR = wthrmngr(OPTION,METHOD,VARARGIN)

Description THR = wthrmngr(OPTION,METHOD,VARARGIN) returns a global threshold or level dependent thresholds depending on OPTION. The inputs, VARARGIN, depend on the OPTION and METHOD values.

This M-file returns the thresholds used throughout the MATLAB Wavelet Toolbox for de-noising and compression tools (command line M-files or GUI tools).

Valid options for the METHOD parameter are listed in the table below.

METHOD Description

'scarcehi' See wdcbm or wdcbm2 when used with 'high' predefined value of parameter M.

'scarceme' See wdcbm or wdcbm2 when used with 'medium' predefined value of parameter M.

'scarcelo' See wdcbm or wdcbm2 when used with 'low' predefined value of parameter M.

'sqtwolog' See 'sqtwolog' option in thselect, and see also wden.

'sqtwologuwn' See 'sqtwolog' option in thselect, and see also wden when used with 'sln' option.

'sqtwologswn' See 'sqtwolog' option in thselect, and see also wden when used with 'mln' option.

'rigsure' See 'rigsure' option in thselect, and see also wden.

'heursure' See 'heursure' option in thselect, and see also wden.

'minimaxi' See 'minimaxi' option in thselect, and see also wden.

'penalhi' See wbmpen or wpbmpen when used with 'high' value of parameter ALPHA.

'penalme' See wbmpen or wpbmpen when used with 'medium' value of parameter ALPHA.

Page 818: Wavelet ug

wthrmngr

8-310

Discrete Wavelet 1-D options.

Compression using a global threshold.X is the signal to be compressed and [C,L] is the wavelet decomposition structure of the signal to be compressed.

THR = wthrmngr('dw1dcompGBL','rem_n0',X)

THR = wthrmngr('dw1dcompGBL','bal_sn',X)

Compression using level dependent thresholds.X is the signal to be compressed and [C,L] is the wavelet decomposition structure of the signal to be compressed.

ALFA is a sparsity parameter (see wdcbm for more information).

THR = wthrmngr('dw1dcompLVL','scarcehi',C,L,ALFA) ALFA must be such that 2.5 < ALFA < 10

THR = wthrmngr('dw1dcompLVL','scarceme',C,L,ALFA) ALFA must be such that 1.5 < ALFA < 2.5

THR = wthrmngr('dw1dcompLVL','scarcelo',C,L,ALFA) ALFA must be such that 1 < ALFA < 2

'penallo' See wbmpen or wpbmpen when used with 'low' value of parameter ALPHA.

'rem_n0' This option returns a threshold close to 0. A typical THR value is median(abs(coefficients)).

'bal_sn' This option returns a threshold such that the percentages of retained energy and number of zeros are the same.

'sqrtbal_sn' This option returns a threshold equal to the square root of the value such that the percentages of retained energy and number of zeros are the same.

METHOD Description

Page 819: Wavelet ug

wthrmngr

8-311

De-noising using level dependent thresholds.[C,L] is the wavelet decomposition structure of the signal to be de-noised, SCAL defines the multiplicative threshold rescaling (see wden for more information) and ALFA is a sparsity parameter (see wbmpen for more information).

THR = wthrmngr('dw1ddenoLVL','sqtwolog',C,L,SCAL)

THR = wthrmngr('dw1ddenoLVL','rigrsure',C,L,SCAL)

THR = wthrmngr('dw1ddenoLVL','heursure',C,L,SCAL)

THR = wthrmngr('dw1ddenoLVL','minimaxi',C,L,SCAL)

THR = wthrmngr('dw1ddenoLVL','penalhi',C,L,ALFA) ALFA must be such that 2.5 < ALFA < 10

THR = wthrmngr('dw1ddenoLVL','penalme',C,L,ALFA) ALFA must be such that 1.5 < ALFA < 2.5

THR = wthrmngr('dw1ddenoLVL','penallo',C,L,ALFA) ALFA must be such that 1 < ALFA < 2

Discrete Stationary Wavelet 1-D options.

De-noising using level dependent thresholds.SWTDEC is the stationary wavelet decomposition structure of the signal to be de-noised, SCAL defines the multiplicative threshold rescaling (see wden for more information) and ALFA is a sparsity parameter (see wbmpen for more information).

THR = wthrmngr('sw1ddenoLVL',METHOD,SWTDEC,SCAL)

THR = wthrmngr('sw1ddenoLVL',METHOD,SWTDEC,ALFA)

The options for METHOD are the same as in the 'dw1ddenoLVL'case.

Discrete Wavelet 2-D options.

Compression using a global threshold.X is the image to be compressed and [C,S] is the wavelet decomposition structure of the image to be compressed.

THR = wthrmngr('dw2dcompGBL','rem_n0',X)

Page 820: Wavelet ug

wthrmngr

8-312

THR = wthrmngr('dw2dcompGBL','bal_sn',C,S)

THR = wthrmngr('dw2dcompGBL','sqrtbal_sn',C,S)

Compression using level dependent thresholds. X is the image to be compressed and [C,S] is the wavelet decomposition structure of the image to be compressed. ALFA is a sparsity parameter (see wdcbm2 for more information).

THR = wthrmngr('dw2dcompLVL','scarcehi',C,L,ALFA) ALFA must be such that 2.5 < ALFA < 10

THR = wthrmngr('dw2dcompLVL','scarceme',C,L,ALFA) ALFA must be such that 1.5 < ALFA < 2.5

THR = wthrmngr('dw2dcompLVL','scarcelo',C,L,ALFA) ALFA must be such that 1 < ALFA < 2

De-noising using level dependent thresholds.[C,S] is the wavelet decomposition structure of the image to be de-noised, SCAL defines the multiplicative threshold rescaling (see wden for more information) and ALFA is a sparsity parameter (see wbmpen for more information).

THR = wthrmngr('dw2ddenoLVL','penalhi',C,S,ALFA) ALFA must be such that 2.5 < ALFA < 10

THR = wthrmngr('dw2ddenoLVL','penalme',C,L,ALFA) ALFA must be such that 1.5 < ALFA < 2.5

THR = wthrmngr('dw2ddenoLVL','penallo',C,L,ALFA) ALFA must be such that 1 < ALFA < 2

THR = wthrmngr('dw2ddenoLVL','sqtwolog',C,S,SCAL)

THR = wthrmngr('dw2ddenoLVL','sqrtbal_sn',C,S)

Discrete Stationary Wavelet 2-D options.

De-noising using level dependent thresholds.SWTDEC is the stationary wavelet decomposition structure of the image to be de-noised, SCAL defines the multiplicative threshold rescaling (see wden for more information) and ALFA is a sparsity parameter (see wbmpen for more information).

Page 821: Wavelet ug

wthrmngr

8-313

THR = wthrmngr('sw2ddenoLVL',METHOD,SWTDEC,SCAL)

THR = wthrmngr('sw2ddenoLVL',METHOD,SWTDEC,ALFA)

The options for METHOD are the same as in the 'dw2ddenoLVL' case.

Discrete Wavelet Packet 1-D options.

Compression using a global threshold.X is the signal to be compressed and WPT is the wavelet packet decomposition structure of the signal to be compressed.

THR = wthrmngr('wp1dcompGBL','bal_sn',WPT)

THR = wthrmngr('wp1dcompGBL','rem_n0',X)

De-noising using a global threshold.WPT is the wavelet packet decomposition structure of the signal to be de-noised.

THR = wthrmngr('wp1ddenoGBL','sqtwologuwn',WPT)

THR = wthrmngr('wp1ddenoGBL','sqtwologswn',WPT)

THR = wthrmngr('wp1ddenoGBL','bal_sn',WPT)

THR = wthrmngr('wp1ddenoGBL','penalhi',WPT) see wbmpen with ALFA = 6.25

THR = wthrmngr('wp1ddenoGBL','penalme',WPT) see wbmpen with ALFA = 2

THR = wthrmngr('wp1ddenoGBL','penallo',WPT) see wbmpen with ALFA = 1.5

Discrete Wavelet Packet 2-D options.

Compression using a global threshold.X is the image to be compressed and WPT is the wavelet packet decomposition structure of the image to be compressed.

THR = wthrmngr('wp2dcompGBL','bal_sn',WPT)

THR = wthrmngr('wp2dcompGBL','rem_n0',X)

THR = wthrmngr('wp2dcompGBL','sqrtbal_sn',WPT)

Page 822: Wavelet ug

wthrmngr

8-314

De-noising using a global threshold.WPT is the wavelet packet decomposition structure of the image to be de-noised.

THR = wthrmngr('wp2ddenoGBL','sqtwologuwn',WPT)

THR = wthrmngr('wp2ddenoGBL','sqtwologswn',WPT)

THR = wthrmngr('wp2ddenoGBL','sqrtbal_sn',WPT)

THR = wthrmngr('wp2ddenoGBL','penalhi',WPT) see wbmpen with ALFA = 6.25

THR = wthrmngr('wp2ddenoGBL','penalme',WPT) see wbmpen with ALFA = 2

THR = wthrmngr('wp2ddenoGBL','penallo',WPT) see wbmpen with ALFA = 1.5

Page 823: Wavelet ug

wtreemgr

8-315

8wtreemgrPurpose NTREE object manager.

Syntax VARARGOUT = wtreemgr(OPT,T,VARARGIN)

Description wtreemgr is a tree management utility.

This function returns information on the tree T depending on the value of the OPT parameter.

Allowed values for OPT are listed in the table below.

The functionality associated with the OPT value you specify are described in the functions listed in the “See Also” section.

See Also allnodes, isnode, istnode, leaves, nodeasc, nodedesc, nodepar, noleaves, ntnode, tnodes, treedpth, treeord

'allnodes' : Tree nodes

'isnode' : True for existing node

'istnode' : True for terminal nodes

'nodeasc' : Node ascendants

'nodedesc' : Node descendants

'nodepar' : Node parent

'ntnode' : Number of terminal nodes

'tnodes' : Terminal nodes

'leaves' : Terminal nodes

'noleaves' : Not terminal nodes

'order' : Tree order

'depth' : Tree depth

Page 824: Wavelet ug

wvarchg

8-316

8wvarchgPurpose Find variance change points.

Syntax [PTS_OPT,KOPT,T_EST] = wvarchg(Y,K,D)[PTS_OPT,KOPT,T_EST] = wvarchg(Y,K)[PTS_OPT,KOPT,T_EST] = wvarchg(Y)

Description [PTS_OPT,KOPT,T_EST] = wvarchg(Y,K,D)computes the estimated change points of the variance of signal Y for j change points, with j = 1, 2, … , K-1. Integer KOPT is the proposed number of change points (0 ≤ KOPT < K-1). The vector PTS_OPT contains the corresponding change points. If KOPT = 0, PTS_OPT = [].

Integer D is the minimum delay between two change points.

K and D must be integers such that 1 < K << length(Y) and 1 ≤ D << length(Y).

The signal Y should be zero mean.

For 2 ≤ i ≤ K, T_EST(i,1:i-1) contains the i-1 instants of the variance change points and if KOPT > 0, then PTS_OPT = T_EST(KOPT+1,1:KOPT).

wvarchg(Y,K) is equivalent to wvarchg(Y,K,10).

wvarchg(Y) is equivalent to wvarchg(Y,6,10).

Examples % Generate signal from a fixed design regression model% with two change points in the noise variance located% at positions 200 and 600. % Generate block test function.x = wnoise(1,10); % Generate noisy blocks with change points.init = 2055615866; randn('seed',init);bb = randn(1,length(x));cp1 = 200; cp2 = 600;x = x + [bb(1:cp1),bb(cp1+1:cp2)/3,bb(cp2+1:end)]; % The aim of this example is to recover the two % change points in signal x.% In addition, this example illustrates how the GUI% tools propose change point locations for interval% dependent de-noising thresholds.

Page 825: Wavelet ug

wvarchg

8-317

% 1. Recover a noisy signal by suppressing an% approximation.% Perform a single-level wavelet decomposition % of the signal using db3.wname = 'db3'; lev = 1;[c,l] = wavedec(x,lev,wname);

% Reconstruct detail at level 1.det = wrcoef('d',c,l,wname,1);

% 2. Replace 2% of the biggest values by the mean% in order to remove almost all the signal.x = sort(abs(det));v2p100 = x(fix(length(x)*0.98));ind = find(abs(det)>v2p100);det(ind) = mean(det);

% 3. Use wvarchg for estimating the change points with% the following default parameters.% - the minimum delay between two change points d = 10.% - the maximum number of change points is 5. [pts_Opt,kopt,t_est] = wvarchg(det)pts_Opt = 199 601

kopt = 2

t_est = 1024 0 0 0 0 0 601 1024 0 0 0 0 199 601 1024 0 0 0 199 261 601 1024 0 0 207 235 261 601 1024 0 207 235 261 393 601 1024

% Estimated change points are close to the true change % points [200,600].

Page 826: Wavelet ug

wvarchg

8-318

% 4. (Optional) Replace the estimated change points.% For 2 <= i <= 6, t_est(i,1:i-1) contains the i-1 instants% of the variance change points and since kopt is the proposed% number of change points, then:% cp_est = t_est(kopt+1,1:kopt);% You can replace the estimated change points by:% cp_New = t_est(knew+1,1:knew);% where 2 ≤ knew ≤ 6

References Lavielle, M. (1999), “Detection of multiple changes in a sequence of dependent variables,” Stoch. Proc. and their Applications, 83, 2, pp. 79–102.

Page 827: Wavelet ug

A

GUI Reference

General Features . . . . . . . . . . . . . . . . . . A-3Color Coding . . . . . . . . . . . . . . . . . . . . A-3Connection of Plots . . . . . . . . . . . . . . . . . . A-3Using the Mouse . . . . . . . . . . . . . . . . . . . A-4Controlling the Colormap . . . . . . . . . . . . . . . A-6Using Menus . . . . . . . . . . . . . . . . . . . A-10Using the View Axes Button . . . . . . . . . . . . . A-14Using the Interval Dependent Threshold Settings Tool . . A-16

Continuous Wavelet Tool Features . . . . . . . . . A-18

Wavelet 1-D Tool Features . . . . . . . . . . . . . A-19Tree Mode . . . . . . . . . . . . . . . . . . . . A-19More Display Options . . . . . . . . . . . . . . . . A-19

Wavelet 2-D Tool Features . . . . . . . . . . . . . A-21

Wavelet Packet Tool Features (1-D and 2-D) . . . . A-22Node Action Functionality . . . . . . . . . . . . . . A-23

Wavelet Display Tool . . . . . . . . . . . . . . . A-26

Wavelet Packet Display Tool . . . . . . . . . . . A-27

Page 828: Wavelet ug

A GUI Reference

A-2

This appendix explains some of the features of the Wavelet Toolbox graphical user interface (GUI).

Sections include:

• “General Features” on page A-3

• “Continuous Wavelet Tool Features” on page A-19

• “Wavelet 1-D Tool Features” on page A-20

• “Wavelet 2-D Tool Features” on page A-22

• “Wavelet Packet Tool Features (1-D and 2-D)” on page A-23

• “Wavelet Display Tool” on page A-28

• “Wavelet Packet Display Tool” on page A-29

Note In this appendix, axis (or axes) refers to the MATLAB graphic object.

Page 829: Wavelet ug

General Features

A-3

General FeaturesSome features of the Wavelet Toolbox’s graphical user interface are:

• Color coding

• Connectedness of plots

• Using the mouse

• Controlling the colormap

• Controlling the number of colors

• Controlling the coloration mode

• Customizing graphical objects

• Using menus

• Using View Axes button

• Using Interval Dependent Threshold Settings tool

Color CodingIn all the graphical tools, signals and analysis components are color coded as follows.

Connection of PlotsPlots containing related information and graphed on the same abscissa are connected in the sense that manipulations performed on one plot affect all others in the same way. For images, the connection holds in both abscissa and ordinate. You can manipulate all plots along an individual axis (X or Y) or you can manipulate all plots along both axes at the same time (XY).

Signal Shown in

Original RedReconstructed or synthesized YellowApproximations Variegated shades of blue

(high level = darker)Details Variegated shades of green

(high level = darker)

Page 830: Wavelet ug

A GUI Reference

A-4

For example, the approximations and details shown in the separate mode view of a decomposition all respond together when any of the plots is magnified or zoomed.

Using the MouseThe Wavelet Toolbox uses three types of mouse control.

Left Mouse Button Middle Mouse Button Right Mouse Button

Make selections Activate controls

Display a cross-hair to show position-dependent information

Translate plots up and down, and left and right

Zooming here

Magnifies all the plots in unison

Shift + Option +

Page 831: Wavelet ug

General Features

A-5

Note The functionality of the Middle Mouse Button and the Right Mouse Button can be inverted depending on the platform.

Making Selections and Activating ControlsMost of your work with the Wavelet Toolbox graphical tools involves making selections and activating controls. You do this using the left (or only) mouse button.

Translating PlotsBy holding down the right mouse button (or its equivalent on a one- or two-button mouse), you can move the mouse to draw a rectangle in either a horizontal or vertical orientation. Releasing the middle mouse button then causes the plot to shift horizontally (or vertically) by an amount proportional to the width (or height) of the rectangle.

Displaying Position-Dependent InformationWhen you hold down the middle mouse button (or its equivalent on a one- or two-button mouse), a cross-hair cursor appears over the graph or plot.

Page 832: Wavelet ug

A GUI Reference

A-6

Position-dependent information also appears in the Info box located at the bottom center of the tool. The type of information that appears depends on what tool you are using and the plot in which your cursor is located. For example, the figure on the right shows information for a discrete wavelet packet.

Controlling the ColormapThe Colormap selection box, located at the lower right of the window, allows you to adjust the colormap that is used to plot images or coefficients (wavelet or wavelet packet).

This is more than an aesthetic adjustment because you are likely to see different features depending on your colormap selection.

Consider these images of the Mandelbrot set generated in the Wavelet Packet 2-D tool, shown here using the bone and 1–bone colormaps.

Page 833: Wavelet ug

General Features

A-7

Controlling the Number of ColorsThe Nb. Colors slider, located at the bottom right of the window, allows you to adjust how many colors the tool uses to plot images or coefficients (wavelet or wavelet packet). You can also use the edit control to adjust the number of colors. Adjusting the number of colors can highlight different features of the plot.

Consider the coefficients plot of the Koch curve generated in the Continuous Wavelet tool, shown here using 129 colors.

bone 1–bone

Page 834: Wavelet ug

A GUI Reference

A-8

and here using 68 colors.6

Controlling the Coloration ModeIn the Continuous Wavelet tools, the coloration of coefficients can be done in several different ways.

Page 835: Wavelet ug

General Features

A-9

In the Wavelet 1-D tool, you access coefficients coloration with the More Display Options button, and then select the desired Coloration Mode option.

The More Display Options button appears only when the Display mode is one of the following — Show and Scroll, Show and Scroll (Stem Cfs), Superimposed and Separate). In this case, scales are replaced by levels in all options of the Coloration Mode menu.

Three parameters are used to do coefficients coloration:

init or current:

by scale or all scales:

abs (or not):

When init is selected, coloration is performed with all the coefficient values.

When current is selected, only a portion of the coefficients is used to make the coloration. This portion is taken from the current axis limits of the displayed coefficients.

When by scale is selected, the coloration is done separately for each scale. Otherwise the wavelet coefficients at all scales are used to scale the coloration.

When abs is not selected, the values of the coefficients are used (this is called a Normal Mode). Otherwise, the absolute values are used (this is called an Absolute Mode).

Page 836: Wavelet ug

A GUI Reference

A-10

Using Menus

General MenubarAt the top of most windows you find the same kind of structure. The menubar of each figure in the Wavelet Toolbox is very similar to the menubar of the default MATLAB figures. You can use many of the tools that are offered in the menus and associated toolbar of the standard MATLAB figures.

One of the main differences is the View menu, which depends on the current tool used.

View Dynamical Visualization Tool Option.

The View⇒Dynamical Visualization Tool option lets you enable or disable the Dynamical Visualization Tool located at the bottom of each window.

Page 837: Wavelet ug

General Features

A-11

Before using Zoom In, Zoom Out, or Rotate 3D options (or the equivalent icons from the toolbar), you must disable the Dynamical Visualization Tool to avoid possible conflicts.

Default Display Mode Option.

The Default Display Mode option is specific to the Wavelet 1-D tool and lets you set a default Display Mode for all the different analyses you perform inside the same tool.

File Menu OptionsDepending on the tool you are using, some customized options are added to the File menu. For example, for the Wavelet 1-D tool, the following options are added:

Page 838: Wavelet ug

A GUI Reference

A-12

Many windows have a File⇒Example Analysis menu option, which allows you to select an analysis example using predefined parameters.

Export the current figure

Close the current figure

Page 839: Wavelet ug

General Features

A-13

Here is an example of the Wavelet 1-D tool.

Help Menu OptionsThe help menu structure is very similar in all the figures, but many options are specific to the current tool in use.

Page 840: Wavelet ug

A GUI Reference

A-14

Using the View Axes Button The Dynamical Visualization Tool is located at the bottom of most of the windows in the Wavelet Toolbox. In this tool, the View Axes toggle button lets you magnify the axis that you choose.

Help on the current tool

General help on the Wavelet Toolbox

Contextual help mechanism

Help on related items

Access to the demos

Page 841: Wavelet ug

General Features

A-15

The toggle buttons in the View Axes figure are positioned so that you can understand which axis is correlated with a button.

Page 842: Wavelet ug

A GUI Reference

A-16

When you click the same toggle button again, you restore the original view.

Clicking the View Axes toggle button again closes the View Axes figure.

Page 843: Wavelet ug

General Features

A-17

Using the Interval-Dependent Threshold Settings Tool The following tools in the Wavelet Toolbox let you define interval-dependent thresholds:

• Wavelet De-noising 1-D

• Wavelet Compression 1-D

• SWT De-noising 1-D

• Regression Estimation 1-D

• Density Estimation 1-D

To the right of the main window for these tools, you see a command frame similar to the following

Clicking the Int. dependent threshold settings toggle button displays the Int. dependent Threshold Settings for ... window. After some computation is performed, the following figure appears.

Page 844: Wavelet ug

A GUI Reference

A-18

For more information on how to change interval limits and threshold values, see the section “One-Dimensional Variance Adaptive Thresholding of Wavelet Coefficients” on page 2-136.

Page 845: Wavelet ug

Continuous Wavelet Tool Features

A-19

Continuous Wavelet Tool FeaturesHere is an example of an option that allows you to perform analysis using different scale modes.

The three edit boxes allow you to specify the first scale value, the maximum scale value and the step size.

Default: min = 2, step = 2, max = 32

In power 2 mode, the scale values used

are: 20, ..., 21, 2k where k is the pop-up menu value.

The scale values are the same as those used for the discrete analysis.

This edit box allows you to specify the scales used for the continuous analysis, using MATLAB syntax for the input.

Page 846: Wavelet ug

A GUI Reference

A-20

Wavelet 1-D Tool FeaturesThe Wavelet 1-D tool is described in the section “One-Dimensional Analysis Using the Graphical Interface” on page 2-34. Here are two examples of options not covered there.

Tree ModeThis is one of the display options in which you can view the corresponding signal by selecting a node in the tree.

Here, on the left, the node d3 is selected and the corresponding detail is displayed under the original signal.

More Display OptionsThis option allows you to customize what is displayed and is dependent on the current visualization mode.

Page 847: Wavelet ug

Wavelet 1-D Tool Features

A-21

In this example for the Separate Mode, we have chosen not to display the coefficients of approximation for levels 2 and 3, nor the coefficients of detail for levels 4 and 5. The coefficients’ coloration mode has been changed, and the synthesized signal is displayed in the right hand column, rather than the original signal.

Page 848: Wavelet ug

A GUI Reference

A-22

Wavelet 2-D Tool FeaturesThe Wavelet 2-D tool is described in the section “Two-Dimensional Analysis Using the Graphical Interface” on page 2-66. Here is an example of an option that allows you to view a selected part of the window at a full window resolution.

Page 849: Wavelet ug

Wavelet Packet Tool Features (1-D and 2-D)

A-23

Wavelet Packet Tool Features (1-D and 2-D)For descriptions of the Wavelet Packet 1-D and Wavelet Packet 2-D tools, refer to “Using Wavelet Packets” on page 5-1. These tools are almost identical in their layout and function. The only difference involves the extra coloration modes available in the Wavelet Packet 1-D tool, as well as the ability of the tools to work with signals or images, as appropriate. Let us focus on the 1-D capabilities.

Coefficients colorationNAT or FRQ is for Natural or Frequency order (see “Wavelet Packet Atoms” on page 6-124).

By level or Global is for a coloration made level by level or taking all detail levels.

abs is used to take the absolute values of coefficients.

Page 850: Wavelet ug

A GUI Reference

A-24

Node ActionWhen you select a node in the tree, the selected option is performed. A complete description of options is provided in the following sections.

Node Label:The node labels can be changed using the pop-up menu. For example, the Type option labels the nodes with (a) for approximation and (d) for detail.

Node Action FunctionalityThe available options in the Node Action menu are:

• Visualize: When you select a node in the wavelet packet tree the corresponding signal appears.

• Split/Merge: If a terminal node is selected, it is split, growing the wavelet packet tree. Selecting other nodes has the behavior of merging all the nodes below it in the wavelet packet tree.

Page 851: Wavelet ug

Wavelet Packet Tool Features (1-D and 2-D)

A-25

• Recons.: When you select a node in the wavelet packet tree, the corresponding reconstructed signal appears.

• Select On/Off: When On, you can select many nodes in the wavelet packet tree. Then you can reconstruct a synthesized signal from the selected nodes using the Reconstruct button on the main window. Use the Off selection to deselect all the previous selected nodes.

SPLIT

MERGE

Page 852: Wavelet ug

A GUI Reference

A-26

• Statistics: When you select a node in the wavelet packet tree, the Statistics tool appears using the signal corresponding to the selected node.

Page 853: Wavelet ug

Wavelet Packet Tool Features (1-D and 2-D)

A-27

• View Col. Cfs.: When active, this option removes all the colored coefficients displayed, and lets you redraw only the corresponding coefficients by selecting a node in the wavelet packet tree.

Page 854: Wavelet ug

A GUI Reference

A-28

Wavelet Display ToolThe Wavelet Display tool is mentioned in the section “An Introduction to the Wavelet Families” on page 1-32.

Here, we show the main window and the associated information windows with some additional comments.

Information on the selected waveletInformation on all the wavelets

This parameter decides the precision used for the wavelet computation.

Here, functions are computed over 28 points.

Page 855: Wavelet ug

Wavelet Packet Display Tool

A-29

Wavelet Packet Display ToolThe Wavelet Packet Display tool is very similar to the Wavelet Display tool.

Here, the main window and the associated information windows are displayed with some additional comments.

This parameter decides the precision used for the wavelet packet computation. Here,

functions are computed over 28 points.

Information on the selected waveletInformation on wavelet packets

Number (-1) of wavelet packet functions to compute and display.

Page 856: Wavelet ug

A GUI Reference

A-30

Page 857: Wavelet ug

BObject-Oriented Programming

Short Description of Objects in the Toolbox . . . . . . B-3

Simple Use of Objects Through Four Examples . . . . B-4Example 1: plot and wpviewcf . . . . . . . . . . . . . B-4Example 2: drawtree and readtree . . . . . . . . . . . B-7Example 3: A Funny One . . . . . . . . . . . . . . . B-9Example 4: Thresholding Wavelet Packets . . . . . . . B-11

Detailed Description of Objects in the Toolbox . . . B-15WTBO object . . . . . . . . . . . . . . . . . . . B-15NTREE object . . . . . . . . . . . . . . . . . . . B-16DTREE object . . . . . . . . . . . . . . . . . . . B-17WPTREE object . . . . . . . . . . . . . . . . . . B-19

Advanced Use of Objects . . . . . . . . . . . . . B-22Example 1: Building a Wavelet Tree Object (WTREE) . . . B-22Example 2: Building a Right Wavelet Tree

Object (RWVTREE) . . . . . . . . . . . . . . B-23Example 3: Building a Wavelet Tree Object (WVTREE) . . B-25Example 4: Building a Wavelet Tree Object (EDWTTREE) . B-26

Page 858: Wavelet ug

B Object-Oriented Programming

B-2

In the Wavelet Toolbox, some object-oriented programming features are used for wavelet packet tree structures.

You may want to skip this appendix, if you prefer to use the command line functions and graphical user interface (GUI) without knowing about the underlying objects and classes. But, it is useful for Save and Load actions where objects are involved.

These aspects, related to a minimal use, are described in “Using Wavelet Packets” on page 5-1, and in the reference pages for the corresponding functions.

This appendix lets you understand the objects used in the toolbox, use some functions that are not fully documented in the reference pages, and extend the toolbox functionality using the predefined tree structures and some object programming features.

Of course, it is helpful to be familiar with the basic MATLAB object-oriented language and terminology.

Sections include:

• “Short Description of Objects in the Toolbox” on page B-3

• “Simple Use of Objects Through Four Examples” on page B-4

• “Detailed Description of Objects in the Toolbox” on page B-15

• “Advanced Use of Objects” on page B-22 (which tells how to extend the toolbox with new objects through four examples)

Page 859: Wavelet ug

Short Description of Objects in the Toolbox

B-3

Short Description of Objects in the ToolboxFour classes of objects are defined in the Wavelet Toolbox.

The hierarchical organization of these objects is described in the following scheme:

WTBO Å NTREE Å DTREE Å WPTREEOnly the Wavelet Packet tools (1-D and 2-D) use the previous objects. More precisely, WPTREE objects are used to build wavelet packets.

A short description of this hierarchy of objects follows. For a more detailed description see “Detailed Description of Objects in the Toolbox” on page B-15.

The WTBO class is an abstract class. Any object in the toolbox is parented by a WTBO object and would inherit the methods and fields of the WTBO class.

The NTREE class is dedicated to tree manipulation (node labels, node splitting, node merging, …), and it is also an abstract class. The main methods are:

• nodejoin, which recomposes nodes

• nodesplt, which decomposes nodes

• wtreemgr, which lets you access most of tree and node information (order, depth, terminal nodes, ascendants of a node, …)

In fact, the wtreemgr method is not used directly, but you can use the functions treeord, treedpth, leaves, nodeasc, …, and the method get.

The DTREE class is dedicated to trees with associated data: vectors or matrices.

This class is also an abstract class and some methods have to be overloaded.

The aim of the WPTREE class is to manage wavelet packets 1-D and 2-D.

Some methods of the DTREE class have been overloaded, for example: split, merge, and recons.

Most of the methods are specific to the class WPTREE; for example: bestlevt, besttree, and wp2wtree.

Typing help wavelet you can see the available methods in the Tree Management Utilities and Wavelets Packets Algorithms sections.

Page 860: Wavelet ug

B Object-Oriented Programming

B-4

Simple Use of Objects Through Four ExamplesYou can use command line functions, GUI functions, or you can mix both of them to work with wavelet packet trees (WPTREE objects). The most useful commands are:

• plot, drawtree, and readtree, which let you plot and get a wavelet packet tree

• wjoin and wpsplt, which let you change a wavelet packet tree structure

• get, read, and write, which let you read and write coefficients or information in a wavelet packet tree

We can see some of these features in the following examples.

• “Example 1: plot and wpviewcf”

• “Example 2: drawtree and readtree” on page B-7

• “Example 3: A Funny One” on page B-9

• “Example 4: Thresholding Wavelet Packets” on page B-11

Example 1: plot and wpviewcfload noisbumpx = noisbump;t = wpdec(x,3,'db2');fig = plot(t);

% Change Node Label from Depth_position to Index and% click the node (7). You get the following figure.

Page 861: Wavelet ug

Simple Use of Objects Through Four Examples

B-5

% Change Node Action from Visualize to Split-Merge and% merge the node 2. You get the following figure.

% From the command line, you can get the new tree.newt = plot(t,'read',fig);

% The first argument of the plot function in the last command% is dummy. Then the general syntax is:% newt = plot(DUMMY,'read',fig);

Page 862: Wavelet ug

B Object-Oriented Programming

B-6

% where DUMMY is any object parented by an NTREE object.% DUMMY can be any object constructor name, which returns% an object parented by an NTREE object. For example:% newt = plot(ntree,'read',fig);% newt = plot(dtree,'read',fig);% newt = plot(wptree,'read',fig);

% From the command line you can modify the new tree,% then plot it.newt = wpjoin(newt,3);fig2 = plot(newt);

% Change Node Label from Depth_position to Index and% click the node (3). You get the following figure.

% Using plot(newt,fig), the plot is done in the figure fig,% which already contains a tree object.

% You can see the colored wavelet packets coefficients using% from the command line, the wpviewcf function (type help% wpviewcf for more information).wpviewcf(newt,1)

% You get the following plot, which contains the terminal nodes% colored coefficients.

Page 863: Wavelet ug

Simple Use of Objects Through Four Examples

B-7

Example 2: drawtree and readtreeload noisbumpx = noisbump;t = wpdec(x,3,'db2');fig = drawtree(t);

% The last command creates a GUI. % The same GUI can be obtained using the main menu and:% - clicking the Wavelet Packet 1-D button,% - loading the signal noisbump,% - choosing the level and the wavelet% - clicking the decomposition button. % You get the following figure.

Page 864: Wavelet ug

B Object-Oriented Programming

B-8

% From the GUI, you can modify the tree. % For example, change Node label from Depth_Position to Index, % change Node Action from Visualize to Split_Merge and % merge the node 2. % You get the following figure.

Page 865: Wavelet ug

Simple Use of Objects Through Four Examples

B-9

% From the command line, you can get the new tree.newt = readtree(fig);

% From the command line you can modify the new tree;% then plot it in the same figure.newt = wpjoin(newt,3);drawtree(newt,fig);

You can mix previous commands. The GUI associated with the plot command is simpler and quicker, but more actions and information are available using the full GUI tools related to wavelet packets.

The methods associated with WPTREE objects let you do more complicated actions.

Namely, using read and write methods, you can change terminal node coefficients.

Let's illustrate this point with the following “funny” example.

Example 3: A Funny Oneload gatlin2t = wpdec2(X,1,'haar');plot(t);

Page 866: Wavelet ug

B Object-Oriented Programming

B-10

% Change Node Label from Depth_position to Index and% click the node (0). You get the following figure.

% Now modify the coefficients of the four terminal nodes.newt = t;NBcols = 40;

for node = 1:4 cfs = read(t,'data',node); tmp = cfs(1:end,1:NBcols); cfs(1:end,1:NBcols) = cfs(1:end,end-NBcols+1:end); cfs(1:end,end-NBcols+1:end) = tmp; newt = write(newt,'data',node,cfs);endplot(newt)

% Change Node Label from Depth_position to Index and% click on the node (0). You get the following figure.

Page 867: Wavelet ug

Simple Use of Objects Through Four Examples

B-11

You can use this method for a more useful purpose. Let’s see a de-noising example.

Example 4: Thresholding Wavelet Packetsload noisblocx = noisbloc;t = wpdec(x,3,'sym4');plot(t);% Change Node Label from Depth_position to Index and% click the node (0). You get the following plot.

Page 868: Wavelet ug

B Object-Oriented Programming

B-12

% Global thresholding.t1 = t;sorh = 'h';thr = wthrmngr('wp1ddenoGBL','penalhi',t);cfs = read(t,'data');cfs = wthresh(cfs,sorh,thr);t1 = write(t1,'data',cfs);plot(t1)

% Change Node Label from Depth_position to Index and% click the node (0). You get the following plot.

Page 869: Wavelet ug

Simple Use of Objects Through Four Examples

B-13

% Node by node thresholding. t2 = t;sorh = 's';thr(1) = wthrmngr('wp1ddenoGBL','penalhi',t);thr(2) = wthrmngr('wp1ddenoGBL','sqtwologswn',t);tn = leaves(t);for k=1:length(tn) node = tn(k); cfs = read(t,'data',node); numthr = rem(node,2)+1; cfs = wthresh(cfs,sorh,thr(numthr)); t2 = write(t2,'data',node,cfs);endplot(t2)

Page 870: Wavelet ug

B Object-Oriented Programming

B-14

% Change Node Label from Depth_position to Index and% click the node (0). You get the following plot.

Page 871: Wavelet ug

Detailed Description of Objects in the Toolbox

B-15

Detailed Description of Objects in the ToolboxThe following sections describe the objects in the Wavelet Toolbox:

• “WTBO object”

• “NTREE object” on page B-16

• “DTREE object” on page B-17

• “WPTREE object” on page B-19

WTBO objectClass WTBO (Wavelet Toolbox Object) -- Parent class: none

Fields

Methods

CommentsSince any object in the toolbox is parented by a WTBO object, you can associate your own data to an object using the 'ud' field, and then access it.

If Obj is an object (parented by a WTBO object), use:

Obj = set(Obj,'ud',MyData)

to define the data.

To retrieve the data, use:

MyData = get(O,'ud')

wtboInfo Object information (Not used).

ud Userdata field.

wtbo Constructor for the class WTBO.

get Get WTBO object field contents.

set Set WTBO object field contents.

Page 872: Wavelet ug

B Object-Oriented Programming

B-16

NTREE objectClass NTREE (New Tree) -- Parent class: WTBO

Fields

Methods

Private

wtbo Parent object.

order Tree order.

depth Tree depth.

spsch Split scheme for nodes.

tn Column vector with terminal nodes indices.

ntree Constructor for the class NTREE.

findactn Find active nodes.

get Get NTREE object field contents.

nodejoin Recompose node(s).

nodesplt Split (decompose) node(s).

plot Plot NTREE object.

set Set NTREE object field contents.

tlabels Labels for the nodes of a tree.

wtreemgr Manager for NTREE object.

locnumcn Local number for a child node.

tabofasc Table of ascendants of nodes.

Page 873: Wavelet ug

Detailed Description of Objects in the Toolbox

B-17

DTREE objectClass DTREE (Data Tree) -- Parent class: NTREE

Fields

Fields descriptionallNI is a NBnodes-by-3 array such that:

allNI(N,:) = [ind,size(1,1),size(1,2)]

ind = index of the node N

size = size of data associated with the node N

terNI is a 1-by-2 cell array such that:

terNI{1} is an NB_TerminalNodes-by-2 array such that:

terNI{1}(N,:) is the size of coefficients associated with the N-th termi-nal node. The nodes are numbered from left to right and from top to bot-tom. The root index is 0.

terNI{2} is a row vector containing the previous coefficients storedrow-wise in the above specified order.

ntree Parent object.

allNI All Nodes Information.

terNI Terminal Nodes Information.

Page 874: Wavelet ug

B Object-Oriented Programming

B-18

Methods

Comments

• After the constructor, the first set of methods (between two double line separators) might not be overloaded (or only with great care). The second set of methods can be overloaded. The third set of methods must be overloaded to recompose, reconstruct, or decompose nodes data.

• The method nodejoin calls the method merge, the method nodesplt calls the method split, and the method rnodcoef calls the method recons.

• To define nodes information, you must overload the method defaninf. For each node N, the basic information is given by:

allNI(N,1:3): [index,size(1,1),size(1,2)];

you can add other information by adding columns to allNI.

See the WPTREE object method for an example.

• If the method get is not overloaded, using the DTREE get method you can get some object field contents (but not all).

dtree Constructor for the class DTREE.

expand Expand data tree.

fmdtree Field manager for DTREE object.

nodejoin Recompose node.

nodesplt Split (decompose) node.

rnodcoef Reconstruct node coefficients.

defaninf Define node information (all nodes).

get Get DTREE object field contents.

plot Plot DTREE object.

read Read values in DTREE object fields.

set Set DTREE object field contents.

write Write values in DTREE object fields.

merge Merge (recompose) the data of a node.

recons Reconstruct node coefficients.

split Split (decompose) the data of a terminal node.

Page 875: Wavelet ug

Detailed Description of Objects in the Toolbox

B-19

For example, if T is parented by a DTREE object of order 2 and if 'Tfield' is a field of T, whose content is Tval, [a,b] = get(t,'order','Tfield') returns a = 2 and b = 'errorWTBX'. Nevertheless, using a nondocumented method you can get the right values. Namely: [a,b] = getwtbo(t,'order','Tfield') returns a = 2 and b=Tval.

WPTREE objectClass WPTREE (Wavelet Packet Tree) -- Parent class: DTREE

Fields

Fields description

dtree Parent object.

wavInfo Structure (wavelet Information).

entInfo Structure (entropy Information).

wavInfo Structure (wavelet Information).

wavName - Wavelet Name.

Lo_D - Low Decomposition filter.

Hi_D - High Decomposition filter.

Lo_R - Low Reconstruction filter.

Hi_R - High Reconstruction filter.

entInfo Structure (entropy Information).

entName - Entropy Name.

entPar - Entropy Parameter.

allNI Array(nbnode,5) (field of the dtree parent object)

[ind,size,ent,ento]

ind - indice.

size - size of data.

ent - Entropy.

ento - Optimal Entropy.

Page 876: Wavelet ug

B Object-Oriented Programming

B-20

Methods

Constructor.

Methods that Overload Those of DTREE Class.

Method Descriptionwptree Constructor for the class WPTREE.

Method Descriptiondefaninf Define node information (all nodes).

get Get WPTREE object field contents.

merge Merge (recompose) the data of a node.

read Read values in WPTREE object fields.

recons Reconstruct wavelet packet coefficients.

set Set WPTREE object field contents.

split Split (decompose) the data of a terminal node.

tlabels Labels for the nodes of a wavelet packet tree.

write Write values in WPTREE object fields.

Page 877: Wavelet ug

Detailed Description of Objects in the Toolbox

B-21

Proper Methods of WPTREE Class.

Method Descriptionbestlevt Best level of a wavelet packet tree.

besttree Best wavelet packet tree.

entrupd Entropy update (wavelet packet tree).

wp2wtree Extract wavelet tree from wavelet packet tree.

wpcoef Wavelet packet coefficients.

wpcutree Cut wavelet packet tree.

wpjoin Recompose wavelet packet.

wpplotcf Plot wavelet packets colored coefficients.

wprcoef Reconstruct wavelet packet coefficients.

wprec Wavelet packet reconstruction 1-D.

wprec2 Wavelet packet reconstruction 2-D.

wpsplt Split (decompose) wavelet packet.

wpthcoef Wavelet packet coefficients thresholding.

wpviewcf Plot wavelet packets colored coefficients.

Page 878: Wavelet ug

B Object-Oriented Programming

B-22

Advanced Use of ObjectsThe following sections explain how to extend the toolbox with new objects through four examples.

• “Example 1: Building a Wavelet Tree Object (WTREE)”

• “Example 2: Building a Right Wavelet Tree Object (RWVTREE)” on page B-23

• “Example 3: Building a Wavelet Tree Object (WVTREE)” on page B-25

• “Example 4: Building a Wavelet Tree Object (EDWTTREE)” on page B-26

Example 1: Building a Wavelet Tree Object (WTREE)This example creates a new class of objects: WTREE.

Starting from the class DTREE and overloading the methods split and merge, we define a wavelet tree class.

To plot a WTREE, the DTREE plot method is used.

You can have a look at a one-dimensional example in the ex1_wt M-file and at a two-dimensional example in the ex2_wt M-file located in the toolbox/wavelet/wavedemo directory. These examples can be used directly, but they are also useful to learn how to build new object-oriented programming functions.

The definition of the new class is described below.

Class WTREE (parent class: DTREE)

Page 879: Wavelet ug

Advanced Use of Objects

B-23

Fields

Fields description

Methods

Example 2: Building a Right Wavelet Tree Object (RWVTREE)This example creates a new class of objects: RWVTREE.

We define a right wavelet tree class starting from the class WTREE and overloading the methods split, merge, and plot (inherited from DTREE).

The plot method shows how to add Node Labels.

You can have a look at a one-dimensional example in the ex1_rwvt M-file and at a two-dimensional example in the ex2_rwvt M-file located in the toolbox/wavelet/wavedemo directory. These programs can be used directly, but they are also useful to learn how to build new object-oriented programming functions.

dtree Parent object.

dwtMode DWT extension mode.

wavInfo Structure (wavelet Information).

wavInfo Structure (wavelet Information).

wavName - Wavelet Name

Lo_D - Low Decomposition filter

Hi_D - High Decomposition filter

Lo_R - Low Reconstruction filter

Hi_R - High Reconstruction filter

wtree Constructor for the class WTREE.

merge Merge (recompose) the data of a node.

split Split (decompose) the data of a terminal node.

Page 880: Wavelet ug

B Object-Oriented Programming

B-24

The definition of the new class is described below.

Class RWVTREE (parent class: WTREE)

Fields

Methods

Running This ExampleThe following figure is obtained using the example ex1_rwvt and clicking the node 14.

The approximations are labeled in yellow and the details are labeled in red. The last nodes cannot be split.

dummy Not Used.

wtree Parent object.

rwvtree Constructor for the class RWVTREE.

merge Merge (recompose) the data of a node.

plot Plot RWVTREE object.

split Split (decompose) the data of a terminal node.

Page 881: Wavelet ug

Advanced Use of Objects

B-25

Example 3: Building a Wavelet Tree Object (WVTREE)This example creates a new class of objects: WVTREE.

We define a wavelet tree class starting from the class WTREE and overloading the methods get, plot, and recons (all inherited from DTREE).

The split and merge methods of the class WTREE are used.

The plot method shows how to add Node Labels and Node Actions.

You can have a look at a one-dimensional example in the ex1_wvt M-file and at a two-dimensional example in the ex2_wvt M-file located in the toolbox/wavelet/wavedemo directory. These programs can be used directly, but they are also useful to learn how to build new object-oriented programming functions.

The definition of the new class is described below.

Class WVTREE (parent class: WTREE)

Fields

Methods

Running This exampleThe following figure is obtained using the example ex2_wvt and clicking the node 2.

The approximations are labeled in yellow and the details are labeled in red. The last nodes cannot be split. The title of the figure contains the DWT extension mode used ('sym' in the present example).

dummy Not Used.

wtree Parent object.

wvtree Constructor for the class WVTREE.

get Get WVTREE object field contents.

plot Plot WVTREE object.

recons Reconstruct node coefficients.

Page 882: Wavelet ug

B Object-Oriented Programming

B-26

Example 4: Building a Wavelet Tree Object (EDWTTREE)This example creates a new class of objects: EDWTTREE.

We define an ε-DWT tree class starting from the class DTREE and overloading the methods merge, plot, recons, and split.

For more information on the ε-DWT, see the section “ε-decimated DWT” on page 6-44.

The plot method shows how to add Node Labels, Node Actions and Tree Actions.

You can have a look at the example in the ex1_edwt M-file located in the toolbox/wavelet/wavedemo directory. This program can be used directly, but it is also useful to learn how to build new object-oriented programming functions.

The definition of the new class is described below.

Class EDWTTREE (parent class: DTREE)

Page 883: Wavelet ug

Advanced Use of Objects

B-27

Fields

Fields description

Methods

Running This ExampleThe following figure is obtained using the example ex1_edwt, selecting the De-noise option in the Tree Action menu and clicking the node 0.

The approximations are labeled in yellow and the details are labeled in red. The last nodes cannot be split.

The title of the figure contains the DWT extension mode used ('sym' in the present example) and the name of de-noising method.

dtree Parent object.

dwtMode DWT extension mode.

wavInfo Structure (wavelet Information).

wavInfo Structure (wavelet Information).

wavName - Wavelet Name

Lo_D - Low Decomposition filter

Hi_D - High Decomposition filter

Lo_R - Low Reconstruction filter

Hi_R - High Reconstruction filter

edwttree Constructor for the class EDWTTREE.

merge Merge (recompose) the data of a node.

plot Plot EDWTTREE object.

recons Reconstruct node coefficients.

split Split (decompose) the data of a terminal node.

Page 884: Wavelet ug

B Object-Oriented Programming

B-28

Page 885: Wavelet ug

I-1

Index

Symbols“An Introduction to the Wavelet Families” on page

1-32 A-28

AAdding a new wavelet 7-2–7-16Algorithm

Coifman-Wickerhauser 1-30, 6-133Decomposition 6-23–6-25, 6-28–6-29Discrete Wavelet Transform (DWT) 6-19Fast Wavelet Transform (FWT) 6-19Filters 6-19–6-22For biorthogonal 6-28Mallat 1-18, 6-19Rationale 6-28–6-31Reconstruction 6-24–6-27, 6-30–6-31Stationary Wavelet Transform (SWT) 6-44

AnalysisBiorthogonal 6-28, 6-66–6-67Case study 4-36–4-47Continuous 1-12–1-17, 2-3–2-23, 6-12–6-13Continuous complex 2-16–2-23Continuous or discrete 6-51Continuous real 2-3–2-15Discrete 1-18–1-21, 2-24–2-81, 6-12–6-13Illustrated examples 4-3–4-35Local 1-8Local and global 6-14Multiscale 4-35, 4-36One-dimensional discrete wavelet 2-24–2-56One-dimensional wavelet packet 5-7–5-20Orthogonal 6-19, 6-29, 6-61, 6-64Redundant 6-13Time-scale 1-7, 1-14, 6-13Translation invariant 6-44Two-dimensional discrete wavelet 2-57–2-81

Two-dimensional wavelet packet 5-21–5-28Wavelet 1-7, 1-9Wavelet Packet 5-2–5-36See also Transform

Approximation 1-18–1-20, 6-5, 6-15–6-18Coefficients 2-28, 2-62, 6-23Definition 6-4, 6-17Reconstruction 1-23–1-24, 2-29

AxesView A-14

BBasis 6-28–6-30, 6-127Binning 2-125, 2-131, 6-102, 6-107Biorthogonal wavelets 1-34, 6-66–6-67

See also AnalysisBorder distortion 6-35

Boundary value replication 6-35Periodic extension 6-35Periodized Wavelet Transform 6-44Smooth padding 6-36, 6-40, 6-43Symmetric extension 6-39, 6-42Symmetrization 6-35Zero-padding 6-35, 6-39, 6-42

Breakdown 3-6, 4-18–4-23, 4-25, 4-27, 4-35Frequency 3-3–3-4, 4-10–4-11Variance 6-96

CChirp 5-8, 6-121, 6-125Coefficients

Approximation 2-28, 2-62, 6-23Coloration A-23Complex Continuous Wavelet 2-18

Page 886: Wavelet ug

Index

I-2

Continuous Wavelet 2-5Detail 2-28, 2-62, 6-23Discrete Wavelet 2-55, 2-80Line 2-9Load

See Importing to the GUISave

See Exporting from the GUICoiflets 1-35, 6-65Coloration mode 2-13, A-8

Color coding A-3Controlling the colormap A-6

Complex frequency B-Spline wavelets 6-75Complex Gaussian wavelets 6-74Complex Morlet wavelets 6-74Complex Shannon wavelets 6-76Compression 2-25, 2-64, 2-72, 3-26–3-27, 5-25,

6-98Default values 5-4, 6-109, 6-113Difference with de-noising 6-98Energy ratio 6-101Methods 6-113Norm recovery 6-101Number of zeros 6-101Procedure 5-5, 6-98Retained energy 6-101

Continuous Wavelet TransformSee Analysis, Transform

CWTSee Transform

DDaubechies wavelets 1-33, 6-62Decimation

See Downsampling

Decomposition 1-21, 1-27, 2-36, 2-39, 6-24–6-25, 6-32

Best-level 6-133Entropy-based criteria 6-128–6-132Hierarchical organization 6-10Load

See Importing to the GUIMulti-step 1-27Optical comparison 6-6Optimal 6-128–6-133Save

See Exporting from the GUIStructure 2-80, 6-32, 6-134

De-noising 2-25, 2-31–2-33, 2-41–2-44, 3-18–3-20, 6-134

Basic model 6-85, 6-94Default values 5-4, 6-109, 6-113Fixed form threshold 6-88Image 2-116, 3-21, 6-94Methods 6-113Minimax performance 6-88Noise size estimate 6-90Non-white noise 6-90Procedure 5-5, 6-86SURE estimate 6-88Using SWT 2-95, 2-97, 2-111, 2-113, 3-24Variance adaptive 6-95White noise 6-84

Density estimation 2-129, 6-101Detail 1-18–1-20, 6-5, 6-15–6-17

Coefficients 2-28, 2-62, 6-23–6-24Decomposition 6-117–6-118Definition 6-4, 6-17Orientation 6-25Reconstruction 1-23–1-24, 2-29

Dilation 1-11, 6-19Discontinuity 1-8, 3-3–3-6, 4-10, 4-20, 4-22, 6-39

Page 887: Wavelet ug

Index

I-3

See also BreakdownDiscrete Meyer wavelet 6-73Discrete Wavelet Transform

See Analysis, TransformDisplay mode 2-D

Square 2-69Tree 2-70

Downsampling 6-23, 6-25DWT

See Transform

EEdge effects

See Border distortionEntropy 1-30, 6-129–6-132Estimation

Default values 6-109See Function estimation

Exporting from the GUIComplex Continuous Wavelet 2-23Continuous Wavelet 2-14Discrete Stationary Wavelet 1-D 2-101Discrete Stationary Wavelet 2-D 2-118Discrete Wavelet 1-D 2-49Discrete Wavelet 2-D 2-74Image extension 2-169Signal extension 2-166Variance adaptive thresholding 2-143Wavelet Density Estimation 1-D 2-134Wavelet Packets 5-29Wavelet Regression Estimation 1-D 2-127

Extension modeSee Border distortion

FFast multiplication of large matrices 3-28Fast Wavelet Transform (FWT)

See TransformFilter

Banks 1-18Decomposition 6-23FIR 6-20, 6-55, 6-67, 6-78, 6-79, 7-5High-pass 6-23Low-pass 6-23Minimum phase 6-65Quadrature mirror 1-23, 1-27, 6-21Reconstruction 1-23, 6-23Scaling 6-20See also Twin-scale relation

Fingerprint 3-26–3-27Fixed design

See Regression estimationFourier 1-5, 1-10, 3-3

Analysis 4-9, 4-11, 6-14, 6-55Short-time analysis (STFT) 1-6–1-7Windowed analysis 4-11

Fractal 3-11, 6-13Frequency 1-6–1-7, 1-15, 1-18, 2-31, 3-12

Parameter 6-125Related to scale 6-56See also Fourier

Frequency B-Spline wavelets 6-75Full decomposition mode 2-39Function estimation 6-101FWT

See Transform

GGaussian wavelets 6-72GUI 2-2, 5-2, A-2–A-29

Page 888: Wavelet ug

Index

I-4

Complex Continuous Wavelet 2-19Continuous Wavelet 2-7Density estimation 2-129Full window resolution A-22Image de-noising using SWT 2-113Image extension / truncation 2-167Local variance adaptive thresholding 2-136Regression estimation 2-120Signal de-noising using SWT 2-97Signal extension / truncation 2-160Using menus A-10Using the mouse A-4Wavelet coefficients selection 1-D 2-145Wavelet coefficients selection 2-D 2-153Wavelet Display A-28Wavelet one-dimensional 2-34Wavelet Packet 5-7Wavelet Packet Display A-29Wavelet two-dimensional 2-66

HHaar wavelet 1-33, 6-63Heisenberg uncertainty principle 6-14History 1-31

IIDWT

See TransformImage 2-78Importing to the GUI

Complex Continuous Wavelet 2-23Continuous Wavelet 2-14Discrete Stationary Wavelet 1-D 2-101Discrete Stationary Wavelet 2-D 2-118Discrete Wavelet 1-D 2-49

Discrete Wavelet 2-D 2-74Variance adaptive thresholding 2-143Wavelet Density Estimation 1-D 2-134Wavelet Packets 5-29Wavelet Regression Estimation 1-D 2-127

Indexed image 2-82matrix indices, shifting 2-83

ISWTSee Transform

LLevel 1-24, 1-29, 2-27, 2-36, 2-39, 2-67, 6-2–6-4,

6-5See also Multilevel, Wavelet Packet Best level

LoadSee Importing in the GUI

LocalSee Analysis

Local Maxima Lines 2-9, 2-10Long-term evolution 3-8, 4-9, 4-11, 4-25, 4-27, 4-31,

4-35

MMathematical conventions 6-2Merge

See Wavelet PacketMexican hat 1-36, 6-70Meyer wavelet 1-37, 6-68Minimax 6-88Missing data 4-47More display options 2-41, A-20Morlet wavelet 1-36, 6-71Multilevel 2-28, 2-30, 2-39, 2-62–2-64Multiresolution 6-19, 6-28–6-29Multistep 1-27

Page 889: Wavelet ug

Index

I-5

NNode

Action A-24–A-27Noise 2-41, 4-24–4-29, 4-32, 4-44

ARMA 4-15Colored 4-26Gaussian 6-83, 6-85Processing 4-13, 4-15, 4-25, 4-27, 4-29, 6-83,

6-95Suppressing 3-15–3-17

See also De-noisingUnscaled 6-90White 4-12, 4-16, 4-24, 4-28, 6-84

Non-decimated DWTSee Transform (Stationary Wavelet)

OObjects B-3–B-27Outliers 4-46

PPacket

See Wavelet PacketPadding

See Border distortionPeriodized Wavelet Transform

See Border distortionPositions 1-18

QQuadrature mirror filters (QMF) 1-23, 1-27, 6-21

RRandom design

See Regression estimationReconstruction 1-22–1-25, 1-27, 6-24, 6-27, 6-32

Approximation 1-23Detail 1-23Filters 1-23Multi-step 1-27

Redundancy 6-51Regression estimation 2-120, 6-106Regularity 6-78, 6-79

Definition 6-52Resemblance index 3-10Residuals display 2-46, 2-100, 2-101, 2-116,

2-139Reverse Biorthogonal wavelets 6-72RGB images 2-82

Converting from 2-86

SSave

See Exporting from the GUIScale 1-11, 1-16

And frequency 1-15Choosing 2-6, 2-19Dyadic 1-18, 6-2, 6-4To frequency 2-11, 3-14, 6-56

Scale mode A-19Scaling filter 6-20Scaling function 1-27, 6-6, 6-7Self-similarity 1-8, 3-10Separate mode 2-40Shannon wavelets 6-76Shift 1-11–1-12

See also TranslationShow and scroll mode 2-40

Page 890: Wavelet ug

Index

I-6

Show and scroll mode (stem coefs) 2-40Shrink

See ThresholdingSignal-end effects

See Border distortionSpline 6-28, 6-69Split

See Wavelet PacketSquare mode 2-69Stationary Wavelet Transform

See TransformSTFT

See FourierSuperimpose mode 2-40Support

See Wavelet FamiliesSWT

See TransformSymlets 1-35, 6-64Symmetry

See Wavelet FamiliesSynthesis 1-22, 6-15

TThresholding 2-32

Hard 6-87–6-88Interval dependent 6-96Rules 6-88–6-89, 6-113Soft 6-87See also De-noising, Compression

Time-scaleSee Analysis

TransformContinuous versus discrete 6-13Continuous Wavelet (CWT) 1-10, 1-12–1-14,

1-17, 6-78, 6-79

Discrete Wavelet (DWT) 1-18, 6-23–6-24, 6-25, 6-78, 6-79

Fast Wavelet (FWT) 6-19Inverse (IDWT) 1-22, 6-15, 6-24, 6-27Inverse Stationary Wavelet (ISWT) 6-50Stationary Wavelet (SWT) 6-44Translation invariant 6-44

Transient 1-5See also Breakdown

Translation 6-9–6-10, A-5Dyadic 6-2Invariance 6-44See also Shift

TreeBest 5-11Best-level 6-133Decomposition 1-29–1-30Mode 2-40, 2-70, A-20Objects B-3–B-27Wavelet 1-21, 1-29, 6-27Wavelet Packet 1-29, 6-117, 6-127, 6-133

Tree mode 2-40, 2-70, A-20Trend 1-5

See Long-term evolutionTwin-scale relation 6-19, 6-29, 6-30, 6-54typographical conventions (table) xxx

UUpsampling 1-22, 6-24, 6-27

VVanishing moments 3-17, 6-52, 6-78, 6-79Variance adaptive thresholding 6-95View Axes A-14

Page 891: Wavelet ug

Index

I-7

WWavelet 6-4, 6-6, 6-7

Add new 7-2–7-16Applications 3-1–3-27Associated family 6-4, 6-7–6-11Battle-Lemarie 6-69Biorthogonal 1-34, 6-66Candidate to be a 6-54Coefficients 1-10Coiflets 1-35, 6-65Complex frequency B-Spline 6-75Complex Gaussian 6-74Complex Morlet 6-74Complex Shannon 6-76Daubechies 1-33, 6-62Discrete Meyer 6-73Gaussian 6-72Haar 1-33, 6-63History of 1-31Mexican hat 1-36, 6-70Meyer 1-37, 6-68Morlet 1-36, 6-71One-dimensional capabilities 2-24, 6-32–6-33Order 7-4Organization 6-11Relationship of filters to 1-25Reverse Biorthogonal 6-72Shapes 6-6Symlets 1-35, 6-64Translation 6-2, 6-9–6-10

See also ShiftTree 1-21, 1-29, 2-40, 5-11, 6-27, 6-132Two-dimensional 6-8Two-dimensional capabilities 2-57, 6-33–6-34Type 7-4Vanishing moments 3-17, 6-52, 6-61, 6-78,

6-79

Wavelet Families 1-32, 6-4, 6-61, 6-78, 6-79Add new 7-3Full name 7-3Properties 6-78, 6-79Regularity 6-52, 6-61Short name 7-3Support 6-61Symmetry 6-61Vanishing moments 6-61, 6-78, 6-79, 6-80

Wavelet Packet 1-29, 5-1, 6-117–6-134Atoms 6-124Best level 1-30, 5-4, 6-133Best tree 1-30, 5-4, 5-11, 5-18Building 6-122Compression 5-12, 6-134Decomposition 6-133, 6-134De-noising 5-15–5-20Frequency order 6-125From wavelets to 6-117Merge 6-128Natural order 6-125Objects B-3–B-27Organization 6-127Split 6-128Tree 1-29, 6-117, 6-127, 6-133

ZZoom 2-12, 2-37, 2-71, 6-53