The mathIT Library
A Java™ API for mathematics
org.mathIT.approximation

## Class Wavelets

• ```public class Wavelets
extends Object```
This class provides static constants and methods to implement wavelets.
Version:
1.1
Author:
Andreas de Vries
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `ACCURACY`
Standard accuracy of computations of wavelet values.
`static long` `accuracyBitMask`
The bitmask which corresponds to the accuracy bits.
`static int` `accuracyBits`
Number of the stored highervalued (leftmost) bits of the mantissa of a double value.
`static double[][]` `h`
Daubechies filter coefficients Nhk = h[N-1][k] for the D-2N wavelet, N = 1, 2, ..., 10, i.e., D2, D4, ..., D20.
`static double[][]` `initialValues`
Initial values phi(j) of the Daubechies scaling functions phi=phiN for the D2 - D20 wavelets in dimension n=1.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static String` `checkH()`
This routine checks the conditions the Daubechies coefficients have to satisfy.
`static double[]` ```inverseTransform(int N, double[][] w)```
Computes the inverse fast Daubechies wavelet transform of a two-dimensional array `w` containing a vector `w[0]` of the Daubechies D-N wavelet coefficients, and an array `w[1]` containing the scaling function coefficient.
`static double` ```phi(int N, double x)```
returns the value of the scaling function Nφ(x) of the Daubechies wavelet DN, where N = 2, 4, ..., 20.
`static double` ```psi(int N, double x)```
returns the function value of the Daubechies wavelet Nψ(x) of the Daubechies class DN, where N = 2, 4, ..., 20.
`static String` `showDaubCoefficients(String format)`
Returns a structured string representation of the normalized Daubechies filter coefficients `h`, in the specified format.
`static String` `showWaveletCoefficients(double[][] w)`
Returns a structured string representation of the wavelet coefficients given by the array w.
`static double[][]` ```transform(int N, double[] a)```
Computes the fast Daubechies wavelet transform of a data vector, applying the Daubechies D-N wavelet; the returned two-dimensional array contains the wavelet coefficients in its [0]-component, and the scaling function coefficient in its [1]-component; N has to be an even number with 2 ≤ N ≤ 20.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### accuracyBits

`public static final int accuracyBits`
Number of the stored highervalued (leftmost) bits of the mantissa of a double value. It is used to compute the wavelet function values of non-dyadic numbers, i.e., numbers with an infinite binary expansion, such as 1/3, or irrational numbers such √2 or π. The value 10 results in a pretty good approximation, 16 is fine, and 22 is excellent (but needs some 10 millions recursive calls for 1/3!). For plotting, however, the scaling functions and wavelets D2--D10 are OK with the value 7.
`accuracyBitMask`, Constant Field Values

`public static final long accuracyBitMask`
The bitmask which corresponds to the accuracy bits. It is computed by `0xfffffffffffffL << (52 - accuracyBits)`, since the mantissa of a double value consists of 52 bits.
`accuracyBits`, Constant Field Values
• #### ACCURACY

`public static final double ACCURACY`
Standard accuracy of computations of wavelet values.
Constant Field Values
• #### h

`public static final double[][] h`
Daubechies filter coefficients Nhk = h[N-1][k] for the D-2N wavelet, N = 1, 2, ..., 10, i.e., D2, D4, ..., D20. We have 0 ≤ k < 2N. In the i-th row (0 ≤ i < 10) there are the 2(i+1)=2N coefficients of D2N.
• #### initialValues

`public static final double[][] initialValues`
Initial values phi(j) of the Daubechies scaling functions phi=phiN for the D2 - D20 wavelets in dimension n=1. We have 0 ≤ j < 2N. In the i-th row (0 ≤ i < 10) there are the 2(i+1) - 1 = 2N - 1 initial values of D2N.
• ### Method Detail

• #### phi

```public static double phi(int N,
double x)```
returns the value of the scaling function Nφ(x) of the Daubechies wavelet DN, where N = 2, 4, ..., 20. The function value is computed recursively for any dyadic number x, i.e., a number with a finite binary expansion. More exactly, the mantissa of x containing at most the first 52 bits of its binary expansion according to the IEEE754 format is truncated by the accuracyBitMask. This way the recursions always terminate at an integer which yields either zero or one of the predefined initial values.
Parameters:
`N` - the index of the Daubechies wavelet class D2 ... D20,
`x` - the value for which the scaling function value is computed
Returns:
the value of the scaling function Nφ(x) of DN
`accuracyBits`, `accuracyBitMask`, `initialValues`, `psi(int,double)`
• #### psi

```public static double psi(int N,
double x)```
returns the function value of the Daubechies wavelet Nψ(x) of the Daubechies class DN, where N = 2, 4, ..., 20. The computation uses the scaling function Nφ(x).
Parameters:
`N` - the index of the Daubechies wavelet class D2 ... D20,
`x` - the value for which the wavelet value is computed
Returns:
the function value of the Daubechies wavelet Nψ(x)
`phi(int,double)`
• #### transform

```public static double[][] transform(int N,
double[] a)```
Computes the fast Daubechies wavelet transform of a data vector, applying the Daubechies D-N wavelet; the returned two-dimensional array contains the wavelet coefficients in its [0]-component, and the scaling function coefficient in its [1]-component; N has to be an even number with 2 ≤ N ≤ 20. If the number of data points is not a power of 2, the data are augmented to the next power n of two and filled up with zeros.

The principle of the Daubechies wavelet transform is as follows. Initially, the data points a[0], ..., a[2n - 1] are identified as the coefficients of the Daubechies scaling function (or "father wavelet"). They determine recursively the wavelet coefficients c[k] according to the scheme

c0[k] =
 null
a0[k] =
 a[0] a[1] ... a[2n - 1]

c1[k] =
 c1[0] c1[1] ... c1[2n-1 - 1]
a1[k] =
 a1[0] a1[1] ... a1[2n-1 - 1]

c2[k] =
 c2[0] ... c2[2n-2 - 1]
 c1[0] c1[1] ... c1[2n-1 - 1]
a2[k] =
 a2[0] ... a2[2n-2 - 1]

. . .

cn[k] =
 cn[0]
 cn-1[0] cn-1[1]
. . .    c2[0] ... c2[2n-2 - 1]
 c1[0] c1[1] ... c1[2n-1 - 1]
an[k] =
 an[0]
Hence there are 20 + 21 + ... + 2n-2 + 2n-1 = 2n-1 wavelet coefficients c[k], and a single scaling function coefficient a[0] returned. The coefficient a[0] is necessary to reconstruct the data completely. See http://haegar.fh-swf.de/Publikationen/Wavelets.pdf for details.
Parameters:
`N` - the index of the applied Daubechie wavelet (N = 2, 4, ..., 20)
`a` - the data to be transformed
Returns:
a two-dimensional array containing the wavelet coefficients in its [0]-component, and the scaling function coefficient in its [1]-component
`inverseTransform(int,double[][])`
• #### inverseTransform

```public static double[] inverseTransform(int N,
double[][] w)```
Computes the inverse fast Daubechies wavelet transform of a two-dimensional array `w` containing a vector `w[0]` of the Daubechies D-N wavelet coefficients, and an array `w[1]` containing the scaling function coefficient. There are the following three mandatory restrictions for the parameters, due to the wavelet transform algorithm as performed by `transform` method:
• N must an even number with 2 ≤ N ≤ 20.
• The number `w[0].length` of wavelet coefficients must satisfy `w[0].length` = 2n-1 for an integer n.
• The number `w[1].length` of scaling function coefficients must be 1.
Parameters:
`N` - the index of the applied Daubechie wavelet (N = 2, 4, ..., 20)
`w` - the wavelet coefficients `w[0]` and scaling function coefficients `w[1]` to be transformed
Returns:
a one-dimensional array of the transformed data (more exactly, the scaling function coefficients)
`transform(int,double[])`
• #### checkH

`public static String checkH()`
This routine checks the conditions the Daubechies coefficients have to satisfy. These are, for each wavelet D2N (N = 1, ..., 10):
```    - sumEven = sum_k^{N-1} h_{2k} = 1/sqrt(2);
- sumOdd  = sum_k^{N-1} h_{2k+1} = 1/sqrt(2);
- For each integer m = 0, 1, ..., N-1:
sum_{k=2m}^{2N-1+2m} h_{k} h_{k-2m}
= 1 if m=0,
= 0 otherwise.
```
See http://math-it.org/Publikationen/Wavelets.pdf for details.
Returns:
a message about the relevant data
• #### showWaveletCoefficients

`public static String showWaveletCoefficients(double[][] w)`
Returns a structured string representation of the wavelet coefficients given by the array w.
Parameters:
`w` - array of wavelet coefficients
Returns:
a structured string representation of w
• #### showDaubCoefficients

`public static String showDaubCoefficients(String format)`
Returns a structured string representation of the normalized Daubechies filter coefficients `h`, in the specified format. The format can be one of the following string values:
• `"LaTeX"` for LaTeX format
• `"Mathematica"` for Mathematica input format
• `"Java (rescaled)"` for a Java formatted output of the filter coefficients times `√2`
Parameters:
`format` - format of the string to be returned. E.g., "LaTeX", "Mathematica", or "Java (rescaled)"
Returns:
a structured string representation of w