Interface Summary Interface Description Filter This interface is used to define wavelet filters.Class Summary Class Description BasisFunctionLibrary This class is meant to be used for Fast Wavelet Transform, Matching Pursuit and related signal processing algorithm.Cascades This class is a standard implementation of the Cascades algorithm.Cosine This class is used to be able to mix the wavelet and cosine transforms.DiscreteFunction This class is used to be able to mix the wavelet and other type of functions such as given signals.DiscreteHilbertSpace This class provides support for basic operations on MultiscaleFunction.FWT Abstract class for using very fast, in-place, implementations of the Fast Wavelet Transform.FWTCoef This class is used to encapsulate wavelet coefficients.FWTCoefMath This class allows to do some operations on wavelet coefficientsFWTPacketCoef This class is used to encapsulate wavelet packets coefficients.MatchingPursuit A Wavelet (and more) matching pursuit class Uses adaptative Morse coding for better performance.Multiresolution This class is used to encapsulate the various wavelet multiresolution (Dau2, Haar, ...).MultiscaleFunction Abstract encapsulation mostly meant for wavelet functions (dyadic case).Signal This class use the linear spline as a general model for a signal.Sine This class is used to be able to mix the wavelet and sine transforms.SparseDiscreteFunction Exception Summary Exception Description IllegalScalingException This exception is used to indicate that the current chosen multiresolution is not appropriate because the number of scaling functions is incompatible (with the multiresolution).

## Package jsci.maths.wavelet Description

## History

This package was designed with Alain Béliveau and Mohamed Jardak in the winter of 1998 (at the École Polytechnique de Montréal).The idea was to provide a wavelet package that could equally well handle numerical analysis and signal processing.This is made possible by an extensive use of object-oriented design.

## Terminology and background

This package assumes you know wavelet theory.If not, a good start is Daubechies' book "Ten lectures on wavelets" published by SIAM.

Numbers of the form k/2^j are called dyadic numbers and form the dyadic grid.If j is the smallest (positive) integer so that x=k/2^j, we say that x is a dyadic number of depth j.The set of all dyadic numbers is a dense set of the reals.A uniformly continuous function over the dyadic numbers is therefore continuous.

In this package, a multiscale function is a function defined (iteratively) on the dyadic grid.

## Conventions

- Numbering of wavelets
When wavelets and scaling functions are created, one must keep in mind that the dimension() parameter (often noted n0) is the number of scaling functions (numbered from 0 to n0-1 according the the C-like notation).

In the dyadic context, with filters of type k (for example), you'll have n0-k wavelets numbered from 0 to n0-k-1.With Haar, for example, which has a filters of type 0, you'll have as many wavelets as you have scaling functions.

- DiscreteHilbertSpace and numerical integration
Numerical integration of irregular functions such as wavelets is a delicate problem.The methods in the class

`DiscreteHilbertSpace`

are only some tested solutions.They are not necessarily the best choices and contributions are welcomed (as always)!

## To add wavelets (subpackages)

The wavelet package was designed so that one could add wavelets at will.Simply create you own subpackage and obey a few simple rules.

- Use numerical integration as included in the
`DiscreteHilbertSpace`

class for testing (bi)orthonormality. (You should get the identity matrix). - The lowpass filters must preserve constants away from the boundaries.That is, if you apply the filter to the array {1,1,1,1,1,...,1} then, you'll get {1,1,1,1,1,...,1} (except maybe at the boundaries). This mean that for a dyadic filter, the sum of the coefficients of the filter should be 2 (away from the boundaries).
- The euclidean norm of your wavelet filter should be 1 away from the boundary.
- Use final static constants whenever possible for performance considerations.
- Use the
`IllegalScalingException`

whenever it applies. - You should have at least one object of type
`Multiresolution`

if you filters are dyadic. - As a rule, you should handle boundaries properly.

## Optimisation and performance

While this package is not designed primarily for speed, it uses fast algorithms and should be adequately fast for most purposes. It was succesfully used for signal processing and numerical analysis and real-time applications have been written from it.

Some notes:

- Precision parameter
Numerous methods have a "precision parameter" or "number of iterations" (same meaning).You should use as small a value as possible for this parameter.Note that it follows a logarithmic scale (everytime you add one, your code slows down by half).A value of 3 or 5 should be sufficient.

- Caching results
The method "evaluate" should be cached whenever possible because it is the costliest method in most cases.

Exampe : You must replace

for(int k=0;k<10000;k++) { d[k]=f.evaluate(j)[k];}

by

double[] t=f.evaluate(j);for(int k=0;k<10000;k++) { d[k]=t[k];}

## The future

Image processing is planned in the near future.Wavelets will be added periodically and performance should be gradually enhanced.In particular, the package should include more of in-place computations maybe using the lifting scheme.

Preprocessing and postprocessing is needed for wavelets other than `Haar`

and `CDF2_4`

when using them in a signal processing context because of boundary effects.

## Examples

There is a lot to this package, from wavelet packets to matching pursuit...All the latest ideas are included somehow in this package.But, since one has to start somehow, here are some basic examples.

- (Bi)orthonormality
This code can be used to test the orthonormality of the Daubechies wavelet.Similar code would work for any wavelet.

- Signal processing
This code is an example of signal processing using Daubechies wavelets.

## F.A.Q.

**Question:**How do I calculate the number of low/high-pass coefficients?**Answer:**If there are`n`data samples and the wavelet has filter type`filterType`, then

no. low-pass coeffs = (n + filterType)/2,

no. high-pass coeffs = (n - filterType)/2.**Help!**FWT doesn't work with level 2, 3 ,4.I don't understand because when I try to execute FWT Daubechies 4 of level 4 (2, 3 too) on a 1024 sample vector it throws this exception:"JSci.maths.wavelet.IllegalScalingException: Even number of values into anodd filter! Change the number of values/iterations: 515".This is the code:public class Sub_Band { Daubechies4 ondelette = new Daubechies4(); public Sub_Band() {} public void jbInit(short[] data) { double d[] = new double[data.length]; for (int i=0; i<data.length; i++) { d = data; } System.out.println(d.length); Signal s = new Signal(d); s.setFilter(ondelette); int level=4; FWTCoef sCoef = s.fwt(level); // for some level int ArrayMath.print(sCoef.getCoefs()[0]); ArrayMath.print(sCoef.getCoefs()[1]); }}

This only works with level 1.**Solution:**Sure it does, but you need proper padding (Meyer boundaries!).The JSci implementation of Daubechies 4 uses the Meyer technique to adapt the filters to the interval.Basically, many pieces of code you can find out there will simply assume you have an infinite signaland do something really fishy at the boundaries.This implementation does something proposed by Meyer which isa bit cleaner than some alternatives.The key point is that if your original signal is a polynomial, you'd want thewavelet coefficients, even near the boundary, to be small.Because the filter type in this case is 6, this means that starting withn=1024 samples, you'll get n/2+3=515 low-pass coefficients and n/2-3=509 high-passcoefficients.The problem here is that 515 is odd, so Meyer's trick doesn't apply.But if you had started with a signal of length 1026, then you'd have 516low-pass coefficients and 510 high-pass ones, and so you'd be able totransform 516 to get 175 low-pass coefficients and 169 high-passcoefficients... Try a signal of length 1030 and it should work as you want.

## Further information

Visit the Wavelet Forum to discuss both JSci specific and general issues relating to wavelets.

Daniel Lemire (Daniel.Lemire@ondelette.com)## Links

**SCaVis 2.2 © jWork.ORG**