当前位置: 首页 > >

二阶IIR滤波器系数计算方法

发布时间:

1、

2、
滤波器主要有以下几种:高通/低通/带通。下分别说明此三种滤波器的系统的求取方法。
通常,对一个滤波器的要求,我们主要给出以下技术规格:中心频率frequency,采样频率sampleRate,增益dBgain,品质因数Q。
为计算方便,先计算出以下几个值:
A = sqrt[ 10^(dBgain/20) ]
omega = 2pifrequency/sampleRate
sin = sin(omega)
cos = cos(omega)
alpha = sin/(2Q)
3、
高通滤波器系数的计算:
b0 = (1 + cos)/2
b1 = -(1 + cos)
b2 = (1 + cos)/2
a0 = 1 + alpha
a1 = -2
cos
a2 = 1 ? alpha
4、
低通滤波器系数的计算:
b0 = (1 - cos)/2
b1 = 1 - cos
b2 = (1 - cos)/2
a0 = 1 + alpha
a1 = -2cos
a2 = 1 ? alpha
5、
带通滤波器系统计算:
b0 = sin/2 = Q
alpha
b1 = 0
b2 = -sin/2 = -Qalpha
a0 = 1 + alpha
a1 = -2
cos
a2 = 1 - alpha
6、程序代码
typedef struct
{
float b0,b1,b2,a1,a2;
float d1,d2;
}biquadFilter_t;


#define PI 3.14159265358979323846f
#define BIQUAD_Q 1.0f/sqrtf(2.0f)


void biquadFilterInit(biquadFilter_t filter,uint32_t filterFreq,uint32_t refreshRate,float Q)
{
const float SampleRate = 1/((float)refreshRate
0.000001f);
const float omega = 2* PIfilterFreq/SampleRate;
const float sn = sinf(omega);
const float cs = cosf(omega);
//const float alpha = sinf(2
Q);
const float alpha = sn/(2*Q); // 对二阶低通滤波参数进行优化


float b0 = 0,b1=0,b2=0,a0=0,a1=0,a2=0;
b0 = (1-cs)/2;
b1 = 1-cs;
b2 = (1-cs)/2;
a0 = 1+ alpha;
a1 = -2*cs;
a2 = 1-alpha;

filter->b0 = b0/a0;
filter->b1 = b1/a0;
filter->b2 = b2/a0;
filter->a1 = a1/a0;
filter->a2 = a2/a0;
filter->d1 = 0;
filter->d2 = 0;

}


float biquadFilterApply(biquadFilter_t filter,float input)
{
const float result = filter->b0
input + filter->d1;
filter->d1 = filter->b1 * input - filter->a1result + filter->d2;
filter->d2 = filter->b2
input - filter->a2*result;
return result;
}


biquadFilter_t gryo_51Hz_parameter1,gryo_51Hz_parameter2,gryo_51Hz_parameter3;


biquadFilterInit(&gryo_51Hz_parameter1,51, 1000, BIQUAD_Q);



友情链接: