KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > Sine


1 package JSci.maths.wavelet;
2
3 import JSci.maths.wavelet.*;
4 import JSci.maths.*;
5
6 /**********************************************
7 * This class is used to be able to mix the wavelet
8 * and sine transforms. It is in fact a normalised
9 * sine.
10 * @author Daniel Lemire
11 *************************************************/

12 public final class Sine extends MultiscaleFunction implements NumericalConstants, Cloneable JavaDoc {
13
14         private int n0; private int freq;private double normalisation;
15
16   /*******************************
17   * Return a String representation
18   * of the object
19   ********************************/

20   public String JavaDoc toString() {
21     String JavaDoc ans=new String JavaDoc("[n0=");
22     ans.concat(Integer.toString(n0));
23     ans.concat("][freq=");
24     ans.concat(Integer.toString(freq));
25     ans.concat("]");
26     return(ans);
27   }
28
29   public Sine (int N0,int FREQ) {
30             if(N0<0) {
31                 throw new IllegalArgumentException JavaDoc("The length paramenter "+N0+" must be positive");
32             }
33             if((FREQ<0)||(FREQ>=N0)) {
34                 throw new IllegalArgumentException JavaDoc("The frequency parameter "+FREQ+" must be between "+0+" and "+(N0-1));
35             }
36             n0=N0;freq=FREQ;
37             normalisation=Math.sqrt(n0/2d);
38
39         }
40
41   /*****************************************
42   * Check if another object is equal to this
43   * Sine object
44   ******************************************/

45   public boolean equals(Object JavaDoc a) {
46     if((a!=null) && (a instanceof Sine)) {
47       Sine iv=(Sine)a;
48       return (this.dimension(0)==iv.dimension(0)) && (this.getFrequency()==iv.getFrequency());
49     }
50     return false;
51   }
52
53   public int getFrequency() {
54     return(freq);
55   }
56
57
58     /************************************************
59   * Return as an array the sampled values
60   * of the function
61     *************************************************/

62         public double[] evaluate() {
63             return(ArrayMath.scalarMultiply(1.0/normalisation,evaluate(n0,freq)));
64         }
65
66     private static double[] evaluate(int N0,int FREQ) {
67             double[] ans=new double[N0];
68             for(int k=0;k<ans.length;k++) {
69                 ans[k]=Math.sin(TWO_PI*k*FREQ/N0);
70             }
71             return(ans);
72     }
73
74   /*****************************************
75   * Tells you how many samples you'll get
76   * from this function (will not depend
77   * on the parameter)
78   ******************************************/

79     public int dimension(int jfin) {
80         return(n0);
81     }
82   /*****************************************
83   * Tells you how many samples you'll get
84   * from this function
85   ******************************************/

86     public int dimension() {
87         return(n0);
88     }
89   /********************************************
90   * Return a copy of this object
91   *********************************************/

92     public Object JavaDoc clone() {
93     Sine s = (Sine)super.clone();
94     s.n0=n0;
95     s.freq=freq;
96     return(s);
97     }
98     /************************************************
99   * Return as an array the sampled values
100   * of the function
101   * @param j number of iterations (doesn't do anything)
102     *************************************************/

103     public double[] evaluate (int j) {
104         return(evaluate());
105     }
106   /******************************************
107   * Compute the mass (integral)
108   * @param a left boundary of the interval
109   * @param b right boundary of the interval
110   * @param jfin number of iterations to consider
111   * (precision)
112   **********************************************/

113     public double mass(double a, double b, int jfin) {
114         double somme=0.0;
115         double[] values=evaluate(jfin);
116         for(int k=0;k<values.length;k++) {
117             somme+=values[k];
118         }
119         somme=somme/(values.length-1)*Math.abs(b-a);
120         return(somme);
121     }
122     /****************************************
123   * This method is used to compute
124   * how the number of scaling functions
125   * changes from on scale to the other.
126   * Basically, if you have k scaling
127   * function and a filter of type t, you'll
128   * have 2*k+t scaling functions at the
129   * next scale (dyadic case).
130   * Notice that this method assumes
131   * that one is working with the dyadic
132   * grid while the method "previousDimension"
133   * define in the interface "filter" doesn't.
134     ******************************************/

135     public int getFilterType () {
136         return(n0);
137     }
138 }
139
Popular Tags