KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > haar > MultiSplineHaar


1 package JSci.maths.wavelet.haar;
2
3 import JSci.maths.*;
4 import JSci.maths.wavelet.splines.*;
5 import JSci.maths.wavelet.*;
6
7 /****************************************
8 * Haar Wavelets
9 * @author Daniel Lemire
10 *****************************************/

11 public final class MultiSplineHaar extends Multiresolution implements Filter, NumericalConstants {
12     protected final static int filtretype=0;
13     public MultiSplineHaar() {}
14
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     public MultiscaleFunction primaryScaling(int n0, int k) {
32         return(scaling(n0,k));
33     }
34
35     public MultiscaleFunction dualScaling(int n0, int k) {
36         return(scaling(n0,k));
37     }
38     public MultiscaleFunction primaryWavelet(int n0, int k) {
39         return(wavelet(n0,k));
40     }
41     public MultiscaleFunction dualWavelet(int n0, int k) {
42         return(wavelet(n0,k));
43     }
44     static final double[] vg={1d,1d};
45     static final double[] vog={1.0/SQRT2,-1.0/SQRT2};
46     /****************************************
47   * This method return the number of "scaling"
48   * functions at the previous scale given a
49   * number of scaling functions. The answer
50   * is always smaller than the provided value
51   * (about half since this is a dyadic
52   * implementation). This relates to the same idea
53   * as the "Filter type". It is used by
54   * the interface "Filter".
55     *****************************************/

56     public int previousDimension(int k) {
57         int i=(int) Math.round(k/2d);
58         if(2*i==k) {
59             return(i);
60         } else {
61             throw new IllegalScalingException("Odd number of values into an even Filter. Please change the number of values.");
62         }
63     }
64
65     /***************************************************
66     ****************************************************/

67     public double[] lowpass (double[] v, double[] param) {
68         return(lowpass(v));
69     }
70
71     /****************************************
72     * This is the implementation of the highpass
73   * Filter. It is used by the interface
74   * "Filter". Highpass filters are normalized
75   * in order to get L2 orthonormality of the
76   * resulting wavelets (when it applies).
77   * See the class DiscreteHilbertSpace for
78   * an implementation of the L2 integration.
79     *****************************************/

80     public double[] highpass (double[] v, double[] param) {
81         return(highpass(v));
82     }
83
84     /**************************************
85
86     ***************************************/

87     public double[] lowpass(double[] gete) {
88         if(gete.length<1) {
89             throw new IllegalArgumentException JavaDoc("The array is not long enough : "+gete.length+" < 1");
90         }
91         double[] sortie=new double[2*gete.length];
92         for(int k=0;k<gete.length;k++) {
93             sortie[2*k]+=gete[k]*vg[0];
94             sortie[2*k+1]+=gete[k]*vg[1];
95         }
96         return(sortie);
97     }
98     /****************************************
99     * This is the implementation of the highpass
100   * Filter. It is used by the interface
101   * "Filter". Highpass filters are normalized
102   * in order to get L2 orthonormality of the
103   * resulting wavelets (when it applies).
104   * See the class DiscreteHilbertSpace for
105   * an implementation of the L2 integration.
106     *****************************************/

107     public double[] highpass(double[] gete) {
108         if(gete.length<1) {
109             throw new IllegalArgumentException JavaDoc("The array is not long enough : "+gete.length+" < 1");
110         }
111         double[] sortie=new double[2*gete.length];
112         for(int k=0;k<gete.length;k++) {
113             sortie[2*k]+=gete[k]*vog[0];
114             sortie[2*k+1]+=gete[k]*vog[1];
115         }
116         return(sortie);
117     }
118
119
120     /************************************
121     *************************************/

122     public static PiecewiseConstant scaling(int n0, int k) {
123         if((k<0)||(n0<0)||(k>=n0)) {
124             throw new IllegalArgumentException JavaDoc("Incorrect parameters : "+n0+", "+k);
125         }
126         double[] v=new double[n0];
127         v[k]=1;
128         return(new PiecewiseConstant(v));
129     }
130
131     /*************************************
132     **************************************/

133     public static PiecewiseConstant wavelet(int n0, int k) {
134         if((k<0)||(n0<0)||(k>=n0)) {
135             throw new IllegalArgumentException JavaDoc("Incorrect parameters : "+n0+", "+k);
136         }
137         double[] v=new double[2*n0];
138         v[2*k]=vog[0];
139         v[2*k+1]=vog[1];
140         return(new PiecewiseConstant(v));
141     }
142 }
143
Popular Tags