histtxt

Capsim Block Documentation

Short Description

Top
Parameters
Num Description Type Name Default Value
0 Starting point of left most bin float start -5.0
1 Ending point of right most bin float stop 5.0
2 Number of bins int numberOfBins 100
3 File name for output file file_spec none
4 Number of points to collect int npts 1000
5 Points to skip before first plot int skip 0
6 Title file graphTitle Histogram
7 X axis label file x_axis Bins
8 Y axis label file y_axis Histogram
9 Plot Style: 1=Line,2=Points,5=Bar Chart int plotStyleParam 5
10 Control: 1=On, 0=Off int control 1
11 Buffer Type: 0= float, 1=image int bufferType 0
Top
States
Num Type Name Initial Value Description
0 int ibufs
1 int obufs
2 float* bin
3 float* plotbin
4 float* xbin
5 float binWidth
6 int numberOfSamples
7 int totalCount 0
8 int total 0
9 FILE* histo_F
Top

Declarations


 

	float x;
	int i;
	int ii;
	int j;
	int jj;
        int     widthImage;
        int     heightImage;
        image_t         img;
	char title[80];
	char	filename[100];
	FILE* file_F;



Top

Initialization Code



 

/*
 * store as state the number of input/output buffers
 */
if((ibufs = NO_INPUT_BUFFERS()) <= 0) {
        fprintf(stderr,"hist: no inputs connected\n");
        return(2);
}
if((obufs = NO_OUTPUT_BUFFERS()) > ibufs) {
        fprintf(stderr,"hist: too many outputs connected\n");
        return(3);
}
binWidth=(stop-start)/((float)numberOfBins);
if(numberOfBins>512 || binWidth<0.)return(1);
if(control) {
	bin = (float *) malloc(numberOfBins * sizeof(float));  
	plotbin = (float *) malloc(numberOfBins * sizeof(float));  
	xbin = (float *) malloc(numberOfBins * sizeof(float));  
	if(bin == NULL || plotbin == NULL || xbin ==NULL) {
		fprintf(stderr,"hist could not allocate memory\n");
		return(4);
	}
}
for(i=0;i
    
Top

Main Code



 

for(ii=MIN_AVAIL();ii>0;--ii) {
	for(i=0; i i) {
                                if(IT_OUT(i)) {
				    KrnOverflow("hist",i);
				    return(99);
				}
                                if(bufferType==IMAGE_BUFFER)
                                        OUTIMAGE(i,0) = INIMAGE(i,0);
                                else
                                        OUTF(i,0) = INF(i,0);
                        }
	}
	switch(bufferType) {
	  case IMAGE_BUFFER:
		img=INIMAGE(0,0);
                widthImage=img.width;
                heightImage=img.height;
		total = widthImage*heightImage;
                for(i=0; i=numberOfBins)
                           bin[numberOfBins-1] = bin[numberOfBins-1] + 1.;
                        else
			   bin[j] = bin[j] + 1.;
	
		   }	

	     break;
	  case FLOAT_BUFFER:
	     if(++totalCount > skip && control ) {
		if(total == npts) continue;
		x=INF(0,0);
		x=(x-start)/binWidth;
		j=(int)x;
		if(j<0)
			bin[0] = bin[0] +1.;
		else if (j>=numberOfBins)
			bin[numberOfBins-1] = bin[numberOfBins-1] + 1.;
		else
			bin[j] = bin[j] + 1.;
		total++;
	     }
	     break;
	}

}
return(0);




Top

Wrapup Code



 

if((totalCount - skip) > 0  || bufferType==IMAGE_BUFFER ) {
if(total != npts && bufferType == FLOAT_BUFFER)
            total = totalCount -skip;
for(j=0;j
    
Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* hist.s */
/**********************************************************************
                hist()
***********************************************************************
	inputs:		in, the signal of interest
	outputs:	none
	parameters:	float start, the start of the leftmost bin
			float stop, the end of the rightmost bin
			int numberOfBins
			file file_spec, the name of the output file
			int npts, how many points to wait before plotting
			number of samples to skip
			x axis label
			y axis label
			plot style ( line, bar chart)
			control to turn on and off
***********************************************************************
This program computes a histogram of the received data.  For a large no.
of data points this distribution should approach the probability dist. of
the signal . Any samples outside the range are put in the appropriate outer-
most bin.
-Parameter one is the starting point for the leftmost bin
-Parameter two is the ending point for the rightmost bin
-Parameter three is the number of bins (less than 2048)
-Parameter four is the filename for the output
-Parameter five is the number of points to obtain before plotting
Programmer: 	John T. Stonick
Date: 		January 1988
Modified:	March 29, 1988
Modified:	June 18, 1990 Sasan H. Ardalan
*/