Algorithm Alley by Steven Pigeon Listing One #include #include #include /***************************************************************************/ /* Those two routines implement the Mallat decimation algorithm. First */ /* phase computes the means, second phase the differences. All isO(2n), */ /* which is rather efficient. */ /* keeps ~20 bits of precision (out of 23), or a precision of about 1e-7 */ /***************************************************************************/ void FMT(const float source[], float destination[], int length) { float *t; int i,d,j; t = (float *)malloc(2*length*sizeof(float)); for (i=0;ilength-1; i--, j-=2, d--) destination[d] = t[j]-t[i]/2.0f; free(t); } /*******************************/ void iFMT(const float source[], float destination[], int length) { float *t; int i,d,p; t = (float *)malloc(2*length*sizeof(float)); t[2*length-2]=source[length-1]; for ( p=length-2, i=2*length-4 , d=2*length-2; i>=0; i-=2, d--, p--) { float t0 = t[d]/2; float s0 = source[p]; t[i] = t0 - s0; t[i+1] = t0 + s0; } for (i=0;i 3. */ /* Lonely coefficients are left as is, since we can't pair them correctly, */ /* but are put in the result vector. The precision is also about ~20 bits */ /* (out of 23) */ /***************************************************************************/ void FHT(const float source[], float destination[], int length) { int i,l; float *t = (float *)malloc(length*sizeof(float)); for (i=0;i