Wednesday, March 23, 2016

Comparing HWT with CDF(4, 4) in Removing Slow Variations from Signals: Programmatic Note 14 on Ripples in Mathematics




Problem
  
This is my programmatic note 14 on Ch. 04, p. 31-34, in "Ripples in Mathematics" by A. Jensen & A. la Cour-Harbo. These notes document my programmatic journey, sometimes easy, sometimes painful, but always joyful, through this great text. My notes are for those who want to use Java as a programming investigation tool of various wavelet algorithms and Octave for plotting the results. You can find my previous notes by searching my blog on "ripples in mathematics." If you are on the same journey, let me know of any bugs in my code or improvements you have found that let us all, fellow travelers on the wavelet road, get better and more beautiful results.

In this note, I continue with the example in Section 4.2 on p. 31 that I started in note 13. Recall that the example investigates the logarithm function defined in Eq. 4.1 on p. 31. The function, f(t) = log(2 + sin(3*pi*sqrt(t)), is sampled 1024 times at points 1/1024, 2/1024, 3/1024, ..., 1024/1024. The values at 1/1024, 33/1024, 65/1024, etc. are set to 2. These are the fast variations.  The multi-resolution analysis uses CDF(4, 4) to remove slow variations from the signal. This note compares HWT with CDF(4, 4) in removing slow variations from this signal.

Removing Slow Variations from 1D Signal with HWT and CDF(4, 4)


The static method  keepFastVariationsInSignal() in ApplyDWT.java, with a method keepFastVariationsInSignal() implements a fast variation signal filter which keeps fast variations and removes slow ones. The second argument in this method is a two-value static enum, CDF44 or HWT, where the caller specifies which DWT is used in the multi-resolution analysis. The logical steps in the method keepFastVariationsInSignal() are detailed in note 13.  The two static methods below  are implemented in RipplesInMathCh04.java. The first method uses CDF(4, 4); the second one - HWT. 

 static void fig_4_15_cdf44_p35() {
       for(int i = 0; i < 1024; i++)  {
            sRangeFig_4_12_p33[i] = sRipples_F_p33.v(sDomainFig_4_12_p33[i]);
        }
       
        for(int i = 1; i < 1024; i += 32) {
            sRangeFig_4_12_p33[i] += 2;
        }
       
        ApplyDWT.keepFastVariationsInSignal(sRangeFig_4_12_p33, ApplyDWT.DWT.CDF44, 5, S6_START_1024, S6_END_1024);
       
        display_signal(sRangeFig_4_12_p33);
        System.out.println("========================="); 

}

static void fig_4_15_hwt_p35() {
       for(int i = 0; i < 1024; i++)  {
            sRangeFig_4_12_p33[i] = sRipples_F_p33.v(sDomainFig_4_12_p33[i]);
        }
       
        for(int i = 1; i < 1024; i += 32) {
            sRangeFig_4_12_p33[i] += 2;
        }
       
        ApplyDWT.keepFastVariationsInSignal(sRangeFig_4_12_p33, ApplyDWT.DWT.HWT, 5, S6_START_1024, S6_END_1024);
       
        display_signal(sRangeFig_4_12_p33);
        System.out.println("=========================");
    }



Removing Slow Variations from 1D Signal with CDF(4, 4) and HWT

The output of the static method fig_4_15_cdf44_p35() is plotted with fig_4_15_cdf44_p35.m in Fig. 1. The output of the static method fig_4_15_hwt_p35() is plotted with fig_4_15_hwt_p35.m in Fig. 2. As these plots show, HWT keeps the fast variations just as well as CDF(4, 4). However, the graph of the reconstructed fast variations obtained with HWT is not as smooth as the graph obtained with CDF(4, 4).

Figure 1. Fig. 4.15, p. 35 reconstructed with CDF(4, 4)

Figure 2. Fig. 4.15, p. 35 reconstructed with HWT