1 package JSci.maths.wavelet.symmlet8; 2 3 import JSci.maths.wavelet.FWT; 4 5 16 public final class FastSymmlet8 extends FWT { 17 18 public FastSymmlet8() { 19 } 20 21 static final float[] scale = {0.0322231006040782f, 22 -0.0126039672622638f, 23 -0.0992195435769564f, 24 0.297857795605605f, 25 0.803738751805386f, 26 0.497618667632563f, 27 -0.0296355276459604f, 28 -0.0757657147893567f}; 29 static final float[] wavelet = {-scale[7],scale[6],-scale[5],scale[4],-scale[3],scale[2],-scale[1],scale[0]}; 30 31 public static void transform (float[] v,int last) { 32 float[] ans=new float[last]; 33 final int half=last/2; 34 try { 35 for(int k=0;;k++) { 36 ans[k+half]=v[(2*k+0)]*wavelet[0]+v[(2*k+1)]*wavelet[1]+v[(2*k+2)]*wavelet[2]+v[(2*k+3)]*wavelet[3]+v[(2*k+4)]*wavelet[4]+v[(2*k+5)]*wavelet[5]+v[(2*k+6)]*wavelet[6]+v[(2*k+7)]*wavelet[7]; 37 ans[k]=v[(2*k+0)]*scale[0]+v[(2*k+1)]*scale[1]+v[(2*k+2)]*scale[2]+v[(2*k+3)]*scale[3]+v[(2*k+4)]*scale[4]+v[(2*k+5)]*scale[5]+v[(2*k+6)]*scale[6]+v[(2*k+7)]*scale[7]; 38 } 39 } catch (IndexOutOfBoundsException e) {} 40 ans[last-3]=v[last-6]*wavelet[0]+v[last-5]*wavelet[1]+v[last-4]*wavelet[2]+v[last-3]*wavelet[3]+v[last-2]*wavelet[4]+v[last-1]*wavelet[5]+v[0]*wavelet[6]+v[1]*wavelet[7]; 41 ans[half-3]=v[last-6]*scale[0]+v[last-5]*scale[1]+v[last-4]*scale[2]+v[last-3]*scale[3]+v[last-2]*scale[4]+v[last-1]*scale[5]+v[0]*scale[6]+v[1]*scale[7]; 42 ans[last-2]=v[last-4]*wavelet[0]+v[last-3]*wavelet[1]+v[last-2]*wavelet[2]+v[last-1]*wavelet[3]+v[0]*wavelet[4]+v[1]*wavelet[5]+v[2]*wavelet[6]+v[3]*wavelet[7]; 43 ans[half-2]=v[last-4]*scale[0]+v[last-3]*scale[1]+v[last-2]*scale[2]+v[last-1]*scale[3]+v[0]*scale[4]+v[1]*scale[5]+v[2]*scale[6]+v[3]*scale[7]; 44 ans[last-1]=v[last-2]*wavelet[0]+v[last-1]*wavelet[1]+v[0]*wavelet[2]+v[1]*wavelet[3]+v[2]*wavelet[4]+v[3]*wavelet[5]+v[4]*wavelet[6]+v[5]*wavelet[7]; 45 ans[half-1]=v[last-2]*scale[0]+v[last-1]*scale[1]+v[0]*scale[2]+v[1]*scale[3]+v[2]*scale[4]+v[3]*scale[5]+v[4]*scale[6]+v[5]*scale[7]; 46 System.arraycopy(ans,0,v,0,last); 47 } 48 49 public void transform (float[] v) { 50 int last; 51 for (last=v.length;last>8;last/=2) { 52 transform(v,last); 53 } 54 if(last!=8) 55 System.err.println("Careful! this should be a power of 2 : "+v.length); 56 } 57 58 public void invTransform(float[] v) { 59 int last; 60 for (last=8;2*last<=v.length;last*=2) { 61 invTransform(v,last); 62 } 63 if(last!=v.length) 64 System.err.println("Careful! this should be a power of 2 : "+v.length); 65 } 66 67 public static void invTransform (float[] v, int last) { 68 final int ResultingLength=2*last; 69 float[] ans=new float[ResultingLength]; 70 try { 71 for(int k=0;;k++) { 72 ans[(2*k+7)]+=scale[7]*v[k]+wavelet[7]*v[k+last] ; 73 ans[(2*k+6)]+=scale[6]*v[k]+wavelet[6]*v[k+last] ; 74 ans[(2*k+5)]+=scale[5]*v[k]+wavelet[5]*v[k+last] ; 75 ans[(2*k+4)]+=scale[4]*v[k]+wavelet[4]*v[k+last] ; 76 ans[(2*k+3)]+=scale[3]*v[k]+wavelet[3]*v[k+last] ; 77 ans[(2*k+2)]+=scale[2]*v[k]+wavelet[2]*v[k+last] ; 78 ans[(2*k+1)]+=scale[1]*v[k]+wavelet[1]*v[k+last] ; 79 ans[(2*k+0)]+=scale[0]*v[k]+wavelet[0]*v[k+last] ; 80 } 81 } catch (IndexOutOfBoundsException e) {} 82 ans[ResultingLength-6]+=scale[0]*v[last-3]+wavelet[0]*v[ResultingLength-3] ; 83 ans[ResultingLength-5]+=scale[1]*v[last-3]+wavelet[1]*v[ResultingLength-3] ; 84 ans[ResultingLength-4]+=scale[2]*v[last-3]+wavelet[2]*v[ResultingLength-3] ; 85 ans[ResultingLength-3]+=scale[3]*v[last-3]+wavelet[3]*v[ResultingLength-3] ; 86 ans[ResultingLength-2]+=scale[4]*v[last-3]+wavelet[4]*v[ResultingLength-3] ; 87 ans[ResultingLength-1]+=scale[5]*v[last-3]+wavelet[5]*v[ResultingLength-3] ; 88 ans[0]+=scale[6]*v[last-3]+wavelet[6]*v[ResultingLength-3] ; 89 ans[1]+=scale[7]*v[last-3]+wavelet[7]*v[ResultingLength-3] ; 90 ans[ResultingLength-4]+=scale[0]*v[last-2]+wavelet[0]*v[ResultingLength-2] ; 91 ans[ResultingLength-3]+=scale[1]*v[last-2]+wavelet[1]*v[ResultingLength-2] ; 92 ans[ResultingLength-2]+=scale[2]*v[last-2]+wavelet[2]*v[ResultingLength-2] ; 93 ans[ResultingLength-1]+=scale[3]*v[last-2]+wavelet[3]*v[ResultingLength-2] ; 94 ans[0]+=scale[4]*v[last-2]+wavelet[4]*v[ResultingLength-2] ; 95 ans[1]+=scale[5]*v[last-2]+wavelet[5]*v[ResultingLength-2] ; 96 ans[2]+=scale[6]*v[last-2]+wavelet[6]*v[ResultingLength-2] ; 97 ans[3]+=scale[7]*v[last-2]+wavelet[7]*v[ResultingLength-2] ; 98 ans[ResultingLength-2]+=scale[0]*v[last-1]+wavelet[0]*v[ResultingLength-1] ; 99 ans[ResultingLength-1]+=scale[1]*v[last-1]+wavelet[1]*v[ResultingLength-1] ; 100 ans[0]+=scale[2]*v[last-1]+wavelet[2]*v[ResultingLength-1] ; 101 ans[1]+=scale[3]*v[last-1]+wavelet[3]*v[ResultingLength-1] ; 102 ans[2]+=scale[4]*v[last-1]+wavelet[4]*v[ResultingLength-1] ; 103 ans[3]+=scale[5]*v[last-1]+wavelet[5]*v[ResultingLength-1] ; 104 ans[4]+=scale[6]*v[last-1]+wavelet[6]*v[ResultingLength-1] ; 105 ans[5]+=scale[7]*v[last-1]+wavelet[7]*v[ResultingLength-1] ; 106 System.arraycopy(ans,0,v,0,ans.length); 107 } 108 } 109 110
| Popular Tags
|