fixpoint_directiir.c

来自「CHP 5 - Real-Time Digital Signal Process」· C语言 代码 · 共 51 行

C
51
字号
// 
//  Project: Experiment 5.7.2: implementation of fixed-point IIR filter in direct form I - Chapter 5
//  File name: fixPoint_directIIR.c   
//
//  Description: This is the fixed-point IIR filter in direct form I realization
//
//  For the book "Real Time Digital Signal Processing: 
//                Implementation and Application, 2nd Ed"
//                By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
//                Publisher: John Wiley and Sons, Ltd
//
//  Tools used: CCS v.2.12.07
//              TMS320VC5510 DSK Rev-C
//

#include "fixPointIIR.h"

void fixPoint_IIR(short in, short *x, short *y, 
                  short *b, short nb, short *a, short na)
{
  long  z1,z2,temp;
  short i;

  for(i=nb-1; i>0; i--)         // Update the delay line x[]
  {
    x[i] = x[i-1];
  }
  x[0] = in;                    // Insert new data to delay line x[0]

  for(z1=0, i=0; i<nb; i++)     // Filter the x[] with coefficient b[]
  {
    temp = (long)x[i] * b[i];
    temp += 0x400;
    z1 += (short)(temp>>11);
  }
	
  for(i=na-1; i>0; i--)         // Update the y delay line
  {
    y[i] = y[i-1];
  }

  for(z2=0, i=1; i<na; i++)     // Filter the y[] with coefficient a[]
  {
    temp = (long)y[i] * a[i];
    temp += 0x400;
    z2 += (short)(temp>>11);
  }

  y[0] = (short)(z1 - z2);      // Place the result into y[0]
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?