KickJava   Java API By Example, From Geeks To Geeks.

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


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

15 public final class MultiSpline3_5 implements Filter {
16     public MultiSpline3_5() {}
17
18     static final double[] vg={1/4d, 3/4d, 3/4d, 1/4d};
19     static final double[] v0={3/4d, 1/4d};
20
21     // constantes pour le filtre passe-haut
22

23     static final double[] og={5/1024d, 15/1024d, -19/1024d, -97/1024d, 13/512d, 175/512d, -175/512d, -13/512d, 97/1024d, 19/1024d, -15/1024d, -5/1024d};
24     static final double[] o0={-7917/10240d, 2877/10240d, -26593/204800d, -1139/204800d, 3951/102400d, 53/20480d, -451/40960d, -453/204800d, 21/12800d, 7/12800d};
25     static final double[] o1={6237/10240d, -1197/10240d, -38927/204800d, 79779/204800d, -22911/102400d, -613/20480d, 1971/40960d, 2133/204800d, -81/12800d, -27/12800d};
26     static final double[] o2={-1405/2048d, 205/2048d, 5897/24576d, -2183/8192d, -813/4096d, 5455/12288d, -1395/8192d, -337/8192d, 9/512d, 3/512d};
27     static final double[] on0_1=ArrayMath.scalarMultiply(-1.0,ArrayMath.invert(o0));
28     static final double[] on0_2=ArrayMath.scalarMultiply(-1.0,ArrayMath.invert(o1));
29     static final double[] on0_3=ArrayMath.scalarMultiply(-1.0,ArrayMath.invert(o2));
30
31
32     /****************************************
33   * This method return the number of "scaling"
34   * functions at the previous scale given a
35   * number of scaling functions. The answer
36   * is always smaller than the provided value
37   * (about half since this is a dyadic
38   * implementation). This relates to the same idea
39   * as the "Filter type". It is used by
40   * the interface "Filter".
41     *****************************************/

42     public int previousDimension (int k) {
43         int i=(int) Math.round((k-2)/2d+2);
44         if(2*(i-2)+2==k) {
45             return(i);
46         } else {
47             throw new IllegalScalingException("Odd number of values into an even Filter. Please change the number of values/iterations: "+k);
48         }
49     }
50
51     /****************************************
52     * This is the implementation of the lowpass
53   * Filter. It is used by the interface
54   * "Filter". Lowpass filters are normalized
55   * so that they preserve constants away from
56   * the boundaries.
57     *****************************************/

58     public double[] lowpass (double[] v, double[] param) {
59         return(lowpass(v));
60     }
61     /****************************************
62     * This is the implementation of the highpass
63   * Filter. It is used by the interface
64   * "Filter". Highpass filters are normalized
65   * in order to get L2 orthonormality of the
66   * resulting wavelets (when it applies).
67   * See the class DiscreteHilbertSpace for
68   * an implementation of the L2 integration.
69     *****************************************/

70     public double[] highpass (double[] v, double[] param) {
71         return(highpass(v));
72     }
73     /****************************************
74     * This is the implementation of the lowpass
75   * Filter. It is used by the interface
76   * "Filter". Lowpass filters are normalized
77   * so that they preserve constants away from
78   * the boundaries.
79     *****************************************/

80     public double[] lowpass (double[] gete) {
81         if(gete.length<3) {
82             throw new IllegalScalingException("The array is not long enough : "+gete.length+" < 3");
83         }
84         double[] sortie=new double[2*gete.length-2];
85         for(int k=1;k<gete.length-1;k++) {
86             sortie[2*k-2]+=gete[k]*vg[0];
87             sortie[2*k-1]+=gete[k]*vg[1];
88             sortie[2*k]+=gete[k]*vg[2];
89             sortie[2*k+1]+=gete[k]*vg[3];
90         }
91         sortie[0]+=v0[0]*gete[0];
92         sortie[1]+=v0[1]*gete[0];
93         sortie[sortie.length-1]+=v0[0]*gete[gete.length-1];
94         sortie[sortie.length-2]+=v0[1]*gete[gete.length-1];
95         return(sortie);
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) {
107         int n0=v.length+2;
108         double[] ans=ArrayMath.scalarMultiplyFast(v[0],wavelet(n0,0).interpolate(0));
109         for(int k=1;k<v.length;k++) {
110             ans=ArrayMath.add(ans,ArrayMath.scalarMultiply(v[k],wavelet(n0,k).interpolate(0)));
111         }
112         return(ans);
113     }
114
115
116     /************************************
117     *************************************/

118     public static QuadraticSpline scaling(int n0, int k) {
119         if((k<0)||(n0<0)||(k>=n0)) {
120             throw new IllegalArgumentException JavaDoc("Incorrect parameters : "+n0+", "+k+" !");
121         }
122         if(n0<CDF3_5.minlength) {
123             throw new IllegalScalingException(n0,CDF3_5.minlength);
124         }
125         double[] v=new double[n0];
126         v[k]=1;
127         return(new QuadraticSpline(v));
128     }
129
130     /*************************************
131     **************************************/

132     public static QuadraticSpline wavelet(int n0, int k) {
133         if((k<0)||(n0<0)||(k>=n0-2)) {
134             throw new IllegalArgumentException JavaDoc("Incorrect parameters : "+n0+", "+k);
135         }
136         if(n0<CDF3_5.minlength) {
137             throw new IllegalScalingException(n0,CDF3_5.minlength);
138         }
139         double[] v=new double[2*n0-2];
140         if ((k>2)&&(k<n0-5)) {
141             v=ArrayMath.padding(v.length,2*k-4,og);
142         } else if (k==0) {
143             v=ArrayMath.padding(v.length,0,o0);
144         } else if (k==1) {
145             v=ArrayMath.padding(v.length,0,o1);
146         } else if (k==2) {
147             v=ArrayMath.padding(v.length,0,o2);
148         } else if (k==n0-3) {
149             v=ArrayMath.padding(v.length,v.length-on0_1.length,on0_1);
150         } else if (k==n0-4) {
151             v=ArrayMath.padding(v.length,v.length-on0_2.length,on0_2);
152         } else if (k==n0-5) {
153             v=ArrayMath.padding(v.length,v.length-on0_3.length,on0_3);
154         } else {
155             throw new IllegalArgumentException JavaDoc("Oups!");
156         }
157         return(new QuadraticSpline(v));
158     }
159 }
160
Popular Tags