00001
00005 #include "bpm/bpm_dsp.h"
00006
00007 int normalise_filter( filter_t *f, filterrep_t *s ) {
00008
00009 double w0, bw;
00010 complex_t hba, tmp;
00011 double w1 = 2. * PI * f->w_alpha1;
00012 double w2 = 2. * PI * f->w_alpha2;
00013 int i = 0;
00014
00015 if ( ! f || ! s ) {
00016 bpm_error( "Invalid pointer in normalise_filter()", __FILE__, __LINE__ );
00017 return BPM_FAILURE;
00018 }
00019
00020
00021 w0 = sqrt( w1 * w2 );
00022 bw = w2 - w1;
00023
00024 if ( f->options & LOWPASS ) {
00025
00026
00027 for ( i=0; i< s->npoles; i++ ) s->pole[i] = c_scale( w1, s->pole[i] );
00028 s->nzeros = 0;
00029
00030 } else if ( f->options & HIGHPASS ) {
00031
00032
00033 for ( i=0; i<s->npoles; i++ ) s->pole[i] = c_div( complex(w1,0.), s->pole[i] );
00034 for ( i=0; i<s->npoles; i++ ) s->zero[i] = complex( 0., 0.);
00035 s->nzeros = s->npoles;
00036
00037 } else if ( f->options & BANDPASS ) {
00038
00039
00040 for( i=0; i<s->npoles; i++ ) {
00041 hba = c_scale( .5 * bw, s->pole[i] );
00042
00043 tmp = c_sqrt( c_diff( complex( 1., 0.),
00044 c_div( complex( w0*w0, 0. ), c_sqr( hba ) ) ) );
00045
00046 s->pole[i] = c_mult( hba, c_sum( complex( 1., 0.), tmp ) );
00047 s->pole[s->npoles+i] = c_mult( hba, c_diff( complex( 1., 0.), tmp ) );
00048 }
00049
00050 for( i=0; i<s->npoles; i++ ) s->zero[i] = complex( 0., 0.);
00051 s->nzeros = s->npoles;
00052 s->npoles *= 2.;
00053
00054 } else if ( f->options & BANDSTOP ) {
00055
00056 for( i=0; i<s->npoles; i++ ) {
00057 hba = c_div( complex( .5 * bw, 0.), s->pole[i] );
00058 tmp = c_sqrt( c_diff( complex( 1., 0.),
00059 c_div( complex( w0*w0, 0. ), c_sqr( hba ) ) ) );
00060
00061 s->pole[i] = c_mult( hba, c_sum( complex(1.,0.), tmp ) );
00062 s->pole[s->npoles+i] = c_mult( hba, c_diff( complex(1.,0.), tmp ) );
00063 }
00064
00065 for( i=0; i<s->npoles; i++ ) {
00066 s->zero[i] = complex( 0., w0 );
00067 s->zero[s->npoles+i] = complex( 0., -w0 );
00068 }
00069 s->npoles *= 2.;
00070 s->nzeros = s->npoles;
00071
00072 }
00073
00074 return BPM_SUCCESS;
00075 }