01: package JSci.tests;
02:
03: import JSci.maths.WaveletMath;
04:
05: /**
06: * Testcase for wavelet methods.
07: * @author Mark Hale
08: */
09: public class WaveletTest extends junit.framework.TestCase {
10: public static void main(String arg[]) {
11: junit.textui.TestRunner.run(WaveletTest.class);
12: }
13:
14: public WaveletTest(String name) {
15: super (name);
16: }
17:
18: protected void setUp() {
19: JSci.GlobalSettings.ZERO_TOL = 1.0e-6;
20: }
21:
22: /**
23: * This is a test that verifies perfect reconstruction
24: * for a signal null near the boundaries (to avoid the
25: * effects of the zero-padding we used).
26: * @author Daniel Lemire
27: */
28: public void testReconstruction() {
29: double[] data = { 0, 0, 0, 1, 0, 0, 0, 0 };
30: double[] filter = { 0.48296291314, 0.8365163037, 0.224143868,
31: -0.12940952255126 };
32: double[] lowpass = WaveletMath.downsample(filter, data);
33: double[] filterh = { -0.12940952255126, -0.224143868,
34: 0.8365163037, -0.48296291314 };
35: double[] highpass = WaveletMath.downsample(filterh, data);
36: double[] reconstlow = WaveletMath.upsample(filter, lowpass);
37: double[] reconsthigh = WaveletMath.upsample(filterh, highpass);
38: double[] reconst = new double[data.length];
39: for (int i = 0; i < data.length; i++) {
40: reconst[i] = reconstlow[i] + reconsthigh[i];
41: assertEquals(data[i], reconst[i],
42: JSci.GlobalSettings.ZERO_TOL);
43: }
44: }
45:
46: /**
47: * This is a test to verify interpolation from a Lagrange filter.
48: * @author Daniel Lemire
49: */
50: public void testLagrange() {
51: double[] data = { 0, 0, 1, 0, 0 };
52: double[] filter = { -0.0625, 0, 0.5625, 0, 1, 0, 0.5625, 0,
53: -0.0625 };
54: double[] interpol = WaveletMath.upsample(filter, data);
55: for (int i = 0; i < data.length; i++)
56: assertEquals(filter[i], interpol[i],
57: JSci.GlobalSettings.ZERO_TOL);
58: }
59: }
|