1 package JSci.maths.wavelet; 2 3 import JSci.maths.wavelet.*; 4 import JSci.maths.*; 5 6 12 public final class Sine extends MultiscaleFunction implements NumericalConstants, Cloneable { 13 14 private int n0; private int freq;private double normalisation; 15 16 20 public String toString() { 21 String ans=new String ("[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 ("The length paramenter "+N0+" must be positive"); 32 } 33 if((FREQ<0)||(FREQ>=N0)) { 34 throw new IllegalArgumentException ("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 45 public boolean equals(Object 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 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 79 public int dimension(int jfin) { 80 return(n0); 81 } 82 86 public int dimension() { 87 return(n0); 88 } 89 92 public Object clone() { 93 Sine s = (Sine)super.clone(); 94 s.n0=n0; 95 s.freq=freq; 96 return(s); 97 } 98 103 public double[] evaluate (int j) { 104 return(evaluate()); 105 } 106 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 135 public int getFilterType () { 136 return(n0); 137 } 138 } 139 | Popular Tags |