KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > daubechies4 > Daubechies4


1
2 package JSci.maths.wavelet.daubechies4;
3
4 import JSci.maths.wavelet.*;
5 import JSci.maths.*;
6
7 /******************************************
8 * Daubechies wavelets adapted to the
9 * interval by Meyer. Thanks to Pierre Vial
10 * for the filters.
11 * @author Daniel Lemire
12 *****************************************/

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

29     public int getFilterType () {
30         return(filtretype);
31     }
32
33     public MultiscaleFunction primaryScaling(int n0, int k) {
34         return(new Scaling4(n0,k));
35     }
36
37     public MultiscaleFunction dualScaling(int n0, int k) {
38         return(new Scaling4(n0,k));
39     }
40     public MultiscaleFunction primaryWavelet(int n0, int k) {
41         return(new Wavelet4(n0,k));
42     }
43     public MultiscaleFunction dualWavelet(int n0, int k) {
44         return(new Wavelet4(n0,k));
45     }
46
47   
48     final static double[] vg={
49       -0.107148901418,
50        -0.0419109651251,
51        0.703739068656,
52        1.13665824341,
53        0.421234534204,
54        -0.140317624179,
55        -0.0178247014417,
56        0.045570345896
57     };
58
59     final static double[] v0temp={
60     0.7983434920E+00,
61     0.6022023488E+00};
62     final static double[] v1temp={
63    -0.3918024327E-01,
64     0.5194149822E-01,
65    -0.4817281609E+00,
66     0.8739021503E+00};
67     final static double[] v2temp={
68     0.1774707150E-01,
69    -0.2352740580E-01,
70    -0.1232594861E+00,
71    -0.6575127688E-01,
72    -0.9620570014E-01,
73     0.9850684416E+00};
74     final static double[] v3temp={
75    -0.2636405192E-01,
76     0.3495099166E-01,
77     0.8114147375E+00,
78     0.4440233637E+00,
79     0.3192581817E+00,
80     0.1636579832E+00,
81    -0.4282797155E-01,
82     0.1094933054E+00};
83     final static double[] v4temp={
84    -0.1670338745E-01,
85     0.2214378721E-01,
86    -0.1643714751E-01,
87    -0.1112580065E-01,
88     0.2995602574E+00,
89     0.2728668922E-01,
90     0.8472064764E+00,
91    -0.4270166998E+00,
92    -0.3309408518E-01,
93     0.8460780753E-01};
94     final static double[] v5temp={
95     0.2727915769E-02,
96    -0.3616415322E-02,
97    -0.5206157868E-01,
98    -0.2836107693E-01,
99    -0.4413123462E-01,
100    -0.1285294872E-01,
101     0.4543141690E+00,
102     0.8282235028E+00,
103     0.3000539798E+00,
104    -0.1037443976E+00,
105    -0.1262470890E-01,
106     0.3227612835E-01};
107
108     final static double[] vd0temp={
109     0.7629809303E+00,
110    -0.6464209928E+00};
111     final static double[] vd1temp={
112     0.1555526564E+00,
113     0.1836012627E+00,
114     0.4620817399E+00,
115    -0.8535657052E+00};
116     final static double[] vd2temp={
117     0.3793246643E+00,
118     0.4477229057E+00,
119     0.4284467089E+00,
120     0.3973740378E+00,
121    -0.2021221018E+00,
122    -0.5228106220E+00};
123     final static double[] vd3temp={
124     0.2385999808E+00,
125     0.2816233343E+00,
126     0.1056438723E+00,
127     0.1612498770E+00,
128     0.8548427132E+00,
129     0.2929411663E+00,
130    -0.3647382801E-01,
131    -0.9324840384E-01};
132     final static double[] vd4temp={
133     0.6526723701E-01,
134     0.7703595299E-01,
135     0.7744666349E-01,
136     0.7039069048E-01,
137    -0.6529437593E-01,
138     0.2555397028E+00,
139     0.8099281093E+00,
140     0.4965300820E+00,
141    -0.2995738718E-01,
142    -0.7658857572E-01};
143     final static double[] vd5temp={
144     0.1517778948E-02,
145     0.1791458518E-02,
146    -0.3127686151E-02,
147    -0.1031248163E-02,
148     0.3237561439E-01,
149    -0.1322822647E-01,
150    -0.9898430026E-01,
151     0.2979273659E+00,
152     0.8037308261E+00,
153     0.4975940939E+00,
154    -0.2963560969E-01,
155    -0.7576592454E-01
156     };
157     final static double[] v0=ArrayMath.scalarMultiply(SQRT2,v0temp);
158     final static double[] v1=ArrayMath.scalarMultiply(SQRT2,v1temp);
159     final static double[] v2=ArrayMath.scalarMultiply(SQRT2,v2temp);
160     final static double[] v3=ArrayMath.scalarMultiply(SQRT2,v3temp);
161     final static double[] v4=ArrayMath.scalarMultiply(SQRT2,v4temp);
162     final static double[] v5=ArrayMath.scalarMultiply(SQRT2,v5temp);
163
164     final static double[] vd0=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd0temp));
165     final static double[] vd1=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd1temp));
166     final static double[] vd2=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd2temp));
167     final static double[] vd3=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd3temp));
168     final static double[] vd4=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd4temp));
169     final static double[] vd5=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd5temp));
170     /********************************************
171     * On définit ici le filtre comme tel par le
172     * vecteur phvg (filtre passe-haut).
173     *********************************************/

