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

📄 iir_filter.c

📁 合众达SEED-DTK2812 光盘内容 DSP源码 用户指南 实验手册
💻 C
字号:
/******************************************************************************/
/*  Copyright 2006 by SEED Electronic Technology LTD.                         */
/*  All rights reserved. SEED Electronic Technology LTD.                      */
/*  Restricted rights to use, duplicate or disclose this code are             */
/*  granted through contract.                                                 */
/******************************************************************************/


/******************************************************************************/
/*  Tiltle:IIR_filter.c                                                       */
/*  Platform:TMS320F2812                                                      */
/*  Author:Marine@seeddsp.com                                                 */
/*  Purpose:IIR filter procedure for processing a group of data               */
/*  void iir_filter(const short x[],const short sos[],const short g[],\       */
/*                  short y[],int m,int s);                                   */
/*  const short x[]:输入信号的缓冲数组,short类型,在滤波中不可修改          */
/*  const short sos[]:滤波器的SOS系数数组,short类型,在滤波中不可修改       */
/*  const short g[]:滤波器的G系数数组,short类型,在滤波中不可修改           */
/*  short y[]:输出信号的缓冲数组,short类型                                  */
/*  m:输入信号的长度,即数组x[]的长度                                        */ 
/*  s:生成整型的滤波器系数时使用的移位数目,本例中为ROUND_IIR                */
/*  Note:-o3 compile option recommended.                                      */
/*       x[] and y[] not permitted to have relative addresses.                */
/*  Version:1.0   Dec25,2006   Marine@seeddsp.com                             */
/*  Rivision:                                                                 */
/******************************************************************************/
#ifndef ORDER_IIR
    #define   ORDER_IIR  3
#endif



  
void iir_filter(const short x[],const short sos[],const short g[],
                short y[],int m,int s)             

{
  int   i;
  int   j;
  
  int   xx;            
  int   ym[ORDER_IIR];       
  int   d1[ORDER_IIR];
  int   d2[ORDER_IIR];
  int   d3[ORDER_IIR];
  int   k;
  long   dd;
  long   yy;

//initialize middle parameters  
  for(i=0;i<ORDER_IIR;i++)
     {
     d1[i]=0;
     d2[i]=0;
     d3[i]=0;
     ym[i]=0;
     }
     
 
  for(i=0;i<m;i++)
   { for(j=0;j<ORDER_IIR;j++)
      {
        if(!j)              //the first level input is x[i]
              xx=(int)x[i];
          else
              xx=ym[j-1];   //other levels input is ym[j-1]
       
       k=j*6+4;             //index
       
    
       dd=(long)xx-(long)sos[k]*(long)d2[j]; //AR part
       dd-=(long)sos[k+1]*(long)d3[j];      
       //dd>>=sos[k-1];      //eleminate a[0]
       dd>>=10;
       d1[j]=(int)dd;
       
       yy=(long)sos[k-4]*(long)d1[j];  //FIR part
       yy+=(long)sos[k-3]*(long)d2[j];
       yy+=(long)sos[k-2]*(long)d3[j];
       
       yy=(long)yy*(long)g[j];       //level gain
       yy>>=16;              //round bits
     
       ym[j]=(int)yy;
      
       
       d3[j]=d2[j];  //put forward registers chain
       d2[j]=d1[j];
       
       if(j==ORDER_IIR-1)    //output at last level
           y[i]=(short)yy;
          
      }
   }
}


/*********************************************************************************

//End of file

*********************************************************************************/


⌨️ 快捷键说明

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