Wavelets are mathematical functions that you can use to transform signals, images, and videos before compressing them. One of the simplest wavelet functions is the Hear transform. It recursively uses averages and differences to process a signal using the following formulas:
signal Average =(a+b)/2, where a and b are two adjacent signal values or pixels
details Part=b-a
For example, let’s apply the Haar transform to the one-dimensional array of original signal values shown in Figure 14-10a. We first process the entire array, comparing each pair of entries and finding the averages and differences. Figure 14-10b shows the half-resolution signals as a result of these calculations. Note that you can store the averages and differences directly into the original array, or you can use a temporary array which you then copy to the original array.
Figure 14-10
We recursively repeat the process on pairs of the averages to get new averages and differences, resulting in quarter-resolution signals and eighth-resolution signals as given in Figures 14-10c and 14-10d. In Figure 14-10d of this figure, notice that we have one average. This is the base case of the =(a + b ) /2, =b−arecursion. At this point, we rebuild the array as follows. The final average is the first entry in the array. Then, beginning with the lowest resolution level (one-eighth in this case), we append the difference values to the array. Our transformed signal is shown in Figure 14-10e. We could compress this result by setting the values below a certain threshold to zero.
Implement the Haar transform for a one-dimensional signal, such an AIFF audio file.