You are on page 1of 94

Pgina Web 1 de 2

Next: Contents Contents

Wavelets and Filter Banks Course Notes


Copyright Dr. W. J. Phillips January 9, 2003

Contents 1. Analysis and Synthesis of Signals 2. Time-Frequency Analysis 2.1 The Short Time Fourier Transform 2.2 The spectrogram 2.3 An Orthgonal Basis of Functions 3. Time-Scale Analysis 3.1 The Continuous Wavelet Transform 3.2 Comparision with STFT 3.3 The Scalogram 3.4 Examples of Wavelets 3.5 Analysis and Synthesis with Wavelets 3.6 The Haar Wavelet 4. Multiresolution Analysis 4.1 The Scaling Function 4.2 The Discrete Wavelet Transform 5. Filter Banks and the Discrete Wavelet Transform 5.1 Analysis: From Fine Scale to Coarser Scale 5.1.1 Filtering and Downsampling 5.1.2 The One-Stage Analysis Filter Bank 5.1.3 The Analysis Filter Bank 5.2 Synthesis: From Course Scale to Fine Scale 5.2.1 Upsampling and Filtering 5.2.2 The One-Stage Synthesis Filter Bank 5.2.3 Perfect Reconstruction Filter Bank 5.2.4 The Synthesis Filter Bank 5.2.5 Approximations and Details 5.3 Numerical Complexity of the Discrete Wavelet Transform 5.4 Matlab Examples 5.4.1 One-Stage Perfect Reconstruction 5.4.2 Approximations and Details 5.4.3 A Useful Function 5.5 Initialization of the Discrete Wavelet Transform 6. Properties of the Filters, and the Scale and Wavelet Functions 6.1 Double Shift Orthogonality of the Filters 6.2 Frequency Domain Formulas 6.3 Support of the Scale Function 6.4 The Cascade Algorithm 7. Designing Wavelets 7.1 Short Filters 7.1.1 Length 2 Filter

http://www.engmath.dal.ca/courses/engm6610/notes/notes.html

24-04-2006

Pgina Web 2 de 2

7.1.2 Length 4 Filter 7.1.3 Length 6 Filter 7.2 K-Regular Scaling Filters 7.2.1 The db2 Wavelet 7.2.2 The db3 Wavelet 7.3 Characterizing K-Regular Filters 7.4 The Daubechies Maximally Flat Polynomial 7.4.1 Factoring the Daubechie Maximally Flat Polynomial 7.5 Coiflets 7.5.1 Coif1 7.5.2 Coif2 About this document ...

Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/notes.html

24-04-2006

Pgina Web 1 de 1

Next: 1. Analysis and Synthesis Up: Wavelets and Filter Banks Previous: Wavelets and Filter Banks

Contents
Contents 1. Analysis and Synthesis of Signals 2. Time-Frequency Analysis 2.1 The Short Time Fourier Transform 2.2 The spectrogram 2.3 An Orthgonal Basis of Functions 3. Time-Scale Analysis 3.1 The Continuous Wavelet Transform 3.2 Comparision with STFT 3.3 The Scalogram 3.4 Examples of Wavelets 3.5 Analysis and Synthesis with Wavelets 3.6 The Haar Wavelet 4. Multiresolution Analysis 4.1 The Scaling Function 4.2 The Discrete Wavelet Transform 5. Filter Banks and the Discrete Wavelet Transform 5.1 Analysis: From Fine Scale to Coarser Scale 5.2 Synthesis: From Course Scale to Fine Scale 5.3 Numerical Complexity of the Discrete Wavelet Transform 5.4 Matlab Examples 5.5 Initialization of the Discrete Wavelet Transform 6. Properties of the Filters, and the Scale and Wavelet Functions 6.1 Double Shift Orthogonality of the Filters 6.2 Frequency Domain Formulas 6.3 Support of the Scale Function 6.4 The Cascade Algorithm 7. Designing Wavelets 7.1 Short Filters 7.2 K-Regular Scaling Filters 7.3 Characterizing K-Regular Filters 7.4 The Daubechies Maximally Flat Polynomial 7.5 Coiflets

Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node1.html

24-04-2006

Pgina Web 1 de 7

Next: 2. Time-Frequency Analysis Up: Wavelets and Filter Banks Previous: Contents Contents

1. Analysis and Synthesis of Signals


Signal Spaces Signals defined on the time interval , then a signal, Given two signals, and can be added, subtracted and multiplied by constants. for . and is: , gives rise to a vector

This should remind us of vectors. In fact if we take samples of the signal at times

, the dot product of the corresponding vectors,

In this sense we can regard the integral of

times

as a sort of dot product of the two signals. . We define the inner product of

Note that the analogy is not exact except in the limit where two signals as:

If

and

are complex signals then we use the complex conjugate of

in computing the

inner product:

Note that in the wedge bracket notation for the inner product the variable is not necessary as the integration is over the variable . We use this notation so that we can write things like . In analogy with the length of a vector we define the norm of a the signal to be:

Note that the square of the norm of a signal is the energy in the siganl (think of the signal as a voltage driving a 1 ohm resistor).

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 2 de 7

Given the analogy with vectors, we define two signals

and

to be orthogonal if

Orthogonal Vectors in the Plane There is a simple formula for resolving a vector, vectors and . Recall that we can project , in the plane in terms of a a pair of orthogonal

onto each of the vectors .

and

obtaining multiples

and

from which we can synthesize

This geometric construction can be obtained through dot products. By taking the dot product of first with we have:

So, we can solve for

Similarily, by taking the inner product of

with

we have:

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 3 de 7

Recall that we say that the vectors plane. When we compute the coefficients the basis and .

and

are an orthogonal basis for the set of vectors in the

and

we say that we are analyzing the vector

in terms of

When we express the vector as the basis. That is, we have two processes going on:

we say that we are synthesising the vector from

Orthogonal Basis of Signals In the case of signals we say that a set of signals values like from to

(where

ranges over some infinite set of

) is an orthgonal basis provided: if .

1. The signals are mutually orthgonal. That is, 2. The signals are complete in the sense that the only signal, is the zero signal. That is, if for all

, which is orthgonal to all then .

Generalized Analysis and Synthesis Given an orthogonal basis of signals and synthesize the signal back again:

we can then analyze any signal

in terms of the basis

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 4 de 7

The Analysis coefficients

are called the Generalized Fourier Coefficients and the Synthesis

equation is called the Generalized Fourier Series. To see that the Generalized Fourier Series does converge to the original signal let's call the signal which it does converge to . That is,

Now consider the difference orthogonality of the basis shows that:

. A straight forward calculation using the

The completeness condition implies that

must be zero or that

Parseval's Theorem The energy in the signal can be obtained from the Generalized Fourier Coefficents just as in the case of Fourier Series.

That is,

where

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 5 de 7

Example: Fourier Series If we have a signal defined on Fourier Series ( ):

then we know that we can compute its complex

The functions

are orthogonal and the formula for

is the usual analysis formula:

Note that the functions . Example: Cosine Basis If we have defined on orthgonal basis of functions on

are solutions to the boundary value problem

then we can extend given by:

to be an even function on has only cosine terms. This gives an

and then its Fourier Series, with period

The Analysis-Synthesis equations are:

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 6 de 7

Note that interval.

completes 1/2 of a cycle on the interval. In general

completes

cycles on the

Note that the functions .

are solutions to the boundary value problem

