📄 iir.c
字号:
/*
iir.c - IIR direct form II biquads implementation
prototype: void iir(int *, int, int *, float *, int, 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
*/
#define CHECK_OVERFLOW 1
#if CHECK_OVERFLOW
static float w_max=-1.,w_min=1.;
#endif
void iir(int *x, int Nx, int *y, float *coef, int Ns, float *w)
{
int i,j,n,m,k,l,p;
float temp, w_0;
m=Ns*5; /* Setup for circular buffer coef[] */
k=Ns*2; /* Setup for circular buffer d[] */
for (j=0,l=0,n=0; n<Nx; n++) /* IIR filter */
{
w_0 = (float)(x[n]/32767.0); /* Q15 to float */
for (i=0; i<Ns; i++)
{
w_0 -= *(w+l) * *(coef+j); j++; l=(l+Ns)%k;
w_0 -= *(w+l) * *(coef+j); j++;
temp = *(w+l);
*(w+l) = w_0;
#if CHECK_OVERFLOW
for (p=0;p<k;p++)
{
if (w_max <= w_0) w_max = w_0;
if (w_min > w_0) w_min = w_0;
}
#endif
w_0 = temp * *(coef+j); j++;
w_0 += *(w+l) * *(coef+j); j++; l=(l+Ns)%k;
w_0 += *(w+l) * *(coef+j); j=(j+1)%m; l=(l+1)%k;
#if CHECK_OVERFLOW
for (p=0;p<k;p++)
{
if (w_max <= w_0) w_max = w_0;
if (w_min > w_0) w_min = w_0;
}
#endif
}
y[n] = (int)(w_0*32767); /* Q15 format output */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -