You are on page 1of 6

MATLAB Programs for Generating Orthonormal Wavelets

B.G. SHERLOCK and Y.P. KAKAD


Department of Electrical and Computer Engineering
University of North Carolina at Charlotte
Charlotte, NC 28223
USA

Abstract: - This paper presents MATLAB programs for generating the coefficients of the lowpass analysis
filter corresponding to orthonormal wavelet analyses. One of the programs generates the famous Daubechies
maxflat wavelets, and a second generates the Daubechies complex symmetric orthonormal wavelets. The
remaining two programs generate the space of all orthonormal wavelets in terms of parameterizations whereby
the space of wavelets of a given length 2N is generated by N parameters. This software should prove useful
where it is desired to perform an optimization to obtain the best wavelet for a given application.

Key-Words: - Wavelets, Orthonormal, Software, Parameterization

1 Introduction obtained at a cost, however: the DWT using


Wavelet analysis has been widely used in recent biorthogonal wavelets does not preserve energy, i.e.
years in a variety of application areas. The reason the Parseval relation is no longer valid.
for this success is that wavelet analysis provides a It is possible to obtain linear phase without
mixed time-frequency representation that gives a sacrificing orthonormality if we allow the
useful compromise between analysis purely in terms coefficients of the filter to be complex. In the paper
of frequency (as exemplified by the Fourier we show how the parameterizations can be used to
transform) and purely time-domain analysis. generate spaces of symmetric orthonormal wavelets.
A further advantage is that, unlike the Discrete Two further MATLAB programs are included.
Fourier Transform, the Discrete Wavelet Transform One of these generates the lowpass filter coefficients
(DWT) is not unique the user may choose between for the famous Daubechies maxflat wavelets, and
an infinite number of different wavelets, each the other for the Daubechies maxflat symmetric
providing its own unique corresponding DWT. complex wavelets.
This opens up the possibility of performing an
optimization procedure in order to obtain the best 2 The Space of Orthonormal
wavelet for any given application according to some Wavelets
given optimality criterion. In order to perform this In this section, software is presented to generate the
optimization, it is necessary to have a coefficients for the scaling filters corresponding to
parameterization of the space of wavelets under all orthonormal wavelets, including wavelets with
consideration. The optimization cost function will complex filter coefficients. To do this, a
then be passed the values of the parameters for each parameterization of the space of orthonormal
wavelet as the optimization proceeds. One of the wavelets is required. We make use of two
authors has successfully used this approach to obtain parameterizations; each of these generates scaling
optimal wavelets for the compression of fingerprint filter coefficents from a given set of parameter
images [7]. values. To generate the space of all orthonormal
The main disadvantage of orthonormal wavelet wavelets with real-valued coefficients, the
analysis is that symmetry of real-valued filters parameterization of Section 2.1 requires the
cannot be achieved. Symmetry is of great parameters to be angles in the range 0 to 2,
importance because of the linear phase exhibited by whereas that of Section 2.2 allows the parameters to
such filters, and also because symmetry permits the have any real values. Both parameterizations
use of a reflective data extension that substantially produce the space of orthonormal wavelets with
reduces edge effects. The usual way of obtaining complex coefficients if the parameters are given
linear phase filters within the context of a wavelet complex values. The major advantage of complex
analysis is to relax the requirement of orthonormal wavelets over real orthonormal
orthonormality, and this has led to the widespread wavelets is that linear phase can be achieved.
use of biorthogonal wavelets [1]. Linear phase is
2.1 Generating Wavelets Using Angle even length 2M can be produced by choosing M
Parameters
Let the coefficients of the scaling filter be denoted
parameters i (with
i
i =
4
if regularity is
by {hi }, with z-transform H ( z ) =
hi z i . desired) and passing through the flow diagram,
i
terminating after M-1 stages of processing.
Vaidyanathan [9] proposed the following An efficient implementation in MATLAB is given
parameterization of the space of all perfect- in Figure 2.
reconstruction two-channel filter banks of length 2M function h = orthogen(alpha);
in terms of M angle parameters { 0 , 1 ,..., M 1 }: % Constructs an array, h(1...N) of lowpass
% orthonormal FIR filter coefficients for any
M 1 1 % even N>=2. The input array, alpha(1...N/2)
H ( z ) = (1 0)R0 Ri 1 , where % gives N/2 free parameters that are angles
i =1 z % in radians. If the angles sum to pi/4 the
% filter corresponds to a regular wavelet.
1 0 ci si N = 2*length(alpha);
= and R i =
1
, with h = zeros(1, N);
0 z si ci lo = N/2;
hi = lo + 1;
c i = cos i and s i = sin i . h(lo) = cos(alpha(1));
h(hi) = sin(alpha(1));
Sherlock and Monro [6] derived from this nstages = N/2;
recursive formulae expressing the coefficients
{h } for a filter of length 2(k+1) in terms of the
i
( k +1) for stage = 1 : nstages-1
c = cos(alpha(stage+1));
coefficients {h } for a filter of length 2k. They
(k ) s = sin(alpha(stage+1));
i h(lo-1) = c*h(lo);
h(lo) = s*h(lo);
obtained, for the even numbered filter coefficients h(hi+1) = c*h(hi);
{h2i } : h(hi) = -s*h(hi);
nbutterflies = stage-1;
h0( k +1) = ck h0( k ) butterflybase = lo+1;
( k +1) for butterfly = 1 : nbutterflies
h2 i = ck h2 i sk h2 i 1 for i = 1, 2, ..., k 1
(k ) (k ) hlo = h(butterflybase);
hhi = h(butterflybase+1);
( k +1)
h2 k = sk h2 k 1
(k ) h(butterflybase) = c*hhi - s*hlo;
h(butterflybase+1)= s*hhi + c*hlo;
with h0(1) = c0 and h1(1) = s0 . The corresponding butterflybase = butterflybase + 2;
end;
formula for the odd numbered filter coefficients lo = lo - 1;
{h2i +1} is: hi = hi + 1;
end;
h1( k +1) = s k h0( k ) Figure 2. MATLAB function for generating orthonormal
( k +1) wavelets from angle parameters.
h2i +1 = s k h2i + c k h2i 1 for i = 1, 2, ..., k 1
(k ) (k )
This parameterization is, however, a redundant
h ( k +1) = c h ( k ) representation because of inherent symmetries in our
2 k +1 k 2 k 1 parameter space. It is shown in [6] that the filter
The recurrence of the above equations can be coefficients will be unchanged if any even number
elegantly expressed in the form of the flow diagram of the i are changed by . The space can therefore
of Figure 1. In this diagram a filter of any desired
be fully covered by choosing 0 from the interval
[0,2) and 1 through M 1 from [0,).
When generating wavelets, however, regularity,
M 1

