KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > daubechies5 > Daubechies5


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

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

28     public int getFilterType () {
29         return(filtretype);
30     }
31
32     public MultiscaleFunction primaryScaling(int n0, int k) {
33         return(new Scaling5(n0,k));
34     }
35
36     public MultiscaleFunction dualScaling(int n0, int k) {
37         return(new Scaling5(n0,k));
38     }
39     public MultiscaleFunction primaryWavelet(int n0, int k) {
40         return(new Wavelet5(n0,k));
41     }
42     public MultiscaleFunction dualWavelet(int n0, int k) {
43         return(new Wavelet5(n0,k));
44     }
45
46   
47     final static double[] vg={
48        0.0386547959548,
49        0.0417468644215,
50        - 0.0553441861166,
51       0.281990696854,
52       1.02305296689,
53       0.89658164838,
54       0.0234789231361,
55        - 0.247951362613,
56       - 0.0298424998687,
57       0.0276321529578};
58
59       final static double[] v0temp={
60         0.5149588736E+00,
61         0.8572148847E+00};
62   final static double[] v1temp={
63    -0.7062608421E-01,
64     0.4242755162E-01,
65    -0.9680855135E+00,
66     0.2366902992E+00};
67   final static double[] v2temp={
68     0.1166375834E+00,
69    -0.7006826369E-01,
70     0.2569251462E-01,
71     0.1524482921E+00,
72    -0.8988377800E+00,
73     0.3868800469E+00};
74   final static double[] v3temp={
75     0.4678469852E+00,
76    -0.2810519985E+00,
77     0.8265463674E-01,
78     0.5280457443E+00,
79     0.8615307089E-01,
80    -0.2053530811E+00,
81    -0.4422572318E+00,
82     0.4138613016E+00};
83   final static double[] v4temp={
84    -0.1341363044E+00,
85     0.8058035557E-01,
86    -0.3810281736E-01,
87    -0.2103133707E+00,
88     0.3026059798E-01,
89     0.2107415482E+00,
90    -0.8553851730E+00,
91    -0.3335028061E+00,
92    -0.1496490635E+00,
93     0.1385649939E+00};
94   final static double[] v5temp={
95    -0.2809362553E+00,
96     0.1687682052E+00,
97    -0.4001455131E-01,
98    -0.2777441959E+00,
99     0.9006724682E-02,
100     0.2482896416E+00,
101    -0.9917949547E-01,
102     0.8098971461E+00,
103    -0.2582323890E+00,
104    -0.1241046836E+00,
105    -0.4791583558E-01,
106     0.4436684941E-01};
107   final static double[] v6temp={
108    -0.8360649632E-01,
109     0.5022533782E-01,
110    -0.1533783538E-01,
111    -0.9668361515E-01,
112    -0.4952912706E-02,
113     0.6191148032E-01,
114    -0.5197035907E-01,
115     0.2312568194E+00,
116     0.6976664051E+00,
117     0.6350643725E+00,
118     0.1189068293E-01,
119    -0.1727260340E+00,
120    -0.2133407205E-01,
121     0.1975391957E-01};
122   final static double[] v7temp={
123    -0.1591308791E-02,
124     0.9559546817E-03,
125     0.3515007474E-03,
126     0.7914817671E-03,
127    -0.1039035431E-02,
128    -0.2096326217E-02,
129     0.2722494187E-01,
130     0.2963704669E-01,
131    -0.3930998378E-01,
132     0.1995579157E+00,
133     0.7233513164E+00,
134     0.6339755574E+00,
135     0.1659420760E-01,
136    -0.1753213559E+00,
137    -0.2110191042E-01,
138     0.1953895348E-01};
139
140
141     final static double[] vd0temp={
142     0.9116496405E+00,
143     0.4109682870E+00};
144     final static double[] vd1temp={
145    -0.1759262671E+00,
146     0.3902566773E+00,
147     0.6301011968E+00,
148     0.6478596732E+00};
149     final static double[] vd2temp={
150     0.2825379610E-03,
151    -0.6267530579E-03,
152     0.4175827162E+00,
153    -0.4056820940E+00,
154     0.6289312762E+00,
155     0.5152588582E+00};
156     final static double[] vd3temp={
157    -0.5113299639E-01,
158     0.1134281628E+00,
159     0.4836999717E+00,
160    -0.5526531145E+00,
161    -0.2269223725E+00,
162    -0.5499800740E+00,
163     0.2214856571E+00,
164     0.2051843068E+00};
165     final static double[] vd4temp={
166     0.2756002147E-02,
167    -0.6113630773E-02,
168    -0.1460819570E+00,
169     0.1465088170E+00,
170     0.1654940540E+00,
171     0.3172833766E-01,
172     0.9500926016E+00,
173    -0.1444971260E-01,
174     0.1180200176E+00,
175     0.1092786192E+00};
176     final static double[] vd5temp={
177     0.1425700173E-01,
178    -0.3162626148E-01,
179    -0.7075177701E-01,
180     0.9173486581E-01,
181    -0.6745433251E-01,
182     0.2118550693E+00,
183    -0.1051600438E-01,
184     0.9395202801E+00,
185     0.1694709068E+00,
186    -0.1464208651E+00,
187     0.4001747247E-01,
188     0.3705349502E-01};
189     final static double[] vd6temp={
190    -0.1315787444E-02,
191     0.2918807090E-02,
192     0.1730939444E-01,
193    -0.1895045515E-01,
194    -0.1537869850E-02,
195    -0.2706707215E-01,
196    -0.1556669346E+00,
197    -0.6193750436E-05,
198     0.6330645158E+00,
199     0.7286274296E+00,
200     0.1987062136E+00,
201    -0.3988654553E-01,
202     0.2953429005E-01,
203     0.2734677134E-01};
204     final static double[] vd7temp={
205    -0.8561071719E-04,
206     0.1899099809E-03,
207    -0.9013424188E-06,
208    -0.1367686226E-03,
209    -0.3599933730E-03,
210     0.3327378221E-03,
211     0.1961899121E-01,
212    -0.2117649690E-01,
213    -0.1753299891E+00,
214     0.1662647625E-01,
215     0.6339762696E+00,
216     0.7234044479E+00,
217     0.1993976399E+00,
218    -0.3913415866E-01,
219     0.2951949191E-01,
220     0.2733306926E-01};
221
222     final static double[] v0=ArrayMath.scalarMultiply(SQRT2,v0temp);
223     final static double[] v1=ArrayMath.scalarMultiply(SQRT2,v1temp);
224     final static double[] v2=ArrayMath.scalarMultiply(SQRT2,v2temp);
225     final static double[] v3=ArrayMath.scalarMultiply(SQRT2,v3temp);
226     final static double[] v4=ArrayMath.scalarMultiply(SQRT2,v4temp);
227     final static double[] v5=ArrayMath.scalarMultiply(SQRT2,v5temp);
228     final static double[] v6=ArrayMath.scalarMultiply(SQRT2,v6temp);
229     final static double[] v7=ArrayMath.scalarMultiply(SQRT2,v7temp);
230
231     final static double[] vd0=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd0temp));
232     final static double[] vd1=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd1temp));
233     final static double[] vd2=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd2temp));
234     final static double[] vd3=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd3temp));
235     final static double[] vd4=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd4temp));
236     final static double[] vd5=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd5temp));
237     final static double[] vd6=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd6temp));
238     final static double[] vd7=ArrayMath.invert(ArrayMath.scalarMultiply(SQRT2,vd7temp));
239
240     /********************************************
241     * On définit ici le filtre comme tel par le
242     * vecteur phvg (filtre passe-haut).
243     *********************************************/

