1 2 package JSci.maths.wavelet; 3 4 import JSci.maths.*; 5 6 12 public final class Cosine extends MultiscaleFunction implements NumericalConstants, Cloneable { 13 private int n0; private int freq;private double normalisation; 14 double tol=Double.MIN_VALUE; 15 19 public String toString() { 20 String ans=new String ("[n0="); 21 ans.concat(Integer.toString(n0)); 22 ans.concat("][freq="); 23 ans.concat(Integer.toString(freq)); 24 ans.concat("]"); 25 return(ans); 26 } 27 28 32 public boolean equals(Object a) { 33 if((a!=null) && (a instanceof Cosine)) { 34 Cosine iv=(Cosine)a; 35 return (this.dimension(0)==iv.dimension(0)) && (this.getFrequency()==iv.getFrequency()); 36 } 37 return false; 38 } 39 40 public int getFrequency() { 41 return(freq); 42 } 43 44 public Cosine (int N0,int FREQ) { 45 if(N0<0) { 46 throw new IllegalArgumentException ("The length paramenter "+n0+" must be positive"); 47 } 48 if((FREQ<0)||(FREQ>=N0)) { 49 throw new IllegalArgumentException ("The frequency parameter "+FREQ+" must be between "+0+" and "+(N0-1)); 50 } 51 n0=N0;freq=FREQ; 52 normalisation=Math.sqrt(n0/2d); 53 if((2*freq==n0)||(freq==0)) { 54 normalisation*=SQRT2; 55 } 56 } 57 61 public double[] evaluate() { 62 return(ArrayMath.scalarMultiply(1/normalisation,evaluate(n0,freq))); 63 } 64 65 private static double[] evaluate(int N0,int FREQ) { 66 double[] ans=new double[N0]; 67 for(int k=0;k<ans.length;k++) { 68 ans[k]=Math.cos(TWO_PI*k*FREQ/N0); 69 } 70 return(ans); 71 } 72 77 public int dimension(int jfin) { 78 return(n0); 79 } 80 84 public int dimension() { 85 return(n0); 86 } 87 90 public Object clone() { 91 Cosine c = (Cosine)super.clone(); 92 c.n0=n0; 93 c.freq=freq; 94 return(c); 95 } 96 101 public double[] evaluate (int j) { 102 return(evaluate()); 103 } 104 111 public double mass(double a, double b, int jfin) { 112 double somme=0; 113 double[] values=evaluate(jfin); 114 for(int k=0;k<values.length;k++) { 115 somme+=values[k]; 116 } 117 somme=somme/(values.length-1)*Math.abs(b-a); 118 return(somme); 119 } 120 133 public int getFilterType () { 134 return(n0); 135 } 136 } 137 138 | Popular Tags |