Example: 1/4 Cycle Cosine Basis Given defined on we can extend extend oddly across Series ( and

evenly to

. We can then . The Fourier and the

to obtain an even function on

has only cosine terms but because of the odd extensions at

terms of even frequency have zero amplitude. This gives an orthogonal basis of functions on given by:

Note that

completes 1/4 of a cycle on the interval. To simplify the notation let's define:

With this definition

completes

cycles on

The Analysis-Synthesis equations are:

Note that the functions .

are solutions to the boundary value problem

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 7 de 7

Example: Sinc Basis The Shannon Sampling Theorem gives an orthogonal basis of sinc functions. Recall that if band limited to Hz and we take samples of with a sampling interval then

is

To see that this is the Analysis/Synthesis formula in terms of inner products, recall that we have the Fourier Transform pair:

So,

Using the fact that the Fourier Transform preserves inner products we can show that the sinc functions are orthogonal.

Also, the Analysis formula becomes:

Next: 2. Time-Frequency Analysis Up: Wavelets and Filter Banks Previous: Contents Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node2.html

24-04-2006

Pgina Web 1 de 8

Next: 3. Time-Scale Analysis Up: Wavelets and Filter Banks Previous: 1. Analysis and Synthesis Contents Subsections 2.1 The Short Time Fourier Transform 2.2 The spectrogram 2.3 An Orthgonal Basis of Functions

2. Time-Frequency Analysis
In many applications such as speech processing, we are interested in the frequency content of a signal locally in time. That is, the signal parameters (frequency content etc.) evolve over time. Such signals are called non-stationary. For a non-stationary signal, , the standard Fourier Transform is not useful for analyzing the signal. Information which is localized in time such as spikes and high frequency bursts cannot be easily detected from the Fourier Transform. Time-localization can be achieved by first windowing the signal so as to cut off only a well-localized slice of and then taking its Fourier Transform. This gives rise to the Short Time Fourier Transform, (STFT) or Windowed Fourier Transform. The magnitude of the STFT is called the spectrogram. By restricting to a discrete range of frequencies and times we can obtain an orthogonal basis of functions.

2.1 The Short Time Fourier Transform


The Short Time Fourier Transform of a signal follows. using a window function is defined as

Think of the window

as sliding along the signal

and for each shift . For example, if

we compute is the box of

the usual Fourier Transform of the product function width 1/2 then we have (see the Matlab m-file fig1.m):

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 2 de 8

In the frequency domain we can use the convolution theorem to recognize convolution of with the Fourier transform of (which is ).

as the

Recall that we have the Fourier Transform pair:

In the case where That is, the nulls of .

is a box of width

, that is,

then

are at multiple of

. See the figure below where the box has width

In the case where the signal is a pure sinusoid of frequency sinc function shifted by has frequency

the windowed transform will be the and the first sinusoid

. In the figure below the box has width Hz. and

In the case where the signal consists of two sinusoids of frequencies

the windowed

transform will be the superposition of two shifted sinc functions. The individual frequencies cannot

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 3 de 8

be resolved unless .

. In fact, for adequate separation we should have

That is, the ``frequency resolution'' of this analysis is

. Hz and

In the following figure a signal is the sum of two sinusoids with frequencies Hz. The window size is (see fig2.m).

. We get two distinct peaks in the frequency response

In the case where the signal consists of two spikes close together in time we can resolve the spikes if the window size is smaller that the time difference between the spikes. This analysis shows the ``trade-off'' between time resolution and frequency resolution: if we use a window of length then we have a ``time-resolution'' of but our frequency resolution is .

2.2 The spectrogram


The magnitude of the Short Time Fourier Transform is called the spectrogram. We can make 2 dimensional plots of the spectrogram with time on the horizontal axis, frequency on the vertical axis and amplitude given by a gray-scale colour. Alternately we can make 3 dimensional plots where we plot amplitude on the third axis. The Matlab command specgram can be used to generate these

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 4 de 8

plots. In the following example, (see fig3.m) a signal and window width of ms (

is the sum of two sinusoids of frequencies ms and ms. We use a

and two impulses at times Hz).

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 5 de 8

The resolution in frequency is

Hz. The time resolution is

ms. As the plots show,

we can can resolve both the sinusoids and the impulses. Now suppose that we move the two frequencies closer together. Let's use a signal sum of two sinusoids of frequencies ms and and which is the

and two impulses at times ms (see fig4.m).

ms with a window width of

As the spectrograms now show we cannot resolve the frequencies but we can still resolve the spikes.

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 6 de 8

Now suppose that we change the window size to ms. As the spectrograms below show, we can resolve the frequencies but not the spikes (see fig4cd.m).

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 7 de 8

2.3 An Orthgonal Basis of Functions


We can obtain an orthogonal basis of functions related to the Short Time Fourier Transform when using the window function = the box of width as follows. Instead of computing for all frequencies and all time shifts we restrict the calculation to and

. To see that this corresponds to orthonormal functions define:

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 8 de 8

Then we have:

Since functions.

is non-zero only for

it is clear that these are orthogonal

Because we have analysis and synthesis on each interval analysis and synthesis in general. That is:

to

it follows that we have

In summary, if we restrict the STFT calculation to a discrete set of frequencies and times we can regard the STFT values as the coordinates of our signal with respect to an orthogonal basis. Hence we can recover our signal from these STFT values.

Next: 3. Time-Scale Analysis Up: Wavelets and Filter Banks Previous: 1. Analysis and Synthesis Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node3.html

24-04-2006

Pgina Web 1 de 13

Next: 4. Multiresolution Analysis Up: Wavelets and Filter Banks Previous: 2. Time-Frequency Analysis Contents Subsections 3.1 The Continuous Wavelet Transform 3.2 Comparision with STFT 3.3 The Scalogram 3.4 Examples of Wavelets 3.5 Analysis and Synthesis with Wavelets 3.6 The Haar Wavelet

3. Time-Scale Analysis
The Continous Wavelet Transform (CWT) provides a time-scale description similar to the STFT with a few important differences: Frequency is related to scale which may have a better relationship to the problem at hand. The CWT is able to resolve both time and scale (frequency) events better than the STFT. By restricting to a discrete set of paramaters we get the Discrete Wavelet Transform (DWT) which corresponds to an orthogonal basis of functions all derived from a single function called the mother wavelet. The basis functions in the DWT are not solutions of differential equations as in the Fourier case. The basis functions are ``near optimal'' for a wide class of problems. This means that the analysis coefficients drop off rapidly. There is a connection and equivalence to filter bank theory from DSP which leads to a computationally efficient algorithm. The computational complexity of the FFT is while that of the DWT is .

3.1 The Continuous Wavelet Transform


The formula for the continuous wavelet transform (CWT) is:

Note that the roles of The function

and

are reversed from the usage in the book WWT.

is called the (mother) wavelet. It is taken to be a ``small wave''. For example, the

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 2 de 13

Haar wavelet is a single cycle of the square wave of period 1. The morlet wavelet has formula:

It is also a small wave since the gaussian exponential, . The graph of

, is effectively zero outside the interval

is obtained stretching the graph of

by a the factor

, called the

scale, and shifting in time by . The time-shifted and time-scaled wavelet is sometimes called a baby wavelet. The figure below shows a signal shifts (see fig5.m). The subsequent figure shows a signal (see fig6.m). along with the morelet wavelet at three scales and shifts along with the Haar wavelet with two different scales and

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 3 de 13

We can think of the CWT in different ways: 1. The CWT is the inner product or cross correlation of the signal shifted wavelet with the scaled and time

. This cross correlation is a measure of the similarity

between signal and the scaled and shifted wavelet. It is this point of view that is illustrated in the figures above. 2. For a fixed scale, wavelet , the CWT is the convolution of the signal . with the time reversed

That is, the CWT is the output when we feed our signal to the filter with with impulse response .

It is this filter point of view which will show the connection to STFT

3.2 Comparision with STFT


We can write the STFT as:

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 4 de 13

We use the variable, , for frequency so that later when we take the Fourier Transform we avoid confusing this frequency variable with the usual one in the transform. Aside from the initial phase factor, , this last equation is the convolution of the signal, . That is, ,

with the frequency shifted and time reversed window function,

To understand the significance of the filter interpretations of CWT and STFT we can consider the case of the Morlet wavelet, , and the STFT with gaussian window function, . The Fourier Transform of the gaussian window function is: . Note that this

is a window function in the frequency domain. It is a low pass filter which blocks all frquencies above

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 5 de 13

The frequency response of the filter in the STFT is this transform shifted by frequency . That is, . This is a band pass filter centered at frquency and of approximate width 1 Hz. That is, computing the spectrogram of a signal using a Gaussian window function is the same as passing the signal through a series of bandpass filters of constant bandwidth 1 Hz. In the case of the CWT the frequency repsonse of the filter when the scale, , is: This is a band pass filter centered at frquency Hz with bandwidth 1 Hz. At scale the frequency response is with a bandwidth of Hz. . This is band pass

filter centered at frequency

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 6 de 13

The is a constant Q filter

That is, computing the CWT of a signal using the Morlet wavelet is the same as passing the . signal through a series of bandpass filters centered at with constant Q of This shows the essential difference between the STFT and the CWT. In the STFT the frquency bands have a fixed width (1 Hz for Gaussian). In the CWT the frequency bands grow and shrink with the frequency (scale) being used. This allows good frequency resolution at low frequencies and good time resolution at high frequencies.

3.3 The Scalogram


The magnitude of the Continuous Wavelet Transform is called the scalogram. We can make 2 dimensional plots of the scalogram with time on the horizontal axis, scale on the vertical axis, and amplitude given by a gray-scale colour. Alternately, we can make 3 dimensional plots. The matlab command cwt can be used to generate these plots. In the following example (see fig7.m) we use the same signal as in fig4.m. That is, of two sinusoids of frequencies ms and ms. and is the sum

and two impulses at times

Using the Morlet wavelet we obtain the following scalogram.

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 7 de 13

We can convert between scale,

to frequency,

using the formula

. We can make a

new scalogram using frequency instead of scale.

To see clearly that the frequencies are resolved by the scalograms we can make a 3 dimensional plot.

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 8 de 13

3.4 Examples of Wavelets


There are a number of wavelets with explicit formulas. These wavelets are generally not useful in practice but are good examples for working out the theory. It turns out the the useful wavelets do not have explicit formulas but they do have a ``fast wavelet transform'' using filter banks. The Morlet Wavelet The morlet wavelet and its Fourier Transform are:

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 9 de 13

The Haar Wavelet The Haar wavelet and its Fourier Transform are:

The Mexican Hat Wavelet The Mexican Hat wavelet and its Fourier Transform are:

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 10 de 13

The Shannon Wavelet The Shannon wavelet and its Fourier Transform are:

3.5 Analysis and Synthesis with Wavelets


http://www.engmath.dal.ca/courses/engm6610/notes/node4.html 24-04-2006

Pgina Web 11 de 13

Recall that with the STFT we obtained an orthogonal basis of functions by choosing equally spaced frequency and time samples . This does not apply in general. To ensure the orthogonality we chose the window function to be the box of width .

In some cases we can get an orthogonal basis of functions in the CWT case by choosing the scales to be powers of 2 and the times to be an integer multiple of the scales. That is, for integers and we consider:

To simplify the notation we define a doubly indexed set of baby wavelets as follows:

It then follows that the values is,

are the analysis coefficients for these functions. That

There is a large class of wavelet functions for which the the set of baby wavelets is an orthogonal basis. These are the orthogonal wavelets. the simplest of these is the Haar wavelet. In the case of an orthogonal wavelet the analysis formula is called the Discrete Wavelet Transform.

The recovery of the signal through the synthesis formula is called the Inverse Discrete Wavelet Transform.

Note that the Time-Scale Diagram for the Discrete Wavelet Transform is a a set of samples of the Time-Scale Diagram for the Continuous Wavelet Transform. The samples are quite ``sparse'' for large scale and more ``dense'' for small scale.

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 12 de 13

3.6 The Haar Wavelet


Most results about wavelets are simple to see in the case of the Haar wavelet. It is best to keep this case in mind to guide your thinking about wavelets in general. With this in mind we should thoroughly understand the Haar case. The first point to understand is that the Haar baby wavelets are orthogonal to each other. The wavelet function is a single cycle of a square wave of period 1.

Then,

The factor of The function

is to make the energy of the signal 1. is a single cycle of a square wave extending from time and to of the same scale, .

From this description it is easy to see that baby Haar wavelets, , but different positions and

, are orthogonal because their graphs don't overlap.

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 13 de 13

It is also true that Haar baby wavelets of differnt scales are orthogonal. To see this it is best to first consider the case of and . Since positive to negative while it follows (see the figure below) that completes its cycle from

is constantly 1 so that the integral of the product is 0.

In the general case of

and

if the graphs overlap then one of the functions completes its

cycle from 1 to -1 while the other is constant. This shows that these two are orthogonal. The other property of an orthogonal basis is that of completeness. We will see later that the Haar baby wavelets are complete.

Next: 4. Multiresolution Analysis Up: Wavelets and Filter Banks Previous: 2. Time-Frequency Analysis Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node4.html

24-04-2006

Pgina Web 1 de 13

Next: 5. Filter Banks and Up: Wavelets and Filter Banks Previous: 3. Time-Scale Analysis Contents Subsections 4.1 The Scaling Function 4.2 The Discrete Wavelet Transform

4. Multiresolution Analysis
We would like to find wavelets, wavelets, , with the same properties as the Haar case. That is, The baby , for all and , form an orthogonal basis. This implies that we

have the usual Analysis-Synthesis for all signals:

Such wavelets give rise to a Multiresolution Analysis derived as follows. Define to be set of all signals, , which can be synthesized from the baby wavelets ,

. These spaces are orthogonal to each other and we can synthesize any (energy) signal, as (Note that in the following formula is in the space ):

There is another way to express this idea. Define synthesized from the baby wavelets where

to be the set of all signals, and

, which can be

. That is

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 2 de 13

The spaces

are nested inside each other. That is,

As As

goes to infinity

enlarges to become all energy signals (

).

goes to negative infinity

shrinks down to only the zero signal. is a sum of a signal in and because:

It is clear from the definitions that every signal in

That is, we can write:

This shows that the spaces and .

are the differences (in the subspace sense) between adjacent spaces

We can visualize the spaces

and

as follows:

The term Multiresolution Analysis refers to analyzing signals in relation to this nested sequence of subspaces. To get a better idea of multiresolution analysis, let's decompose a signal, We can use the breakdown: , in a few times.

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 3 de 13

This leads to various decompositions:

Where at level .

, in

, is called the detail at level

and

, in

, is called the approximation

Example: This decompostion can be carried out in Matlab using the wavemenu interface. There are a number of sample signals which can be used for a demo analysis. The signal sumsin is a sum of two sine waves. In the following figures we decompose the signal 4 times as above.

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 4 de 13

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 5 de 13

Note that different aspects of the signal appear in the details and the approximations. The spaces have a very important property related to time compression by factors of 2. is in the space if and only if

The Two Scale Property of Multiresolution: A signal is in the next space .

This follows from the formula:

Investigation of the multiresolution analysis leads to a scaling function, a pair of discrete time filters, and a perfect reconstruction filter bank which can be used to calculate the DWT quickly.

4.1 The Scaling Function


The useful wavelets, subspaces as follows. , have a scaling function which can produce the Multiresolution

Define the ``baby scaling functions'':

where

and

. is and the ``position'' is .

Just as for the wavelet, the ``scale'' of We want to find functions Since the spaces ,

so that the signals in the space . are obtained from

can be synthesized from the baby scale

by time compression or dilation by powers of 2 we only so that the signals in can be

need to check the space

. That is, we want to find a function

synthesized from the integer translates Example: Haar Case

of the scale function.

In the Haar case the scaling function is the unit box delayed by

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 6 de 13

Then

is the box of length

extending from form a basis for

to note that:

To see that the integer translates of

By a similar formula we can synthesize The Two Scale Equation and the Filters

from

and its translates for any negative .

There is an important formula connecting the scale function to itself at two different time scales. This fundamental formula is called the Two Scale Equation and it gives rise to one of the filters. There are discrete time filter coefficients such that:

This follows trivially from the assumption that equation involving the scale function. Since is also a subset of

but is probably the most important

there is another two scale equation for the wavelet which gives rise

to another filter

, such that:

Example: Haar Case In the Haar case, the scale function is the box of width 1 extending from time 0 to time 1. It follows that is the box of width 1/2 extending from time 0 to time 1/2.

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 7 de 13

Similarily,

is the box of width 1/2 extending from time 1/2 to time 1. . That is,

When we add these two smaller box functions we obtain

The filter for the scale function is

Similarily, the Haar wavelet can be expressed as:

The filter for the wavelet is

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 8 de 13

4.2 The Discrete Wavelet Transform


We have previously defined the Discrete Wavelet Transform of a signal, analysis coefficients: , to be the set of

From these we can recover the signal as:

Assuming the existence of a scaling function, Since the spaces are getting larger and larger as

we can now modify this defintion as follows. goes to we can approximate any signal, using the

, closely by choosing a large enough value of basis , (all values of ).

and projecting the signal into

From these we can approximately recover the signal as:

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 9 de 13

In effect, we replace the signal, .

, by the approximate signal given by the projection coefficients,

After this approximation our signal is now in and with their bases

and we can decompose it using the subspaces and . Note that the scale is getting larger

and larger as the index If we take we get:

gets more negative.

Using the basis

in

and

in

we have:

As before, we call the signals We call the coefficients at level 1. We can further decompose and

and

the approximation and detail at level 1. the approximation coefficients and the detail coeffients

to get:

We call the signals We call the coefficients at level 2.

and and

the approximation and detail at level 2. the approximation coefficients and the detail coeffients

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 10 de 13

We can continue in this way to decompose our signal further and further. In terms of coefficients we have (using [...] to indicate vectors as in Matlab):

The calculations of the coefficients can be carried out in Matlab using the dwt (Discrete Wavelet Transform) command. The signal can be recovered from the coefficinets using the idwt (Inverse Discrete Wavelet Transform) command. The Matlab implementation uses the filters is done in the next section. The continuous time meaning of the decomposition can be visualized as follows: and previously mentioned. We shall see how this

Matlab Example: The Matlab routines used in this example will be discussed in the next section. In this example we will decompose a speech signal using the Haar wavelet and a 4 level decomposition. This signal is the word ``two'' sampled at 8000 samples per second.

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 11 de 13

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 12 de 13

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 13 de 13

Next: 5. Filter Banks and Up: Wavelets and Filter Banks Previous: 3. Time-Scale Analysis Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node5.html

24-04-2006

Pgina Web 1 de 21

Next: 6. Properties of the Up: Wavelets and Filter Banks Previous: 4. Multiresolution Analysis Contents Subsections 5.1 Analysis: From Fine Scale to Coarser Scale 5.1.1 Filtering and Downsampling 5.1.2 The One-Stage Analysis Filter Bank 5.1.3 The Analysis Filter Bank 5.2 Synthesis: From Course Scale to Fine Scale 5.2.1 Upsampling and Filtering 5.2.2 The One-Stage Synthesis Filter Bank 5.2.3 Perfect Reconstruction Filter Bank 5.2.4 The Synthesis Filter Bank 5.2.5 Approximations and Details 5.3 Numerical Complexity of the Discrete Wavelet Transform 5.4 Matlab Examples 5.4.1 One-Stage Perfect Reconstruction 5.4.2 Approximations and Details 5.4.3 A Useful Function 5.5 Initialization of the Discrete Wavelet Transform

5. Filter Banks and the Discrete Wavelet Transform


In the previous section we found that the a Multiresolution Analysis allows us to decompose a signal into approximations and details. On the theoretical level this is an Analysis-Synthesis situation. That is, we have bases and we use these bases to decompose our signal. On the practical level, we assume that our signal is represented by its approximation coefficients at some scale and we decompose it in terms of its coefficients at larger scale. Both points of view are necessary for a real understanding of the subject. In this section we will show that the approximation and detail coefficients can be computed using the filters previously mentioned. As we must compute these coefficients at many different scales we will need a filter bank. and

5.1 Analysis: From Fine Scale to Coarser Scale


In the Discrete Wavelet Transform (DWT) we have . That is, each signal in can be expressed in two ways using the basis functions in each of the spaces.

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 2 de 21

We start with the coefficients and coefficients index at scale index and

at scale index

and produce the two sets of coefficients

(Analysis). Alternately, we can start with the two sets of and produce the coefficients at scale

at scale index

(Synthesis).

We can show that the two operations of Analysis and Synthesis are produced by certain filter banks. As the wavelets and the scales at each index level are orthogonal we can compute the coefficients and by the usual inner product formula:

To complete this calculation we have to compute the inner product:

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 3 de 21

We can now complete the calculation previously started:

The detail coefficients can be computed similarily.

To complete this calculation we have to compute the inner product:

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 4 de 21

Upon substitution of this formula into the previous calculation we get:

5.1.1 Filtering and Downsampling


The two formulas for the approximation and detail coefficients look similar to convolution but there is a downsampling involved.

Downsampling a discrete time signal system whose input is

consists of omitting every other value. We can think of a .

and whose output is

To understand the approximation and detail formulas it will help to define the time reversed filters and . We temporarily use to see the convolution.

If we follow this filter by the downsampler we get the approximation coefficients at the next level.

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 5 de 21

The same calculation holds for the detail coefficients. That is, convolution with the time reversed filter followed by downsampling produces the detail coefficients at the next level.

5.1.2 The One-Stage Analysis Filter Bank


We really should think of the two filtering operations followed by downsampling as a filter bank. We are analyzing a function in in into a detail in and and an approximation, . ,

, using a filter bank to calculate the coefficients

The dwt command in the Wavelet toolbox of Matlab carries out the calculations in this one stage filter bank. The syntax is:
[cA, cD] = dwt(x, Lo, Hi); = dwt(x, 'wname');

Note that the number of data values produced by the filter bank is about the same as the number of data values entering the system. To see this let, be the length of the input vector and assume that the filters both have length . The length of the convolution is so that the lengths of and are . The overall size of the data emerging from the filterbank is

increased by the length of the filter minus 1.

5.1.3 The Analysis Filter Bank

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 6 de 21

We can further decompose

to get:

We can then decompose

to get:

The coefficients,

and

form

can be calculated by iterataing or cascading

the single stage filter bank to obtain a multiple stage filter bank.

The wavedec command in the Wavelet toolbox of Matlab carries out the calculations in the multistage filter bank. The syntax is:
[C, L] = wavedec(x, N, Lo, Hi); = wavedec(x, N, 'wname');

The vector is the set of details coefficients at each level together with the approximation coefficients at the final level.

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 7 de 21

The vector is the vector of lengths of each of the entries in wavedec reference page).

