00001
00006 #include "bpm/bpm_dsp.h"
00007
00008 filterrep_t* zplane_transform( filter_t *f, filterrep_t *s ) {
00009
00010 int i = 0;
00011 filterrep_t *r;
00012
00013 if ( ! s ) {
00014 bpm_error( "Invalid pointer argument in zplane_transform(...).", __FILE__, __LINE__ );
00015 return NULL;
00016 }
00017
00018
00019
00020 r = (filterrep_t*) calloc( 1, sizeof( filterrep_t) );
00021
00022 if ( ! r ) {
00023 bpm_error( "Cannot allocate memory for z-plane representation.", __FILE__, __LINE__ );
00024 return NULL;
00025 }
00026
00027
00028 r->npoles = s->npoles;
00029 r->nzeros = s->nzeros;
00030
00031 if ( f->options & MATCHED_Z_TRANSFORM ) {
00032
00033
00034 for ( i=0; i<r->npoles; i++ ) r->pole[i] = c_exp( s->pole[i] );
00035 for ( i=0; i<r->nzeros; i++ ) r->zero[i] = c_exp( s->zero[i] );
00036
00037 } else {
00038
00039
00040 for ( i=0; i<r->npoles; i++ ) {
00041 r->pole[i] = c_div( c_sum( complex(2.,0.), s->pole[i] ),
00042 c_sum( complex(2.,0.), c_scale(-1.0,s->pole[i])) );
00043 }
00044
00045 for ( i=0; i<r->nzeros; i++ ) {
00046 r->zero[i] = c_div( c_sum( complex(2.,0.), s->zero[i] ),
00047 c_sum( complex(2.,0.), c_scale(-1.0,s->zero[i])) );
00048 }
00049
00050 while ( r->nzeros < r->npoles ) r->zero[r->nzeros++] = complex( -1.0, 0. );
00051
00052 }
00053
00054
00055 return r;
00056 }
00057
00058