KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > daubechies3 > Daubechies3


1
2 package JSci.maths.wavelet.daubechies3;
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 Daubechies3 extends Multiresolution implements Filter, NumericalConstants {
14     protected final static int filtretype=4;
15     protected final static int minlength=8;
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 Scaling3(n0,k));
35     }
36
37     public MultiscaleFunction dualScaling(int n0, int k) {
38         return(new Scaling3(n0,k));
39     }
40     public MultiscaleFunction primaryWavelet(int n0, int k) {
41         return(new Wavelet3(n0,k));
42     }
43     public MultiscaleFunction dualWavelet(int n0, int k) {
44         return(new Wavelet3(n0,k));
45     }
46
47   
48     final static double[] vgtemp={
49     .332670552950,
50     .806891509311,
51     .459877502118,
52     -.135011020010,
53     -.085441273882,
54     .035226291882};
55
56     final static double[] v0temp={
57     0.689047760315,
58     0.724715933318};
59
60     final static double[] v1temp={
61     0.0306457241755,
62     -0.0291374408035,
63     -0.986047279405,
64     0.161005005859};
65     final static double[] v2temp={
66     0.0172802631418,
67     -0.0164297845102,
68     0.00443452721664,
69     0.0208960300827,
70     -0.924034270866,
71     0.380966943247};
72     final static double[] v3temp={
73     0.027026368393,
74     -0.0256962180001,
75     0.0639688879804,
76     0.381971870809,
77     0.176750229211,
78     0.404677356783,
79     -0.747429432607,
80     0.308155135811};
81
82     final static double[] vd0temp={
83       0.889500699418,
84       0.456933808921};
85     final static double[] vd1temp={
86     - 0.198411021088,
87       0.386241373662,
88       0.832668382346,
89       0.343677222149};
90     final static double[] vd2temp={
91       0.0390630495665,
92     - 0.0760429831027,
93     - 0.143921176769,
94       0.456707890812,
95       0.807766275151,
96       0.33303120718};
97     final static double[] vd3temp={
98     - 0.000276799784313,
99       0.000538838660959,
100       0.0349752642807,
101     - 0.085504178774,
102     - 0.134969198046,
103       0.459895243878,
104       0.806892290508,
105       0.332670875027};
106
107
108
109
110     final static double[] vg=ArrayMath.scalarMultiply(SQRT2,vgtemp);
111     final static double[] vd0=ArrayMath.scalarMultiply(SQRT2,ArrayMath.invert(vd0temp));
112     final static double[] vd1=ArrayMath.scalarMultiply(SQRT2,ArrayMath.invert(vd1temp));
113     final static double[] vd2=ArrayMath.scalarMultiply(SQRT2,ArrayMath.invert(vd2temp));
114     final static double[] vd3=ArrayMath.scalarMultiply(SQRT2,ArrayMath.invert(vd3temp));
115     final static double[] v0=ArrayMath.scalarMultiply(SQRT2,v0temp);
116     final static double[] v1=ArrayMath.scalarMultiply(SQRT2,v1temp);
117     final static double[] v2=ArrayMath.scalarMultiply(SQRT2,v2temp);
118     final static double[] v3=ArrayMath.scalarMultiply(SQRT2,v3temp);
119
120     /********************************************
121     * On définit ici le filtre comme tel par le
122     * vecteur phvg (filtre passe-haut).
123     *********************************************/

124     final static double[] phvg=WaveletMath.lowToHigh(vgtemp);
125
126     final static double[] phv0={
127     0.720522830617,
128     -0.685061028561,
129     0.0259917491699,
130     -0.101939535681,
131     0.0200641216304,
132     -0.00827216838973};
133
134     final static double[] phv1={
135     0.0639675079235,
136     -0.0608192341872,
137     0.151405112504,
138     0.904072212264,
139     -0.0510574707719,
140     -0.18071490589,
141     0.315790060572,
142     -0.130196008824};
143
144     final static double[] phvd0temp={
145     -0.409742284317,
146     0.797634233593,
147     -0.419058128916,
148     -0.117669342504,
149     0.0741631890253,
150     0.0305764886814};
151
152     final static double[] phvd0=ArrayMath.invert(phvd0temp);
153
154     final static double[] phvd1temp={
155     -0.00261427398522,
156     0.00508913652903,
157     0.330328738376,
158     -0.807556085169,
159     0.460310974517,
160     0.13519444871,
161     -0.0854338960798,
162     -0.0352232501168};
163
164
165     final static double[] phvd1=ArrayMath.invert(phvd1temp);
166
167     /****************************************
168   * This method return the number of "scaling"
169   * functions at the previous scale given a
170   * number of scaling functions. The answer
171   * is always smaller than the provided value
172   * (about half since this is a dyadic
173   * implementation). This relates to the same idea
174   * as the "Filter type". It is used by
175   * the interface "Filter".
176     *****************************************/