174     final static double[] vgtemp=ArrayMath.scalarMultiply(1.0/SQRT2,vg);
175     final static double[] phvg=WaveletMath.lowToHigh(vgtemp);
176     final static double[] phv0={
177     0.5979027428E+00,
178    -0.7926434769E+00,
179    -0.1659403671E-01,
180     0.6477069526E-01,
181     0.9713044594E-01,
182    -0.1797030610E-01,
183    -0.3192898087E-03,
184     0.8162911886E-03};
185     final static double[] phv1={
186     0.4823971249E-01,
187    -0.6395169431E-01,
188     0.3010034664E+00,
189     0.1718883936E+00,
190    -0.8873256413E+00,
191    -0.3991915695E-01,
192     0.2462565991E+00,
193    -0.1524149055E+00,
194    -0.9080945357E-02,
195     0.2321619929E-01};
196     final static double[] phv2={
197    -0.1162436086E-02,
198     0.1541048928E-02,
199     0.2218479707E-01,
200     0.1208539488E-01,
201     0.1880547055E-01,
202     0.5476976811E-02,
203    -0.8114432093E-01,
204    -0.3089428579E+00,
205     0.8028339176E+00,
206    -0.4957693566E+00,
207    -0.2962669767E-01,
208     0.7574314021E-01};
209     final static double[] phvd0temp={
210    -0.4071236735E+00,
211    -0.4805345164E+00,
212     0.7323866385E+00,
213     0.2189246571E+00,
214     0.1377492261E+00,
215     0.6432723244E-02,
216    -0.5725128723E-03,
217    -0.1463677232E-02};
218     final static double[] phvd1temp={
219    -0.1510687974E+00,
220    -0.1783088929E+00,
221    -0.2220387683E+00,
222    -0.1860863787E+00,
223     0.4453190824E+00,
224    -0.7578721319E+00,
225     0.2811170011E+00,
226     0.9317065817E-01,
227    -0.1190456353E-01,
228    -0.3043501623E-01};
229     final static double[] phvd2temp={
230    -0.3568796396E-02,
231    -0.4212306878E-02,
232     0.7354216552E-02,
233     0.2424802855E-02,
234    -0.7612569411E-01,
235     0.3110390153E-01,
236     0.4970737955E+00,
237    -0.8039165747E+00,
238     0.2978757587E+00,
239     0.9927560396E-01,
240    -0.1260377436E-01,
241    -0.3222260742E-01};
242    final static double[] phvd0=ArrayMath.invert(phvd0temp);
243    final static double[] phvd1=ArrayMath.invert(phvd1temp);
244    final static double[] phvd2=ArrayMath.invert(phvd2temp);
245     /****************************************
246   * This method return the number of "scaling"
247   * functions at the previous scale given a
248   * number of scaling functions. The answer
249   * is always smaller than the provided value
250   * (about half since this is a dyadic
251   * implementation). This relates to the same idea
252   * as the "Filter type". It is used by
253   * the interface "Filter".
254     *****************************************/

255     public int previousDimension (int k) {
256         return(Cascades.previousDimension(filtretype,k));
257
258     }
259
260
261     public Daubechies4 () {}
262
263     /****************************************
264     * This is the implementation of the lowpass
265   * Filter. It is used by the interface
266   * "Filter". Lowpass filters are normalized
267   * so that they preserve constants away from
268   * the boundaries.
269     *****************************************/

