/* prog1p1.c -- Restoration of Analog Audio Recordings Written October 28, 2011 by Eric Olson for Math 761 This program makes use of the fast Fourier transform given in the file fft.c. The command gcc -o prog1p1 prog1p1.c fft.c -lm will compile this program in most POSIX/GNU environments. Please use a version of the GNU C compiler that supports native complex data types. */ #include #include #include #include #include #include #include #define N 262144 #define alpha 1.75 #define beta 0.5 #define sigma 0.0004 #define epsilon 0.000001 /* The filter kfunc specifies the loss of high frequencies and tape print through by means of the constants alpha, beta and sigma. */ double kfunc(double t){ double tm1=t; double tm2=t+0.5; return alpha*exp(-tm1*tm1/(2*sigma*sigma))/(sigma*sqrt(2*M_PI)) +beta*exp(-tm2*tm2/(4*sigma*sigma))/(sigma*sqrt(4*M_PI)); } void readsignal(complex double X[],char *p){ float buf[N]; int fd,i; printf("Reading %s...\n",p); if((fd=open(p,O_RDONLY))==-1){ fprintf(stderr,"Can't open %s for read!\n",p); exit(1); } if(read(fd,buf,sizeof(float)*N)!=sizeof(float)*N){ fprintf(stderr,"Error reading data from %s!\n",p); exit(2); } close(fd); for(i=0;iepsilon) W[i]/=Ki; else W[i]=0; } fft(W,N,-1); writesignal(W,"wtox.raw"); /* Compute the error in the recovered signal */ readsignal(X,"signalx.raw"); printf("\nThe error is E=%g\n",relerr(W,X)); exit(0); }