spectrogram

Capsim Block Documentation

Short Description

This routine produces the spectrogram of the input buffer.

Top
Parameters
Num Description Type Name Default Value
0 Number of points int npts 128
1 Number of points to skip int skip 0
2 Window size (samples) int windowLength 128
3 Overlap (samples) int overlap 0
4 Zero padding (samples) int zeropad 0
5 Threshold (DB) float threshold 40
6 Sampling Rate (KHz) float samplingRate 8
7 Window:0= Rec.,1=Hamming int windowType 1
8 Linear = 0, dB = 1 int dBFlag 1
9 Surface Plot: 1=True 0=False int surfaceFlag 0
10 Image: 1=True 0=False int imageFlag 1
11 Plot title file spectTitle Spectrogram
12 Time Domain On/Off (1/0) int timeFlag 1
13 Control: 1=On, 0=Off int control 1
14 Buffer type:0= Float,1=Integer int bufferType 0
Top
States
Num Type Name Initial Value Description
0 int numberInputBuffers
1 int numberOutputBuffers
2 float* xpts
3 float* xTime_P
4 float* ypts
5 float* spect_P
6 int count 0
7 int totalCount 0
8 int blockOff 0
9 int bufi 0
10 float dx
Top

Declarations


 

        iip_Curve_Pt     curveTime_P;
        iip_Curve_Pt     curve_P;
	int samples;
	int numberPoints;
    	int i,j,ii;
	float tmp;
	complex val;
	float wind;
	char title1[80];
	char fname[80];
        char curveSubTitle[80];
	float* mag_P;
	float* phase_P;
	FILE *time_F;
	FILE *freq_F;



Top

Initialization Code



 

/* store as state the number of input/output buffers */
if((numberInputBuffers = NO_INPUT_BUFFERS()) <= 0) {
	fprintf(stderr,"spectrogram: no inputs connected\n");
	return(1);
}
if(numberInputBuffers > 1) {
	fprintf(stderr,"spectrogram: only one  input allowed \n");
	return(2);
}
if((numberOutputBuffers = NO_OUTPUT_BUFFERS()) > numberInputBuffers) {
	fprintf(stderr,"spectrogram: too many outputs connected\n");
	return(3);
}
if(samplingRate)
	dx=1.0/samplingRate;
else
	dx=1.0;
if (control) {
	/*                                                      
	 * allocate arrays                                      
	 */                                                     
	xpts = (float* )calloc(BLOCK_SIZE,sizeof(float));           
	ypts = (float* )calloc(BLOCK_SIZE,sizeof(float));           
	if(xpts==NULL  || ypts ==NULL) {
		fprintf(stderr,"Spectrogram could not allocate space\n");
		return(4);
	}
}
count = 0;
totalCount = 0;
switch(bufferType) {
	case FLOAT_BUFFER: 
		SET_CELL_SIZE_IN(0,sizeof(float));
		if(numberOutputBuffers == 1)
			SET_CELL_SIZE_OUT(0,sizeof(float));
		break;
	case INTEGER_BUFFER: 
		SET_CELL_SIZE_IN(0,sizeof(int));
		if(numberOutputBuffers == 1)
			SET_CELL_SIZE_OUT(0,sizeof(int));
		break;
	default: 
		fprintf(stderr,"Bad buffer type specified in spectrogram \n");
		return(5);
		break;
}




Top

Main Code



 


for(samples = MIN_AVAIL(); samples > 0; --samples) {

  for(i=0; i i) {
			if(IT_OUT(i)) {
				KrnOverflow("spectrogram",i);
				return(99);
			}

			switch(bufferType) {
				case INTEGER_BUFFER:
	 				OUTI(i,0) = INI(i,0);
					break;
				case FLOAT_BUFFER:
	 				OUTF(i,0) = INF(i,0);
					break;
			}

		}
  }
  if(++totalCount > skip && control ) {
		count=blockOff + bufi;
		bufi++;
		if (bufi == BLOCK_SIZE) {
			blockOff += BLOCK_SIZE;
			xpts = (float *)realloc((char *) xpts, 
				sizeof(float) * (blockOff + BLOCK_SIZE));
			ypts = (float *)realloc((char *) ypts, 
				sizeof(float) * (blockOff + BLOCK_SIZE));
			bufi=0;
		}
		if(xpts == NULL || ypts==NULL) {
			fprintf(stderr,"spectrogram: could not allocate space\n");
			return(6);
		}

		switch(bufferType) {
			case INTEGER_BUFFER:
          	     		ypts[count] = INI(0,0);
				break;
			case FLOAT_BUFFER:
          	     		ypts[count] = INF(0,0);
				break;
		}
		xpts[count]=count*dx;

		
  }

} 

return(0);





Top

Wrapup Code



 

if(control == 0) return(0);
if((totalCount - skip) > 0 ) {
   /*
    * callup the plot routine 
    */
   if(iip_hdr_P ) {
	/*
	 * if in graphic mode callup iip
	 */
	 xpts = (float *) realloc((char *) xpts, sizeof(float) *
				 (blockOff + bufi));
	 ypts = (float *) realloc((char *) ypts, sizeof(float) *
				 (blockOff + bufi));
	if(xpts == NULL || ypts==NULL) {
		fprintf(stderr,"spectrogram: could not allocate space\n");
		return(6);
	}
	curveTime_P = IIP_NewInitedCurveRec();
	curveTime_P->qpCurveFlag = TRUE;
	curveTime_P->x_P = xpts;
	curveTime_P->y_P = ypts;
	curveTime_P->points = count;
	curveTime_P->note_A = NULL;
        curveTime_P->funcType = PLT_GROUP_TIME_DOMAIN;
	sprintf(title1,"%s Time Domain %s",spectTitle,SNAME(0));
	IIP_SetTitles(curveTime_P,title1,NULL);
	if(timeFlag)
		IIP_AppendCurve(curveTime_P);
		curve_P=IIP_Spectrogram(curveTime_P,windowLength,overlap,
				zeropad,
				samplingRate, windowType,threshold,surfaceFlag,
				imageFlag,dBFlag,0,NULL);
	if(curve_P)
		strcpy(curve_P->title,spectTitle);
   }
}




Top

License



/*  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://www.xcad.com
    XCAD Corporation
    Raleigh, North Carolina 
*/


Top

Description



 

/* spectrogram.s */
/**********************************************************************
                                spectrogram()
***********************************************************************
        inputs:         (One channel)
        outputs:        (optional feed-through of input channels)
*************************************************************************
This routine produces the spectrogram 
of the input buffer.
Programmer: 	Sasan Ardalan
Date: 		Dec. 4, 1993	
*/