lpcanalysis

Capsim Block Documentation

Short Description

This routine produces the lpcanalysis of the input buffer. The samples are analyzed a window at a time.

Top
Parameters
Num Description Type Name Default Value
0 Number of points to skip int skip 0
1 Method: 0=AUTO, 1=COVAR int method 0
2 LPC Order int m 8
3 Window size (samples) int windowLength 128
4 Zero padding (samples) int zeropad 0
5 Sampling Rate (KHz) float samplingRate 8
6 Linear = 0, dB = 1 int dBFlag 1
7 Plot Expanded Spectrum:1=True 0=False int expandFlag 1
8 Points per Spectrum int npts 100
9 Plot Residual: 1=True 0=False int residualFlag 0
10 Plot Poles: 1=True 0=False int poleZeroFlag 0
11 Plot Formants: 1=True 0=False int formantFlag 0
12 Plot Zero Crossing: 1=True 0=False int zeroCrossingFlag 0
13 Plot Stacked Reflection Coeff: 1=True 0=False int reflectionFlag 0
14 Surface Plot: 1=True 0=False int surfaceFlag 0
15 Image: 1=True 0=False int imageFlag 0
16 Plot title file spectTitle LPC_Analysis
17 Time Domain On/Off (1/0) int timeFlag 1
18 Control: 1=On, 0=Off int control 1
19 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
9 int bufi
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,"lpcanalysis: no inputs connected\n");
	return(1);
}
if(numberInputBuffers > 1) {
	fprintf(stderr,"lpcanalysis: only one  input allowed \n");
	return(2);
}
if((numberOutputBuffers = NO_OUTPUT_BUFFERS()) > numberInputBuffers) {
	fprintf(stderr,"lpcanalysis: 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 lpcanalysis \n");
		return(5);
		break;
}




Top

Main Code



 


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

  for(i=0; i i) {
			if(IT_OUT(i)) {
				KrnOverflow("lpcanalysis",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,"lpcanalysis: 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,"lpcanalysis: 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);


	IIP_LPCAnalysis(ypts,count,
                "LPC Analysis",method+1,m,windowLength,npts,0,
		samplingRate, dBFlag,expandFlag,surfaceFlag,
			imageFlag,reflectionFlag,residualFlag,
			poleZeroFlag,formantFlag,zeroCrossingFlag,
			0,"lpcresults.dat", 0,NULL);
   }
}




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



 

/* lpcanalysis.s */
/**********************************************************************
                                lpcanalysis()
***********************************************************************
        inputs:         (One channel)
        outputs:        (optional feed-through of input channels)
        parameters:     int npts, the number of points to plot
                        int skip, number of points to skip before first plot
                        file title,  the title of the plot
                        dB flag (0=linear 1=dB)
                        window flag (0=Rect 1= Hamming )
*************************************************************************
This routine produces the lpcanalysis 
of the input buffer.
The first parameter represents the number of points plotted from the channel.
Default is set to (int 128).
The second parameter is the number of points to skip before the first plot set
is presented.  This enables skipping of any transient period.
Default is set to (int 0).
The third parameter represents the title for the plot.
Default is set to "PLOT".
The fourth parameter is the dB flag (0 for linear, 1 for dB );
The fifth parameter is the window flag ( 0 for Rectangular 1 for hammming)
Programmer: 	Sasan Ardalan
Date: 		Dec. 4, 1993	
*/