Mercurial > hg > aim92
comparison tools/gauss.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5242703e91d3 |
---|---|
1 /* | |
2 gauss.c generate a Gaussian window for a given variance over a given | |
3 ------- range of standard deviations. | |
4 | |
5 Output to stdout in binary shorts or floats. | |
6 | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <math.h> | |
11 #include "options.h" | |
12 #include "units.h" | |
13 #include "strmatch.h" | |
14 #include "sigproc.h" | |
15 | |
16 char applic[] = "generate a Gaussian window." ; | |
17 | |
18 static char *helpstr, *debugstr, *sampstr, *varstr ; | |
19 static char *ranstr, *normstr, *scalestr, *typestr, *sizestr ; | |
20 | |
21 static Options option[] = { | |
22 { "help" , "off" , &helpstr , "help" , DEBUG }, | |
23 { "debug" , "off" , &debugstr , "debugging switch" , DEBUG }, | |
24 { "samplerate", "20kHz" , &sampstr , "samplerate " , VAL }, | |
25 { "variance" , "20" , &varstr , "Variance of Gaussian window" , VAL }, | |
26 { "range" , "4" , &ranstr , "Range in standard deviations about mean" , VAL }, | |
27 { "normalize" , "off" , &normstr , "Unit area under curve (unit max if off)" , SETFLAG }, | |
28 { "scale" , "1000" , &scalestr , "Scale factor for output" , VAL }, | |
29 { "type" , "short" , &typestr , "Output datatype (short/float)" , VAL }, | |
30 { "size" , "off" , &sizestr , "Print size of window in samples" , VAL }, | |
31 ( char * ) 0 } ; | |
32 | |
33 | |
34 int samplerate ; | |
35 | |
36 float *window ; | |
37 int points ; | |
38 | |
39 short *buf ; | |
40 | |
41 | |
42 main (argc, argv) | |
43 int argc; | |
44 char **argv; | |
45 { | |
46 float f ; | |
47 | |
48 getopts( option,argc,argv ) ; | |
49 if ( !isoff( helpstr ) ) | |
50 helpopts( helpstr, argv[0], applic, option ) ; | |
51 | |
52 samplerate = to_Hz( sampstr ) ; | |
53 | |
54 window = gauss_window( to_p( sqrt_units( varstr ), samplerate ), atof( ranstr ), &points ) ; | |
55 | |
56 if ( ison( normstr ) ) normalize_area( window, points ) ; | |
57 else if ( !isoff( normstr ) ) { | |
58 fprintf(stderr,"gauss: unknown normalization [%s]\n", normstr) ; | |
59 exit( 1 ) ; | |
60 } | |
61 | |
62 if ( ison( sizestr ) ) | |
63 printf( "%d\n", points ) ; | |
64 | |
65 else if ( iststr( typestr, "float" ) ) { | |
66 scalar( window, points, atof( scalestr ) ) ; | |
67 fwrite( window, sizeof(float), points, stdout ) ; | |
68 } | |
69 | |
70 else if ( iststr( typestr, "short" ) ) { | |
71 buf = (short *)malloc( points * sizeof(short) ) ; | |
72 if ( ( f = ftos( window, buf, points, atof( scalestr ) ) ) < 1. ) | |
73 fprintf( stderr,"Warning: 16-bit overflow. Try scale factor < %f\n", f ) ; | |
74 fwrite( buf, sizeof(short), points, stdout ) ; | |
75 } | |
76 | |
77 else | |
78 fprintf(stderr,"gauss: unknown datatype [%s]\n", typestr) ; | |
79 } | |
80 | |
81 | |
82 scalar( y, n, scale ) | |
83 float *y ; | |
84 int n ; | |
85 float scale ; | |
86 { | |
87 int i ; | |
88 | |
89 if ( scale != 1. ) { | |
90 for ( i=0 ; i < n ; i++ ) | |
91 y[i] *= scale ; | |
92 } | |
93 } | |
94 | |
95 |