00001
00006 #include "bpm_dsp.h"
00007
00008 int gaussian_filter_coeffs( filter_t *f ) {
00009
00010
00011
00012
00013
00014
00015 int i = 0;
00016 double bw = 0.;
00017 char msg[80];
00018
00019 if ( f->options & GAUSSIAN_SIGMA_BW ) {
00020
00021 bw = f->f1;
00022 } else {
00023
00024 bw = sqrt(SQR(f->f1)/(-2.*log(pow(10.,-3./20.))));
00025 }
00026
00027
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
00039 f->nxc_ac = f->nxc;
00040
00041
00042
00043
00044 for ( i = 0; i<f->nxc; i++ ) {
00045
00046
00047 f->xc[i] = exp(-SQR(2*PI*bw*(double) (f->nxc-1-i) /f->fs )/2.);
00048
00049
00050
00051 f->xc_ac[i] = exp(-SQR(2*PI*bw*(double)( i )/f->fs)/2.);
00052 }
00053
00054
00055
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 }