⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixpoint_cascadetiir.c

📁 CHP 5 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
//
//  Project: Experiment 5.7.3: implementation of fixed-point IIR filter in direct form II - Chapter 5
//  File name: fixPoint_cascadeIIR.c   
//
//  Description: This is the fixed-point IIR filter implementation in direct form II
//
//  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
//
//  fixPoint_cascadeIIR.c - IIR direct form II biquads implementation
//  prototype: void cascadeIIR(short *, short, short *, float *, short, float *);
//
//  Entry: arg0: pointer to the input sample buffer
//         arg1: size of the input sample buffer
//         arg2: pointer to the output sample buffer
//         arg3: pointer to the coefficients array
//         arg4: number of second-order IIR sections
//         arg5: pointer to the filter delay-line buffer
//
//  Return: None
//
//  Tools used: CCS v.2.12.07
//              TMS320VC5510 DSK Rev-C
//

void cascadeIIR(short *x, short Nx, short *y, 
                short *coef, short Ns, short *w)
{      
  short i,j,n,m,k,l;
  short temp16;
  long  w_0, temp32;
        
  m=Ns*5;                            // Setup for circular buffer coef[]  
  k=Ns*2;                            // Setup for circular buffer w[]  

  for (j=0,l=0,n=0; n<Nx; n++)       // IIR filter begin 
  {
    w_0 = (long)x[n]<<12;            // Scale input to prevent overflow  
    for (i=0; i<Ns; i++)
    {
      temp32 = (long)(*(w+l)) * *(coef+j); j++; l=(l+Ns)%k;
      w_0   -= temp32<<1;
      temp32 = (long)(*(w+l)) * *(coef+j); j++; 
      w_0   -= temp32<<1;
      w_0   += 0x4000;               // Rounding

      temp16 = *(w+l);
      *(w+l) = (short)(w_0>>15);     // Save in Q15  
 
      w_0    = (long)temp16 * *(coef+j); j++;
      w_0  <<= 1;
      temp32 = (long)*(w+l) * *(coef+j); j++; l=(l+Ns)%k;
      w_0   += temp32<<1;
      temp32 = (long)*(w+l) * *(coef+j); j=(j+1)%m; l=(l+1)%k; 
      w_0   += temp32<<1;
      w_0   += 0x800;                // Rounding
    }
    y[n] = (short)(w_0>>12);         // Output in Q15 format 
  }
}

⌨️ 快捷键说明

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