1.使用matlab产生产生参数。
static float test_f(float input)
{
static float xv[2+1], yv[2+1];
xv[0] = xv[1]; xv[1] = xv[2];
xv[2] = input/ 1.949595788e+02;
yv[0] = yv[1]; yv[1] = yv[2];
yv[2] = (xv[0] + xv[2]) + 2 * xv[1]
+ ( -0.8079495914 * yv[0]) + ( 1.7874325180 * yv[1]);
return yv[2];
}
static float iir_filter_matab(float input)
{
//y[n] = 1*x[n] + 2*x[n-1] + 1*x[n-2] - (-1.1429805025)*y[n-1] - (0.412801596)*y[n-2]
// matlab 都是二阶滤波级联
double gain = 0.005129268366107;
float table_N[3] = {1,2,1};
float table_D[3] = { 1, -1.787432517956, 0.8079495914209};
static float xv[3], yv[3];
xv[2] = input*gain;
xv[0] = xv[1]; xv[1] = xv[2];
yv[0] = yv[1]; yv[1] = yv[2];
yv[2] = table_N[0]*xv[2]+table_N[1]*xv[1]+table_N[2]*xv[0] - table_D[1]*yv[1] - table_D[2]*yv[0];
return yv[2];
}
y[n]=b0⋅x[n]+b1⋅x[n−1]+b2⋅x[n−2]−a1⋅y[n−1]−a2⋅y[n−2]
matlab 中高阶滤波是用二阶滤波级联。
测试和网页版生成的代码 滤波效果基本上一样。
网页版生成 C语言
https://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html
总结方差为数据离散度。