package library.wavelets.lift;_x000D_
_x000D_
/**_x000D_
 <p>_x000D_
 Haar (flat line) wavelet._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 As with all Lifting scheme wavelet transform functions, the_x000D_
 first stage of a transform step is the split stage.  The_x000D_
 split step moves the even element to the first half of an_x000D_
 N element region and the odd elements to the second half of the N_x000D_
 element region._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 The Lifting Scheme version of the Haar transform uses a wavelet_x000D_
 function (predict stage) that "predicts" that an odd element will_x000D_
 have the same value as it preceeding even element.  Stated another_x000D_
 way, the odd element is "predicted" to be on a flat (zero slope_x000D_
 line) shared with the even point.  The difference between this_x000D_
 "prediction" and the actual odd value replaces the odd element._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 The wavelet scaling function (a.k.a. smoothing function) used_x000D_
 in the update stage calculates the average between an even and_x000D_
 an odd element._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 The merge stage at the end of the inverse transform interleaves_x000D_
 odd and even elements from the two halves of the array_x000D_
 (e.g., ordering them even<sub>0</sub>, odd<sub>0</sub>,_x000D_
 even<sub>1</sub>, odd<sub>1</sub>, ...)_x000D_
 </p>_x000D_
_x000D_
 <h4>_x000D_
 Copyright and Use_x000D_
 </h4>_x000D_
_x000D_
 <p>_x000D_
 You may use this source code without limitation and without_x000D_
 fee as long as you include:_x000D_
 </p>_x000D_
 <blockquote>_x000D_
 This software was written and is copyrighted by Ian Kaplan, Bear_x000D_
 Products International, www.bearcave.com, 2001._x000D_
 </blockquote>_x000D_
 <p>_x000D_
 This software is provided "as is", without any warrenty or_x000D_
 claim as to its usefulness.  Anyone who uses this source code_x000D_
 uses it at their own risk.  Nor is any support provided by_x000D_
 Ian Kaplan and Bear Products International._x000D_
 <p>_x000D_
 Please send any bug fixes or suggested source changes to:_x000D_
 <pre>_x000D_
 iank@bearcave.com_x000D_
 </pre>_x000D_
_x000D_
 @author Ian Kaplan_x000D_
_x000D_
 */_x000D_
public class Haar extends Liftbase {_x000D_
_x000D_
  /**_x000D_
   Haar predict step_x000D_
   */_x000D_
  protected void predict(double[] vec, int N, int direction) {_x000D_
    int half = N >> 1;_x000D_
_x000D_
    for (int i = 0; i < half; i++) {_x000D_
      double predictVal = vec[i];_x000D_
      int j = i + half;_x000D_
_x000D_
      if (direction == forward) {_x000D_
        vec[j] = vec[j] - predictVal;_x000D_
      } else if (direction == inverse) {_x000D_
        vec[j] = vec[j] + predictVal;_x000D_
      } else {_x000D_
        System.out.println("haar::predict: bad direction value");_x000D_
      }_x000D_
    }_x000D_
  }_x000D_
_x000D_
  /**_x000D_
   <p>_x000D_
   Update step of the Haar wavelet transform._x000D_
   </p>_x000D_
   <p>_x000D_
   The wavelet transform calculates a set of detail or_x000D_
   difference coefficients in the predict step.  These_x000D_
   are stored in the upper half of the array.  The update step_x000D_
   calculates an average from the even-odd element pairs._x000D_
   The averages will replace the even elements in the _x000D_
   lower half of the array._x000D_
   </p>_x000D_
   <p>_x000D_
   The Haar wavelet calculation used in the Lifting Scheme_x000D_
   is_x000D_
   </p>_x000D_
   <pre>_x000D_
   d<sub>j+1, i</sub> = odd<sub>j+1, i</sub> = odd<sub>j, i</sub> - even<sub>j, i</sub>_x000D_
   a<sub>j+1, i</sub> = even<sub>j, i</sub> = (even<sub>j, i</sub> + odd<sub>j, i</sub>)/2_x000D_
   </pre>_x000D_
   <p>_x000D_
   Note that the Lifting Scheme uses an in-place algorithm.  The odd_x000D_
   elements have been replaced by the detail coefficients in the_x000D_
   predict step.  With a little algebra we can substitute the_x000D_
   coefficient calculation into the average calculation, which_x000D_
   gives us_x000D_
   </p>_x000D_
   <pre>_x000D_
   a<sub>j+1, i</sub> = even<sub>j, i</sub> = even<sub>j, i</sub> + (odd<sub>j, i</sub>/2)_x000D_
   </pre>_x000D_
   */_x000D_
  protected void update(double[] vec, int N, int direction) {_x000D_
    int half = N >> 1;_x000D_
_x000D_
    for (int i = 0; i < half; i++) {_x000D_
      int j = i + half;_x000D_
      double updateVal = vec[j] / 2.0;_x000D_
_x000D_
      if (direction == forward) {_x000D_
        vec[i] = vec[i] + updateVal;_x000D_
      } else if (direction == inverse) {_x000D_
        vec[i] = vec[i] - updateVal;_x000D_
      } else {_x000D_
        System.out.println("update: bad direction value");_x000D_
      }_x000D_
    }_x000D_
  }_x000D_
_x000D_
} // haar_x000D_

/**_x000D_
   Haar predict step_x000D_
   */
