/* Discrete Fast Hartley Transform based upon BASIC code in 2nd revised edition of R. N. Bracewell's "The Fourier Transform and its Applications" (McGraw-Hill,1986). various modifications have been made to reduce storage required (transform is done in place, unlike Bracewell) and reduce computation (e.g., cos and sin only computed for n4+1 values, not n as in Bracewell). from Handbook of C tools for Scientists and Engineers by L. Baker */ #define min(a,b) (((a)<(b))? (a): (b)) #define max(a,b) (((a)>(b))? (a): (b)) #define abs(x) ((x)? (x):-(x)) #define DOFOR(i,to) for(i=0;i>1; i++; } return(i); } #define twopi 6.283185307 int cols,logn,n2,n4,log1; fhtinit(c,s,m,n,columns) int n,m[],columns; double c[],s[]; { int i,log2(),l; double cos(),sin(),con,angl; cols=columns; con=twopi/n; m[0]=1; logn=log2(n);log1=logn-1; n2=n>>1;n4=n2>>1; DOFOR(i,logn) { m[i+1]=(m[i])<<1; } ; angl=0.; DOFOR(i,n4+1) {c[i]=cos(angl);s[i]=sin(angl); angl+=con; } return; } fht(f,r,x,c,s,m,n) int n,m[]; double x[],r[],c[],s[],f[]; { double temp,temp2,temp3,temp4,temp1,invn; int t,u,i,j,k,l,l1,d,e,ss,so,s2,exponent,p; invn=1./n; /*reorder-(i.e.,permute)*/ if(logn>1) { j=-1;i=-1; do { do{ i++; k=logn; do { k--; j-=m[k]; }while(j>=-1); j+=m[k+1]; }while(i<=j); temp=f[i+1]; f[i+1]= f[j+1]; f[j+1]=temp; } while(i2) { ss=4; u=log1; for(l=2;l