next up previous contents
Next: Function: is_gaussian() Up: GRASP Routines: General purpose Previous: Function: avg_spec()   Contents

Function: binshort()

0 void binshort(short *input,int ninput,double *bins,int offset)
This function performs the ``binning" which is needed to study the statistics of an array of short integers, such as the output of a 12 or 16 bit analog-to-digitial converter. Its output is a histogram showing the number of times that a particular value occurred in an input array. Note that this routine increments the output histogram, so that you can use it for accumulating statistics of a particular variable.

The arguments are:

input: Input. This routine makes a histogram of the values input[0..ninput-1].
ninput: Input. The number of elements in the previous array.
bins: Output. Upon return from the function, this array contains a histogram showing the probability distribution of the values input[0..ninput-1]. The array element bins[offset] is incremented by the number of elements $x$ of input[] that had value $x=0$. The array element bins[offset+i] is incremented by the number of elements $x$ of input[] that had value $x=i$. If the output of your 16 bit ADC ranges from -32,768 to +32,767 and nbins has value $2^{16}=65,536$ then you would want ${\tt offset}=32,768$. For a 12-bit ADC you would probably want ${\tt nbins}=2^{12}=4096$, and depending upon the sign conventions either ${\tt offset}=2047$ or ${\tt offset}=2048$.
offset: Input. The offset defined above.

Note that in the interests of speed and efficiency this routine does not check that your values lie within range. So if you try to bin a value that lies outside of the range $-{\tt offset}, -{\tt offset}+1,\cdots,{\tt offset}-1$ you may end up over-writing another array! You'll then spend unhappy hours trying to locate the source of bizzare unpredictable behavior in your code, when you could be doing better things, like seeing if your ADC has dynamic range problem (reaches the end-point values too often) or has a mean value of zero (even with AC-coupled inputs the ADC may have substantial DC offset).

Authors: Bruce Allen, ballen@dirac.phys.uwm.edu
Comments: None.


next up previous contents
Next: Function: is_gaussian() Up: GRASP Routines: General purpose Previous: Function: avg_spec()   Contents
Bruce Allen 2000-11-19