fxfirtaps

Capsim Block Documentation

Short Description

This block implements an FIR based on taps stored in a file.

Top
Input Connections
Port Type Name
0 int x
Top
Output Connections
Port Type Name
0 int y
1 float error
Top
Parameters
Num Description Type Name Default Value
0 File with Taps (first line # of taps) file fileName tmp.tap
1 Number of bits to represent fraction int qbits 8
2 Word length int size 32
3 Accumulator Roundoff bits int roundoff_bits 8
4 Accumulator Word length int accumSizeRound 32
5 saturation mode int saturation_mode 1
6 Error Out (1=error 0=floating point response) int errorControl 1
Top
States
Num Type Name Initial Value Description
0 int* x_P
1 double* h_P
2 int N
3 int fxfactor
4 int* fxfactor1_P
5 int* fxfactor0_P
6 int* fxfactLessFlag_P
7 int* less_flag2_P
8 int maxv
9 int* overflow
Top

Declarations


 

   	int i;
   	int j;
	int val;
	int status;
	int numberTaps;
	int tmp1,tmp2;
        float sum;
	int	no_samples;
	FILE *imp_F;
	doublePrecInt	accumulate;
        int sum1, sum0;
	int out;
	double factor;
	int input1,input0;
	int less_flag2;
	int out1,out0;



Top

Initialization Code



 


	/*
	 * open file containing impulse response samples. Check 
	 * to see if it exists.
	 *
	 */
        if( (imp_F = fopen(fileName,"r")) == NULL) {
		fprintf(stderr,"firtaps: file could not be opened.\n");
		return(4);
	}
	fscanf(imp_F,"%d",&numberTaps);
	/*
	 * Allocate memory and return pointers for tapped delay line x_P and
	 * array containing impulse response samples, h_P.
	 *
	 */
	if( (x_P = (int*)calloc(numberTaps,sizeof(int))) == NULL ||
	    (h_P = (double*)calloc(numberTaps,sizeof(double))) == NULL ) {
	   	fprintf(stderr,"fxfirtaps: can't allocate work space\n");
		return(4);
	}
	if( (fxfactor0_P = (int*)calloc(numberTaps,sizeof(int))) == NULL ||
	    (fxfactor1_P = (int*)calloc(numberTaps,sizeof(int))) == NULL ||
	    (fxfactLessFlag_P = (int*)calloc(numberTaps,sizeof(int))) == NULL) {
	   	fprintf(stderr,"fxfirtaps: can't allocate work space\n");
		return(5);
	}
	
	/*
	 * Read in the impulse response samples into the array
	 * and initialize the tapped delay line to zero.
	 *
	 */
	for (i=0; i 32) {
		fprintf(stderr,"fxfirtaps: size can not be greater than 32\n");	
                return(6);
		}
	if ((size & 1) == 1) {
		fprintf(stderr,"fxfirtaps: Sorry, size can not be an odd number\n");	
                return(7);
		}
		
	/*
	 * store fixed point tap coefficients (part1,part2,lessFlag)
	 */
        if (qbits > 30) {
	/* 
	 * Because 1<<31 becomes a negative number in this machine 
	 */
		fprintf(stderr,"fxfirtaps:At most 30 bits are allowed for fraction\n"); 
	        return(7);
       }
	/* 
	 * Calculate the maximum number to be represented by size bits 
	 */
        maxv=1;
        maxv <<= (size-1); 
	maxv -= 1;
	val=1; 
	val <<= qbits;	
        for (i=0; i0.0)
		   fxfactor = (int)(factor * val + 0.5);
              else
		   fxfactor = (int)(factor * val - 0.5);
              if (fxfactor > maxv || (-fxfactor) > maxv) {
        	    fprintf(stderr,"fxfirtaps: gain can not be represented by size bits\n");
        	    return(8);
              }
              Fx_Part(size,fxfactor,&fxfactor1_P[i],&fxfactor0_P[i],&fxfactLessFlag_P[i]);
	}




Top

Main Code



 




	for(no_samples=MIN_AVAIL();no_samples >0; --no_samples) {
		IT_IN(0);
		/*
		 * Shift input sample into tapped delay line
		 */
		tmp2=x(0);
		for(i=0; i
    
Top

Wrapup Code



 

	free(x_P); free(h_P); 
	free(fxfactor0_P);
	free(fxfactor1_P);
	free(fxfactLessFlag_P);




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



 

/* fxfirfil.s */
/***********************************************************************
                             fxfirfil()
************************************************************************
This star designs FIR low pass, high pass, band pass, and band stop 
filters using the windowing method.
The star stores the specs of the FIR filter in the file tmp.spec.
The star stores the FIR filter taps in the file tmp.tap.
Date:  October 19, 1989 
Programmer: Sasan H. Ardalan. 

firfil


This star designs FIR low pass, highj pass, band pass, and band stop 
filters using the windowing method.
The star stores the specs of the FIR filter in the file tmp.spec.
The star stores the FIR filter taps in the file tmp.tap.


Date:  October 19, 1989 
Programmer: Sasan H. Ardalan. 
Modified: June 17, 2007 for fixed point

*/