270     public double[] lowpass (double[] v, double[] param) {
271         return(lowpass(v));
272     }
273     /****************************************
274     * This is the implementation of the highpass
275   * Filter. It is used by the interface
276   * "Filter". Highpass filters are normalized
277   * in order to get L2 orthonormality of the
278   * resulting wavelets (when it applies).
279   * See the class DiscreteHilbertSpace for
280   * an implementation of the L2 integration.
281     *****************************************/

282     public double[] highpass (double[] v, double[] param) {
283         return(highpass(v));
284     }
285     /****************************************
286     * This is the implementation of the lowpass
287   * Filter. It is used by the interface
288   * "Filter". Lowpass filters are normalized
289   * so that they preserve constants away from
290   * the boundaries.
291     *****************************************/

292     public double[] lowpass (double[] gete) {
293         if(gete.length<minlength) {
294             throw new IllegalScalingException("The array is not long enough : "+gete.length+" < "+minlength);
295         }
296         double[] sortie=new double[2*gete.length-filtretype];
297         int dl0=gete.length-1;
298         for(int k=6;k<=dl0-6;k++) {
299             for(int L=-4;L<4;L++){
300                 sortie[2*k+L-2]+=vg[L+4]*gete[k];
301             }
302         }
303         sortie=ArrayMath.add(sortie,gete[0],v0,0);
304         sortie=ArrayMath.add(sortie,gete[1],v1,0);
305         sortie=ArrayMath.add(sortie,gete[2],v2,0);
306         sortie=ArrayMath.add(sortie,gete[3],v3,0);
307         sortie=ArrayMath.add(sortie,gete[4],v4,0);
308         sortie=ArrayMath.add(sortie,gete[5],v5,0);
309         int p0=sortie.length-vd0.length;
310         int p1=sortie.length-vd1.length;
311         int p2=sortie.length-vd2.length;
312         int p3=sortie.length-vd3.length;
313         int p4=sortie.length-vd4.length;
314         int p5=sortie.length-vd5.length;
315         sortie=ArrayMath.add(sortie,gete[dl0],vd0,p0);
316         sortie=ArrayMath.add(sortie,gete[dl0-1],vd1,p1);
317         sortie=ArrayMath.add(sortie,gete[dl0-2],vd2,p2);
318         sortie=ArrayMath.add(sortie,gete[dl0-3],vd3,p3);
319         sortie=ArrayMath.add(sortie,gete[dl0-4],vd4,p4);
320         sortie=ArrayMath.add(sortie,gete[dl0-5],vd5,p5);
321         return(sortie);
322     }
323
324     /****************************************
325     * This is the implementation of the highpass
326   * Filter. It is used by the interface
327   * "Filter". Highpass filters are normalized
328   * in order to get L2 orthonormality of the
329   * resulting wavelets (when it applies).
330   * See the class DiscreteHilbertSpace for
331   * an implementation of the L2 integration.
332     *****************************************/

333     public double[] highpass(double[] gete) {
334         double[] sortie=new double[2*gete.length+filtretype];
335         int dl0=gete.length-1;
336         for(int k=3;k<=dl0-3;k++) {
337             for(int L=-4;L<4;L++){
338                 sortie[2*k+ L + 4]+=phvg[L+4]*gete[k];
339             }
340         }
341         sortie=ArrayMath.add(sortie,gete[0],phv0,0);
342         int p0=sortie.length-phvd0.length;
343         sortie=ArrayMath.add(sortie,gete[dl0],phvd0,p0);
344         sortie=ArrayMath.add(sortie,gete[1],phv1,0);
345         int p1=sortie.length-phvd1.length;
346         sortie=ArrayMath.add(sortie,gete[dl0-1],phvd1,p1);
347         sortie=ArrayMath.add(sortie,gete[2],phv2,0);
348         int p2=sortie.length-phvd2.length;
349         sortie=ArrayMath.add(sortie,gete[dl0-2],phvd2,p2);
350
351         return(sortie);
352
353     }
354
355
356     public double[] evalScaling (int n0, int k, int j1) {
357         return(Cascades.evalScaling(this,n0,j1,k));
358     }
359
360     public double[] evalWavelet (int n0, int k, int j1) {
361         return(Cascades.evalWavelet(this,filtretype,n0,j1,k));
362     }
363
364 }
365
Popular Tags