KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > daubechies2 > Daubechies2


1
2 package JSci.maths.wavelet.daubechies2;
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 Daubechies2 extends Multiresolution implements Filter, NumericalConstants {
14     protected final static int filtretype=2;
15     protected final static int minlength=4;
16
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(new Scaling2(n0,k));
36     }
37
38     public MultiscaleFunction dualScaling(int n0, int k) {
39         return(new Scaling2(n0,k));
40     }
41     public MultiscaleFunction primaryWavelet(int n0, int k) {
42         return(new Wavelet2(n0,k));
43     }
44     public MultiscaleFunction dualWavelet(int n0, int k) {
45         return(new Wavelet2(n0,k));
46     }
47
48
49   
50     final static double[] vgtemp={0.482962913145,0.836516303738,0.224143868042,-0.129409522551};
51     final static double[] v0temp={0.848528137424,-0.529150262213};
52     final static double[] v1temp={0.132287565553, 0.212132034356, 0.838525491562,- 0.484122918276};
53
54     final static double[] vd0temp={
55     0.848528137424,
56     0.529150262213};
57
58     final static double[] vd1temp={
59     -0.132287565553,
60     0.212132034356,
61     0.838525491562,
62     0.484122918276};
63
64     final static double[] vg=ArrayMath.scalarMultiply(SQRT2,vgtemp);
65     final static double[] vd0=ArrayMath.scalarMultiply(SQRT2,ArrayMath.invert(vd0temp));
66     final static double[] vd1=ArrayMath.scalarMultiply(SQRT2,ArrayMath.invert(vd1temp));
67     final static double[] v0=ArrayMath.scalarMultiply(SQRT2,v0temp);
68     final static double[] v1=ArrayMath.scalarMultiply(SQRT2,v1temp);
69
70
71     /********************************************
72     * On définit ici le filtre comme tel par le
73     * vecteur phvg (filtre passe-haut).
74     *********************************************/

75     final static double[] phvg=WaveletMath.lowToHigh(vgtemp);
76     final static double[] phv0={-0.512347538298, -0.821583836258, 0.216506350947, -0.125};
77
78     final static double[] phvd0temp={
79     0.512347538298,
80     -0.821583836258,
81     0.216506350946,
82     0.125};
83     final static double[] phvd0=ArrayMath.invert(phvd0temp);
84
85     /****************************************
86   * This method return the number of "scaling"
87   * functions at the previous scale given a
88   * number of scaling functions. The answer
89   * is always smaller than the provided value
90   * (about half since this is a dyadic
91   * implementation). This relates to the same idea
92   * as the "Filter type". It is used by
93   * the interface "Filter".
94     *****************************************/

95     public int previousDimension (int k) {
96         return(Cascades.previousDimension(filtretype,k));
97     }
98
99
100     public Daubechies2 () {}
101
102     /****************************************
103     * This is the implementation of the lowpass
104   * Filter. It is used by the interface
105   * "Filter". Lowpass filters are normalized
106   * so that they preserve constants away from
107   * the boundaries.
108     *****************************************/

109     public double[] lowpass (double[] v, double[] param) {
110         return(lowpass(v));
111     }
112
113     /****************************************
114     * This is the implementation of the highpass
115   * Filter. It is used by the interface
116   * "Filter". Highpass filters are normalized
117   * in order to get L2 orthonormality of the
118   * resulting wavelets (when it applies).
119   * See the class DiscreteHilbertSpace for
120   * an implementation of the L2 integration.
121     *****************************************/

122     public double[] highpass (double[] v, double[] param) {
123         return(highpass(v));
124     }
125
126     /****************************************
127     * This is the implementation of the lowpass
128   * Filter. It is used by the interface
129   * "Filter". Lowpass filters are normalized
130   * so that they preserve constants away from
131   * the boundaries.
132     *****************************************/

133     public double[] lowpass (double[] gete) {
134         if(gete.length<minlength) {
135             throw new IllegalScalingException("The array is not long enough: "+gete.length+" < "+minlength);
136         }
137         double[] sortie=new double[2*gete.length-2];
138         int dl0=gete.length-1;
139         for(int k=2;k<=dl0-2;k++) {
140             for(int L=-2;L<2;L++){
141                 sortie[2*k+L]+=vg[L+2]*gete[k];
142             }
143         }
144         sortie=ArrayMath.add(sortie,gete[0],v0,0);
145         sortie=ArrayMath.add(sortie,gete[1],v1,0);
146         int p0=sortie.length-vd0.length;
147         int p1=sortie.length-vd1.length;
148         sortie=ArrayMath.add(sortie,gete[dl0],vd0,p0);
149         sortie=ArrayMath.add(sortie,gete[dl0-1],vd1,p1);
150         return(sortie);
151     }
152
153     /****************************************
154     * This is the implementation of the highpass
155   * Filter. It is used by the interface
156   * "Filter". Highpass filters are normalized
157   * in order to get L2 orthonormality of the
158   * resulting wavelets (when it applies).
159   * See the class DiscreteHilbertSpace for
160   * an implementation of the L2 integration.
161     *****************************************/

162     public double[] highpass(double[] gete) {
163         double[] sortie=new double[2*gete.length+2];
164         int dl0=gete.length-1;
165         for(int k=1;k<=dl0-1;k++) {
166             for(int L=-2;L<2;L++){
167                 sortie[2*k+L + 2 ]+=phvg[L+2]*gete[k];
168             }
169         }
170         sortie=ArrayMath.add(sortie,gete[0],phv0,0);
171         int p0=sortie.length-phvd0.length;
172         sortie=ArrayMath.add(sortie,gete[dl0],phvd0,p0);
173         return(sortie);
174     }
175
176
177     public double[] evalScaling (int n0, int k, int j1) {
178         return(Cascades.evalScaling(this,n0,j1,k));
179     }
180
181     public double[] evalWavelet (int n0, int k, int j1) {
182         return(Cascades.evalWavelet(this,filtretype,n0,j1,k));
183         //return(Cascades.evalWavelet(this,n0,j1,k));
184
}
185
186 }
187
Popular Tags