1 2 package JSci.maths.wavelet.cdf3_5; 3 4 import JSci.maths.*; 5 import JSci.maths.wavelet.splines.*; 6 import JSci.maths.wavelet.*; 7 8 15 public final class MultiSpline3_5 implements Filter { 16 public MultiSpline3_5() {} 17 18 static final double[] vg={1/4d, 3/4d, 3/4d, 1/4d}; 19 static final double[] v0={3/4d, 1/4d}; 20 21 23 static final double[] og={5/1024d, 15/1024d, -19/1024d, -97/1024d, 13/512d, 175/512d, -175/512d, -13/512d, 97/1024d, 19/1024d, -15/1024d, -5/1024d}; 24 static final double[] o0={-7917/10240d, 2877/10240d, -26593/204800d, -1139/204800d, 3951/102400d, 53/20480d, -451/40960d, -453/204800d, 21/12800d, 7/12800d}; 25 static final double[] o1={6237/10240d, -1197/10240d, -38927/204800d, 79779/204800d, -22911/102400d, -613/20480d, 1971/40960d, 2133/204800d, -81/12800d, -27/12800d}; 26 static final double[] o2={-1405/2048d, 205/2048d, 5897/24576d, -2183/8192d, -813/4096d, 5455/12288d, -1395/8192d, -337/8192d, 9/512d, 3/512d}; 27 static final double[] on0_1=ArrayMath.scalarMultiply(-1.0,ArrayMath.invert(o0)); 28 static final double[] on0_2=ArrayMath.scalarMultiply(-1.0,ArrayMath.invert(o1)); 29 static final double[] on0_3=ArrayMath.scalarMultiply(-1.0,ArrayMath.invert(o2)); 30 31 32 42 public int previousDimension (int k) { 43 int i=(int) Math.round((k-2)/2d+2); 44 if(2*(i-2)+2==k) { 45 return(i); 46 } else { 47 throw new IllegalScalingException("Odd number of values into an even Filter. Please change the number of values/iterations: "+k); 48 } 49 } 50 51 58 public double[] lowpass (double[] v, double[] param) { 59 return(lowpass(v)); 60 } 61 70 public double[] highpass (double[] v, double[] param) { 71 return(highpass(v)); 72 } 73 80 public double[] lowpass (double[] gete) { 81 if(gete.length<3) { 82 throw new IllegalScalingException("The array is not long enough : "+gete.length+" < 3"); 83 } 84 double[] sortie=new double[2*gete.length-2]; 85 for(int k=1;k<gete.length-1;k++) { 86 sortie[2*k-2]+=gete[k]*vg[0]; 87 sortie[2*k-1]+=gete[k]*vg[1]; 88 sortie[2*k]+=gete[k]*vg[2]; 89 sortie[2*k+1]+=gete[k]*vg[3]; 90 } 91 sortie[0]+=v0[0]*gete[0]; 92 sortie[1]+=v0[1]*gete[0]; 93 sortie[sortie.length-1]+=v0[0]*gete[gete.length-1]; 94 sortie[sortie.length-2]+=v0[1]*gete[gete.length-1]; 95 return(sortie); 96 } 97 106 public double[] highpass(double[] v) { 107 int n0=v.length+2; 108 double[] ans=ArrayMath.scalarMultiplyFast(v[0],wavelet(n0,0).interpolate(0)); 109 for(int k=1;k<v.length;k++) { 110 ans=ArrayMath.add(ans,ArrayMath.scalarMultiply(v[k],wavelet(n0,k).interpolate(0))); 111 } 112 return(ans); 113 } 114 115 116 118 public static QuadraticSpline scaling(int n0, int k) { 119 if((k<0)||(n0<0)||(k>=n0)) { 120 throw new IllegalArgumentException ("Incorrect parameters : "+n0+", "+k+" !"); 121 } 122 if(n0<CDF3_5.minlength) { 123 throw new IllegalScalingException(n0,CDF3_5.minlength); 124 } 125 double[] v=new double[n0]; 126 v[k]=1; 127 return(new QuadraticSpline(v)); 128 } 129 130 132 public static QuadraticSpline wavelet(int n0, int k) { 133 if((k<0)||(n0<0)||(k>=n0-2)) { 134 throw new IllegalArgumentException ("Incorrect parameters : "+n0+", "+k); 135 } 136 if(n0<CDF3_5.minlength) { 137 throw new IllegalScalingException(n0,CDF3_5.minlength); 138 } 139 double[] v=new double[2*n0-2]; 140 if ((k>2)&&(k<n0-5)) { 141 v=ArrayMath.padding(v.length,2*k-4,og); 142 } else if (k==0) { 143 v=ArrayMath.padding(v.length,0,o0); 144 } else if (k==1) { 145 v=ArrayMath.padding(v.length,0,o1); 146 } else if (k==2) { 147 v=ArrayMath.padding(v.length,0,o2); 148 } else if (k==n0-3) { 149 v=ArrayMath.padding(v.length,v.length-on0_1.length,on0_1); 150 } else if (k==n0-4) { 151 v=ArrayMath.padding(v.length,v.length-on0_2.length,on0_2); 152 } else if (k==n0-5) { 153 v=ArrayMath.padding(v.length,v.length-on0_3.length,on0_3); 154 } else { 155 throw new IllegalArgumentException ("Oups!"); 156 } 157 return(new QuadraticSpline(v)); 158 } 159 } 160 | Popular Tags |