and the length of

(see the

Matlab provides functions, appcoef and detcoef compute any of the approximation or detail coefficients from the output of the wavedec command.

5.2 Synthesis: From Course Scale to Fine Scale


The decomposition of a signal into an approximation and a detail can be reversed. That is, we start with the two sets of coefficients and at scale index and produce the coefficients at scale index (Synthesis). We have:

Using the fact that

is an orthogonal basis for

we have:

This synthesis formula can be understood in terms of upsampling and filtering.

5.2.1 Upsampling and Filtering


The expressions:

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 8 de 21

look like convolutions but upsampling is involved. Upsampling of a discrete time signal consists of inserting zeros between the values. We can think about a system with input output for even values of and for odd values of . and

The expressions for

and

consist of upsampling followed by filtering.

5.2.2 The One-Stage Synthesis Filter Bank


It follows that the synthesis formula consists of adding the outputs of the upsampled and filtered approximation and detail coefficients.

The idwt command in the Wavelet toolbox of Matlab carries out the calculations in this one stage filter bank. The syntax is:
x = idwt(cA, cD, Lo, Hi); = idwt(cA, cD, 'wname');

5.2.3 Perfect Reconstruction Filter Bank


If we feed the output of the one-stage analysis filterbank to the input of the one-stage synthesis fitler

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 9 de 21

bank then we get the original coefficients back. We say the we have a perfect reconstruction filter bank.

Note that the non-causal nature of the Analysis Bank filters is does not cause a problem in practice as we are dealing with FIR filters. This means that we can apply a fixed delay, to each filter to make it causal before applying the input signal. This is the same as delaying the input signal by before applying it to the filter bank. To make things simple, assume that the filters delay the time reversed filter Denote the reversed filters by the same a delaying the signal by by and both have length . If we . is

then we obtain the ``causal flip'' of the filter , . Filtering a signal . by

then filtering by

Hence, we can have a filter bank consisting of causal filters which gives perfect reconstruction with an overall delay of . The analysis filters are and while the synthesis filters are and .

5.2.4 The Synthesis Filter Bank


The outputs of the multiple stage analysis filter bank can be fed into a multiple stage synthesis filter bank to reproduce the original coefficients. For example, a 3 level analysis bank produces outputs , , , and . These are fed into the 3 level synthesis filter bank as

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 10 de 21

shown:

5.2.5 Approximations and Details


We have seen that we can reconstruct the signal coefficients, and at level 1. in from the approximation and detail

As

and

are in

we can resolve them as:

Using the same reasoning as before:

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 11 de 21

That is, we obtain the approximation coefficients at level 0 by upsampling the approximation coefficients, at level 1 and then filtering with the low pass filter . Similarily, we obtain the detail coefficients at level 0 by upsampling the detail coefficients, at level 1 and then filtering with the high pass filter .

5.3 Numerical Complexity of the Discrete Wavelet Transform


We have previously analyzed the one-stage analysis filterbank to count the number of coefficients produced.

We can also count the number of floating point operations involved. Assume that we are feeding in operations. coefficients and the filter have length . Each convolution takes approximately So, the system requires total floating point operations.

Now if we use two-stage filter bank then the input to the next bank has length (approximately) so that the second stage adds only operations to the first stage operations.

Continuing in this way, a multi-level bank requires:

That is, the computational complexity of the algorithm is linear in the size of the data.

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 12 de 21

Compare this to the FFT algorithm which has complexity

. We really should not make too

much of this apparent computational advantage as we know the CWT reflects a logarithmic division of frequency while the FFT uses equally spaced frequency divisions. The point is that for some applcations the logarithmic frquency divisions are sufficent for analyzing the situation so that the DWT has a computational advantage is these cases.

5.4 Matlab Examples


5.4.1 One-Stage Perfect Reconstruction
The m-file checkfb.m produced the following diary file.
echo on % m file to generate and test the analysis and synthesis banks % % | % +------+ +------+ | +------+ +------+ % | | y1 | | v1 | | | u1 | | w1 % +-----| rh1 |-----| dwn2 |----|----| up2 |-----| h1 |----+ % | | | | | | | | | | | % | +------+ +------+ | +------+ +------+ | %x | | | z %----+ | +---% | | | % | +------+ +------+ | +------+ +------+ | % | | | y0 | | v0 | | | u0 | | w0 | % +-----| rh0 |-----| dwn2 |----|----| up2 |-----| h1 |----+ % | | | | | | | | | % +------+ +------+ | +------+ +------+ % | % Analysis Bank | Synthesis Bank % % % N = 2; % which db filters to use len = 2*N; % filter length p = 10; % size of input vectors % construct the string for dbN wave = ['db',int2str(N)]; % get some filters to work with [rh0 rh1 h0 h1] = wfilters(wave); % Have a look at the filters [rh0' rh1' h0' h1'] ans = -0.1294 0.2241 0.8365 0.4830 -0.4830 0.8365 -0.2241 -0.1294 0.4830 0.8365 0.2241 -0.1294 -0.1294 -0.2241 0.8365 -0.4830

x=randn(p,1); % white noise % first handle the analysis bank y0 = conv(rh0',x); y1 = conv(rh1',x);

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 13 de 21

v0 = dyaddown(y0); v1 = dyaddown(y1); % print them out [y0 y1] ans = -0.0381 0.2389 -0.1457 -1.0255 0.4057 1.4370 0.2355 0.8709 1.2926 -1.1244 -1.8471 -0.2182 0.2758 [v0 v1] ans = 0.2389 -1.0255 1.4370 0.8709 -1.1244 -0.2182 0.8916 0.0748 -1.4494 1.7159 -1.2863 0.0585 -0.1422 0.8916 -1.5287 0.0748 1.7050 -1.4494 0.0570 1.7159 -1.0294 -1.2863 1.0070 0.0585 -0.0739

% now do the synthesis bank u0 = dyadup(v0); u1 = dyadup(v1); w0 = conv(h0,u0); w1 = conv(h1,u1); % print them out [u0 u1] ans = 0 0.2389 0 -1.0255 0 1.4370 0 0.8709 0 -1.1244 0 -0.2182 0 [w0 w1] 0 0.8916 0 0.0748 0 -1.4494 0 1.7159 0 -1.2863 0 0.0585 0

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 14 de 21

ans = 0 0.1154 0.1998 -0.4417 -0.8888 0.4642 1.3348 0.7427 0.5426 -0.3478 -1.0533 -0.3574 -0.0370 -0.0489 0.0282 0 0 -0.1154 -0.1998 0.7362 -0.4474 0.2502 0.2887 -1.4345 0.3154 1.6018 -0.5404 -1.0836 0.6081 0.0489 -0.0282 0

% now add up the streams z = w0 + w1; % to compare x to z we pad the end with zeros cx = [x ; zeros(2*(len-1),1)]; [cx z] ans = 0.2944 -1.3362 0.7143 1.6236 -0.6918 0.8580 1.2540 -1.5937 -1.4410 0.5711 0 0 0 0 0 0 >> diary off 0 0.0000 -0.0000 0.2944 -1.3362 0.7143 1.6236 -0.6918 0.8580 1.2540 -1.5937 -1.4410 0.5711 -0.0000 0.0000 0

5.4.2 Approximations and Details


The m-file wavdemo.m produced the following plots.
% File: wavdemo.m % demonstrates various commands in the wavelet toolbox load sumsin x=sumsin; % Compute the wavelet decomposition at level 3 [C,L] = wavedec(x,3,'db2');

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 15 de 21

figure(1) subplot(2,1,1); subplot(2,1,2);

plot(x); title('original signal');axis([0 1000 -5 5]); plot(C); title('wavelet decomposition');axis([0 1000 -5 5]);

orient landscape; print wavdemofig1.eps % Now cA3 = cD3 = cD2 = cD1 = extract the coefficients appcoef(C, L, 'db2', 3); detcoef(C, L, 3); detcoef(C, L, 2); detcoef(C, L, 1);

% plot these figure(2) subplot(4,2,1); subplot(4,2,3); subplot(4,2,5); subplot(4,2,7);

plot(cA3); plot(cD3); plot(cD2); plot(cD1);

title('cA3');axis([0 title('cD3');axis([0 title('cD2');axis([0 title('cD1');axis([0

1000 1000 1000 1000

-5 -5 -5 -5

5]); 5]); 5]); 5]);

% Now compute the reconstructed coefficients A3 = wrcoef('a', C, L, 'db2', 3); D3 = wrcoef('d', C, L, 'db2', 3); D2 = wrcoef('d', C, L, 'db2', 2); D1 = wrcoef('d', C, L, 'db2', 1); % plot these subplot(4,2,2); subplot(4,2,4); subplot(4,2,6); subplot(4,2,8); plot(A3); plot(D3); plot(D2); plot(D1); title('A3');axis([0 title('D3');axis([0 title('D2');axis([0 title('D1');axis([0 1000 1000 1000 1000 -5 -5 -5 -5 5]); 5]); 5]); 5]);

orient landscape; print wavdemofig2.eps

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 16 de 21

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 17 de 21

5.4.3 A Useful Function


The function examine_recon.m can be useful in examining the reconstruction or synthesis of a signal. It was used to produce the plots of approximations and details for the speech signal in the multiresolution section.
function [cA,A,cD,D] = examine_recon(x, N, wname) %[cA,A,cD,D] = examine_recon(x,N,wname) calculate and plot approx and details %up to level N for a signal x using wavelet type given by wname [m,n]=size(x); if m == 1 x=x'; end % perform wavelet decompostion at level N [C,L] = wavedec(x,N,wname); A = zeros(length(x),N); D = zeros(length(x),N); cA = zeros(length(x),N); cD = zeros(length(x),N); lena = zeros(1,N); lend = zeros(1,N); % compute the approximations at various levels for i=1:N A(:,i) = wrcoef('a',C,L,wname,i);

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 18 de 21

end % compute the approximation coeff at various levels for i=1:N temp = appcoef(C,L,wname,i); lena(i)=length(temp); cA(1:lena(i),i) = temp; end % compute the details at various levels for i=1:N D(:,i) = wrcoef('d',C,L,wname,i); end % compute the detail coeff at various levels for i=1:N temp = detcoef(C,L,i); lend(i)=length(temp); cD(1:lend(i),i) = temp; end % make plots figure; subplot(N+1,1,1); plot(x); title(['Signal and approximations 1 to ', num2str(N)]); for i=1:N subplot(N+1,1,i+1); plot(A(:,i)); end figure; subplot(N+1,1,1); plot(x); title(['Signal and approximation coef 1 to ', num2str(N)]); for i=1:N subplot(N+1,1,i+1); plot(cA(1:lena(i),i)); end figure; subplot(N+1,1,1); plot(x); title(['Signal and details 1 to ', num2str(N)]); for i=1:N subplot(N+1,1,i+1); plot(D(:,i)); end figure; subplot(N+1,1,1); plot(x); title(['Signal and detail coef 1 to ', num2str(N)]); for i=1:N subplot(N+1,1,i+1); plot(cD(1:lend(i),i)); end

5.5 Initialization of the Discrete Wavelet Transform


Given a signal one of the spaces , to apply the Discrete Wavelet Transform our starting point must be a signal in . Since the spaces, , are getting larger and larger as goes to infinity we can and projecting the

approximate our signal, signal into

, closely by choosing a large enough value of , (all values of ). That is:

using the orthogonal basis

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 19 de 21

The projection coefficients, continuous time filter. That is,

, in this summation can be obtained by sampling the output of a

This shows that we obtain the coordinates of the projection of through the filter with impulse response

onto the space

by passing .

and then sampling at times

We will show that if index,

is bandlimited then by choosing an appropriate sampling rate and a scale

, we can recognize the projection coefficents in terms of a discrete time filtering process.

Assume that we have sampled a band limited signal at 20% above the Nyquist rate. After normalization we can assume that the sampling rate is 1Hz so that our signal contains only frequencies below 0.5/1.2 = 0.417. That is, we can represent our signal as

Where the Discrete Fourier Transform,

, of

is zero for

. . After rearranging

We can now pass this signal into the above filter to find the projection onto the summation and itegration we find:

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 20 de 21

Where signal onto

evaluated at are just the samples,

. Hence the coordinates of the projection of our . is approximately magnitude 1 over

, filtered by

Fact: For almost all orthogonal wavelets the filter frequencies

and the phase response is linear. That is, the filter acts as a delay on our signal

and so aside from that delay, we may use the samples of the signal as the scaling coefficients. Example: The m-file initdwt.m can be used to investigate the filter
% % % % % % % % % % %

for various wavelets.

This m file investigates the filter which carries out the projection of a band limited signal into V0 This filter is alpha(n) = sinc(r) * phi(-r), at r = n alpha(n) = integral phi(-s) sinc(n-s) ds = integral phi(t) sinc(t+n) dt Since the support of phi(t) is 0 <= t <= N-1 the values of this integral will become quite small outside the interval -2N <= n <= 2N-1. So, we approximate alpha(n) by an FIR filter of length 4N.

iter = 10; dt = 1/2^iter; wave = 'db7'; [f0 f1 h0 h1] = wfilters(wave); [phi, psi, t] = wavefun(wave,iter); N = length(h0); alpha = zeros(1,4*N); for n=(-2*N:(2*N-1)) alpha(n+2*N+1) = sinc(t + n) * phi' * dt; end subplot(3,1,1) ;stem(alpha); title(['Projection Filter for ' wave]); [Alpha,W]=freqz(alpha); subplot(3,1,2); plot(W/(2*pi), abs(Alpha)); axis([0 0.5 0 1.2]); title('Magnitude Response'); subplot(3,1,3); plot(W/(2*pi), unwrap(angle(Alpha)));

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 21 de 21

title('Phase Response');

Next: 6. Properties of the Up: Wavelets and Filter Banks Previous: 4. Multiresolution Analysis Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node6.html

24-04-2006

Pgina Web 1 de 11

Next: 7. Designing Wavelets Up: Wavelets and Filter Banks Previous: 5. Filter Banks and Contents Subsections 6.1 Double Shift Orthogonality of the Filters 6.2 Frequency Domain Formulas 6.3 Support of the Scale Function 6.4 The Cascade Algorithm

6. Properties of the Filters, and the Scale and Wavelet Functions


In this section we will examine properties of the filters, scale and wavelet using the two-scale equation:

The fact that the scale function and the low pass filter satisfy this equation has some remarkable consequences. Keep in mind that we are making a number of assumptions: 1. Orthogonality for the Wavelet: The baby wavelets are orthgonal and to have unit energy.

2. Orthogonality for the Scale: The translates have unit energy ( ).

, are orthogonal and

3. Completness: The translates , and

, .

, span the same space as the wavelets

6.1 Double Shift Orthogonality of the Filters

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 2 de 11

The two-scale equation shows that coordinates of the filter coefficients If we delay .

with respect to the basis

are

by n then the coordinates of

are the filter coefficients delayed by for in the two-scale equation.

(i.e.

. This can be easily seen by substituting

The same is true of the wavelet function and the filter

Since the integer time shifts of the wavelet and the scale are orthogonal we have:

These equations are called the double shift orthogonality relations of the filters. They lead to a number of other properties of the filters. 1. If we take in the equations above we get:

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 3 de 11

2. If we integrate both sides of the two-scale equations we get:

3. The even and odd sums of both filters are:

For a proof of this equation see Proof 3 in Appendix A, page 247 of the textbook (WWT). 4. The filter such that: is an alternating flip of the filter . That is, there is an odd integer

For a proof of this fact see Proof 10 in Appendix A, page 250 of the textbook (WWT). Example To illustrate these equations we can use the m-file dshift.m as follows:
[h0 h1] = wfilters('db3','r') h0 = 0.3327 h1 = 0.0352 sum(h0) ans = 1.4142 sum(h1) 0.0854 -0.1350 -0.4599 0.8069 -0.3327 0.8069 0.4599 -0.1350 -0.0854 0.0352

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 4 de 11

ans = -2.9981e-12 h0even = dyaddown(h0,1) h0even = 0.3327 0.4599 -0.0854

h0odd = dyaddown(h0,0) h0odd = 0.8069 sum(h0even) ans = 0.7071 sum(h0odd) ans = 0.7071 h1even = dyaddown(h1,1) h1even = 0.0352 -0.1350 0.8069 -0.1350 0.0352

h1odd = dyaddown(h1,0) h1odd = 0.0854 sum(h1even) ans = 0.7071 sum(h1odd) ans = -0.7071 p0 = conv(h0,wrev(h0)) p0 = Columns 1 through 7 0.0117 -0.0000 -0.0977 0.0000 0.5859 1.0000 0.5859 -0.4599 -0.3327

Columns 8 through 11 0.0000 -0.0977 -0.0000 0.0117

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 5 de 11

p1 = conv(h1, wrev(h1)) p1 = Columns 1 through 7 -0.0117 -0.0000 0.0977 0.0000 -0.5859 1.0000 -0.5859

Columns 8 through 11 0.0000 >> diary off 0.0977 -0.0000 -0.0117

6.2 Frequency Domain Formulas


In the frequency domain we have a number of properties. 1. Frequency Domain Version of the Two-Scale Equation:

This is proven by taking the Fourier Transform of both sides of the two-scale equation. Note that this is a very unique equation because is the discrete time Transform. 2. If we iterate the previous equation we get: is the continuous time transform while

3.

and

. That is,

is a low pass filter since the frequency .

response is zero at the highest (normalized) frequency 4. and . That is, . is a mirror of

is a high pass filter since the frequency

response is zero at the lowest frequency 5. point . . That is,

around the quadrature

6. Frequency Domain Version of Double Shift Orthogonality

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 6 de 11

To understand this equation we can define the filter

Notice that the double shift orthognality shows that is, is a centered, symmetric half-band filter.

and

for

. That

In the frequency domain we have . The filter with frequency response . We therefore have:
Frequency Domain P(f) <----> [ . . . p(-3) P(f+1/2) <----> [ . . .-p(-3) sum <----> [ . . . 0

so that we are trying to show that

is the filter

with alternating signs:

Time Domain 0 p(-1) 0 -p(-1) 0 0 1 p(1) 1 -p(1) 2 0 0 p(3) 0 -p(3) 0 0 0 p(5) . . . ] 0 -p(5) . . . ] 0 0

It follows that Example

To illustrate these equations we can use the m-file dshiftf.m as follows:


% File: dshiftf.m % Illustrates the frequency domain properties of the filters %echo on; %diary dshiftf.diary; [h0 h1] = wfilters('db3','r') p0 = conv(h0,wrev(h0)); % alternate signs ind = 1:2:length(p0); p0shift = p0; p0shift(ind) = -p0shift(ind); [H0,W] = freqz(h0); [H1,W] = freqz(h1); [P0,W] = freqz(p0); [P0shift,W] = freqz(p0shift); subplot(2,2,1); plot(W/(2*pi), abs(H0)); title('Low Pass Filter Response H_{0}(f)');

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 7 de 11

xlabel('Frequency'); axis([0 0.5 0 2.1]); subplot(2,2,2); plot(W/(2*pi), abs(H1)); title('High Pass Filter Response H_{1}(f)'); xlabel('Frequency'); axis([0 0.5 0 2.1]); subplot(2,2,3); plot(W/(2*pi), abs(P0),W/(2*pi),abs(P0shift)); title('P_{0}(f) and P_{0}(f + 1/2)'); xlabel('Frequency'); axis([0 0.5 0 2.1]); subplot(2,2,4); plot(W/(2*pi), abs(P0)+abs(P0shift)); title('P_{0}(f) + P_{0}(f + 1/2)'); xlabel('Frequency'); axis([0 0.5 0 2.1]); %orient landscape; %print -depsc 'dshiftf.eps';

6.3 Support of the Scale Function


The support of a function is the range of values of where the function is non-zero.

The two-scale equation imposes a restriction on the support of the scale function.

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 8 de 11

Assume that the low pass filter support of is the interval

is causal with length .

. Then we will show that the

The two-scale equation becomes:

If we assume that has support

has support on an interval and the last term in the sum, .

then the first term in the sum, , has support

It follows that the largest possible support for the sum is and . Hence and .

. That is

6.4 The Cascade Algorithm


The two-scale equation can be used to approximate the scale function using the low pass filter . We can think of the two-scale equation as an iteration. That is, starting with an approximation we produce a sequence of approximations by considering the two-

scale equation as an update formula:

As a numerical algorithm we start with estimates Then, the first iteration produces an approximation to

of

on the integer values

. via:

at the half-integer points

The next iteration produces estimates of

at the quarter-integer points

and so on.

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 9 de 11

If we carry out this algorithm for M steps then we get approximate values of where ranges over . That is, the times range from

at points up to .

Once we have an estimate for the scale function we can produce an estimate of the wavelet function from it and the high pass filter . This algorithm can be implemented directly in Matlab but it is somewhat slow to carry out as Matlab is an interprted language. This slowness is a general Matlab problem for any algorithm involving many nested for loops. If we can formulate our algorithm to use built in vector operations rather than for loops it will be much faster. There is a vector version of the algorithm which we can derive as follows. We know that the subspaces using the basis functions That is, any function basis in : in , . can be written in terms of the basis in and also in terms of the , , ..., give a finer and finer decomposition of functions

We know that the coefficients levels of the synthesis bank.

are obtained by passing the coefficients

through

Now recall that the coordinates of the scale function, coefficents, coefficients, , and the coordinates of the wavelet, .

, in

are exaclty the low pass filter

, in V1 are exactly the high pass filter

Hence we should upsample and low pass filter these two sets of coefficents coefficients in . . We know that

times to get their

At this point we must ``estimate''

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 10 de 11

So we can estimate this function by a box of height might as well center this box in the interval . Define . Then

extending for , where

units of time. We = length of the filter

Substituting this for

we get that

The m-file ocascade.m carries out this algorithm.


function [phi,psi,x]=ocascade(h0,iter) %[phi,psi,x]=ocascade(h0,iter) % %carrys out the cascade algorithm %iter is the number of iterations used. if nargin == 1 iter = 8; end N=length(h0)-1; % compute the high pass filter (alternating flip) h1 = fliplr(h0); h1(2:2:(N+1)) = - h1(2:2:(N+1)); % do the first iteration phi = h0; psi = h1; % now the rest of the iterations for i=(2:iter) % upsample top = 2*length(phi)-1; temp = phi; phi = zeros(1,top); phi(1:2:top) = temp; temp = psi; psi = zeros(1,top); psi(1:2:top) = temp; % filter phi = conv(h0,phi);

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 11 de 11

psi = conv(h0,psi); end % scale the answers and pad with zeros on both ends to account for the offset % note that the last x sample is exactly N - 1/2^iter. offset = (N-1)/2; pad = zeros(1,offset); %pad=[]; phi=2^(iter/2)*[pad phi pad]; psi=2^(iter/2)*[pad psi pad]; % compute the grid x nf=length(phi); % same for all %x = linspace(0, (nf-1)/2^iter,nf); x = (0:(nf-1))/2^iter;

Example The m-file ocascadedemo.m demonstrates the use the this m-file.

Next: 7. Designing Wavelets Up: Wavelets and Filter Banks Previous: 5. Filter Banks and Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node7.html

24-04-2006

Pgina Web 1 de 17

Next: About this document ... Up: Wavelets and Filter Banks Previous: 6. Properties of the Contents Subsections 7.1 Short Filters 7.1.1 Length 2 Filter 7.1.2 Length 4 Filter 7.1.3 Length 6 Filter 7.2 K-Regular Scaling Filters 7.2.1 The db2 Wavelet 7.2.2 The db3 Wavelet 7.3 Characterizing K-Regular Filters 7.4 The Daubechies Maximally Flat Polynomial 7.4.1 Factoring the Daubechie Maximally Flat Polynomial 7.5 Coiflets 7.5.1 Coif1 7.5.2 Coif2

7. Designing Wavelets
The properties of the low pass filter, , shown in the previous section can be used as design criteria. Once we have found a filter with the desired properties we can derive the scale and wavelet functions using the cascade algorithm provided that the algorithm converges for this filter. The minimal properties on the filter 1. Normalization: . are:

2. Double Shift orthogonality:

for

3. Low Pass:

7.1 Short Filters


The equations above can be explicitly solved for the filter coefficents when the filter length is small. See pages 65 and 66 of the book Wavelets and Wavelet Transforms.

7.1.1 Length 2 Filter


If the length of the filter is 2 then . This leads to the Haar wavelet and scale

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 2 de 17

function.

7.1.2 Length 4 Filter


The double shift orthogonality amounts to a single equation so that the 3 equations above should lead to one degree of freedom in the solution. The solution can be expressed in terms of a single parameter, , as follows:

Most values of from .

do not lead to a useful wavelet. The Daubechies wavelet with filter length 4 arises

7.1.3 Length 6 Filter


The double shift orthogonality amounts to a two equations so that the we have four equations in total. This leaves two degrees of freedom in the solution. The solution can be expressed in terms of two parameters as in the m-file h246.m. See page 261 of the book Wavelets and Wavelet Transforms.
function h = h246(a,b) % h = h246(a,b) generates orthogonal scaling function % coefficients h(n) for lengths 2, 4, and 6 using % Resnikoff's parameterization with angles a and b. % csb. 4/4/93 if a==b, h = [1,1]/sqrt(2); % Length-2 elseif b==0 h0 = (1 - cos(a) + sin(a))/2; % Length-4 h1 = (1 + cos(a) + sin(a))/2; h2 = (1 + cos(a) - sin(a))/2; h3 = (1 - cos(a) - sin(a))/2; h = [h0 h1 h2 h3]/sqrt(2); else % Length-6 h0 = ((1+cos(a)+sin(a))*(1-cos(b)-sin(b))+2*sin(b)*cos(a))/4; h1 = ((1-cos(a)+sin(a))*(1+cos(b)-sin(b))-2*sin(b)*cos(a))/4; h2 = (1+cos(a-b)+sin(a-b))/2; h3 = (1+cos(a-b)-sin(a-b))/2; h4 = (1-h0-h2); h5 = (1-h1-h3); h = [h0 h1 h2 h3 h4 h5]/sqrt(2); end

Most values of the two parameters do not lead to useful wavelets. The m-file twoparam.m can be used to explore the various wavelets arising from these filters.

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 3 de 17

for alpha=(-1:0.1:1)*pi for beta=(-1:0.1:1)*pi h0=h246(alpha,beta); % frequency responses [H0,W]=freqz(h0); F=W/(2*pi); %figure(1); axis; subplot(3,1,1); plot(F,abs(H0)); title(['Frequency Response, alpha = ', num2str(alpha), ... ', beta = ', num2str(beta)]); % roots r=roots(h0); subplot(3,1,2); zplane(r); title('roots'); % wavelet and scale [phi,w,t]=ocascade(h0,8); subplot(3,1,3); plot(t,phi,t,w); title('scale and wavelet functions'); pause; end end

7.2 K-Regular Scaling Filters


The filters, In , which lead to ``good' wavelets have a high order zero of -regularity means a high order zero at at .

transform terms

. This means that the

transform looks like:

where least The

. In this case we say that the filter is regular. th derivative of evaluated at is:

-regular. Note that the filter

is at

So, in the time domain terms we call a filter

-regular if:

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 4 de 17

7.2.1 The db2 Wavelet


When we looked for a scaling filter of length 4 we found that we had three equations for the 4 unknown coefficients. If we impose the extra condtion that the filter be 2-regular we will add one more condtion. 1. Normalization: 2. Double Shift orthogonality: 3. Low Pass: 4. 2-regular: These equations can be solved exactly but we will use the Matlab numerical solver function fsolve.m. This function finds roots of a vector function given as an m-file. The equations above have been coded as db2eqns.m along with the driver program daub2.m.
% File: daub2.m % m file to generate the db2 low pass filter N = 2; len = 2*N; % which sym filters to use % filter length

. .

start = zeros(len,1); % starting guess for the filter start(2)=1; % the file db2eqns.m has the system of non-linear equations % Now call fsolve for this function [h,info]= fsolve('db2eqns',start); % convert to a row vector h = h'; % compare to the wavelet toolbox values h0 = wfilters('db2','r'); [h' h0'] % now construct h1 by the alternating flip h1 = fliplr(h); h1(1:2:length(h1)) = -h1(1:2:length(h1)); [H,W] = freqz(h); [H1,W] = freqz(h1); figure(1); plot(W/(2*pi),abs(H),W/(2*pi),abs(H1)) xlabel('frequency'); title('db2 Filters');

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 5 de 17

[phi,psi,x] = ocascade(h,8); figure(2); plot(x,phi,x,psi); xlabel('time'); title('db2 wavelet and scale'); function y = db2eqns(h) y=zeros(4,1); % norm is 1 y(1) = h(1)*h(1) + h(2)*h(2) + h(3)*h(3) + h(4)*h(4) - 1.0; % double shift orthogonality y(2) = h(3)*h(1) + h(4)*h(2); % H(1/2) = 0 y(3) = h(1) - h(2) + h(3) - h(4); % H'(1/2) = 0 y(4) = -h(2) + 2.0*h(3) - 3.0*h(4);

7.2.2 The db3 Wavelet


When we looked for a scaling filter of length 6 we found that we had four equations for the 6 unknown coefficients. If we impose the extra condtion that the filter be 3-regular we will add two more equations. 1. Normalization: 2. Double Shift orthogonality: . and . 3. Low Pass: 4. 3-regular: .

and

Again, we will use the Matlab numerical solver function fsolve.m. The equations above have been coded as db3eqns.m along with the driver program daub3.m.

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 6 de 17

7.3 Characterizing K-Regular Filters


There is a connection between roots at of the z transform, . Define the , of the filter and zero th moments of the scale and moments of the correpsonding wavelet function wavelet functions as:

Define the discrete

th moments of the filters

, and

as follows:

When we combine the 2-scale equation with these defintions we find (see page 75 of WWT) the following relationships between the discrete and continuous momments.

These equations can be used to calculate any continuous moment as a convolution like formula involving the discrete moments and the lower order continuous moments. In particular, if the discrete moments, of the high pass filter, then follows that the continuous moments of the wavelet, more is true. See page 75 of WWT. Equivalent Characterization of 1. The filter is -Regular Filters The following conditions are all equivalent. , are zero for are zero for it . Much

-regular.

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 7 de 17

2. order

has a zero of order are also zero.

at

. That is,

and all derivatives up to

This is just a restatment of condition 1. 3. The ``alternating moments'' zero. This condition arises by noting that aside from mutiples of , is just the 4. The moments th derivative of , at . are zero. , the alternating moment, , for , are

of the wavelet filter,

This follows from the fact that the wavelet filter filter . ,

is the alternating flip of the scaling

5. The moments

of the wavelet,

, are zero.

This follows from the relationship above between discrete and continuous moments. 6. All polynomials of degree up to translates of the scaling function. This condition follows by noting that zero then it follows that the space . for all . So, that if all these moments are . Hence, the polynomial must be ``in'' can be expressed as a linear combination of integer

7.4 The Daubechies Maximally Flat Polynomial


Let the length of the scaling filter be and suppose that the filter is -regular.

When we consider the number of equations that the coefficients of the largest possible value of is .

must satsify we find that

This is the case since the double shift orthgonality conditions amount to normalization adds one equation leaving at most The form of must therefore be: other equations.

equations and the

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 8 de 17

where The filter

is a filter of length

. must have the form:

Where The filter

comes from a filter of length

is called the Daubechie maxmimally flat filter. Note that the length is .

To understand this form we let have:

and define

. Then we

Daubechie was able to show that up to the term involving

consists of terms of the Binomial series expansion of (see Theorem 23 on page 76 of WWT). That is,

Hence,

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 9 de 17

Of course we still have to transform back to in the

rather than . The simplest way to do this is to work and is:

domain rather than the frequency domain. The relationship between

Solving for

in terms of

we are lead to a quadratic equation:

Hence, every root The roots of

of the polynomial at other roots yield

yields two roots roots of at roots

of the polynomial . of . and ).

There are Note that

which yield so that the roots of

occur in pairs (

The m-file daubpoly.m implements the computation of the polynomial and its roots.
function [p, z] = daubpoly(K) %[p, z] = daubpoly(K) %Function to compute the Daubechie polynomial of order 4K-2 %as per the discussion on pages 76-78 of the book WWT %Not accruate for n > 20. %Input: K where the filter has length 4K-1 %Output: Daubechie Max Flat Polynomial p and its roots z % As stated on pages 76 to 78 (also see pages 166 to 169 of Strang): % % % n n % ( 1+1/z ) ( 1+z ) % P(z) = 2( ----- ) ( ----- ) L(y) % ( 2 ) ( 2 ) % % The relationship between z, y, and frequency f is: % % 2 % y = sin(pi f) % % y = (1 - cos(2pi f))/2 = (2 - z - 1/z)/4 % % then 1 - y = (1 + cos(2pi f))/2 = (2 + z + 1/z)/4

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 10 de 17

% % rearranging the last equation gives a quadratic: % % ( z^2 - 2(1-2y)z + 1) = 0. To solve the quadratic equation: % % Let x = 1 - 2y and u = sqrt(x^2-1) then % % z = x + u and z = x - u are the two roots of M(z) for each root y of P(y) % % Note that x - u = 1/(x + u). That is, we have roots and their inverses % % % L(y) = binonmial series for (1-y)^(-n) up to K terms i.e. % up to the power y^(K-1) % % K - 1 % _____ % \ ( K-1+k ) k % P(y) = ( ) y % / ( k ) % ----% k = 0 % % That is, % % K - 1 % _____ % K \ ( K-1+k ) k % M(z) = (1-y) | ( ) y % / ( k ) % ----% k = 0 % % % coef is the vector of coefficients of P(y/4) (lowest to highest power). % dividing by 4 makes the computation more stable. coef = zeros(1,K); coef(1) = 1; %keep in mind that coef(k) is the coefficient of y^(k-1) for k = 2:K, coef(k) = coef(k-1)*0.25*(k+K-2)/(k-1); end y=roots( fliplr(coef) )/4; x=1-2*y; u = sqrt(x.^2-1); z=[x+u; x-u]; z = [-ones(2*K,1); z]; p = poly(z); p = 2*p /sum(p);

7.4.1 Factoring the Daubechie Maximally Flat Polynomial


For each integer we have the filter of length whose frequency repsonse is at .

maximally flat at frequency

. That is,

has a root of order

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 11 de 17

We can factor

to obtain a has

-regular filter roots at

of length and

. other roots

To carry out the factorization we note that which occur in pairs ( other has and

). We can think of this as

roots inside the unit circle and the

roots outside the unit circle. roots at we have and other roots. These roots occur in conjugate pairs.

That is, for even each of these

complex roots and one real rootin the first quadrant . For or is a root of . This leads to

roots we have two choices: .

possible choices for For odd we have

complex roots in the first quadrant. To pick the choices.

other roots

we have The wavelet

is obtained by choosing all

roots to be inside the unit circle. Other choices

may have ``better'' filters. The m-file daubdemo.m shows how the choice of roots can affect the phase response of the filter for the case .
% File: daubdemo.m % This m-file shows that by choosing the roots of the Daubechie maxflat % polynomial we can get close to linear phase filters % K=6; [p,z] = daubpoly(K); % db6 z1 = z(20); z2=z(18); z3=z(21); r=[-ones(6,1);z1;z2;conj(z2);z3;conj(z3)]; h=poly(r); h=sqrt(2)*h/sum(h); [phi,w,t]=ocascade(h,8); figure; subplot(3,1,1); zplane(r); title('roots'); subplot(3,1,2); plot(t,phi,t,w); title('scale and wavelet'); [H,W]=freqz(h); subplot(3,1,3); plot(W/(2*pi),unwrap(angle(H))); title('phase response'); z1 = z(20); z2=1/z(18); z3=z(21); r=[-ones(6,1);z1;z2;conj(z2);z3;conj(z3)]; h=poly(r); h=sqrt(2)*h/sum(h); [phi,w,t]=ocascade(h,8); figure; subplot(3,1,1); zplane(r); title('roots'); subplot(3,1,2); plot(t,phi,t,w); title('scale and wavelet'); [H,W]=freqz(h); subplot(3,1,3); plot(W/(2*pi),unwrap(angle(H))); title('phase response'); z1 = z(20); z2=z(18); z3=1/z(21); r=[-ones(6,1);z1;z2;conj(z2);z3;conj(z3)]; h=poly(r);

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 12 de 17

h=sqrt(2)*h/sum(h); [phi,w,t]=ocascade(h,8); figure; subplot(3,1,1); zplane(r); title('roots'); subplot(3,1,2); plot(t,phi,t,w); title('scale and wavelet'); [H,W]=freqz(h); subplot(3,1,3); plot(W/(2*pi),unwrap(angle(H))); title('phase response'); z1 = z(20); z2=1/z(18); z3=1/z(21); r=[-ones(6,1);z1;z2;conj(z2);z3;conj(z3)]; h=poly(r); h=sqrt(2)*h/sum(h); [phi,w,t]=ocascade(h,8); figure; subplot(3,1,1); zplane(r); title('roots'); subplot(3,1,2); plot(t,phi,t,w); title('scale and wavelet'); [H,W]=freqz(h); subplot(3,1,3); plot(W/(2*pi),unwrap(angle(H))); title('phase response');

7.5 Coiflets
The Daubechie filters have the property that they are maximally flat. That is, if the length of the low pass filter, , is then the largest possible order of the zero of at is . In terms of conditons on the filter coefficients we have: 1. Normalization: (1 condition) .

2. Double Shift Orthogonality: (

conditions)

3.

-Regular: (

conditions)

for

The most

can be is

. If we allow

to be less than

then we can impose some other

condtions on the filter. To obtain the filters and wavelets commonly known as coiflets we require fewer alternating moments to be zero but require some (usual) moments to be zero. That is: 1. Normalization: (1 condition) .

2. Double Shift Orthogonality: (

conditions)

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 13 de 17

3.

alternating moments are zero: ( .

conditions)

for

4.

moments are zero: (

conditons)

for

Note that filter response at frequency

. Hence with this last condtion we are asking that the be very flat although we know that . at .

There is a simplifying result which comes from computing the derivatives of After some manipulation (see page 91 of WWT) it can be shown that:

This shows that for

even,

can be written in terms of the odd lower order moments

This has an important outcome. If the odd moments are zero for are zero. condtions in item 4 above is actually then if follows that . condtions and we have: then all the even moments are zero

too so that all the moments up to order Hence, what originally appeared to be (assuming that

is even). So, if we choose

1. Normalization: (1 condition)

2. Double Shift Orthogonality: (

conditions)

3.

alternating moments are zero: ( .

conditions)

for

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 14 de 17

4.

moments are zero: ( .

conditons)

for

This set of conditions leads to the alternating moments (0 to ) and

filter and wavelet. The filter has length zero moments (1 to ).

with

zero

We can solve these equations using the numerical solving technique previously discussed. These equations are easy to express in Matlab. If we represent the filter as the column vector h in Matlab then the equations become: 1. Normalization: (1 condition) h'*h -1 = 0 2. Double Shift Orthogonality: (
= 0

conditions) dyaddown(conv(h,flipud(h))

3.

alternating moments are zero: (

conditions) Let n be the row vector [0,1, be the 2L

2, 3, ...,(N-1)],let alter be the row vector [1, -1, 1, -1, ... ] and let A by N matrix whose kth row is alter .* n.^ (k-1). Then we require A*h = 0

4.

moments are zero: (

conditons). As the 0th moment of the filter is not zero

we must advance the filter by 2L. This is reflected in the moments as follows. Let m be the row vector [0,1,2,...,(N-1)] - 2L and let B be the L by N matrix whose kth row is m .(2k-1). Then we require B*h = 0.

7.5.1 Coif1
If we choose
coif1eqns.m

we will get a filter, can be used to find the

, of length wavelet.

. The m-files coif1.m and

% m file to generate the coif1 low pass filter L = 1; N = 6*L; % which coif filters to use % filter length

start = [0 0 0 1 0 0]'; % starting guess for the filter % the file coif1eqns.m has the system of non-linear equations % Now call fsolve for this function [h,info]= fsolve('coif1eqns',start); % convert to a row vector h = h' % compare to the wavelet toolbox values h0 = wfilters('coif1','r');

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 15 de 17

[h' h0'] % now construct h1 by the alternating flip h1 = fliplr(h); h1(2:2:length(h1)) = -h1(2:2:length(h1)); [H,W] = freqz(h); [H1,W] = freqz(h1); figure(1); plot(W/(2*pi),abs(H),W/(2*pi),abs(H1)) xlabel('frequency'); title('coif1 Filters'); [phi,psi,x] = ocascade(h,8); figure(2); plot(x,phi,x,psi); xlabel('time'); title('coif1 wavelet and scale'); function y = coif1eqns(h) L=1; N=6*L; n = (0 : (N-1)); m = ((-2*L) : (N-1-2*L)); % advance by 2L % norm of h is 1 norm2 = h'*h - 1.0; % double shifts of h are orthogonal temp = conv(h, flipud(h)); dblshift = temp(2:2:(N-1)); % 2L derivatives at freq 1/2 (alternating moments of h) are 0 alter = ones(1,N); alter(2:2:N) = -alter(2:2:N); A = [alter; alter .* n]; % L odd derivatives at f = 0 (moments of h) are 0 B = [m]; y = [norm2; dblshift; A * h; B * h];

7.5.2 Coif2
If we choose
coif2eqns.m

we will get a filter, can be used to find the

, of length wavelet.

. The m-files coif2.m and

% m file to generate the coif2 low pass filter L = 2; N = 6*L; % which coif filters to use % filter length

start = zeros(N,1); % starting guess for the filter start(4)=1000;

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 16 de 17

start(5)=1; start(6)=1; % the file coif12eqns.m has the system of non-linear equations % Now call fsolve for this function [h,info]= fsolve('coif2eqns',start); info % convert to a row vector h = h'; % compare to the wavelet toolbox values h0 = wfilters('coif2', 'r'); [h0' h'] % now construct h1 by the alternating flip h1 = fliplr(h); h1(1:2:length(h1)) = -h1(1:2:length(h1)); [H,W] = freqz(h); [H1,W] = freqz(h1); figure(1); plot(W/(2*pi),abs(H),W/(2*pi),abs(H1)) xlabel('frequency'); title('coif2 Filters'); [phi,psi,t] = ocascade(h,8); figure(2); plot(t,phi,t,psi); xlabel('time'); title('coif2 wavelet and scale'); function y = coif2eqns(h) L=2; N=6*L; n = (0 : (N-1)); m = ((-2*L) : (N-1-2*L)); % norm of h is 1 norm2 = h'*h - 1.0; % double shifts of h are orthogonal (5 equations) temp = conv(h, flipud(h)); dblshift = temp(2:2:(N-1)); % 2L derivatives at freq 1/2 (alternating moments of h) are 0 alter = ones(1,N); alter(2:2:N) = -alter(2:2:N); A = [alter; alter .* n; alter .* n .* n; alter .* n .* n .* n]; alter .* n .* n .* n .* n; alter .* n .* n .* n .* n .* n]; % L odd derivatives at f = 0 (moments of h) are 0 % see page 91 of WWT, if moments 1 and 3 are zero then so are 2 and 4 B = [m; m .* m .* m]; y = [norm2;

% %

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 17 de 17

dblshift; A * h; B * h];

Next: About this document ... Up: Wavelets and Filter Banks Previous: 6. Properties of the Contents Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node8.html

24-04-2006

Pgina Web 1 de 1

Up: Wavelets and Filter Banks Previous: 7. Designing Wavelets Contents

About this document ...


Wavelets and Filter Banks Course Notes This document was generated using the LaTeX2HTML translator Version 99.1 release (March 30, 1999) Copyright 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds. Copyright 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney. The command line arguments were: latex2html notes The translation was initiated by Dr. W. J. Phillips on 2003-04-03 Dr. W. J. Phillips 2003-04-03

http://www.engmath.dal.ca/courses/engm6610/notes/node9.html

24-04-2006

You might also like