📄 iir_filter.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:TMS320C5416 */
/* 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. */
/* for speed improvement,expand sos matrix and use left shift */
/* in replacement of multiply operations */
/* Version:1.0 Dec25,2006 Marine@seeddsp.com */
/* Rivision: */
/******************************************************************************/
#include <csl.h>
#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)
{
Int32 i;
Int32 j;
Int32 xx;
Int32 ym[ORDER_IIR];
Int32 d1[ORDER_IIR];
Int32 d2[ORDER_IIR];
Int32 d3[ORDER_IIR];
Int32 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=(Int32)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]
d1[j]=(Int32)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>>=s; //round bits
ym[j]=(Int32)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 + -