177     public int previousDimension (int k) {
178         return(Cascades.previousDimension(filtretype,k));
179
180     }
181
182
183     public Daubechies3 () {}
184     /****************************************
185     * This is the implementation of the lowpass
186   * Filter. It is used by the interface
187   * "Filter". Lowpass filters are normalized
188   * so that they preserve constants away from
189   * the boundaries.
190     *****************************************/

191     public double[] lowpass (double[] v, double[] param) {
192         return(lowpass(v));
193     }
194     /****************************************
195     * This is the implementation of the highpass
196   * Filter. It is used by the interface
197   * "Filter". Highpass filters are normalized
198   * in order to get L2 orthonormality of the
199   * resulting wavelets (when it applies).
200   * See the class DiscreteHilbertSpace for
201   * an implementation of the L2 integration.
202     *****************************************/

203     public double[] highpass (double[] v, double[] param) {
204         return(highpass(v));
205     }
206     /****************************************
207     * This is the implementation of the lowpass
208   * Filter. It is used by the interface
209   * "Filter". Lowpass filters are normalized
210   * so that they preserve constants away from
211   * the boundaries.
212     *****************************************/

213     public double[] lowpass (double[] gete) {
214         if(gete.length<minlength) {
215             throw new IllegalScalingException("The array is not long enough : "+gete.length+" < "+minlength);
216         }
217         double[] sortie=new double[2*gete.length-filtretype];
218         int dl0=gete.length-1;
219         for(int k=4;k<=dl0-4;k++) {
220             for(int L=-3;L<3;L++){
221                 sortie[2*k+L-1]+=vg[L+3]*gete[k];
222             }
223         }
224         sortie=ArrayMath.add(sortie,gete[0],v0,0);
225         sortie=ArrayMath.add(sortie,gete[1],v1,0);
226         sortie=ArrayMath.add(sortie,gete[2],v2,0);
227         sortie=ArrayMath.add(sortie,gete[3],v3,0);
228         int p0=sortie.length-vd0.length;
229         int p1=sortie.length-vd1.length;
230         int p2=sortie.length-vd2.length;
231         int p3=sortie.length-vd3.length;
232         sortie=ArrayMath.add(sortie,gete[dl0],vd0,p0);
233         sortie=ArrayMath.add(sortie,gete[dl0-1],vd1,p1);
234         sortie=ArrayMath.add(sortie,gete[dl0-2],vd2,p2);
235         sortie=ArrayMath.add(sortie,gete[dl0-3],vd3,p3);
236         return(sortie);
237     }
238
239     /****************************************
240     * This is the implementation of the highpass
241   * Filter. It is used by the interface
242   * "Filter". Highpass filters are normalized
243   * in order to get L2 orthonormality of the
244   * resulting wavelets (when it applies).
245   * See the class DiscreteHilbertSpace for
246   * an implementation of the L2 integration.
247     *****************************************/

248     public double[] highpass(double[] gete) {
249         double[] sortie=new double[2*gete.length+filtretype];
250         int dl0=gete.length-1;
251         for(int k=2;k<=dl0-2;k++) {
252             for(int L=-3;L<3;L++){
253                 sortie[2*k+L + 3 ]+=phvg[L+3]*gete[k];
254             }
255         }
256         sortie=ArrayMath.add(sortie,gete[0],phv0,0);
257         int p0=sortie.length-phvd0.length;
258         sortie=ArrayMath.add(sortie,gete[dl0],phvd0,p0);
259         sortie=ArrayMath.add(sortie,gete[1],phv1,0);
260         int p1=sortie.length-phvd1.length;
261         sortie=ArrayMath.add(sortie,gete[dl0-1],phvd1,p1);
262
263         return(sortie);
264     }
265
266
267     public double[] evalScaling (int n0, int k, int j1) {
268         return(Cascades.evalScaling(this,n0,j1,k));
269     }
270
271     public double[] evalWavelet (int n0, int k, int j1) {
272         return(Cascades.evalWavelet(this,filtretype,n0,j1,k));
273     }
274
275 }
276
Popular Tags