## Haar Transform Demo Applets

The two applets on this page were written for Math 371, Spring 2006. Clicking on either of the applet buttons will launch a program in a separate window. To use these programs, your screen should be at least 1024 pixels wide (and even at 1024 pixels, the windows will not quite fit across the screen). The applets require Java 1.4 or higher. If you do not have Java installed properly on your computer, you might not even see any buttons on this page.

### Haar Wavelet Demo

To launch a demo of the Haar Wavelet Transform for finite, discrete signals, click the following button:

Instructions: The button will open a window that has two large white areas representing a portion of the xy-plane. In the left area, an input signal is graphed. The input signal is just a finite list of numbers (s1,s2,...sN), where N is a power of two. The signal values are graphed as points at x-values 1, 2, 3, ..., N. When the window first appears, N is 128, but you can change the number of points using a pop-up menu at the bottom of the screen.

The signal values are the y-values of the points. Initially, all the signal values are zero. You can change the signal values by dragging the points of the input signal up and down. If you drag with the left mouse button, nearby points will be pulled along by the point that you drag. If you drag a point with the right mouse button, only the one point that you drag will move. You can also set the y-values from a function of the variable n, where n takes on the values 1, 2, ..., N for the different points of the signal. Enter the function in the box at the bottom of the window and press return (or click the "Set") button. The definition of the function can use the operators +, -, *, /, and ^ (the latter representing exponentiation). It can include trigonometric, exponential, and logarithmic functions as well as abs (for absolute value) and trunc (for truncating a real number to an integer value). The definition of the function can also use the variable x. For input number n, the value of x is defined to be n/N (where N is the number of points. Thus, the value of x ranges from 1/N for the first signal value to 1 for the last signal value.

The point of the applet is to show the effect of the Haar Transform on the input signal. The applet can show several different outputs for a given signal. You can select the output that you want to see using a pop-up menu at the bottom of the window. If the number of points in the input signal is 2n, there are actually n different transforms, called the 1-level, 2-level, 3-level, ..., n-level transforms. You'll find all of these in the "Output" pop-up menu. There is also another set of possible outputs in the menu: Level 0 Reconstruction, Level 1 Reconstruction, ..., Level n Reconstruction. These reconstructions start with the n-level Haar Transform. The Level 0 Reconstruction is a constant signal whose value is the same as the average value of the input function; this average is obtained from the final "trend" value in the n-level Haar Transform. The Level 1 Reconstruction adds in information from the n-th order difference in the n-level Haar Transform. The Level 2 Reconstruction adds in information from the two (n-1)-th order differences. And so on. The final Level n Reconstruction has added in all the differences from the n-level Haar Transform, and so is equal to the original signal. (The Level n Reconstruction is what you get when you apply the inverse n-level Haar Transform to the transform of the input signal -- the result is that you get the original input signal back.) Another way of looking at this is to say that as you go from one reconstruction to the next, you are adding in information about the input signal at finer and finer scales.

Note that the display areas are initially set up to show a range of y-values between -5.0 and 5.0. However, this range will automatically be expanded if necessary to make sure that all the signal values are visible.

Homework #2 from Math 371 (hw2.pdf) has some exercises based on this program.

### Haar Wavelet Signal Compression Demo

To launch a demo of using the Haar Wavelet Transform for signal compression/decompression, click the following button:

Instructions: The button will open a window that is similar to the Haar Wavelet Demo described above, but in this case, the purpose is to help you understand how the Haar transform can be used to "compress" and decompress a signal. The idea is that some of the numbers in the Haar Transform of a signal are thrown away (that is, set equal to zero). Because of the missing information, when you apply the inverse Haar Transform to the modified signal, you don't get an exact reconstruction of the original input signal; you get an approximation. ("Compression" means that you have less data to store or transmit, because you only have to save the non-zero values. This is "lossy" compression because you have lost some of the information and only get an approximation when you decompress the signal.)

The slider at the bottom-center of the window controls how many elements of the n-level Haar Transform are discarded. Initially, the number is zero, so there is no compression at all. Drag the slider to the right to discard more data from the transform.

In this program, the display area on the right always shows the full n-level Haar Transform of the input signal. The values that have been discarded are shown in pink. As you drag the slider to the right, you'll see that more and more points turn pink. Note that values are discarded in order of increasing absolute value.

The display area on the left actually shows two things (although initially only one of them is visible). In this area, the input signal is first drawn in blue. Then the "decompressed" signal is drawn in red. The decompressed signal is obtained by starting with the n-level Haar Transform of the input signal, "compressing" by setting the specified number of values in the transform to zero, then applying the inverse n-level Haar Transform to the modified transform. The result is an approximation of the input signal. The more points that are discarded, the worse the approximation.

When no points are discarded, the decompressed signal is equal to the original, so all you see are the red points that represent the decompressed signal; the blue points of the input signal are hidden behind them. As you discard more and more points, the decompressed signal generally becomes a poorer approximation of the input, and the blue points of the input signal start to appear as the red points of the decompressed signal move out of alignment. If you discard all the points from the transform, of course, the "decompressed signal" will be equal to zero.

As with the first applet on this page, you can change the input signal by dragging points in the left-hand display area or by entering a function in the function input box.

David Eck, 31 January 2006