1 package JSci.maths.wavelet.haar; 2 3 import JSci.maths.wavelet.FWT; 4 5 public class FastHaar extends FWT { 6 7 public FastHaar() { 8 } 9 10 static final float[] scale = {(float)(1.0/Math.sqrt(2)),(float)(1.0/Math.sqrt(2))}; 11 static final float[] wavelet = {-scale[1],scale[0]}; 12 13 private static void transform (float[] v,int last) { 14 float[] ans=new float[last]; 15 int half=last/2; 16 try { 17 for(int k=0;;k++) { 18 ans[k+half]=v[(2*k+0)]*wavelet[0]+v[(2*k+1)]*wavelet[1]; 19 ans[k]=v[(2*k+0)]*scale[0]+v[(2*k+1)]*scale[1]; 20 } 21 } catch (IndexOutOfBoundsException e) {} 22 System.arraycopy(ans,0,v,0,last); 23 } 24 25 28 public void transform (float[] v) { 29 int last; 30 for (last=v.length;last>2;last/=2) { 31 transform(v,last); 32 } 33 if(last!=2) 34 System.err.println("Careful! this should be a power of 2 : "+v.length); 35 } 36 37 public void invTransform(float[] v) { 38 int last; 39 for (last=2;2*last<=v.length;last*=2) { 40 invTransform(v,last); 41 } 42 if(last!=v.length) 43 System.err.println("Careful! this should be a power of 2 : "+v.length); 44 45 } 46 47 50 private static void invTransform (float[] v, int last) { 51 int ResultingLength=2*last; 52 float[] ans=new float[ResultingLength]; 53 try { 54 for(int k=0;;k++) { 55 ans[(2*k+1)]+=scale[1]*v[k]+wavelet[1]*v[k+last] ; 56 ans[(2*k+0)]+=scale[0]*v[k]+wavelet[0]*v[k+last] ; 57 } 58 } catch (IndexOutOfBoundsException e) {} 59 System.arraycopy(ans,0,v,0,ans.length); 60 } 61 62 } 63 | Popular Tags |