package library.wavelets.lift;_x000D_
_x000D_
/**_x000D_
 <p>_x000D_
 Haar (flat line) wavelet._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 As with all Lifting scheme wavelet transform functions, the_x000D_
 first stage of a transform step is the split stage.  The_x000D_
 split step moves the even element to the first half of an_x000D_
 N element region and the odd elements to the second half of the N_x000D_
 element region._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 The Lifting Scheme version of the Haar transform uses a wavelet_x000D_
 function (predict stage) that "predicts" that an odd element will_x000D_
 have the same value as it preceeding even element.  Stated another_x000D_
 way, the odd element is "predicted" to be on a flat (zero slope_x000D_
 line) shared with the even point.  The difference between this_x000D_
 "prediction" and the actual odd value replaces the odd element._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 The wavelet scaling function (a.k.a. smoothing function) used_x000D_
 in the update stage calculates the average between an even and_x000D_
 an odd element._x000D_
 </p>_x000D_
_x000D_
 <p>_x000D_
 The merge stage at the end of the inverse transform interleaves_x000D_
 odd and even elements from the two halves of the array_x000D_
 (e.g., ordering them even<sub>0</sub>, odd<sub>0</sub>,_x000D_
 even<sub>1</sub>, odd<sub>1</sub>, ...)_x000D_
 </p>_x000D_
_x000D_
 <h4>_x000D_
 Copyright and Use_x000D_
 </h4>_x000D_
_x000D_
 <p>_x000D_
 You may use this source code without limitation and without_x000D_
 fee as long as you include:_x000D_
 </p>_x000D_
 <blockquote>_x000D_
 This software was written and is copyrighted by Ian Kaplan, Bear_x000D_
 Products International, www.bearcave.com, 2001._x000D_
 </blockquote>_x000D_
 <p>_x000D_
 This software is provided "as is", without any warrenty or_x000D_
 claim as to its usefulness.  Anyone who uses this source code_x000D_
 uses it at their own risk.  Nor is any support provided by_x000D_
 Ian Kaplan and Bear Products International._x000D_
 <p>_x000D_
 Please send any bug fixes or suggested source changes to:_x000D_
 <pre>_x000D_
 iank@bearcave.com_x000D_
 </pre>_x000D_
_x000D_
 @author Ian Kaplan_x000D_
_x000D_
 */_x000D_
public class Haar extends Liftbase {_x000D_
_x000D_
  /**_x000D_
   Haar predict step_x000D_<SUF>*/_x000D_
  protected void predict(double[] vec, int N, int direction) {_x000D_
    int half = N >> 1;_x000D_
_x000D_
    for (int i = 0; i < half; i++) {_x000D_
      double predictVal = vec[i];_x000D_
      int j = i + half;_x000D_
_x000D_
      if (direction == forward) {_x000D_
        vec[j] = vec[j] - predictVal;_x000D_
      } else if (direction == inverse) {_x000D_
        vec[j] = vec[j] + predictVal;_x000D_
      } else {_x000D_
        System.out.println("haar::predict: bad direction value");_x000D_
      }_x000D_
    }_x000D_
  }_x000D_
_x000D_
  /**_x000D_
   <p>_x000D_
   Update step of the Haar wavelet transform._x000D_
   </p>_x000D_
   <p>_x000D_
   The wavelet transform calculates a set of detail or_x000D_
   difference coefficients in the predict step.  These_x000D_
   are stored in the upper half of the array.  The update step_x000D_
   calculates an average from the even-odd element pairs._x000D_
   The averages will replace the even elements in the _x000D_
   lower half of the array._x000D_
   </p>_x000D_
   <p>_x000D_
   The Haar wavelet calculation used in the Lifting Scheme_x000D_
   is_x000D_
   </p>_x000D_
   <pre>_x000D_
   d<sub>j+1, i</sub> = odd<sub>j+1, i</sub> = odd<sub>j, i</sub> - even<sub>j, i</sub>_x000D_
   a<sub>j+1, i</sub> = even<sub>j, i</sub> = (even<sub>j, i</sub> + odd<sub>j, i</sub>)/2_x000D_
   </pre>_x000D_
   <p>_x000D_
   Note that the Lifting Scheme uses an in-place algorithm.  The odd_x000D_
   elements have been replaced by the detail coefficients in the_x000D_
   predict step.  With a little algebra we can substitute the_x000D_
   coefficient calculation into the average calculation, which_x000D_
   gives us_x000D_
   </p>_x000D_
   <pre>_x000D_
   a<sub>j+1, i</sub> = even<sub>j, i</sub> = even<sub>j, i</sub> + (odd<sub>j, i</sub>/2)_x000D_
   </pre>_x000D_
   */_x000D_
  protected void update(double[] vec, int N, int direction) {_x000D_
    int half = N >> 1;_x000D_
_x000D_
    for (int i = 0; i < half; i++) {_x000D_
      int j = i + half;_x000D_
      double updateVal = vec[j] / 2.0;_x000D_
_x000D_
      if (direction == forward) {_x000D_
        vec[i] = vec[i] + updateVal;_x000D_
      } else if (direction == inverse) {_x000D_
        vec[i] = vec[i] - updateVal;_x000D_
      } else {_x000D_
        System.out.println("update: bad direction value");_x000D_
      }_x000D_
    }_x000D_
  }_x000D_
_x000D_
} // haar_x000D_
