1 2 package JSci.maths.wavelet.cdf2_4; 3 4 import JSci.maths.wavelet.*; 5 import JSci.maths.*; 6 7 14 public final class CDF2_4 extends Multiresolution implements Filter { 15 protected final static int filtretype=1; 16 protected final static int minlength=5; 17 30 public int getFilterType () { 31 return(filtretype); 32 } 33 34 public MultiscaleFunction primaryScaling(int n0, int k) { 35 return(MultiSpline2_4.scaling(n0,k)); 36 } 37 38 public MultiscaleFunction dualScaling(int n0, int k) { 39 return(new DualScaling2_4(n0,k)); 40 } 41 public MultiscaleFunction primaryWavelet(int n0, int k) { 42 return(MultiSpline2_4.wavelet(n0,k)); 43 } 44 public MultiscaleFunction dualWavelet(int n0, int k) { 45 return(new DualWavelet2_4(n0,k)); 46 } 47 48 50 final static double[] vg={3/64d,-3/32d,-1/4d,19/32d,45/32d,19/32d,-1/4d,-3/32d,3/64d}; 51 final static double[] v3={-5/256d,5/128d,1/64d,-9/128d,-67/256d,19/32d,45/32d,19/32d,-1/4d,-3/32d,3/64d}; 52 final static double[] v2={41/384d,-41/192d,-13/96d,31/64d,187/128d,19/32d,-1/4d,-3/32d,3/64d}; 53 final static double[] v1={-241/768d,241/384d,245/192d,105/128d,-93/256d,-3/32d,3/64d}; 54 final static double[] v0={93/64d,35/32d,-5/16d,-15/32d,15/64d}; 55 final static double[] vd0=ArrayMath.invert(v0); 56 final static double[] vd1=ArrayMath.invert(v1); 57 final static double[] vd2=ArrayMath.invert(v2); 58 final static double[] vd3=ArrayMath.invert(v3); 59 61 final static double[] phvg={-1/2d,1d,-1/2d}; 62 final static double[] phv0={1d,-1/2d}; 63 64 74 public int previousDimension (int k) { 75 int i=(int) Math.round((k+1)/2d); 76 if(2*i-1==k) { 77 return(i); 78 } else { 79 throw new IllegalScalingException("Even number of values into an odd Filter! Change the number of iterations/values."); 80 } 81 } 82 83 84 public CDF2_4 () {} 85 92 public double[] lowpass (double[] v, double[] param) { 93 return(lowpass(v)); 94 } 95 104 public double[] highpass (double[] v, double[] param) { 105 return(highpass(v)); 106 } 107 114 public double[] lowpass (double[] gete) { 115 if(gete.length<8) { 116 throw new IllegalScalingException("The array is not long enough : "+gete.length+" < 8"); 117 } 118 double[] sortie=new double[2*gete.length-1]; 119 int dl0=gete.length-1; 120 for(int k=4;k<=dl0-4;k++) { 121 for(int L=-4;L<=4;L++){ 122 sortie[2*k+L]+=vg[L+4]*gete[k]; 123 } 124 } 125 sortie=ArrayMath.add(sortie,gete[0],v0,0); 126 sortie=ArrayMath.add(sortie,gete[1],v1,0); 127 sortie=ArrayMath.add(sortie,gete[2],v2,0); 128 sortie=ArrayMath.add(sortie,gete[3],v3,0); 129 int p0=sortie.length-vd0.length; 130 int p1=sortie.length-vd1.length; 131 int p2=sortie.length-vd2.length; 132 int p3=sortie.length-vd3.length; 133 sortie=ArrayMath.add(sortie,gete[dl0],vd0,p0); 134 sortie=ArrayMath.add(sortie,gete[dl0-1],vd1,p1); 135 sortie=ArrayMath.add(sortie,gete[dl0-2],vd2,p2); 136 sortie=ArrayMath.add(sortie,gete[dl0-3],vd3,p3); 137 return(sortie); 138 } 139 140 149 public double[] highpass(double[] v) { 150 if(v.length<2) { 151 throw new IllegalScalingException("The array is not long enough : "+v.length+" < 2"); 152 } 153 double[] data=Cascades.supersample(v); 154 int dl=data.length-1; 155 double[] sortie=new double[data.length]; 156 158 for(int k=1;k<=dl-1;k++) { 159 sortie[k]=ArrayMath.scalarProduct(ArrayMath.extract(k-1,k+1,data),phvg); 160 } 161 sortie[0]=ArrayMath.scalarProduct(ArrayMath.extract(0,1,data),phv0); 162 sortie[dl]=ArrayMath.scalarProduct(ArrayMath.extract(dl,dl-1,data),phv0); 163 return(sortie); 164 } 165 166 168 public double[] evalScaling (int n0, int k, int j1) { 169 return(Cascades.evalScaling(this,n0,j1,k)); 170 } 171 172 175 public double[] evalWavelet (int n0, int k, int j1) { 176 return(Cascades.evalWavelet(this,n0,j1,k)); 177 } 178 179 } 180 | Popular Tags |