Monday, April 4, 2016

Removing Faster Variations from 1D Signals: Multi-Resolution Analysis vs. Signal Subtraction: Programmatic Note 17 on Ripples in Mathematics




Problem
  
This is my programmatic note 17 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 my programmatic note 16, I outlined a programmatic approach to removing fast variations from 1D signals through signal subtraction. The idea is to process the signal to keep faster variations and then subtract the preserved faster variations from the original signal. This is a programmatic alternative to the  the multi-resolution analysis.  Recall that in multi-res analysis, the higher the number of iterations, the smoother the signal reconstruction from the scale coefficients. In other words, we apply the multi-res analysis a given number of iterations and reconstruct the signal from the scale coefficients obtained from the last scale. 

Are these two methods programmatically different? This post details a programmatic investigation of this question given the signal in Figure 4.12 on p. 33 in "Ripples in Mathematics" that I programmatically reconstructed in my programmatic note 13. The signal is reproduced for ease of reference in Fig. 1 below.


Figure 1. Graph of Fig. 4.12 on p. 33 in "Ripples in Mathematics"



Removing Faster Variations with Multiresolution Analysis


Below are two static methods from RipplesInMathCh04.java. Both of these methods do the multi-resolution analysis of the signal in Fig. 1 above. 


static void fig_4_13_S6_CDF44_p34() { multires_fig_4_13_cdf_p34("Fig. 4.13, S6-06-07-08-09-010, CDF(4,4), p. 33", S6_START_1024, S6_END_1024); }
static void fig_4_13_S6_HWT_p34() { multires_fig_4_13_hwt_p34("Fig. 4.13, S6-06-07-08-09-010, HWT, p. 33", S6_START_1024, S6_END_1024); }

The graphs in Figures 2 and 3 are generated with the Octave scripts fig_4_13_p34_cdf44_s6.m and fig_4_13_p34_hwt_s6.m, respectively. The multiresolution analysis done with HWT is not as smooth as the one done with CDF(4,4), but it does remove faster variations from the signal.



Figure 2. Signal reconstructed from S6 values obtained with CDF(4,4)


Figure 3. Signal reconstructed from S6 values obtained with HWT


Removing Faster Variations through Signal Subtraction


Below are two static methods from RipplesInMathCh04.java. Both of these methods remove faster variations through signal subtraction. The are called in the main for five iterations.

 static void keep_slow_vars_in_fig_4_12_cdf44(int num_iters) {
        fig_4_12_p33();
        keep_slow_vars_in_fig_4_12_aux(sRangeFig_4_12_p33, ApplyDWT.DWT.CDF44, num_iters);
        System.out.println("======");
        display_signal(sRangeFig_4_12_p33);
    }
  
    static void keep_slow_vars_in_fig_4_12_hwt(int num_iters) {
        fig_4_12_p33();
        keep_slow_vars_in_fig_4_12_aux(sRangeFig_4_12_p33, ApplyDWT.DWT.HWT, num_iters);
        System.out.println("======");
        display_signal(sRangeFig_4_12_p33);
    }


 public static void main(String[] args) {
        keep_slow_vars_in_fig_4_12_cdf44(5);

        keep_slow_vars_in_fig_4_12_hwt(5);    
}

The graphs in Figures 4 and 5 are generated with the Octave scripts keep_slow_vars_in_fig_4_12_p33_cdf44_5_scales.m and keep_slow_vars_in_fig_12_p33_hwt_5_scales.m, respectively.  Note that the results are very similar to the results obtained with the multi-resolution analysis shown in Figures 2 and 3.


Figure 4. Fast variations removed through signal subtraction with CDF(4,4)

Figure 5. Fast variations removed through signal subtraction with HWT