CDI15 6. Haar wavelets (1D) 1027, 1104, 1110 414, 416, 428 SXD Notations 6.1. The Haar transforms 6.2. Haar wavelets 6.3. Multiresolution analysis 6.4. Compression/decompression James S. Walker A primer on wavelets and their scientific application Chapman and Hall, 1999
2 Notations Discrete signal (of length NN): ff = (ff 0, ff 1,, ff NN 1 ) R NN. The choice of indexing, starting with 0, is not the usual convention in mathematics texts, but we adopt it as it facilities the relation with computations. Usually ff is a sample of a function (or continuous signal) φφ = φφ(tt): ff jj = φφ(tt jj ), tt 0 < tt 1 < < tt NN 1. If not said otherwise, the tt jj are assumed to be equally spaced: tt jj = tt 0 + jjjj, δδ > 0 a constant (sampling spacing). tt 0 tt 1 tt 2 tt 3 tt NN 1 δδ Energy. The norm squared, tt 0 + 3δδ ff 2 = ff 2 0 + ff 2 2 1 + + ff NN 1, is also called the energy of the signal. Alternative notation: E(ff).
3 Trend and fluctuation signals The (first) trend signal aa 1 (ff) is defined by the formula aa 1 (ff) = (aa 0, aa 1,, aa NN/2 1 ), aa jj = (ff 2jj + ff 2jj+1 )/ 2 The (first) fluctuation or difference signal dd 1 (ff) is defined by dd 1 (ff) = (dd 0, dd 1,, dd NN/2 1 ), dd jj = (ff 2jj ff 2jj+1 )/ 2
4 6. 1. The Haar transforms The first level Haar transform of ff is the signal defined by HH 1 (ff) = aa 1 (ff) dd 1 (ff). Remark (small fluctuations). If ff is a sampling of φφ, with a small sampling increment δδ, then ff 2jj+1 ff 2jj δδ OO(δδ) ff 2jj+1 ff 2jj + φφ tt 2jj δδ, and hence dd jj = OO(δδ). On the other hand, up to OO(δδ), aa jj 2ff 2jj 2ff 2jj+1. In other words, the components of dd 1 (ff) are small and the signal aa 1 (ff) is like ff at even (or odd) times, scaled by 2.
5 Proposition (inverse of the Haar transform). It is the map given by aa 0, aa 1,, aa NN 2 1, dd 0, dd 1,, dd NN 2 1 (ff 0, ff 1,, ff NN 1 ), where ff 2jj = aa jj+dd jj 2, ff 2jj+1 = aa jj dd jj, jj = 0,, NN/2 1. 2 Example: Sampling φφ(xx) = 20xx 2 (1 xx) 4 cos(12ππππ), NN = 2 10, and its Haar transform. Left: φφ sampled at NN points. Right: Haar transform of the left sample.
6 Proposition. EE(ff) = EE(HH 1 (ff)). Proof: A short computation. N1 In the example, EE(ff) = EE HH 1 (ff) = 31.83, while EE aa 1 (ff) = 31.82 and EE dd 1 (ff) = 0.01. Remark (compaction of energy). E(ff) = E aa 1 (ff) + E(dd 1 (ff)) and E(dd 1 (ff)) tends to be small (see Remark on small fluctuations), in which case E aa 1 (ff) amounts to a large percentage of E(ff). The Haar transform of level rr, HH rr (ff), requires that NN is divisible by 2 rr and is defined recursively by HH rr (ff) = aa rr (ff) dd rr (ff) dd rr 1 (ff) dd 1 (ff), where aa rr (ff) = aa 1 aa rr 11 (ff) aa rr 0, aa rr rr 1,, aa NN/2 rr 1, aa rr jj = aa 2jj rr 1 rr 1 +aa 2jj+1 dd rr (ff) = dd 1 aa rr 11 (ff) dd rr 0, dd rr rr 1,, dd NN/2 rr 1, dd rr jj = aa 2jj rr 1 aa 2jj+1. So HH rr (ff) = HH rr 1 aa 1 (ff) dd 1 (ff). N2 2 2 rr 1
Examples: 2-level and 3-level Haar transforms of a sample of the function defined on page 5. 7
8 6. 2. Haar Wavelets Let vv 0 0 = (1,0,,0), vv 0 0 1 = (0,1,,0),, vv NN 1 = (0,0,,0,1), which are called the 0-level scaling signals. Hence ff = ff 0 vv 0 0 + ff 1 vv 0 0 1 + + ff NN 1 vv NN 1, and ff jj = ff vv jj 0. 1 vv jj 0 Introduce now what are called 1-level Haar scaling signals vv 1 jj = 1 (vv 2 2jj 0 0 + vv 2jj+1 ), jj = 0,, NN/2 1, and the 1-level Haar wavelets ww 1 jj = 1 (vv 2 2jj 0 0 vv 2jj+1 ), jj = 0,, NN/2 1. Proposition. aa jj = ff vv jj 1, dd jj = ff ww jj 1. 1 jj 1 vv jj 2jj 2jj + 2 2jj + 1
9 Remark. {vv 1 1, vv 1 1 2,, vv NN 2 } and ww 1 1, ww 1 1 2,, ww NN 2 are orthonormal systems that are orthogonal to each other: vv jj1 ww 1 kk = 0 for all jj, kk. Assuming that NN is divisible by 2 rr, rr 2, then the rr-level Haar scaling functions and wavelets are defined as vv rr jj = 1 (vv 2 2jj rr 1 + vv rr 1 2jj+1 ), jj = 0,, NN/2 rr 1, ww rr jj = 1 (vv 2 2jj rr 1 vv rr 1 2jj+1 ), jj = 0,, NN/2 rr 1. Proposition. We have the following formulas: aa jj rr = ff vv jj rr, dd jj rr = ff ww jj rr, jj = 0, 1,, NN/2 rr 1. Proof: Indeed, for the case rr = 1, see the Proposition on page 7. For rr > 1, aa rr jj = 1 aa 22 2jj rr 1 + aa rr 1 2jj+1 = 1 ff 22 vv 2jj rr 1 + ff vv rr 1 2jj+1 = ff vv rr jj, and dd rr jj = 1 aa 22 2jj rr 1 aa rr 1 2jj+1 = 1 ff 22 vv 2jj rr 1 ff vv rr 1 2jj+1 = ff ww rr jj.
10 Proposition. The vectors vv jj rr, jj NN rr = {0,, NN/2 rr 1}, can be computed directly from the vv kk 0 as follows. If JJ is a subset of NN rr, let Then vv JJ 0 = vv jj 0 jj JJ (1 s in the positions JJ, 0 otherwise). vv rr jj = 2 rr 2 0 vv [2 rr jj,2 rr (jj+1)) (2 rr 1 s starting at 2 rr jj, scaled by 2 rr 2 ). In a similar way we have, for jj {1,, NN/2 rr 1}, ww rr jj = 2 rr 2 0 (vv [2 rr jj, 2 rr jj+2 rr 1 1) 0 vv [2 rr jj+2 rr 1, 2 rr (jj+1))) (2 rr 1 1 s starting at 2 rr jj followed by 2 rr 1 ( 1) s, all scaled by 2 rr 2 ) In particular it follows that aa rr jj = 2 rr 2 (ff 2 rr jj + ff 2 rr jj+1 + + ff 2 rr jj+2 rr 1) dd rr jj = 2 rr 2 ff 2 rr jj + + ff 2 rr jj+2 rr 1 2 1 2 rr ff 2 rr jj+2 rr 1 + + ff 2 rr jj+2 rr 1)
11 Examples of scaling and wavelet vectors: vv jj 0 vv kk 1 vv ll 2 ww jj 1 ww kk 2
12 Notations. R NN = vv 0 00, vv 0 0 1,, vv NN 1 will be denoted VV 0 and we set, for any rr such that NN is divisible by 2 rr, VV rr = vv rr 0, vv rr rr 1,, vv NN/2 rr 1, WW rr = ww rr 0, ww rr rr 1,, ww NN/2 rr 1 Clearly dim VV rr = dim WW rr = NN/2 rr. Furthermore, VV 0 VV 1 VV rr and VV rr 1 = VV rr WW rr. The inclusion of VV rr and WW rr in VV rr 1, and the fact that VV rr and WW rr are orthogonal, are direct consequences of the defining relations, namely vv rr jj = 1 (vv 2 2jj rr 1 + vv rr 1 2jj+1 ), ww rr jj = 1 (vv 2 2jj rr 1 vv rr 1 2jj+1 ). These expressions also show that vv rr rr 0,, vv NN/2 rr 1, ww rr rr 0,, ww NN/2 rr 1 basis of VV rr, for we also have vv 2jj rr 1 = 1 2 vv jj rr + ww jj rr, vv 2jj+1 rr 1 = 1 2 vv jj rr ww jj rr. form a
13 6. 3. Multiresolution analysis First average and detail signals: AA 1 (ff) = 1 aa 2 0, aa 0, aa 1, aa 1,, aa NN 2 1, aa NN/2 1 = aa 0 vv 1 0 + aa 1 vv 1 1 1 + + aa NN/2 1 vv NN/2 1 = (ff vv 1 0 )vv 1 0 + (ff vv 1 1 )vv 1 1 1 1 + + ff vv NN/2 1 vv NN/2 1 = Π VV 1(ff). N3 DD 1 (ff) = 1 dd 2 0, dd 0, dd 1, dd 1,, dd NN 2 1, dd NN/2 1 = dd 0 ww 1 0 + dd 1 ww 1 1 1 + + dd NN/2 1 ww NN/2 1 = (ff ww 1 0 )ww 1 0 + (ff ww 1 1 )ww 1 1 1 1 + + ff ww NN/2 1 ww NN/2 1 = Π WW 1(ff).
14 Proposition. ff = AA 1 (ff) + DD 1 (ff) Proof : Simple calculation. For example (see Remark on the Haar inverse), 1 2 (aa 0 + dd 0 ) = 1 2 (ff 0 + ff 1 + ff 0 ff 1 ) = ff 0 and 1 2 (aa 0 dd 0 ) = 1 2 (ff 0 + ff 1 ff 0 + ff 1 ) = ff 1. In general, we define (while NN is divisible by 2 rr ) the rr-th average and detail signals by AA rr (ff) = Π VV rr(ff) = (ff vv rr 0 )vv rr 0 + (ff vv rr 1 )vv rr rr rr 1 + + ff vv NN/2 rr 1 vv NN/2 rr 1 = aa rr 0 vv rr 0 + aa rr 1 vv rr rr 1 + + aa NN/2 rr 1 DD rr (ff) = Π WW rr(ff) rr vv NN/2 rr 1, = (ff ww rr 0 )ww rr 0 + (ff ww rr 1 )ww rr rr rr 1 + + ff ww NN/2 rr 1 ww NN/2 rr 1 = dd rr 0 ww rr 0 + dd rr 1 ww rr rr 1 + + dd NN/2 rr 1 rr ww NN/2 rr 1.
15 Proposition (Multiresolution of ff) ff = AA rr (ff) + DD rr (ff) + DD rr 1 (ff) + + DD 2 (ff) + DD 1 (ff). Proof: It is enough to show that AA rr (ff) + DD rr (ff) = AA rr 1 (ff), for then the expression results by induction. But this follows from the definitions and the facts established so far: Computations AA rr (ff) + DD rr (ff) = Π VV rr(ff) + Π WW rr(ff) = Π VV rr 1(ff) (because VV rr 1 = VV rr WW rr ) N4 = AA rr 1 (ff). AA rr (ff) and DD rr (ff) are computed by the functions high_filter(f,r), low_filter(f,r).
16 The image on the left of next page shows the graphs of AA 10 (ff) and DD jj (ff), jj = 1,,10, where ff is the signal of the Example on page 5. By what we have seen so far, the sum of these signals, AA 10 + jj=10 jj=1 DD jj, agrees with ff. That high_filter(f,r) and low_filter(f,r) compute AA rr (ff) and DD rr (ff) is a straightforward observation based on the definitions and the actual coding of these functions. On the right of next page we include images of the AA rr (ff), for rr = 1,,9.
17 AA 10 DD 10 DD 9 DD 8 AA 9 AA 4 DD 7 AA 8 AA 3 DD 6 AA 7 AA 2 DD 5 AA 6 AA 1 DD 4 DD 3 DD 2 DD 1 AA 5 AA 0 = ff
18 6.4 Compression/decompression We can regard the level rr trend vector aa rr as a (lossy) compression of ff (the compression factor is 1/2 rr ) and the (iterative) function D4trend(f,r) provides and efficient means to compute it. The vector AA rr (ff) is then the decompression of aa rr and one way to compute it is to use the formula rr jj aa jj vv rr jj, which presupposes knowing the matrix VV[rr] of the level rr scaling vectors vv rr jj. Fast decompression. Provided by the formula on top of page 13, and its generalization to any level. We are going to see how this works in general (Haar and Daubechies wavelets) at the end of T7.
19 Notes N1 (p. 6). We have: aa 2 jj = ff 2jj + ff 2jj+1 2 2 2 = 1 2 ff 2jj 2 2 + ff 2jj+1 + 2ff 2jj ff 2jj+1, dd 2 jj = ff 2jj ff 2jj+1 = 1 2 2 (ff 2jj 2 2 + ff 2jj+1 2ff 2jj ff 2jj+1 ) and hence aa 2 jj + dd 2 jj = ff 2 2 2jj + ff 2jj+1. Summing for jj = 0,, NN/2 1, the left hand side yields E(HH 1 (ff)) and the right hand side E(ff). N2 (p. 6). HH rr also preserves energy: E HH rr (ff) = E(ff). This follows immediately from the recursion definition: from E HH rr (ff) = E(HH rr 1 (aa 1 (ff)) dd 1 (ff)) = E HH rr 1 (aa 1 (ff)) + E(dd 1 (ff)) and induction we get E HH rr (ff) = E(aa 1 (ff)) + E(dd 1 (ff)) = E(ff).
20 N3 (p. 13). If VV R NN is a linear subspace, and xx R NN, there is a unique vector xx xx xx VV such that xx xx is orthogonal to VV. This VV vector xx is called the orthogonal Π VV (xx) = xx projection of xx to VV and is denoted Π VV (xx). This vector can be calculated quite easily if we know an orthonormal basis uu 1,, uu kk of VV. Indeed, in this case we have xx = (xx uu 1 )uu 1 + + (xx uu kk )uu kk, for the right hand side clearly belongs to VV and xx xx is orthogonal to all the uu jj (for xx uu jj = xx uu jj because of the relations uu ii uu jj = δδ iiii that hold for an orthonormal system). The same argument can be adapted to show the uniqueness of xx. Remark. The computation of xx can also be carried out if we know any basis vv 1,, vv kk of VV. In this case it is enough to impose that a vector xx = tt 1 vv 1 + + tt kk vv kk VV xx
21 satisfies the conditions xx vv jj = xx vv jj for jj = 1,, kk. But these conditions are equivalent to the system of linear equations vv 1 vv jj tt 1 + + vv kk vv jj tt kk = xx vv jj, jj = 1,, kk in the unknowns tt 1,, tt kk. The solution of this system, which is unique, gives then the orthogonal projection of xx to VV. N4 (p. 15). In general, if VV and WW are linear subspaces of RR nn, and VV WW, then Π VV+WW (ff) = Π VV (ff) + Π WW (ff). Indeed, the relations ff Π VV (ff) + Π WW (ff) = ff Π VV (ff) Π WW (ff) = ff Π WW (ff) Π VV (ff) show that the left-hand side is orthogonal to VV (because ff Π VV (ff) and Π WW (ff) are orthogonal to VV) and orthogonal to WW (similar reason). Therefore it is orthogonal to VV + WW and hence Π VV (ff) + Π WW (ff) is the orthogonal projection of ff on VV + WW.