244     final static double[] vgtemp=ArrayMath.scalarMultiply(1.0/SQRT2,vg);
245     final static double[] phvg=WaveletMath.lowToHigh(vgtemp);
246     final static double[] phv0={
247     0.6182708675E+00,
248    -0.3714168701E+00,
249    -0.1886088129E+00,
250    -0.5203639573E+00,
251     0.1728721711E+00,
252     0.3655404713E+00,
253     0.9964278013E-01,
254     0.2321755628E-02,
255     0.8297752060E-04,
256    -0.7683163866E-04};
257     final static double[] phv1={
258    -0.9199155757E-01,
259     0.5526253651E-01,
260     0.1276201402E+00,
261     0.4846229512E+00,
262     0.3921178348E+00,
263     0.7493106089E+00,
264     0.1219411317E+00,
265    -0.8181830470E-01,
266     0.2258502019E-01,
267     0.4446446219E-02,
268     0.3345391169E-02,
269    -0.3097607805E-02};
270     final static double[] phv2={
271    -0.5206990422E-01,
272     0.3128020722E-01,
273    -0.1303591078E-01,
274    -0.7446233534E-01,
275     0.2030318262E-02,
276     0.5628764191E-01,
277    -0.1851188211E+00,
278     0.7400777444E-02,
279     0.6246714288E+00,
280    -0.7215672985E+00,
281     0.1975651316E+00,
282     0.3986516515E-01,
283     0.2939208418E-01,
284    -0.2721509824E-01};
285     final static double[] phv3={
286    -0.1137543931E-02,
287     0.6833623070E-03,
288     0.2512696118E-03,
289     0.5657891708E-03,
290    -0.7427524153E-03,
291    -0.1498554635E-02,
292     0.1946169563E-01,
293     0.2118598397E-01,
294    -0.1754541390E+00,
295    -0.1648697186E-01,
296     0.6339417098E+00,
297    -0.7234098228E+00,
298     0.1993922999E+00,
299     0.3913868175E-01,
300     0.2951943631E-01,
301    -0.2733301778E-01};
302
303     final static double[] phvd0temp={
304     0.3667623662E+00,
305    -0.8135877873E+00,
306     0.3605867008E+00,
307     0.2389793582E+00,
308     0.1721476353E-01,
309    -0.1262774479E+00,
310     0.1354530290E-01,
311     0.7338813977E-03,
312    -0.1058396455E-03,
313    -0.9800040389E-04};
314     final static double[] phvd1temp={
315     0.2440133283E-01,
316    -0.5412939880E-01,
317     0.1933279241E+00,
318    -0.1487960520E+00,
319    -0.7215807244E+00,
320     0.6068591878E+00,
321     0.1499494360E+00,
322    -0.1537729673E+00,
323     0.4017810927E-02,
324     0.4249831221E-01,
325    -0.5115722859E-02,
326    -0.4736816190E-02};
327     final static double[] phvd2temp={
328    -0.2747616845E-02,
329     0.6095029686E-02,
330     0.2424194881E-01,
331    -0.2799508244E-01,
332    -0.5956481976E-02,
333    -0.3440854634E-01,
334    -0.1090515083E-01,
335    -0.2236505386E+00,
336     0.7232999959E+00,
337    -0.6265589773E+00,
338     0.1577095589E-01,
339     0.1743929125E+00,
340    -0.2107998910E-01,
341    -0.1951865580E-01};
342     final static double[] phvd3temp={
343    -0.1197613924E-03,
344     0.2656663148E-03,
345    -0.1260893172E-05,
346    -0.1913265215E-03,
347    -0.5035970875E-03,
348     0.4654691185E-03,
349     0.2744513531E-01,
350    -0.2962394021E-01,
351    -0.3913691676E-01,
352    -0.1993634542E+00,
353     0.7234039987E+00,
354    -0.6339835070E+00,
355     0.1660226434E-01,
356     0.1753282263E+00,
357    -0.2110183265E-01,
358    -0.1953888146E-01};
359
360     final static double[] phvd0=ArrayMath.invert(phvd0temp);
361     final static double[] phvd1=ArrayMath.invert(phvd1temp);
362     final static double[] phvd2=ArrayMath.invert(phvd2temp);
363     final static double[] phvd3=ArrayMath.invert(phvd3temp);
364     /****************************************
365   * This method return the number of "scaling"
366   * functions at the previous scale given a
367   * number of scaling functions. The answer
368   * is always smaller than the provided value
369   * (about half since this is a dyadic
370   * implementation). This relates to the same idea
371   * as the "Filter type". It is used by
372   * the interface "Filter".
373     *****************************************/

