MATLAB生成IIR系数
采用率1k,截止频率30hz,Matlab生成6阶对应的biquad3级系数
Verilog测试代码
// fs=1khz,fc=30hz
initial beginreal Sig_Orig, Noise_white, Mix_sig;real fs = 1000;Int T= 1; //周期int N= T*fs; //1s的采样点数// 数组声明real Mix_sig_arr[1000];real Sig_0rig_arr[1000]; real Sig_result_i_arr[1000];real Sig_result_i_arrl[1000]; real Sig_result_i_arr2[1000];// 中间变量声明real Sig_result_i, Sig_result_ii, Sig_result_i2, Sig_result_i_end;// 滤波器系数矩阵声明real NUM[3][3] = {{1, 2.007504948495, 1.007523744426},{1, 1.999983159466, 1.000001892 }, {1, 1.992511892039, 0.9925305617226}};real DEN[3][3] = {{1, -1.663488912079, 0.6934851906154},{1, -1.734725768632, 0.7660066007869}, {1, -1.873703886013, 0.9074907921583}};real gain = 0.0000004953522354214;#100;@(posedge rstn);// 循环处理2024个点for (int t = 0; t < N; t++) begin @(posedge CLK_REG);// 生成原始信号(10Hz的正弦波)Sig_Orig = 0.5 * sin(2 * PI * 10 * (t / 1000.0)); // Sig_0rig_arr[t] = Sig_Orig; // 生成白噪声Noise_white = 0.25 * sin(2 * PI * 80 * (t / 1000.0)) +0.15 * cos(2 * PI * 150 * (t / 1000.0)) +0.05 * sin(2 * PI * 800 * (t / 1000.0) + 0.33 * PI);// 混合原始信号和白噪声Mix_sig = Sig_Orig + Noise_white;Mix_sig_arr[t] = Mix_sig;// 直接I型的IIRSig_result_i = NUM[0][0] * Mix_sig_arr[t] +NUM[0][1] * Mix_sig_arr[t-1] +NUM[0][2] * Mix_sig_arr[t-2] -DEN[0][1] * Sig_result_i_arr[t-1] -DEN[0][2] * Sig_result_i_arr[t-2];Sig_result_i_arr[t] = Sig_result_i;Sig_result_il = NUM[1][0] * Sig_result_i_arr[t] +NUM[1][1] * Sig_result_i_arr[t-1] +NUM[1][2] * Sig_result_i_arr[t-2] -DEN[1][1] * Sig_result_i_arrl[t-1] -DEN[1][2] * Sig_result_i_arrl[t-2];Sig_result_i_arrl[t] = Sig_result_il;Sig_result_i2 = NUM[2][0] * Sig_result_i_arrl[t] +NUM[2][1] * Sig_result_i_arrl[t-1] +NUM[2][2] * Sig_result_i_arrl[t-2] -DEN[2][1] * Sig_result_i_arr2[t-1] -DEN[2][2] * Sig_result_i_arr2[t-2];Sig_result_i_arr2[t] = Sig_result_i2;// 计算最终结果并应用增益Sig_result_i_end = Sig_result_i2 * gain;end
多级biquad滤波器滤波效果
verdi波形,第一级还有明显的杂波,第二级后就基本还原了原始信号,每级滤波后都会有一定的相位滞后,最终增益后的幅值有细微放大(原始信号最大值500滤波后变为502.5)。