equivalent to
i =0
i =
4
, is also required. With this

additional constraint, it is shown in [6] that the space


of all orthonormal wavelets of length 2M is covered
by choosing M-1 parameters i from the interval
[0,), and calculating the final one from the
regularity constraint.
Figure 1. Flow diagram illustrating generation of For a filter of length 2M corresponding to an
orthonormal wavelets from angle parameters. orthonormal wavelet, the transformation
also possible to express the present parameterization
0 = 0 , in the form of a recurrence. Lina and Mayrand [3]
2
presented recursive formulae expressing the
i = i , i = 1,2,..., M 2
transforms the filter into its time-reverse. Therefore,
{ }
coefficients hi( k +1) for a filter of length 2(k+1) in
half of the parameter space corresponds to wavelets terms of the coefficients hi( k ) { } for a filter of length
which are time-reversals of the other half. A
2k. They obtained, for the even numbered filter
subspace of the parameter space which covers all
orthonormal wavelets but excludes their time coefficients {h2 i } :
reversals is given (for length-2M wavelets) by
choosing one parameter from the interval [0,/2), M-
h2( ik +1) =
1
1 + k k
( )
h2(ik ) k h2(ik)1 + k h2(ik+)1 + k k h2(ik)2 ( 1) k ,

2 parameters [0,), and calculating the remaining and for the odd numbered filter coefficients {h2i +1} :
parameter from the regularity constraint.
The parameterization can be extended to produce h2( ik++11) =
1
1 + k k
(
h2(ik+)1 k h2(ik ) + k h2(ik+)2 + k k h2(ik+)1+ 2 ( 1) k .)
filters with complex-valued coefficients, simply by
The recurrence is started with the Haar length-2
allowing the i to be complex. However, the
wavelet, h0(1) = h1(1) = 12 ; then regularity of the
parameterization of Section 2.2 turns out to be better
suited to this purpose. wavelet is preserved throughout the iterative process
2.2 Generating Wavelets Using Real-Valued irrespective of the choice of i . An advantage over
Parameters the parameterization in Section 2.1 is that this
The parameterization used in this section is based parameterization does not exhibit the redundancies
upon the work of Pollen [5] and the subsequent that occurred in Section 2.1 due to the angular nature
results of Lina [3,4]. As in Section 2.1, let the of the i parameters. Here, the space of all
coefficients of the scaling filter be denoted by {hi }, orthonormal regular wavelets with real coefficients
is simply produced by allowing the i to range over
with z-transform H ( z ) = h z i
i
. Then the
i all real values.
parameterization of the space of all regular perfect- Furthermore, restricting all i to be pure
reconstruction two-channel filter banks of length
imaginary generates the space of all symmetric
2M+2 in terms of M parameters { 0 , 1 ,..., M 1 } is complex orthonormal wavelets. These wavelets are
produced as described below. important because they are the only orthonormal
Define 2-by-2 matrices G i (z ) by function h=nuorthgen(nus)
% Generates all orthonormal regular wavelets.
u i ( z ) wi ( z ) % nus is an array of parameters satisfying:
% nus all real => space of all real
Gi ( z) = , i=0,,M-1. % orthonormal regular wavelets
w ( z) u ( z) % nus all imaginary => space of all
i i % symmetric complex orthonormal
% regular wavelets
i i
where u i ( z ) = 1 + ( z 1 1) % nus complex => space of all orthonormal
1 + i i % regular wavelets
h0 = 1/sqrt(2);
i h1 = 1/sqrt(2);
and wi ( z ) = ( z 1) . h=[h0 h1] ;
1 + i i stages=length(nus);
for stage=1:stages
Then form G ( z ) = G 0 G1T G 2 G 3T ...G M 2 G MT 1 , nu=nus(stage);
nuc=conj(nu);
where the notation G T represents the conjugate N=length(h)+2;
transpose. Note that conjugate transposition is h=[0 0 conj(h) 0 0];
for i=2:2:N+1
applied to every second matrix in the above product. newh(i)= h(i)-nu*h(i-1)+nu*h(i+1)+ ...
Finally, the filter coefficients in this nu*nuc*h(i+2);
parametrization are obtained as i1=i+1;
newh(i1)=h(i1)-nuc*h(i1-1)+ ...
z
H ( z) = 1
(1 1)G ( z 2 ) . end
nuc*h(i1+1)+ nu*nuc*h(i1-2);

