#include <line.h>
Inheritance diagram for line::
Protected Methods  
void  predict (T &vec, int N, transDirection direction) 
Predict phase of line Lifting Scheme wavelet. More...  
void  update (T &vec, int N, transDirection direction) 
Update step of the linear interpolation wavelet. More...  
Private Methods  
double  new_y (double y1, double y2) 
Calculate an extra "even" value for the line wavelet algorithm at the end of the data series. More... 
The wavelet Lifting Scheme "line" wavelet approximates the data set using a line with with slope (in contrast to the Haar wavelet where a line has zero slope is used to approximate the data).
The predict stage of the line wavelet "predicts" that an odd point will lie midway between its two neighboring even points. That is, that the odd point will lie on a line between the two adjacent even points. The difference between this "prediction" and the actual odd value replaces the odd element.
The update stage calculates the average of the odd and even element pairs, although the method is indirect, since the predict phase has over written the odd value.
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 warranty 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
Definition at line 54 of file line.h.

Calculate an extra "even" value for the line wavelet algorithm at the end of the data series. Here we pretend that the last two values in the data series are at the xaxis coordinates 0 and 1, respectively. We then need to calculate the yaxis value at the xaxis coordinate 2. This point lies on a line running through the points at 0 and 1. Given two points, x_{1}, y_{1} and x_{2}, y_{2}, where
x_{1} = 0 x_{2} = 1 calculate the point on the line at x_{3}, y_{3}, where
x_{3} = 2 The "twopoint equation" for a line given x_{1}, y_{1} and x_{2}, y_{2} is
. y_{2}  y_{1} (y  y_{1}) =  (x  x_{1}) . x_{2}  x_{1} Solving for y
. y_{2}  y_{1} y =  (x  x_{1}) + y_{1} . x_{2}  x_{1} Since x_{1} = 0 and x_{2} = 1
. y_{2}  y_{1} y =  (x  0) + y_{1} . 1  0 or
y = (y_{2}  y_{1})*x + y_{1} We're calculating the value at x_{3} = 2, so
y = 2*y_{2}  2*y_{1} + y_{1} or
y = 2*y_{2}  y_{1} Definition at line 125 of file line.h. Referenced by predict().
00126 { 00127 double y = 2 * y2  y1; 00128 return y; 00129 } 

Predict phase of line Lifting Scheme wavelet. The predict step attempts to "predict" the value of an odd element from the even elements. The difference between the prediction and the actual element is stored as a wavelet coefficient. The "predict" step takes place after the split step. The split step will move the odd elements (b_{j}) to the second half of the array, leaving the even elements (a_{i}) in the first half
a_{0}, a_{1}, a_{1}, a_{3}, b_{0}, b_{1}, b_{2}, b_{2}, The predict step of the line wavelet "predicts" that the odd element will be on a line between two even elements.
b_{j+1,i} = b_{j,i}  (a_{j,i} + a_{j,i+1})/2 Note that when we get to the end of the data series the odd element is the last element in the data series (remember, wavelet algorithms work on data series with 2^{n} elements). Here we "predict" that the odd element will be on a line that runs through the last two even elements. This can be calculated by assuming that the last two even elements are located at xaxis coordinates 0 and 1, respectively. The odd element will be at 2. The new_y() function is called to do this simple calculation. Reimplemented from liftbase. Definition at line 169 of file line.h. 00170 { 00171 int half = N >> 1; 00172 double predictVal; 00173 00174 for (int i = 0; i < half; i++) { 00175 int j = i + half; 00176 if (i < half1) { 00177 predictVal = (vec[i] + vec[i+1])/2; 00178 } 00179 else if (N == 2) { 00180 predictVal = vec[0]; 00181 } 00182 else { 00183 // calculate the last "odd" prediction 00184 double n_plus1 = new_y( vec[i1], vec[i] ); 00185 predictVal = (vec[i] + n_plus1)/2; 00186 } 00187 00188 if (direction == forward) { 00189 vec[j] = vec[j]  predictVal; 00190 } 00191 else if (direction == inverse) { 00192 vec[j] = vec[j] + predictVal; 00193 } 00194 else { 00195 printf("predictline::predict: bad direction value\n"); 00196 } 00197 } 00198 } // predict 

Update step of the linear interpolation wavelet. The predict phase works on the odd elements in the second half of the array. The update phase works on the even elements in the first half of the array. The update phase attempts to preserve the average. After the update phase is completed the average of the even elements should be approximately the same as the average of the input data set from the previous iteration. The result of the update phase becomes the input for the next iteration. In a Haar wavelet the average that replaces the even element is calculated as the average of the even element and its associated odd element (e.g., its odd neighbor before the split). This is not possible in the line wavelet since the odd element has been replaced by the difference between the odd element and the midpoint of its two even neighbors. As a result, the odd element cannot be recovered. The value that is added to the even element to preserve the average is calculated by the equation shown below. This equation is given in Wim Sweldens' journal articles and his tutorial (Building Your Own Wavelets at Home) and in Ripples in Mathematics. A somewhat more complete derivation of this equation is provided in Ripples in Mathematics by A. Jensen and A. la CourHarbo, Springer, 2001. The equation used to calculate the average is shown below for a given iteratin i. Note that the predict phase has already completed, so the odd values belong to iteration i+1.
even_{i+1,j} = even_{i,j} op (odd_{i+1,k1} + odd_{i+1,k})/4 There is an edge problem here, when i = 0 and k = N/2 (e.g., there is no k1 element). We assume that the odd_{i+1,k1} is the same as odd_{k}. So for the first element this becomes
(2 * odd_{k})/4 or
odd_{k}/2 Reimplemented from liftbase. Definition at line 253 of file line.h. 00254 { 00255 int half = N >> 1; 00256 00257 for (int i = 0; i < half; i++) { 00258 int j = i + half; 00259 double val; 00260 00261 if (i == 0) { 00262 val = vec[j]/2.0; 00263 } 00264 else { 00265 val = (vec[j1] + vec[j])/4.0; 00266 } 00267 if (direction == forward) { 00268 vec[i] = vec[i] + val; 00269 } 00270 else if (direction == inverse) { 00271 vec[i] = vec[i]  val; 00272 } 00273 else { 00274 printf("update: bad direction value\n"); 00275 } 00276 } // for 00277 } 