/* convolution.c test ffts use for convolution */ /* 16 point, but must antialias using complex */ /* definition * f(t) = h(t) o g(t) = integral, T over range of t, of h(T)*g(t-T) dT * symmetric about 0 * f(t) = h(t) 0 g(t) = sum, T over range range of t, of h(T)*g(t-(max(t)/2-T)) * t from 0 to N-1 discrete * max(t)=N-1 */ #include #include #include "fftc.h" void print16c(char msg[], float a[]) { int i; printf("\n %s \n", msg); for(i=0; i<32; i=i+2) printf("%s[%d] = %g, %g\n", msg, i, a[i], a[i+1]); } void print16(char msg[], float a[]) { int i; printf("\n %s \n", msg); for(i=0; i<16; i++) printf("%s[%d] = %g \n", msg, i, a[i]); } int main(int argc, char * argv[]) { float ant[32]={0.00001, 0.0, 0.00005, 0.0, 0.0003, 0.0, 0.002, 0.0, 0.02, 0.0, 0.4, 0.0, 0.8, 0.0, 1.0, 0.0, 1.0, 0.0, 0.8, 0.0, 0.4, 0.0, 0.02, 0.0, 0.002, 0.0, 0.0003, 0.0, 0.00005, 0.0, 0.00001, 0.0}; float tgt[32]={0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; float A[32], B[32], C[32]; float aa[16] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; float bb[16] = {0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0}; float cc[16]; /* "long" way */ float Amean, Bmean, Csum, rCsum; int i, j; int N; printf("convolution.c \n"); N = 32; /* number of floats in 16 point complex fft */ for(i=0; i=16) continue; cc[i] = cc[i] + aa[j]*bb[i-(7-j)]; } } print16("cc", cc); return 0; } /* end convolution.c */