intrinsics_iir.c

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

C
59
字号
//
//  Project: Experiment 5.7.4: implementation of direct form-II IIR filter in intrinsics - Chapter 5
//  File name: intrinsics_IIR.c   
//
//  Description: This is the intrinsics implementation of a fixed-point IIR filter 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
//
//  intrinsics_IIR.c - IIR direct form II biquads implementation
//  prototype: void intrinsics_IIR(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
//

#include <intrindefs.h>
#include "intrinsics_IIR.h"

void intrinsics_IIR(short *x, short Nx, short *y, 
                    short *coef, short Ns, short *w)
{      
  short i,j,n,m,k,l;
  short temp16;
  long  w_0;
        
  m=Ns*5;                            // Setup for circular buffer coef[]  
  k=Ns*2-1;                          // 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++)
    {
      w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)&k;
      w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; 

      temp16 = *(w+l);
      *(w+l) = (short)(w_0>>15);    // Save in Q15  

      w_0 = _lsmpy(   temp16,*(coef+j)); j++; 
      w_0 = _smac(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)&k; 
      w_0 = _smac(w_0,*(w+l),*(coef+j)); j=(j+1)%m; l=(l+1)&k;
    }
    y[n] = (short)(w_0>>12);        // Q15 format output 
  }
}

⌨️ 快捷键说明

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