Monday, February 15, 2016

Multiresolution Analysis of a Synthetic Signal with CDF(4, 4): Programmatic Note 11 on Ripples in Mathematics




Problem
  
This is my programmatic note 11 on Ch. 04, p. 32, 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 to plot 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 get the results in a better way.

The problem addressed in this post is formulated at the beginning of Section 4.2 on p. 31 in "Ripples in Mathematics." The problem is to reduce noise in a synthetic signal by processing its 3-scale ordered CDF(2,2) representation. The signal is generated by the sinusoid y = sin(4*pi*t), for t in [0, 1], sampled at 512 equidistant points. The the value of the 200th sample is set to 2, and some random noise is added into the sample.  In my notes below, I replaced CDF(2, 2) by CDF(4, 4), because, as I documented in my previous programmatic and conceptual notes on "Ripples" (e.g., programmatic note 7), I could note replicate the graphs in the text with CDF(2, 2) when I used the normalization coefficients on p. 23. I then implemented CDF(4, 4), and the results were much better.   

In this note, I document my reconstruction of the multiresolution analysis in Fig. 4.10, p. 32 with CDF(4, 4). I did the three-scale analysis and then did another scale. This example demonstrates how CDF(4, 4) can be used to denoise a synthetic signal by first applying the 3-scale ordered CDF(4, 4) to the signal to obtain the transform s6, d6, d7, d8. You can look at this post for a sketchy explanation of the notation s6, d6, d7, d8 obtained in the first three scales. Then, the signal is reconstructed for the same number if scales (iterations) and graphed.The fourth-scale gives us s5 and d5.

De-Noising a Synthetic Signal with Small Random Noise and a Spike


The analysis in Fig. 4.10, p. 32, is done to the signal graphed in Fig. 4.7 on p. 30. My implementation of a Java method to generate this signal with small random noise is described here.  My Java implementation of forward and inverse CDF(4, 4) is described in my programmatic notes 7 , 8 , 9 , and 10 .

To apply the n-scale ordered CDF(4, 4) to the signal with the random noise and a spike of 2 at 200 I implemented the multires_fig_4_10_p32() in in RipplesInMathCh04.java. The method applies CDF(4, 4) for a given number if iterations (num_iters) and then inversed the transform for the same number of iterations. Both the signal and the transform are printed out.

static void multires_fig_4_10_p32(String message, int range_start, int range_end, int num_iters) {
        for(int i = 0; i < 512; i++)  {
            sRange[i] = sRipples_F_p25.v(sDomain[i]);
        }

        sRange[200] = 2; // spike at 200
        addNoiseToSignal(sRange);
      
        CDF44.orderedDWTForNumIters(sRange, num_iters, false);
      
        double[] signal = new double[sRange.length];
        for(int i = 0; i < 512; i++) {
            if ( i >= range_start && i <= range_end ) {
                signal[i] = sRange[i];
            }
            else {
                signal[i] = 0;
            }
        }
      
        System.out.println("=========================");
        System.out.println(message);
        display_signal(signal);
        System.out.println("=========================");
        System.out.println("inverse signal");
        CDF44.orderedInverseDWTForNumIters(signal, num_iters, false);
        display_signal(signal);

        System.out.println("=========================");
}

The above method is used in the methods below to print the values for specific graphs in Fig. 4.10, p. 32 in "Ripples." The printed values are copied and pasted into Octave scripts to plot the graphs. The graphs are given below each corresponding Java method.

    // d8 range values for Fig. 4.10, p. 32 in "Ripples in Mathematics." An Octave plot is in Fig. 1 below.
    static void fig_4_10_s06_d06_d07_D8_p32() {
        multires_fig_4_10_p32("06-06-07-D8, Fig. 4.10, p. 32", D8_START_512, D8_END_512, 3);
    }


Figure 1. Graph in Fig. 4.10, p. 32, for D8 with CDF(4, 4)

    // d7 range values for Fig. 4.10, p. 32 in "Ripples in Mathematics." An Octave plot is in Figure 2 below.
    static void fig_4_10_s06_d06_D7_d08_p32() {
        multires_fig_4_10_p32("06-06-D7-08, Fig. 4.10, p. 32", D7_START_512, D7_END_512, 3);
    }



Figure 2. Graph in Fig. 4.10 in "Ripples", p. 32, for D7 with CDF(4, 4)
   
    // d6 range values for Fig. 4.10, p. 32 in "Ripples in Mathematics." An Octave plot is in Fig. 3 below.
    static void fig_4_10_s06_D6_d07_d08_p32() {
        multires_fig_4_10_p32("06-D6-07-08, Fig. 4.10, p. 32", D6_START_512, D6_END_512, 3);
    }
   

Figure 3. Graph in Fig. 4.10 in "Ripples", p. 32, for D6 with CDF(4, 4)
   // s6 range values for Fig. 4.10, p. 32 in "Ripples in Mathematics." An Octave plot is in Fig. 4 below.
    static void fig_4_10_S6_d06_d07_d08_p32() {
        multires_fig_4_10_p32("S6-06-07-08, Fig. 4.10, p. 32", S6_START_512, S6_END_512, 3);

    }  

Figure 4. Graph in Fig. 4.10 in "Ripples", p. 32, for S6 with CDF(4, 4)

    // d5 range values, not in "Ripples." An Octave plot is in Fig. 5 below.
    static void fig_4_10_s05_D5_d06_d07_d08_p32() {
        multires_fig_4_10_p32("05-D5-06-07-08, Fig. 4.10, p. 32", D5_START_512, D5_END_512, 4);
    }


Figure 5. Graph in Fig. 4.10, p. 32, for D5 with CDF(4, 4)
 
   // s5 range values, not in the book.  An Octave plot is in Fig. 6 below. 
   static void fig_4_10_S5_d06_d07_d08_p32() {
        multires_fig_4_10_p32("S5-05-06-07-08, Fig. 4.10, p. 32", S5_START_512, S5_END_512, 4);
    }
   

Figure 6. Graph in Fig. 4.10, p. 32, for S5 with CDF(4, 4)