wavelets
Class simple_haar

java.lang.Object
  |
  +--wavelets.wavelet_base
        |
        +--wavelets.simple_haar

public class simple_haar
extends wavelet_base

Class simple_haar

This object calcalculates the "ordered fast Haar wavelet transform". The algorithm used is the a simple Haar wavelet algorithm that does not calculate the wavelet transform in-place. The function works on Java double values.

The wavelet_calc function is passed an array of doubles from which it calculates the Haar wavelet transform. The transform is not calculated in place. The result consists of a single value and a Vector of coefficients arrays, ordered by increasing frequency. The number of data points in the data used to calculate the wavelet must be a power of two.

The Haar wavelet transform is based on calculating the Haar step function and the Haar wavelet from two adjacent values. For an array of values S0, S1, S2 .. Sn, the step function and wavelet are calculated as follows for two adjacent points, S0 and S1:

HaarStep = (S0 + S1)/2  // average of S0 and S1
HaarWave = (S0 - S1)/2  // average difference of S0 and S1

This yields two vectors: a, which contains the HaarStep values and c, which contains the HaarWave values.

The result of the wavelet_calc is the single Haar value and a set of coefficients. There will be ceil( log2( values.length() )) coefficients.

See Also:
Wavelets Made Easy by Yves Nieverglt, Birkhauser, 1999

Copyright and Use

You may use this source code without limitation and without fee as long as you include:

This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2001.

This software is provided "as is", without any warrenty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.

Please send any bug fixes or suggested source changes to:

iank@bearcave.com

Field Summary
private  java.util.Vector coef
           
private  double[] data
           
private  double haar_value
           
 
Constructor Summary
simple_haar()
           
 
Method Summary
private  double haar_calc(double[] values)
          Recursively calculate the Haar transform.
 void inverse()
           Calculate the inverse haar transform from the coefficients and the Haar value.
 void pr_values()
           Print the data values.
 void pr()
          Print the simple Haar object (e.g, the final Haar step value and the coefficients.
private  void reverseCoef()
          The Haar transform coefficients are generated from the longest coefficient vector (highest frequency) to the shortest (lowest frequency).
 void wavelet_calc(double[] values)
           Calculate the Haar wavelet transform (the ordered fast Haar wavelet tranform).
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

haar_value

private double haar_value

coef

private java.util.Vector coef

data

private double[] data
Constructor Detail

simple_haar

public simple_haar()
Method Detail

wavelet_calc

public void wavelet_calc(double[] values)

Calculate the Haar wavelet transform (the ordered fast Haar wavelet tranform). This calculation is not done in place.

Overrides:
wavelet_calc in class wavelet_base
Parameters:
values - a values: an array of double values on which the Haar transform is applied.

reverseCoef

private void reverseCoef()
The Haar transform coefficients are generated from the longest coefficient vector (highest frequency) to the shortest (lowest frequency). However, the reverse Haar transform and the display of the values uses the coefficients from the lowest to the highest frequency. This function reverses the coefficient order, so they will be ordered from lowest to highest frequency.

haar_calc

private double haar_calc(double[] values)
Recursively calculate the Haar transform. The result of the Haar transform is a single integer value and a Vector of coefficients. The coefficients are calculated from the highest to the lowest frequency.

The number of elements in values must be a power of two.


inverse

public void inverse()

Calculate the inverse haar transform from the coefficients and the Haar value.

The inverse function will overwrite the original data that was used to calculate the Haar transform. Since this data is initialized by the caller, the caller should make a copy if the data should not be overwritten.

The coefficients are stored in in a Java Vector container. The length of the coefficient arrays is ordered in powers of two (e.g., 1, 2, 4, 8...). The inverse Haar function is calculated using a butterfly pattern to write into the data array. An initial step writes the Haar value into data[0]. In the case of the example below this would be

data[0] = 5.0;

Then a butterfly pattern is shown below. Arrays indices start at 0, so in this example c[1,1] is the second element of the second coefficient vector.

wavelet:
{[5.0];
-3.0;
0.0, -1.0;
1.0, -2.0, 1.0, 0.0}

tmp = d[0];
d[0] = tmp + c[0, 0]
d[4] = tmp - c[0, 0]

tmp = d[0];
d[0] = tmp + c[1, 0]
d[2] = tmp - c[1, 0]
tmp = d[4];
d[4] = tmp + c[1, 1]
d[6] = tmp - c[1, 1]

tmp = d[0];
d[0] = tmp + c[2, 0]
d[1] = tmp - c[2, 0]
tmp = d[2];
d[2] = tmp + c[2, 1]
d[3] = tmp - c[2, 1]
tmp = d[4];
d[4] = tmp + c[2, 2]
d[5] = tmp - c[2, 2]
tmp = d[6];
d[6] = tmp + c[2, 3]
d[7] = tmp - c[2, 3]
Overrides:
inverse in class wavelet_base

pr

public void pr()
Print the simple Haar object (e.g, the final Haar step value and the coefficients.
Overrides:
pr in class wavelet_base

pr_values

public void pr_values()

Print the data values.

The pr() method prints the coefficients in increasing frequency. This function prints the data values which were used to generate the Haar transform.