374     public int previousDimension (int k) {
375         return(Cascades.previousDimension(filtretype,k));
376
377     }
378
379     public Daubechies5 () {}
380     /****************************************
381     * This is the implementation of the lowpass
382   * Filter. It is used by the interface
383   * "Filter". Lowpass filters are normalized
384   * so that they preserve constants away from
385   * the boundaries.
386     *****************************************/

387     public double[] lowpass (double[] v, double[] param) {
388         return(lowpass(v));
389     }
390     /****************************************
391     * This is the implementation of the highpass
392   * Filter. It is used by the interface
393   * "Filter". Highpass filters are normalized
394   * in order to get L2 orthonormality of the
395   * resulting wavelets (when it applies).
396   * See the class DiscreteHilbertSpace for
397   * an implementation of the L2 integration.
398     *****************************************/

399     public double[] highpass (double[] v, double[] param) {
400         return(highpass(v));
401     }
402     /****************************************
403     * This is the implementation of the lowpass
404   * Filter. It is used by the interface
405   * "Filter". Lowpass filters are normalized
406   * so that they preserve constants away from
407   * the boundaries.
408     *****************************************/

409     public double[] lowpass (double[] gete) {
410         if(gete.length<minlength) {
411             throw new IllegalScalingException("The array is not long enough : "+gete.length+" < "+minlength);
412         }
413         double[] sortie=new double[2*gete.length-filtretype];
414         int dl0=gete.length-1;
415         for(int k=8;k<=dl0-8;k++) {
416             for(int L=-5;L<5;L++){
417                 sortie[2*k+L-3]+=vg[L+5]*gete[k];
418             }
419         }
420         sortie=ArrayMath.add(sortie,gete[0],v0,0);
421         sortie=ArrayMath.add(sortie,gete[1],v1,0);
422         sortie=ArrayMath.add(sortie,gete[2],v2,0);
423         sortie=ArrayMath.add(sortie,gete[3],v3,0);
424         sortie=ArrayMath.add(sortie,gete[4],v4,0);
425         sortie=ArrayMath.add(sortie,gete[5],v5,0);
426         sortie=ArrayMath.add(sortie,gete[6],v6,0);
427         sortie=ArrayMath.add(sortie,gete[7],v7,0);
428         int p0=sortie.length-vd0.length;
429         int p1=sortie.length-vd1.length;
430         int p2=sortie.length-vd2.length;
431         int p3=sortie.length-vd3.length;
432         int p4=sortie.length-vd4.length;
433         int p5=sortie.length-vd5.length;
434         int p6=sortie.length-vd6.length;
435         int p7=sortie.length-vd7.length;
436         sortie=ArrayMath.add(sortie,gete[dl0],vd0,p0);
437         sortie=ArrayMath.add(sortie,gete[dl0-1],vd1,p1);
438         sortie=ArrayMath.add(sortie,gete[dl0-2],vd2,p2);
439         sortie=ArrayMath.add(sortie,gete[dl0-3],vd3,p3);
440         sortie=ArrayMath.add(sortie,gete[dl0-4],vd4,p4);
441         sortie=ArrayMath.add(sortie,gete[dl0-5],vd5,p5);
442         sortie=ArrayMath.add(sortie,gete[dl0-6],vd6,p6);
443         sortie=ArrayMath.add(sortie,gete[dl0-7],vd7,p7);
444
445         return(sortie);
446     }
447
448     /****************************************
449     * This is the implementation of the highpass
450   * Filter. It is used by the interface
451   * "Filter". Highpass filters are normalized
452   * in order to get L2 orthonormality of the
453   * resulting wavelets (when it applies).
454   * See the class DiscreteHilbertSpace for
455   * an implementation of the L2 integration.
456     *****************************************/

