Edson, Thanks, this will keep me busy studying tonight.
Bob Macklin K5MYJ/7 Seattle, Wa. "REAL RADIOS GLOW IN THE DARK" --- Edson Pereira <[EMAIL PROTECTED]> wrote: > > Bob, > > I have used the code below sometime ago. The > coefficients can be > calculated using the method described in: > > http://www.wwc.edu/~frohro/R2_DSP/R2-DSP.html > > Place the coefficients in a text file with one > coefficient per line. > > 73, > > -- Edson, pu1jte, n1vtn, 7n4ncl > > /* --- fir.h --- */ > > struct fir_filter { > int order; > double h[1024]; > double w[1024]; > }; > > struct fir_filter * new_fir_filter( char * ); > double do_fir( struct fir_filter *, double ); > > /* --- fir.c --- */ > > #include <stdio.h> > #include <stdlib.h> > #include "fir.h" > > struct fir_filter * new_fir_filter( char * > filter_coefficients ) > { > FILE *fp; > int i; > char buf[80]; > struct fir_filter * filter; > double value; > > fp = fopen( filter_coefficients, "r" ); > if ( fp == NULL ) { > perror( filter_coefficients ); > exit(1); > } > > filter = (struct fir_filter *)malloc( sizeof( > struct fir_filter ) ); > if ( filter == NULL ) { > perror( "Unable to allocate memory for filter" > ); > exit(1); > } > > for ( i = 0; fgets( buf, sizeof(buf) - 1, fp ) > > 0; i++ ) { > sscanf( buf, "%lf", &value ); > filter->h[i] = value; > } > filter->order = i; > > fprintf( stderr, "Loaded %d FIR Filter > Coefficients from %s\n", i, > filter_coe > fficients ); > return filter; > } > > inline double do_fir( struct fir_filter * filter, > double input ) > { > double output; > int i; > > for ( i = 0; i < filter->order; i++ ) > filter->w[i] = filter->w[i+1]; > > filter->w[filter->order] = input; > output = 0.0; > > for ( i = 0; i <= filter->order; i++ ) > output += filter->h[i] * filter->w[i]; > > return output; > } > > > > > > > __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com ------------------------ Yahoo! Groups Sponsor --------------------~--> Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/ELTolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/soft_radio/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
