双极点低通滤波器
1 描述
最近看到apollo的滤波器代码,猛一看没整明白,因此就想推导一下公式。代码如下
void LpfCoefficients(const double ts, const double cutoff_freq,
std::vector<double> *denominators,
std::vector<double> *numerators) {
denominators->clear();
numerators->clear();
denominators->reserve(3);
numerators->reserve(3);
double wa = 2.0 * M_PI * cutoff_freq; // Analog frequency in rad/s
double alpha = wa * ts / 2.0; // tan(Wd/2), Wd is discrete frequency
double alpha_sqr = alpha * alpha;
double tmp_term = std::sqrt(2.0) * alpha + alpha_sqr;
double gain = alpha_sqr / (1.0 + tmp_term);
denominators->push_back(1.0);
denominators->push_back(2.0 * (alpha_sqr - 1.0) / (1.0 + tmp_term));
denominators->push_back((1.0 - std::sqrt(2.0) * alpha + alpha_sqr) /
(1.0 + tmp_term));
numerators->push_back(gain);
numerators->push_back(2.0 * gain);
numerators->push_back(gain);
}
从代码上可以看出来,应该是采用的是二阶的巴特沃斯滤波器,下面进行一下推导。
巴特沃斯二阶模拟滤波器传递函数
H ( s ) = w N 2 s 2 + 2 ∗ 0.707 ∗ w N ∗ s + w N 2 (1) H(s) = \frac{w^2_N}{s^2+2*0.707*w_N*s+w^2_N} \tag{1} H(s)=s2+2∗0.707∗wN∗s+wN2w