457     public double[] highpass(double[] gete) {
458         if(gete.length<8) {
459             throw new IllegalScalingException("The array is not long enough : "+gete.length+" < 8");
460         }
461         double[] sortie=new double[2*gete.length+filtretype];
462         int dl0=gete.length-1;
463         for(int k=4;k<=dl0-4;k++) {
464             for(int L=-5;L<5;L++){
465                 sortie[2*k+L + 5 ]+=phvg[L+5]*gete[k];
466             }
467         }
468         sortie=ArrayMath.add(sortie,gete[0],phv0,0);
469         int p0=sortie.length-phvd0.length;
470         sortie=ArrayMath.add(sortie,gete[dl0],phvd0,p0);
471         sortie=ArrayMath.add(sortie,gete[1],phv1,0);
472         int p1=sortie.length-phvd1.length;
473         sortie=ArrayMath.add(sortie,gete[dl0-1],phvd1,p1);
474         sortie=ArrayMath.add(sortie,gete[2],phv2,0);
475         int p2=sortie.length-phvd2.length;
476         sortie=ArrayMath.add(sortie,gete[dl0-2],phvd2,p2);
477         sortie=ArrayMath.add(sortie,gete[3],phv3,0);
478         int p3=sortie.length-phvd3.length;
479         sortie=ArrayMath.add(sortie,gete[dl0-3],phvd3,p3);
480
481         return(sortie);
482     }
483
484
485     public double[] evalScaling (int n0, int k, int j1) {
486         return(Cascades.evalScaling(this,n0,j1,k));
487     }
488
489
490     public double[] evalWavelet (int n0, int k, int j1) {
491         return(Cascades.evalWavelet(this,filtretype,n0,j1,k));
492     }
493
494 }
495
Popular Tags