工作中需要优化PEQ(参数均衡器),平台本身是ARM平台,所以我想到调用ARM本身的滤波器函数,因为PEQ的实现是滤波器级联,所以选择调用ARM的cmsis-dsp库中的arm_biquad_cascade_df1_f32函数来实现
arm_biquad_cascade_df1_f32函数的用法
arm_biquad_cascade_df1_f32可以实现n个二阶滤波器级联
void arm_biquad_cascade_df1_init_f32(
arm_biquad_casd_df1_inst_f32 * S,
uint8_t numStages,
const float32_t * pCoeffs,
float32_t * pState)
numStages是二阶滤波器个数;
pCoeffs是滤波器参数的buffer指针,buffer大小为5*numStages,buffer中滤波器参数排列方式为{b10,b11,b12,a11,a12,b20,b21,b22,a21,a22,........};
注意!!!(该buffer中的an1和an2对应于
matlab中用fdatool工具生成的参数中a1和a2的负数)
pState是状态缓存buffer,大小为4*numStages;
void arm_biquad_cascade_df1_f32(
const arm_biquad_casd_df1_inst_f32 * S,
const float32_t * pSrc,
float32_t * pDst,
uint32_t blockSize)
pSrc输入数据指针
pDst输出数据指针
(pSrc和pDst可以是同一个指针)
blockSize处理数据的长度
仿真C代码
#define DATA_LEN (4096)
#define PI (3.141592653)
arm_biquad_casd_df1_inst_f32 arm_biquad_casd_df1_inst_f32_t;
float peq_para[5] = { 0.019238573667911894, 0.038477147335823789, 0.019238573667911894, 1.5711024401904012, -0.64805673486204896 };
float peq_state[4] = { 0 };
float pin[DATA_LEN] = {0};
float pout[DATA_LEN] = { 0 };
void main()
{
for (int i = 0; i < DATA_LEN; i++)
{
pin
= sinf(2*PI*50*i/DATA_LEN) + sinf(2*PI*500*i/DATA_LEN);
}
arm_biquad_cascade_df1_init_f32(&arm_biquad_casd_df1_inst_f32_t, 1, peq_para, peq_state);
arm_biquad_cascade_df1_f32(&arm_biquad_casd_df1_inst_f32_t, pin, pout, DATA_LEN);
}
处理后波形
原作者:梵高。先生