tomwalters@0: /* tomwalters@0: chi.c repetitative chi-squared curve. tomwalters@0: tomwalters@0: Examples: tomwalters@0: tomwalters@0: chi amp=500 asym=1 per=4ms | x11plot tomwalters@0: chi amp=500 asym=1 per=16ms | x11plot -n512 tomwalters@0: chi amp=500 asym=4 per=16ms | x11plot -n512 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: tomwalters@0: char applic[] = "generate a repeated chi-squared waveform. " ; tomwalters@0: char usage[] = "chi [options]" ; tomwalters@0: tomwalters@0: static char *helpstr, *debugstr, *sampstr, *perstr, *astr, *asymstr, *dstr, *datastr ; 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: { "period" , "8ms" , &perstr , "period [s,ms,p] of repetition" , VAL }, tomwalters@0: { "amplitude" , "1024" , &astr , "amplitude of waveform" , VAL }, tomwalters@0: { "asymmetry" , "1.0" , &asymstr , "parameter controlling assymmetry (>=1)" , VAL }, tomwalters@0: { "duration" , "500ms" , &dstr , "duration of waveform" , VAL }, tomwalters@0: { "datatype" , "short" , &datastr , "o/p datatype (short/float)", VAL }, tomwalters@0: ( char * ) 0 } ; tomwalters@0: tomwalters@0: tomwalters@0: #define e ( 2.718 ) tomwalters@0: tomwalters@0: int samplerate ; tomwalters@0: int amplitude ; tomwalters@0: int duration ; tomwalters@0: int period ; tomwalters@0: float a ; tomwalters@0: tomwalters@0: main(argc, argv) tomwalters@0: int argc ; tomwalters@0: char *argv[] ; tomwalters@0: { tomwalters@0: int i, n, t ; tomwalters@0: short s ; tomwalters@0: float f ; tomwalters@0: float b ; tomwalters@0: float r = 4 ; tomwalters@0: tomwalters@0: getopts( option,argc,argv ) ; tomwalters@0: if ( !isoff( helpstr ) ) tomwalters@0: helpopts3( helpstr, argv[0], applic, usage, option ) ; tomwalters@0: tomwalters@0: samplerate = to_Hz( sampstr, 0 ) ; tomwalters@0: amplitude = atoi( astr ) ; tomwalters@0: period = (int)to_p( perstr, samplerate ) ; tomwalters@0: a = atof( asymstr ) ; tomwalters@0: duration = to_p( dstr, samplerate ) ; tomwalters@0: tomwalters@0: b = ( 2. * a ) / period ; /* sets mode at half-way to period */ tomwalters@0: tomwalters@0: if ( iststr( datastr, "short" ) ) tomwalters@0: for ( i=0 ; i