Capsim Block Documentation
This star calculates the statistics of the incoming signal. The parameter is a filename for storage of the results.
Port | Type | Name | |
---|---|---|---|
0 | float | x |
Num | Description | Type | Name | Default Value | |
---|---|---|---|---|---|
0 | Points to skip | int | skip | ||
1 | File to store results | file | stat_file | stat.dat |
Num | Type | Name | Initial Value | Description |
---|---|---|---|---|
0 | FILE* | file_ptr | ||
1 | int | obufs | ||
2 | int | count | 0 | |
3 | int | totalCount | 0 | |
4 | float | sum_x | 0.0 | |
5 | float | sum_x2 | 0.0 | |
6 | float | max | -1e30 | |
7 | float | min | 1e30 |
int i,j; float xSample; /* current sample of input signal */ float mu; /* mean = sum_x/count */ float var; /* variance = (sum_x2/count - mu**2) */ float sigma; /* std dev = square root of variance */ double sqrt(); char theVar[100]; char theName[100]; #ifdef TCL_SUPPORT Tcl_Obj *varNameObj_P; Tcl_Obj *objVar_P; #endif |
---|
if( (obufs = NO_OUTPUT_BUFFERS()) > 1) { fprintf(stderr,"stats: only one output allowed\n"); return(2); } |
---|
/* note the minimum number of samples on the input */ /* buffers and iterate that many times */ for(i=MIN_AVAIL();i>0; --i) { IT_IN(0); for(j=0; j |
---|
mu = sum_x/count; var = (sum_x2/count) - (mu*mu); sigma = sqrt(var); fprintf(stderr,"samples \t%d \tmean \t%g\n",count,mu); fprintf(stderr,"maximum \t%g \tminimum \t%g\n",max,min); fprintf(stderr,"variance \t%g \tsigma \t%g\n",var,sigma); fprintf(stderr,"samples \t%d \tmean \t%g\n",count,mu); fprintf(stderr,"maximum \t%g \tminimum \t%g\n",max,min); fprintf(stderr,"variance \t%g \tsigma \t%g\n",var,sigma); { if( (file_ptr = fopen(stat_file,"w")) == NULL) { fprintf(stderr,"stats: can't open results file %s \n", stat_file); return(3); } { fprintf(file_ptr,"samples %d mean %e \n",count,mu); fprintf(file_ptr,"maximum %e minimum %e \n",max,min); fprintf(file_ptr,"variance %e sigma %e \n",var,sigma); } #ifdef TCL_SUPPORT if(!krn_TCL_Interp) { return(0); } sprintf(theName,"%s_sigma",STAR_NAME); varNameObj_P=Tcl_NewStringObj(theName, strlen(theName)); objVar_P=Tcl_NewObj(); Tcl_SetDoubleObj(objVar_P,sigma); Tcl_ObjSetVar2(krn_TCL_Interp,varNameObj_P,NULL,objVar_P,TCL_NAMESPACE_ONLY); sprintf(theName,"%s_mean",STAR_NAME); varNameObj_P=Tcl_NewStringObj(theName, strlen(theName)); objVar_P=Tcl_NewObj(); Tcl_SetDoubleObj(objVar_P,mu); Tcl_ObjSetVar2(krn_TCL_Interp,varNameObj_P,NULL,objVar_P,TCL_NAMESPACE_ONLY); sprintf(theName,"%s_max",STAR_NAME); varNameObj_P=Tcl_NewStringObj(theName, strlen(theName)); objVar_P=Tcl_NewObj(); Tcl_SetDoubleObj(objVar_P,max); Tcl_ObjSetVar2(krn_TCL_Interp,varNameObj_P,NULL,objVar_P,TCL_NAMESPACE_ONLY); sprintf(theName,"%s_min",STAR_NAME); varNameObj_P=Tcl_NewStringObj(theName, strlen(theName)); objVar_P=Tcl_NewObj(); Tcl_SetDoubleObj(objVar_P,min); Tcl_ObjSetVar2(krn_TCL_Interp,varNameObj_P,NULL,objVar_P,TCL_NAMESPACE_ONLY); sprintf(theName,"%s_var",STAR_NAME); varNameObj_P=Tcl_NewStringObj(theName, strlen(theName)); objVar_P=Tcl_NewObj(); Tcl_SetDoubleObj(objVar_P,var); Tcl_ObjSetVar2(krn_TCL_Interp,varNameObj_P,NULL,objVar_P,TCL_NAMESPACE_ONLY); #endif } fclose(file_ptr); |
---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks) Copyright (C) 1989-2002 XCAD 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://capsimtmk.sourceforge.net XCAD Corporation Raleigh, North Carolina */ |
---|
/* stats.s */ /*************************************************************** stats() ******************************************************************* Input: x, the signal of interest Output: optional: terminate signal or flow through Parameters: 1: file sig_name, signal identifier 2: file stat_file, statistics file name default => no file created. ******************************************************************* This star calculates the statistics of the incoming signal. The parameter is a filename for storage of the results. |
---|