iirfil

Capsim Block Documentation

Short Description

This star designs and implements a cascade form IIR digital filter.

Top
Input Connections
Port Type Name
0 float x
Top
Output Connections
Port Type Name
0 float y
Top
Parameters
Num Description Type Name Default Value
0 1=Butterworth,2=Chebyshev,3=Elliptic int desType 3
1 1=LowPass,2=HighPass,3=BandPass,4=BandStop int filterType 1
2 Sampling Frequency, Hz float fs 32000.0
3 Enter Passband Ripple in dB's float pbdb 0.1
4 Enter Stopband Attenuation in dB's float sbdb 35.0
5 Passband Freq. Hz/LowPass/HighPass Only float fpb 3400.0
6 Stopband Freq. Hz/LowPass/HighPass Only float fsb 4400.0
7 Lower Passband Freq. Hz/BandPass/BandStop Only float fpl 220.0
8 Upper Passband Freq. Hz/BandPass/BandStop Only float fpu 3400.0
9 Lower Stopband Freq. Hz/BandPass/BandStop Only float fsl 10.0
10 Upper Stopband Freq. Hz/BandPass/BandStop Only float fsu 4400.0
11 Filter Name file filterName tmp
Top
States
Num Type Name Initial Value Description
0 float ycas[20]
1 float xs[3]
2 float ys[3]
3 float pc1[35]
4 float pc2[35]
5 float zc1[35]
6 float zc2[35]
7 float fsamp
8 float wnorm
9 int ns
10 int n
Top

Declarations


 

   	int i,j,jj,jt;
	int status;
	int	no_samples;
	char fname[100];
        FILE *fopen();
        FILE *ird_F;



Top

Initialization Code



 

	switch(filterType) {
	    case LOW_PASS:
		if(fpb >= fsb) {
		   fprintf(stderr,"iirfil:Low pass stop band frequency lower \
			\n than or equal to pass band. \n");
		   return(4);
		}
	 	break;
	    case HIGH_PASS:
		if(fpb <= fsb) {
		   fprintf(stderr,"iirfil:High pass stop band frequency \
			\n heigher than or equal to pass band. \n");
		   return(4);
		}
	 	break;
	    case BAND_PASS:
		if((fpl >= fpu) || (fpl <=fsl) || (fpu >= fsu) || (fsl >=fsu)){
		   fprintf(stderr,"iirfil: Band pass filter spec error.  \n");
		   return(4);
		}
		break;
	    case BAND_STOP:
		if((fpl >= fpu) || (fpl >=fsl) || (fpu <= fsu) || (fsl >=fsu)) {
		   fprintf(stderr,"iirfil: Band pass filter spec error.  \n");
		   return(4);
		}
		break;
	}
	/*
	 * Design the IIR filter.
	 * Put poles and Zeroes in file tmp.pz .
	 */
	status =IIRDesign(filterName,fs,fpb,fsb,fpl,fpu,fsl,fsu,
					pbdb,sbdb,filterType,desType);
	if (status) {
		fprintf(stderr,"Design Error in IIRDesign. \n");
		return(4);
	}
	/*
	 * Generate cascade coefficients from file tmp.pz
	 * Store in filterName.cas 
  	 */
	status=IIRCas(filterName);
	if (status) {
		fprintf(stderr,"Design Error in iircas cascade calc. \n");
		return(4);
	}
	/*
  	 * produce compact version of filterName.pz file
	 * store it in filterName.pz, i.e. overwrite filterName.pz
	 */
	PzConv(filterName);
	/*
	 * open file containing filter coefficients. Check 
	 * to see if it exists.
	 *
	 */
	strcpy(fname,filterName);
	strcat(fname,".cas");
        if( (ird_F = fopen(fname,"r")) == NULL) {
		fprintf(stderr,"iirfil: File tmp.cas could not be opened  \n");
		return(4);
	}
	/*
	 * Read in the filter coefficients and filter parameters.
	 *
	 */
         fscanf(ird_F,"%d",&ns);
      	 for (i=0; i
    
Top

Main Code



 


	for(no_samples=MIN_AVAIL();no_samples >0; --no_samples) {
               IT_IN(0);
               for (j=0; j< ns; j++){
                    if (j==0){
                              xs[1]=0.0;
                              xs[2]=0.0;
                              xs[0]=x(0);
                              if (n>0) xs[1]=x(1);
                              if (n>1) xs[2]=x(2);
                             }
                    if (j>0) { 
                             for (jj=0; jj<3; jj++)
                                           xs[jj] = ys[jj];
                    }

               jt = j*3;
               for (jj=0; jj<2; jj++)  
                     ys[jj+1] = ycas[jt+jj];

               ys[0]=xs[0]+(zc1[j]*xs[1])+(zc2[j]*xs[2])-(pc1[j]*ys[1])-(pc2[j]*ys[2]);

               for (jj=0; jj<2; jj++)   
                    ycas[jt+jj] = ys[jj];
               }

               if(IT_OUT(0)) {
			KrnOverflow("iirfil",0);
			return(99);
		}
               y(0) = ys[0]/wnorm;
               n = n+1;
              }

        return(0);




Top

Wrapup Code



 





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



 

/* iirfil.s */
/***********************************************************************
                             iirfil()
************************************************************************
This star designs and implements a cascade form IIR digital filter.
The specs and results of the design are stored in the file tmp.dat.
The cascade filter coefficients are store in a file tmp.cas as:
           ns: Number of sections
           zc1[i] zc2[i] i=1 to ns the numerator coefficients
           pc1[i] pc2[i] i=1 to ns the denominator coefficients
           in the Z-domain.

iirfil


This star designs and implements a cascade form IIR digital filter.
The specs and results of the design are stored in the file tmp.dat.
The cascade filter coefficients are store in a file tmp.cas as:
           ns: Number of sections
           zc1[i] zc2[i] i=1 to ns the numerator coefficients
           pc1[i] pc2[i] i=1 to ns the denominator coefficients
           in the Z-domain.


Date:  October 28, 1989 
Programmer: Sasan Ardalan.

*/