bpmdsp/gaussian_filter_coeffs.c

Go to the documentation of this file.
00001 
00006 #include "bpm_dsp.h"
00007 
00008 int gaussian_filter_coeffs( filter_t *f ) {
00009 
00010   // implements the calculation of the gaussian filter coefficients
00011   // into the filter_t structure, the filter is implemented as a
00012   // non-causal FIR filter, in order to mimic the yury style filter
00013   // from the original ddc routines. Don't bother about the zero
00014   // calculation, just spit out the coefficients...
00015   int i = 0;
00016   double bw = 0.;
00017   char msg[80];
00018 
00019   if ( f->options & GAUSSIAN_SIGMA_BW ) {
00020     // f1 is frequency of the gaussian sigma bandwidth
00021     bw = f->f1; 
00022   } else {
00023     // f1 is frequency of -3dB bandwidth (default !!)
00024     bw = sqrt(SQR(f->f1)/(-2.*log(pow(10.,-3./20.)))); // convert bw to -3dB level
00025   }
00026 
00027   // number of causal coefficients
00028   f->nxc = (int) dround( sqrt( 2.*log( 2.*PI*bw / ( sqrt(2.*PI) * f->gauss_cutoff ) ) ) / 
00029                          (2.*PI*bw) * f->fs ) + 1 ;
00030   
00031   if ( ( f->nxc > MAXPZ ) || ( f->nxc >= f->ns ) ) {
00032     sprintf( msg, "Too many Gaussian coefficients : %d, encrease filter BW, or cutoff parameter",
00033              f->nxc );
00034     bpm_error( msg, __FILE__, __LINE__ );
00035     return BPM_FAILURE;
00036   }
00037 
00038   // number of anti-causal coefficients
00039   f->nxc_ac = f->nxc;
00040   
00041 
00042   // we kill some factors in the filter coefficient calculation since we
00043   // normalise afterwards anyway using the filter gain...
00044   for ( i = 0; i<f->nxc; i++ ) {
00045     // the causal coefficient array
00046     //f->xc[i] = 2.*PI*bw*exp(-SQR(2*PI*bw*(double) (f->nxc-1-i) /f->fs )/2.)/sqrt( 2.*PI );
00047     f->xc[i] = exp(-SQR(2*PI*bw*(double) (f->nxc-1-i) /f->fs )/2.);
00048     
00049     // the anti-causal coefficient array
00050     //f->xc_ac[i] = 2.*PI*bw*exp(-SQR(2*PI*bw*(double)( i )/f->fs)/2.)/sqrt( 2.*PI );
00051     f->xc_ac[i] = exp(-SQR(2*PI*bw*(double)( i )/f->fs)/2.);
00052   }
00053   
00054   // let's calculate the gain afterwards, we normalise anyway, so any factors in the 
00055   // filter coefficients don't really matter...
00056   f->gain = 0.;
00057   for ( i=0; i<f->nxc;i++)    f->gain += f->xc[i];
00058   for ( i=1; i<f->nxc_ac;i++) f->gain += f->xc_ac[i];
00059 
00060   return BPM_SUCCESS;
00061 }

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1