KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > cdf3_5 > CDF3_5


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

14 public final class CDF3_5 extends Multiresolution implements Filter {
15     protected final static int filtretype=2;
16     protected final static int minlength=12;
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(MultiSpline3_5.scaling(n0,k));
36     }
37
38     public MultiscaleFunction dualScaling(int n0, int k) {
39         return(new DualScaling3_5(n0,k));
40     }
41     public MultiscaleFunction primaryWavelet(int n0, int k) {
42         return(MultiSpline3_5.wavelet(n0,k));
43     }
44     public MultiscaleFunction dualWavelet(int n0, int k) {
45         return(new DualWavelet3_5(n0,k));
46     }
47     /********************************************
48
49     *********************************************/

50     final static double[] v0={8703/5120d, 14851/5120d, -7497/2560d, -4137/2560d, 4703/2560d, 5799/2560d, -3315/1024d, 1105/1024d};
51     final static double[] v1={-983/5120d, 2949/5120d, 4977/2560d, 1617/2560d, -2423/2560d, -2559/2560d, 1515/1024d, -505/1024d};
52     final static double[] v2={2897/51200d, -8691/51200d, -3863/25600d, 23177/25600d, 116611/76800d, 22521/25600d, -3153/2048d, 2833/6144d, 15/256d, -5/256d};
53     final static double[] v3={-789/51200d, 2367/51200d, 531/25600d, -4749/25600d, -869/25600d, 16323/25600d, 4429/2048d, -751/2048d, -97/256d, 19/256d, 15/256d, -5/256d};
54     final static double[] v4={7/3200d, -21/3200d, -3/1600d, 37/1600d, -3/1600d, -99/1600d, -55/128d, 189/128d, 175/128d, -13/128d, -97/256d, 19/256d, 15/256d, -5/256d};
55     final static double[] v5={0d, 0d, 0d, 0d, 0d, 0d, 17/128d, -51/128d, -13/128d, 175/128d, 175/128d, -13/128d, -97/256d, 19/256d, 15/256d, -5/256d};
56     final static double[] vg={-5/256d, 15/256d, 19/256d, -97/256d, -13/128d, 175/128d, 175/128d, -13/128d, -97/256d, 19/256d, 15/256d, -5/256d};
57     final static double[] vd0=ArrayMath.invert(v0);
58     final static double[] vd1=ArrayMath.invert(v1);
59     final static double[] vd2=ArrayMath.invert(v2);
60     final static double[] vd3=ArrayMath.invert(v3);
61     final static double[] vd4=ArrayMath.invert(v4);
62     final static double[] vd5=ArrayMath.invert(v5);
63
64
65     /********************************************
66     *********************************************/

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

79     public int previousDimension (int k) {
80         return(Cascades.previousDimension(filtretype,k));
81     }
82
83
84     public CDF3_5 () {}
85
86     /****************************************
87     * This is the implementation of the lowpass
88   * Filter. It is used by the interface
89   * "Filter". Lowpass filters are normalized
90   * so that they preserve constants away from
91   * the boundaries.
92     *****************************************/

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

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

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

161     public double[] highpass(double[] v) {
162         if(v.length<4) {
163             throw new IllegalScalingException("The array is not long enough : "+v.length+" < 4");
164         }
165         double[] ans=new double[2*v.length+2];
166         for(int k=0;k<v.length;k++) {
167             ans[2*k]+=v[k]*phvg[0];
168             ans[2*k+1]+=v[k]*phvg[1];
169             ans[2*k+2]+=v[k]*phvg[2];
170             ans[2*k+3]+=v[k]*phvg[3];
171         }
172         return(ans);
173     }
174
175     /************************************
176     **************************************/

177     public double[] evalScaling (int n0, int k, int j1) {
178         return(Cascades.evalScaling(this,n0,j1,k));
179     }
180
181     /************************************
182     **************************************/

183     public double[] evalWavelet (int n0, int k, int j1) {
184         return(Cascades.evalWaveletQuadratic(this,n0,j1,k));
185     }
186
187 }
188
Popular Tags