1 2 package JSci.maths.wavelet; 3 4 import JSci.maths.*; 5 6 11 public final class Cascades extends AbstractMath { 12 private Cascades(){} 13 14 23 public static int previousDimension (int filtretype, int k) { 24 int i=(int) Math.round((k+filtretype)/2d); 25 if(2*i-filtretype==k) { 26 return(i); 27 } else { 28 if(2*Math.round(k/2d)==k) { 29 throw new IllegalScalingException("Odd number of values into an even filter! Change the number of values/iterations: "+k); 30 } else { 31 throw new IllegalScalingException("Even number of values into an odd filter! Change the number of values/iterations: "+k); 32 } 33 } 34 } 35 36 public static double[] evalScaling (Filter filtre,int n0, int j1, int k) { 37 if (j1>20) { 38 throw new IllegalArgumentException ("Too many iterations : "+j1); 39 } 40 if(n0<=0) { 41 throw new IllegalArgumentException ("Must have a positive number of scaling functions : "+n0+" < 0."); 42 } 43 double[] init=new double[n0]; 44 if((k>=init.length)||(k<0)) { 45 throw new IllegalArgumentException ("There are "+init.length+" scaling functions going from 0 to "+(init.length-1)+" and you are trying to get the "+k+"th function."); 46 47 } 48 init[k]=1; 49 return(evaluation(filtre, j1, init)); 50 } 51 52 53 public static double[] evalWavelet (Filter filtre, int filtretype, int n0, int j1, int k) { 54 if (j1>20) { 55 throw new IllegalArgumentException ("Too many iterations : "+j1); 56 } 57 if(n0-filtretype<=0) { 58 throw new IllegalArgumentException ("With "+n0+" scaling functions and a filter of type "+filtretype+", you are left with no wavelets. Please change the number of scaling functions, the multiresolution or the number of iterations"); 59 } 60 double[] init=new double[n0-filtretype]; 61 if((k>=init.length)||(k<0)) { 62 throw new IllegalArgumentException ("There are "+init.length+" wavelets going from 0 to "+(init.length-1)+" and you are trying to get to the "+k+"th wavelet."); 63 } 64 init[k]=1; 65 double[] filtreWavelet=filtre.highpass(init); 66 return(evaluation(filtre,j1,filtreWavelet)); 67 } 68 69 public static double[] evalWavelet (Filter filtre,int n0, int j1, int k) { 70 return(evalWavelet(filtre,1,n0,j1,k)); 71 } 72 73 public static double[] evalWaveletHaar (Filter filtre,int n0, int j1, int k) { 74 return(evalWavelet(filtre,0,n0,j1,k)); 75 } 76 77 public static double[] evalWaveletQuadratic (Filter filtre, int n0, int j1, int k) { 78 return(evalWavelet(filtre,2,n0,j1,k)); 79 } 80 81 public static int PowerOf2(int pwrOf2) { 82 if(pwrOf2<0) { 83 throw new IllegalArgumentException ("This parametre must be positive : "+pwrOf2+" < 0"); 84 } 85 int reponse=1; 86 for(int i=pwrOf2;i>0;i--) { 87 reponse=reponse*2; 88 } 89 return(reponse); 90 } 91 92 93 97 public static double[] oversample(double data[]) { 98 double answer[]=new double[2*data.length-1]; 99 for(int i=0;i<data.length-1;i++) { 100 answer[2*i]=data[i]; 101 } 102 answer[2*data.length-2]=data[data.length-1]; 103 return answer; 104 } 105 106 110 public static double[] doublesample(double data[]) { 111 int Nombre=data.length; 112 double answer[]=new double[2*Nombre]; 113 for(int i=0;i<Nombre;i++) { 114 answer[2*i+1]=data[i]; 115 } 116 return answer; 117 } 118 122 public static double[] supersample(double data[]) { 123 int Nombre=data.length; 124 double answer[]=new double[2*Nombre+1]; 125 for(int i=0;i<Nombre;i++) { 126 answer[2*i+1]=data[i]; 127 } 128 return answer; 129 } 130 134 public static double[] quadraticOversample( double[] v) { 135 double[] ans=new double[2*v.length-2]; 136 ans[0]=v[0]; 137 ans[ans.length-1]=v[v.length-1]; 138 for(int k=1;k<v.length-1;k++) { 139 ans[2*k-1]=v[k]; 140 } 141 return(ans); 142 } 143 152 public static int dimension(int n0, int jfin, int filtertype) { 153 return(PowerOf2(jfin)*(n0-filtertype)+filtertype); 154 155 } 156 157 165 public static int dimension(int n0, int jfin) { 166 return(Cascades.PowerOf2(jfin)*(n0-1)+1); 167 } 168 176 public static int dimensionHaar(int n0, int jfin) { 177 return(Cascades.PowerOf2(jfin)*(n0)); 178 } 179 180 public static double[] evaluation (Filter filtre, int j1, double[] init) { 181 if (j1<0) { 182 throw new IllegalArgumentException ("Incorrect parameters : "+j1+" < 0 "); 183 } 184 if (j1>20) { 185 throw new IllegalArgumentException ("Excessive number of iterations: "+j1); 186 } 187 double[] data=init; 188 for (int j=0;j<j1;j++){ 189 data=filtre.lowpass(data); 190 } 191 return(data); 192 } 193 194 } 195 | Popular Tags |