KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > tests > WaveletTest


1 package JSci.tests;
2
3 import JSci.maths.WaveletMath;
4
5 /**
6 * Testcase for wavelet methods.
7 * @author Mark Hale
8 */

9 public class WaveletTest extends junit.framework.TestCase {
10         public static void main(String JavaDoc arg[]) {
11                 junit.textui.TestRunner.run(WaveletTest.class);
12         }
13         public WaveletTest(String JavaDoc name) {
14                 super(name);
15         }
16         protected void setUp() {
17                 JSci.GlobalSettings.ZERO_TOL=1.0e-6;
18         }
19         /**
20         * This is a test that verifies perfect reconstruction
21         * for a signal null near the boundaries (to avoid the
22         * effects of the zero-padding we used).
23         * @author Daniel Lemire
24         */

25         public void testReconstruction() {
26                 double[] data={0,0,0,1,0,0,0,0};
27                 double[] filter={0.48296291314,0.8365163037,0.224143868,-0.12940952255126};
28                 double[] lowpass=WaveletMath.downsample(filter,data);
29                 double[] filterh={-0.12940952255126,-0.224143868,0.8365163037,-0.48296291314};
30                 double[] highpass=WaveletMath.downsample(filterh,data);
31                 double[] reconstlow=WaveletMath.upsample(filter,lowpass);
32                 double[] reconsthigh=WaveletMath.upsample(filterh,highpass);
33                 double[] reconst=new double[data.length];
34                 for(int i=0;i<data.length;i++) {
35                         reconst[i]=reconstlow[i]+reconsthigh[i];
36                         assertEquals(data[i], reconst[i], JSci.GlobalSettings.ZERO_TOL);
37                 }
38         }
39         /**
40         * This is a test to verify interpolation from a Lagrange filter.
41         * @author Daniel Lemire
42         */

43         public void testLagrange() {
44                 double[] data={0,0,1,0,0};
45                 double[] filter={-0.0625,0,0.5625,0,1,0,0.5625,0,-0.0625};
46                 double[] interpol=WaveletMath.upsample(filter,data);
47                 for(int i=0;i<data.length;i++)
48                         assertEquals(filter[i], interpol[i], JSci.GlobalSettings.ZERO_TOL);
49         }
50 }
51
52
Popular Tags