KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > cdf2_4 > CDF2_4


1
2 package JSci.maths.wavelet.cdf2_4;
3
4 import JSci.maths.wavelet.*;
5 import JSci.maths.*;
6
7 /******************************************
8 * Cohen-Daubechies-Feauveau
9 * with N=2 and
10 * Ntilde=4 adapted to the interval
11 * by Deslauriers-Dubuc-Lemire
12 * @author Daniel Lemire
13 *****************************************/

14 public final class CDF2_4 extends Multiresolution implements Filter {
15     protected final static int filtretype=1;
16     protected final static int minlength=5;
17     /****************************************
18   * This method is used to compute
19   * how the number of scaling functions
20   * changes from on scale to the other.
21   * Basically, if you have k scaling
22   * function and a Filter of type t, you'll
23   * have 2*k+t scaling functions at the
24   * next scale (dyadic case).
25   * Notice that this method assumes
26   * that one is working with the dyadic
27   * grid while the method "previousDimension"
28   * define in the interface "Filter" doesn't.
29     ******************************************/

30     public int getFilterType () {
31         return(filtretype);
32     }
33
34     public MultiscaleFunction primaryScaling(int n0, int k) {
35         return(MultiSpline2_4.scaling(n0,k));
36     }
37
38     public MultiscaleFunction dualScaling(int n0, int k) {
39         return(new DualScaling2_4(n0,k));
40     }
41     public MultiscaleFunction primaryWavelet(int n0, int k) {
42         return(MultiSpline2_4.wavelet(n0,k));
43     }
44     public MultiscaleFunction dualWavelet(int n0, int k) {
45         return(new DualWavelet2_4(n0,k));
46     }
47
48     /********************************************
49     *********************************************/

50     final static double[] vg={3/64d,-3/32d,-1/4d,19/32d,45/32d,19/32d,-1/4d,-3/32d,3/64d};
51     final static double[] v3={-5/256d,5/128d,1/64d,-9/128d,-67/256d,19/32d,45/32d,19/32d,-1/4d,-3/32d,3/64d};
52     final static double[] v2={41/384d,-41/192d,-13/96d,31/64d,187/128d,19/32d,-1/4d,-3/32d,3/64d};
53     final static double[] v1={-241/768d,241/384d,245/192d,105/128d,-93/256d,-3/32d,3/64d};
54     final static double[] v0={93/64d,35/32d,-5/16d,-15/32d,15/64d};
55     final static double[] vd0=ArrayMath.invert(v0);
56     final static double[] vd1=ArrayMath.invert(v1);
57     final static double[] vd2=ArrayMath.invert(v2);
58     final static double[] vd3=ArrayMath.invert(v3);
59     /********************************************
60     *********************************************/

61     final static double[] phvg={-1/2d,1d,-1/2d};
62     final static double[] phv0={1d,-1/2d};
63
64     /****************************************
65   * This method return the number of "scaling"
66   * functions at the previous scale given a
67   * number of scaling functions. The answer
68   * is always smaller than the provided value
69   * (about half since this is a dyadic
70   * implementation). This relates to the same idea
71   * as the "Filter type". It is used by
72   * the interface "Filter".
73     *****************************************/

74     public int previousDimension (int k) {
75         int i=(int) Math.round((k+1)/2d);
76         if(2*i-1==k) {
77             return(i);
78         } else {
79             throw new IllegalScalingException("Even number of values into an odd Filter! Change the number of iterations/values.");
80         }
81     }
82
83
84     public CDF2_4 () {}
85     /****************************************
86     * This is the implementation of the lowpass
87   * Filter. It is used by the interface
88   * "Filter". Lowpass filters are normalized
89   * so that they preserve constants away from
90   * the boundaries.
91     *****************************************/

92     public double[] lowpass (double[] v, double[] param) {
93         return(lowpass(v));
94     }
95     /****************************************
96     * This is the implementation of the highpass
97   * Filter. It is used by the interface
98   * "Filter". Highpass filters are normalized
99   * in order to get L2 orthonormality of the
100   * resulting wavelets (when it applies).
101   * See the class DiscreteHilbertSpace for
102   * an implementation of the L2 integration.
103     *****************************************/

104     public double[] highpass (double[] v, double[] param) {
105         return(highpass(v));
106     }
107     /****************************************
108     * This is the implementation of the lowpass
109   * Filter. It is used by the interface
110   * "Filter". Lowpass filters are normalized
111   * so that they preserve constants away from
112   * the boundaries.
113     *****************************************/

114     public double[] lowpass (double[] gete) {
115         if(gete.length<8) {
116             throw new IllegalScalingException("The array is not long enough : "+gete.length+" < 8");
117         }
118         double[] sortie=new double[2*gete.length-1];
119         int dl0=gete.length-1;
120         for(int k=4;k<=dl0-4;k++) {
121             for(int L=-4;L<=4;L++){
122                 sortie[2*k+L]+=vg[L+4]*gete[k];
123             }
124         }
125         sortie=ArrayMath.add(sortie,gete[0],v0,0);
126         sortie=ArrayMath.add(sortie,gete[1],v1,0);
127         sortie=ArrayMath.add(sortie,gete[2],v2,0);
128         sortie=ArrayMath.add(sortie,gete[3],v3,0);
129         int p0=sortie.length-vd0.length;
130         int p1=sortie.length-vd1.length;
131         int p2=sortie.length-vd2.length;
132         int p3=sortie.length-vd3.length;
133         sortie=ArrayMath.add(sortie,gete[dl0],vd0,p0);
134         sortie=ArrayMath.add(sortie,gete[dl0-1],vd1,p1);
135         sortie=ArrayMath.add(sortie,gete[dl0-2],vd2,p2);
136         sortie=ArrayMath.add(sortie,gete[dl0-3],vd3,p3);
137         return(sortie);
138     }
139
140     /****************************************
141     * This is the implementation of the highpass
142   * Filter. It is used by the interface
143   * "Filter". Highpass filters are normalized
144   * in order to get L2 orthonormality of the
145   * resulting wavelets (when it applies).
146   * See the class DiscreteHilbertSpace for
147   * an implementation of the L2 integration.
148     *****************************************/

149     public double[] highpass(double[] v) {
150         if(v.length<2) {
151             throw new IllegalScalingException("The array is not long enough : "+v.length+" < 2");
152         }
153         double[] data=Cascades.supersample(v);
154         int dl=data.length-1;
155         double[] sortie=new double[data.length];
156         /********************************************
157         *********************************************/

158         for(int k=1;k<=dl-1;k++) {
159             sortie[k]=ArrayMath.scalarProduct(ArrayMath.extract(k-1,k+1,data),phvg);
160         }
161         sortie[0]=ArrayMath.scalarProduct(ArrayMath.extract(0,1,data),phv0);
162         sortie[dl]=ArrayMath.scalarProduct(ArrayMath.extract(dl,dl-1,data),phv0);
163         return(sortie);
164     }
165
166     /************************************
167     **************************************/

168     public double[] evalScaling (int n0, int k, int j1) {
169         return(Cascades.evalScaling(this,n0,j1,k));
170     }
171
172     /************************************
173
174     **************************************/

175     public double[] evalWavelet (int n0, int k, int j1) {
176         return(Cascades.evalWavelet(this,n0,j1,k));
177     }
178
179 }
180
Popular Tags