1
2
h=newh(2:N+1)/(1+nu*nuc);
Because, just as in Section 2.1, the filter is end
produced by a successive product of matrices, it is Figure 3. MATLAB function for generating orthonormal
wavelets using parameterization of Section 2.2.
wavelets that exhibit linear phase. Linear phase is function dau=makedau(N)
% Function to generate coefficients of
highly valuable in many applications because the % Daubechies maxflat orthonormal wavelet
position of details is preserved in the filtered signal. % filter of length N.
An efficient implementation in MATLAB is given %
in Figure 3. if mod(N,2) ~=0
error('N must be even');
end
3 Daubechies Wavelets p=N/2;
b(p)=1;
for i=p-1:-1:1
3.1 Generating Daubechies Maxflat b(i)= b(i+1)*(2*p-i-1)/(4*(p-i));
end
Wavelets r=roots(b)/4;
The Daubechies maxflat wavelet of length 2N is the z1= (1-2*r) + sqrt((1-2*r).^2 -1);
unique length 2N wavelet whose frequency response z2= (1-2*r) - sqrt((1-2*r).^2 -1);
z=[z1;z2];
has both minimum phase and also exhibits N zero zchoose = z( abs(z)<1 ); % for minimum phase
derivatives at = 0 [2]. These wavelets are widely q=poly(zchoose);
used because of their regularity. The wavelet is q=real(q);
%add p zeros at -1
obtained by a spectral factorization of the following flat=1;
halfband frequency response [8]: for i=1:p
N k flat=conv(flat,[1 1]);
1 + cos N 1 N + k 1 1 cos

