KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > cdf2_4 > MultiSpline2_4


1
2 package JSci.maths.wavelet.cdf2_4;
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=2 and
11 * Ntilde=4 adapted to the interval
12 * by Deslauriers-Dubuc-Lemire
13 * @author Daniel Lemire
14 *****************************************/

15 public final class MultiSpline2_4 implements Filter {
16
17     public MultiSpline2_4() {}
18
19     // constantes pour le filtre passe-bas
20
static final double[] vg={1/2d,1d,1/2d};
21     static final double[] v0={1d,1/2d};
22
23     // constantes pour le filtre passe-hat
24
static final double[] og={3/128d,3/64d,-1/8d,-19/64d,45/64d,-19/64d,-1/8d,3/64d,3/128d};
25     static final double[] o0={-35/64d,875/1536d,-241/768d,-53/512d,41/384d,67/1536d,-5/256d,-5/512d};
26     static final double[] on0_1=ArrayMath.invert(o0);
27     static final double[] o1={15/64d,-45/512d,-105/256d,345/512d,-31/128d,-53/512d,9/256d,9/512d};
28     static final double[] on0_2=ArrayMath.invert(o1);
29
30
31     /****************************************
32   * This method return the number of "scaling"
33   * functions at the previous scale given a
34   * number of scaling functions. The answer
35   * is always smaller than the provided value
36   * (about half since this is a dyadic
37   * implementation). This relates to the same idea
38   * as the "Filter type". It is used by
39   * the interface "Filter".
40     *****************************************/

41     public int previousDimension (int k) {
42         int i=(int) Math.round((k+1)/2d);
43         if(2*i-1==k) {
44             return(i);
45         } else {
46             throw new IllegalScalingException("Even number of values presented to an odd Filter. Please change the number of values/iterations.");
47         }
48     }
49
50     /***************************************************
51     ****************************************************/

52     public double[] lowpass (double[] v, double[] param) {
53         return(lowpass(v));
54     }
55     /***************************************************
56     ****************************************************/

57     public double[] highpass (double[] v, double[] param) {
58         return(highpass(v));
59     }
60
61     /**************************************
62     ***************************************/

63     public double[] lowpass (double[] donnee) {
64         if(donnee.length<2) {
65             throw new IllegalScalingException("The array is not long enough : "+donnee.length+" < 2");
66         }
67         double[] sortie=new double[2*donnee.length-1];
68         for(int k=1;k<donnee.length-1;k++) {
69             sortie[2*k-1]+=donnee[k]*vg[0];
70             sortie[2*k]+=donnee[k]*vg[1];
71             sortie[2*k+1]+=donnee[k]*vg[2];
72         }
73         sortie[0]+=v0[0]*donnee[0];
74         sortie[1]+=v0[1]*donnee[0];
75         sortie[sortie.length-1]+=v0[0]*donnee[donnee.length-1];
76         sortie[sortie.length-2]+=v0[1]*donnee[donnee.length-1];
77         return(sortie);
78     }
79
80     /**************************************
81     ***************************************/

82     public double[] highpass(double[] v) {
83         int n0=v.length+1;
84         double[] ans=ArrayMath.scalarMultiplyFast(v[0],wavelet(n0,0).interpolate(0));
85         for(int k=1;k<v.length;k++) {
86             ans=ArrayMath.add(ans,ArrayMath.scalarMultiply(v[k],wavelet(n0,k).interpolate(0)));
87         }
88         return(ans);
89     }
90
91     /************************************
92     *************************************/

93     public static LinearSpline hat(int n0, int k) {
94         if((k<0)||(n0<0)||(k>=n0)) {
95             throw new IllegalArgumentException JavaDoc("Incorrect parameters : "+n0+", "+k+" !");
96         }
97         if(n0<CDF2_4.minlength) {
98             throw new IllegalScalingException(n0,CDF2_4.minlength);
99         }
100         double[] v=new double[n0];
101         v[k]=1;
102         return(new LinearSpline(v));
103     }
104
105     /************************************
106     *************************************/

107     public static LinearSpline scaling(int n0, int k) {
108         return(hat(n0,k));
109     }
110
111     /*************************************
112     **************************************/

113     public static LinearSpline wavelet(int n0, int k) {
114         if((k<0)||(n0<0)||(k>=n0-1)) {
115             throw new IllegalArgumentException JavaDoc("Incorrect parameters : "+n0+", "+k);
116         }
117         if(n0<CDF2_4.minlength) {
118             throw new IllegalScalingException(n0,CDF2_4.minlength);
119         }
120         double[] v=new double[2*n0-1];
121         if ((k>1)&&(k<n0-3)) {
122             v=ArrayMath.padding(v.length,2*k-4+1,og);
123         } else if (k==0) {
124             v=ArrayMath.padding(v.length,0,o0);
125         } else if (k==1) {
126             v=ArrayMath.padding(v.length,0,o1);
127         } else if (k==n0-2) {
128             v=ArrayMath.padding(v.length,v.length-on0_1.length,on0_1);
129         } else if (k==n0-3) {
130             v=ArrayMath.padding(v.length,v.length-on0_2.length,on0_2);
131         } else {
132             throw new IllegalArgumentException JavaDoc("Oups!");
133         }
134         return(new LinearSpline(v));
135     }
136 }
137
Popular Tags