fxnl

Capsim Block Documentation

Short Description

This star implements a fixed point normalized lattice filter.

Top
Parameters
Num Description Type Name Default Value
0 File with normalized lattice filter parameters file file_name tmp.lat
1 Fixed point precision for coefficients, bits int regBits 16
2 Input/output quantization bits int quantBits 16
3 Input/output Range e.g. +- 5 volts int quantRange 10.0
4 0=Float Buffers,1=Integer Buffer int bufferType 0
Top
States
Num Type Name Initial Value Description
0 int* k
1 int* c
2 int* nu
3 int* xb
4 int n
5 int numberInputBuffers
6 int numberOutputBuffers
7 float wsc
8 float wnorm
9 float fs
10 int bitPrec
11 int quant
Top

Declarations


 

	int buffer_no;
        float xf,tmp;
	int	xq;
	int	sum,ysum;
	float	val;
	int	xfq,yq;
        int n1,n2,i,j,m;
	int	noSamples;
	FILE* fp;



Top

Initialization Code



 

if((numberInputBuffers = NO_INPUT_BUFFERS()) <= 0) {
        fprintf(stderr,"fxn1: no inputs connected\n");
        return(1);
}
if(numberInputBuffers > 1) {
        fprintf(stderr,"fxnl: only one  input allowed \n");
        return(2);
}
if((numberOutputBuffers = NO_OUTPUT_BUFFERS()) > numberInputBuffers) {
        fprintf(stderr,"fxnl: too many outputs connected\n");
        return(3);
}
if(numberOutputBuffers == 0) {
        fprintf(stderr,"fxnl: no output connected\n");
        return(4);
}
if(strcmp(file_name,"stdin") == 0)
			fp = stdin;
else if((fp = fopen(file_name,"r")) == NULL) {
		fprintf(stderr,"fxnl():can't open file \n");
		return(1); /* nl() file cannot be opened */
}
/*****************************************************
   read lattice filter parameters from file
****************************************************/
fscanf(fp,"%d",&n);
n1=n+1;
/*   allocate work space      */
if(((k=(int*)calloc(n,sizeof(int))) == NULL) ||
		((c=(int*)calloc(n,sizeof(int))) == NULL) ||
		((nu=(int*)calloc(n1,sizeof(int))) == NULL) ||
		((xb=(int*)calloc(n1,sizeof(int))) == NULL )) {
		fprintf(stderr,"fxnl(): can't allocate work space \n");
		return(1);
}
bitPrec=1;
bitPrec = bitPrec<< regBits;
quant=1;
quant = quant<< quantBits;
for (i=0; i
    
Top

Main Code



 


     for(noSamples=MIN_AVAIL();noSamples >0; --noSamples) {
     	  IT_IN(0);
	switch (bufferType) {
		case FLOAT_BUFFER:
			/*
			 * input floating point sample and quantize
			 */
			xf=INF(0,0);
	  		xfq = (int) xf*quant/(2.0 * quantRange);
			break;
		case INTEGER_BUFFER:
			xq=INI(0,0);
			break;
	}
             

        for (m=0; m> regBits;
             xfq=xfq*c[i-1]-k[i-1]*xb[i-1];    
	     xfq = xfq >> regBits;
        }
        xb[0]=xfq;
        sum=0;
        for (m=0; m> regBits;
     	  if(IT_OUT(0)) {
		KrnOverflow("fxnl",0);
		return(99);
	  }
	switch (bufferType) {
		case FLOAT_BUFFER:
			/*
			 * convert to float and output floating point sample
			 */
          		OUTF(0,0)=ysum*wsc/wnorm*quantRange*2.0/quant;
			break;
		case INTEGER_BUFFER:
          		OUTI(0,0)=(int) ysum*wsc/wnorm;
			break;
	}
             

     }





Top

Wrapup Code



 

	free(k);
	free(nu);
	free(c);
	free(xb);




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



 

/*************************************************************
Fixed Point Normalized Lattice Filter
				fxnl()
This star implements a fixed point normalized lattice filter. 
All variables used are of type integer so that the algorithm can 
be directly implemented on a Digital Signal Processor.
This star supports both floating point and integer buffers.
If floating point buffers are used, the input samples are quantized 
with the input quantizer range and number of bits specified as
parameters.
The output is also converted to floating point within the
original quantizer range. e.g. +- 5 volts.
If integer buffers are used, no quantization is used and the
integer input samples are processed directly.
This star can be replace the floating point normalized lattice star
nl.s to analyze the effects of fixed point implementation
with different word sizes.
***************************************************************
(c) 1991-2002 XCAD Corporation, All Rights Reserved

fxnl


Fixed Point Normalized Lattice Filter
				fxnl()
This star implements a fixed point normalized lattice filter. 
All variables used are of type integer so that the algorithm can 
be directly implemented on a Digital Signal Processor.
This star supports both floating point and integer buffers.
If floating point buffers are used, the input samples are quantized 
with the input quantizer range and number of bits specified as
parameters.
The output is also converted to floating point within the
original quantizer range. e.g. +- 5 volts.
If integer buffers are used, no quantization is used and the
integer input samples are processed directly.
This star can be replace the floating point normalized lattice star
nl.s to analyze the effects of fixed point implementation
with different word sizes.


Programmer: Sasan H Ardalan
Date: September 7, 1991 

*/