固定点数学与高性能数字滤波器技术解析
1. 固定点数学基础
固定点数学在许多应用场景中具有重要作用,特别是在对性能要求较高的嵌入式系统中。下面先介绍使用固定点数学计算正弦函数的方法。
首先是一个简单的固定点正弦函数实现:
template<typename fixed_point_type>
fixed_point_type sin(const fixed_point_type& x)
{
// Scale x to chi (+-pi/2 to +-1).
fixed_point_type chi(x * 0.6366198F);
// Calculate chi^2 for the polynomial expansion.
fixed_point_type chi2 = chi * chi;
// Do the order-5 polynomial expansion.
return ((
0.0722739F
* chi2 - 0.6425639F)
* chi2 + 1.5704128F)
* chi;
}
我们使用 Q15.16 固定点表示来计算 sin(1 / 2) 的近似值:
// 0.47937
fixed_point_15pt16 y = sin(fixed_point_15pt16(1) / 2);
计算结果 y 为 0.4