end
P ( ) = 2 dau= conv(q,flat);
2 k =0 k 2 dau= sqrt(2)*dau/sum(dau);
1 cos Figure 4. MATLAB function for generating Daubechies
Introduce y = ; then y , , and the z- maxflat wavelets.
2
transform variable are related by
1 3.2 Generating Daubechies Symmetric
z+z Complex Wavelets
cos = = 1 2 y . Expressing P( ) in
2 A Daubechies symmetric complex wavelet of length
~
terms of y yields P ( y ) = 2(1 y ) N B N ( y ) , where 2N is a length-2N wavelet whose frequency response
N 1 N + k 1 exhibits N zero derivatives at = 0 and also has
k
B N ( y ) = y is the binomial series linear phase [3]. Linear phase is a highly desirable
k =0 k property that cannot be achieved in orthonormal
truncated after N terms. wavelets unless the coefficients are allowed to be
The spectral factorization of P ( ) and the complex. These wavelets are obtained by the
spectral factorization of the same halfband filter as
subsequent determination of the scaling filter
coefficients are performed as follows: in Section 3.1, i.e. :
1. Find the N-1 zeros {y i } of the polynomial
N N 1 k
1 + cos N + k 1 1 cos
P ( ) = 2
2



k

2

BN ( y) . k =0
2. Transform these to the z domain using The coefficients are calculated according to the
same four steps shown in Section 3.1, except that
z i = 1 2 y i (1 2 y i ) 2 1 . Because of the now the roots of the factorization to be retained in
square root, this yields a total of 2N-2 values. step 3 are chosen in order to achieve symmetry
3. Of the 2N-2 values of z i , retain only those N-1 rather than minimum phase. Symmetry is achieved
by ensuring that roots are retained in pairs ( zi , zi1 ).
that have z i < 1 . This choice results in a
(Since more than one solution achieving symmetry
minimum phase filter. can be obtained, we choose also to ensure that
4. Include a further N zeros at z = 1 . The retained zeros within the unit circle are evenly
coefficients of the resultant polynomial are the distributed above and below the real axis.)
taps of the scaling filter for the Daubechies Therefore, step 3 of the process becomes:
maxflat filter of length 2N.
3a. Of the 2N-2 values of z i , retain only those
This procedure is implemented in the MATLAB
program of Figure 4, which generates these 2N 2
that have zi > 1 and positive real
wavelets. 4
part. What this does is to reduce each quadruplet
( zi , zi1 , zi , zi1 ) of roots to a single root
outside the unit circle and having positive 4 Conclusion
imaginary part. We have presented MATLAB implementations of
N 1 two parameterizations of the space of orthonormal
3b. Sort these roots into increasing order of wavelets. In addition to their obvious use in
2 generating wavelets with real coefficients, we have
real part. indicated how these may be used to generate
N 1 symmetric wavelets with complex coefficients. This
3c. Distribute these roots evenly above and
2 software would be useful in an optimization task in
below the real axis, by taking the conjugate of which the best wavelet for a given application is
every second root. sought.
3d. Include the inverse of each root. This results in We also presented MATLAB functions that
a total of N-1 roots. produce the commonly encountered Daubechies
Note that for step 3a to succeed, it is necessary that max-flat wavelets, as well as the symmetric complex
2N 2 Daubechies wavelets.
be an integer, i.e. that N be odd.
4 References:
Consequently, symmetric complex Daubechies [1] A. Cohen, I. Daubechies and J.C. Feauveau,
wavelets exist only for odd N, i.e. filters of length Biorthogonal bases of compactly supported
2N = 2, 6, 10, 14, etc. wavelets, Comm. Pure Appl. Math., vol. 45,
A MATLAB function to generate these wavelets is 1992, pp 485-560.
presented in Figure 5. [2] I. Daubechies, Orthonormal bases of compactly
function dau=makecxdau(N)
% Function to generate coefficients of supported wavelets, Comm. Pure Appl. Math.,
% Daubechies maxflat symmetric complex vol. 41, 1988, pp 909-966.
% orthonormal wavelet filters. [3] J.M. Lina and M. Mayrand, Complex
%
if mod(N,2) ~=0 Daubechies Wavelets, University of Montreal
error('N must be even'); Laboratory of Nuclear Physics Report UdeM-
end PHYSNUM-ANS-15, December 1993.
p=N/2;
b(p)=1; [4] J.M. Lina and M. Mayrand, Parameterizations
for i=p-1:-1:1 for Daubechies Wavelets, Physical Review E,
b(i)= b(i+1)*(2*p-i-1)/(4*(p-i)); Vol. 48, No. 6, 1993, pp. R4160-R4163.
end
r=roots(b)/4;
[5] D. Pollen, SU1(2,F(z,1/z)) for F a subfield of C,
z1= (1-2*r) + sqrt((1-2*r).^2 -1); Journal of the American Mathematical Society,
z2= (1-2*r) - sqrt((1-2*r).^2 -1); Vol.3, No.3, 1990, pp. 611-624.
z=[z1;z2];
% Keep one of every quadruplet z, 1/z, zbar,
[6] B.G. Sherlock and D.M. Monro, On the Space of
% 1/zbar: Orthonormal Wavelets, IEEE Transactions on
zchoose = z( abs(z)>1 & imag(z) >0); Signal Processing, Vol. 46, No. 6, 1998, pp.
% sort in order of increasing real part: 1716-1720.
[junk,index]= sort(real(zchoose));
zchoose = zchoose(index); [7] B.G. Sherlock and D.M. Monro, Optimized
% Distribute evenly above / below real axis: Wavelets for Fingerprint Compression, IEEE
zchoose(1:2:length(zchoose))=... International Conference on Acoustics, Speech and
conj(zchoose(1:2:length(zchoose)));
zchoose = [zchoose; 1./zchoose];
Signal Processing (ICASSP-96), Atlanta, Georgia,
if(length(zchoose) ~= length(z)/2) May 1996, Vol. III, pp. 1447-1450
disp('No symmetric solutions for this N:') [8] G. Strang and T. Nguyen, Wavelets and Filter
error('N must be of form 2*(odd number)') Banks, Wellesley-Cambridge Press, 1996.
end
q=poly(zchoose); [9] P.P. Vaidyanathan, Multirate Systems and Filter
% add p zeros at -1 Banks, Prentice Hall, 1992.
flat=1;
for i=1:p
flat=conv(flat,[1 1]);
end
dau= conv(q,flat);
dau= sqrt(2)*dau/sum(dau);
Figure 5. MATLAB function for generating complex
symmetric Daubechies maxflat wavelets.

You might also like