1 package JSci.maths.wavelet.splines; 2 3 import JSci.maths.wavelet.*; 4 import JSci.maths.*; 5 6 13 public class LinearSpline extends Spline implements Filter, Cloneable { 14 protected final static int filtretype=1; 15 private double[] vecteur; 16 static final double[] vg={1/2d,1d,1/2d}; 17 static final double[] v0={1d,1/2d}; 18 31 public int getFilterType () { 32 return(filtretype); 33 } 34 35 39 public String toString() { 40 return(ArrayMath.toString(vecteur)); 41 } 42 43 47 public boolean equals(Object a) { 48 if(a!=null && (a instanceof LinearSpline) && vecteur.length==((LinearSpline)a).dimension()) { 49 LinearSpline iv=(LinearSpline)a; 50 for(int i=0;i<vecteur.length;i++) { 51 if(vecteur[i]!=iv.getValue(i)) 52 return false; 53 } 54 return true; 55 } else 56 return false; 57 } 58 59 60 70 public int previousDimension (int k) { 71 int i=(int) Math.round((k+1)/2d); 72 if(2*i-1==k) { 73 return(i); 74 } else { 75 throw new IllegalArgumentException ("Even number of values into an odd Filter! Change the number of data values/of iterations."); 76 } 77 } 78 79 86 public double[] lowpass (double[] v, double[] param) { 87 return(lowpass(v)); 88 } 89 90 91 99 public double[] highpass (double[] v, double[] param) { 100 return(highpass(v)); 101 } 102 103 110 public double[] lowpass (double[] donnee) { 111 if(donnee.length<2) { 112 throw new IllegalArgumentException ("The array is not long enough : "+donnee.length+" < 2"); 113 } 114 double[] sortie=new double[2*donnee.length-1]; 115 for(int k=1;k<donnee.length-1;k++) { 116 sortie[2*k-1]+=donnee[k]*vg[0]; 117 sortie[2*k]+=donnee[k]*vg[1]; 118 sortie[2*k+1]+=donnee[k]*vg[2]; 119 } 120 sortie[0]+=v0[0]*donnee[0]; 121 sortie[1]+=v0[1]*donnee[0]; 122 sortie[sortie.length-1]+=v0[0]*donnee[donnee.length-1]; 123 sortie[sortie.length-2]+=v0[1]*donnee[donnee.length-1]; 124 return(sortie); 125 } 126 127 135 public double[] highpass (double[] donnee) { 136 return(lowpass(donnee)); 137 } 138 139 141 public LinearSpline(double[] v) { 142 vecteur=v; 143 } 144 145 146 148 public LinearSpline() { 149 } 150 153 public Object clone() { 154 LinearSpline sod=(LinearSpline) super.clone(); 155 if(vecteur!=null) 156 sod.vecteur=ArrayMath.copy(this.vecteur); 157 return(sod); 158 } 159 160 166 public double getValue(int i) { 167 if ((i<0) || (i>vecteur.length-1)) { 168 throw new IllegalArgumentException ("Incorrect parameter : "+i+", "+vecteur.length); 169 } 170 return(vecteur[i]); 171 } 172 173 179 public void setValue(int i, double d) { 180 if (i<0) { 181 throw new IllegalArgumentException ("The parameter must be positive: "+i); 182 } 183 vecteur[i]=d; 184 } 185 186 190 public void setValues(double[] v) { 191 vecteur=v; 192 } 193 194 198 public PiecewiseConstant derive() { 199 return(this.derive(0,1)); 200 } 201 202 208 public PiecewiseConstant derive(double a, double b) { 209 double[] v=new double[vecteur.length-1]; 210 for(int i=0;i<vecteur.length-1;i++) { 211 v[i]=(vecteur[i+1]-vecteur[i])*(vecteur.length-1)/Math.abs(b-a); 212 } 213 PiecewiseConstant d=new PiecewiseConstant(v); 214 return(d); 215 } 216 217 220 public int dimension () { 221 return(vecteur.length); 222 } 223 224 228 public int dimension(int j) { 229 return(Cascades.dimension(vecteur.length, j)); 230 } 231 232 239 public double[] interpolate(int j) { 240 if (j<0) { 241 throw new IllegalArgumentException ("This parameter must be postive : "+j); 242 } 243 return(Cascades.evaluation(this,j,vecteur)); 244 } 245 246 251 public double[] evaluate ( int j) { 252 return(interpolate(j)); 253 } 254 255 256 } 257 | Popular Tags |