tomwalters@0: /* tomwalters@0: gauss.c generate a Gaussian window for a given variance over a given tomwalters@0: ------- range of standard deviations. tomwalters@0: tomwalters@0: Output to stdout in binary shorts or floats. tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "options.h" tomwalters@0: #include "units.h" tomwalters@0: #include "strmatch.h" tomwalters@0: #include "sigproc.h" tomwalters@0: tomwalters@0: char applic[] = "generate a Gaussian window." ; tomwalters@0: tomwalters@0: static char *helpstr, *debugstr, *sampstr, *varstr ; tomwalters@0: static char *ranstr, *normstr, *scalestr, *typestr, *sizestr ; tomwalters@0: tomwalters@0: static Options option[] = { tomwalters@0: { "help" , "off" , &helpstr , "help" , DEBUG }, tomwalters@0: { "debug" , "off" , &debugstr , "debugging switch" , DEBUG }, tomwalters@0: { "samplerate", "20kHz" , &sampstr , "samplerate " , VAL }, tomwalters@0: { "variance" , "20" , &varstr , "Variance of Gaussian window" , VAL }, tomwalters@0: { "range" , "4" , &ranstr , "Range in standard deviations about mean" , VAL }, tomwalters@0: { "normalize" , "off" , &normstr , "Unit area under curve (unit max if off)" , SETFLAG }, tomwalters@0: { "scale" , "1000" , &scalestr , "Scale factor for output" , VAL }, tomwalters@0: { "type" , "short" , &typestr , "Output datatype (short/float)" , VAL }, tomwalters@0: { "size" , "off" , &sizestr , "Print size of window in samples" , VAL }, tomwalters@0: ( char * ) 0 } ; tomwalters@0: tomwalters@0: tomwalters@0: int samplerate ; tomwalters@0: tomwalters@0: float *window ; tomwalters@0: int points ; tomwalters@0: tomwalters@0: short *buf ; tomwalters@0: tomwalters@0: tomwalters@0: main (argc, argv) tomwalters@0: int argc; tomwalters@0: char **argv; tomwalters@0: { tomwalters@0: float f ; tomwalters@0: tomwalters@0: getopts( option,argc,argv ) ; tomwalters@0: if ( !isoff( helpstr ) ) tomwalters@0: helpopts( helpstr, argv[0], applic, option ) ; tomwalters@0: tomwalters@0: samplerate = to_Hz( sampstr ) ; tomwalters@0: tomwalters@0: window = gauss_window( to_p( sqrt_units( varstr ), samplerate ), atof( ranstr ), &points ) ; tomwalters@0: tomwalters@0: if ( ison( normstr ) ) normalize_area( window, points ) ; tomwalters@0: else if ( !isoff( normstr ) ) { tomwalters@0: fprintf(stderr,"gauss: unknown normalization [%s]\n", normstr) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( ison( sizestr ) ) tomwalters@0: printf( "%d\n", points ) ; tomwalters@0: tomwalters@0: else if ( iststr( typestr, "float" ) ) { tomwalters@0: scalar( window, points, atof( scalestr ) ) ; tomwalters@0: fwrite( window, sizeof(float), points, stdout ) ; tomwalters@0: } tomwalters@0: tomwalters@0: else if ( iststr( typestr, "short" ) ) { tomwalters@0: buf = (short *)malloc( points * sizeof(short) ) ; tomwalters@0: if ( ( f = ftos( window, buf, points, atof( scalestr ) ) ) < 1. ) tomwalters@0: fprintf( stderr,"Warning: 16-bit overflow. Try scale factor < %f\n", f ) ; tomwalters@0: fwrite( buf, sizeof(short), points, stdout ) ; tomwalters@0: } tomwalters@0: tomwalters@0: else tomwalters@0: fprintf(stderr,"gauss: unknown datatype [%s]\n", typestr) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: scalar( y, n, scale ) tomwalters@0: float *y ; tomwalters@0: int n ; tomwalters@0: float scale ; tomwalters@0: { tomwalters@0: int i ; tomwalters@0: tomwalters@0: if ( scale != 1. ) { tomwalters@0: for ( i=0 ; i < n ; i++ ) tomwalters@0: y[i] *= scale ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: