正如其他OS主题中所述,我从这里https://www-users.cs.york.ac.uk/~fisher/mkfilter得到了Bw BP C代码,并做了250Hz的4阶,从10到20Hz。
下面是此滤波器的代码,它是从该站点提供的代码改编而成的,并添加了几行以将输入信号的实部和虚部相乘(来自fw FFT R2C):
const unsigned char NZEROS = 8,
NPOLES = 8;
double GAIN = 1.121655430e+02,
xv[NZEROS + 2] = {}, // NZEROS + 1 for real and + 1 for imag
yv[NPOLES + 2] = {}; // NPOLES + 1 for real and + 1 for imag
for (size_t i = 0; i < array_length_fft_1D; i++)
{
xv[0] = xv[1]; xv[1] = xv[2];
xv[2] = xv[3]; xv[3] = xv[4];
xv[4] = xv[5]; xv[5] = xv[6];
xv[6] = xv[7]; xv[7] = xv[8];
xv[8] = fft_complex_1D[0][i] / GAIN; // Real part, input
xv[9] = fft_complex_1D[1][i] / GAIN; // Imaginary part, input
yv[0] = yv[1]; yv[1] = yv[2];
yv[2] = yv[3]; yv[3] = yv[4];
yv[4] = yv[5]; yv[5] = yv[6];
yv[6] = yv[7]; yv[7] = yv[8];
// Multiplying the real part
yv[8] = (xv[0] + xv[8]) - 4 * (xv[2] + xv[6]) + 6 * xv[4]
+ (-0.1316807150 * yv[0]) + (1.2338753102 * yv[1])
+ (-5.2054087885 * yv[2]) + (12.8890751850 * yv[3])
+ (-20.5097097890 * yv[4]) + (21.4961146820 * yv[5])
+ (-14.4728919700 * yv[6]) + (5.7005626010 * yv[7]);
// Multiplying the imaginary part
yv[9] = (xv[0] + xv[9]) - 4 * (xv[2] + xv[6]) + 6 * xv[4]
+ (-0.1316807150 * yv[0]) + (1.2338753102 * yv[1])
+ (-5.2054087885 * yv[2]) + (12.8890751850 * yv[3])
+ (-20.5097097890 * yv[4]) + (21.4961146820 * yv[5])
+ (-14.4728919700 * yv[6]) + (5.7005626010 * yv[7]);
fft_complex_1D[0][i] = static_cast<float>(yv[8]); // At this point the real part of the complex array is overwritten
fft_complex_1D[1][i] = static_cast<float>(yv[9]); // At this point the imaginary part of the complex array is overwritten
}
fft_complex_1D是来自fw FFT的输入数组,在每次迭代结束时,实数和虚数部分均乘以系数。稍后将其发送到逆FFT C2R,并输出一个浮点数组。
然后,当我去Octave绘制频谱图并查看是否确实在滤除事物时,会衰减10Hz之前和20Hz之后的频率,但是其他所有东西似乎都没有变化,我希望衰减。参见下图,该图显示了10-20Hz区域标记为绿色。输入的是未经过滤的蓝色数据(从-5到+5的实数)。红色为过滤后的数据。没有对任何数据应用缩放。
此过滤器代码中有错误或缺失。你们能提供一些反馈(不要双关语)吗?
答案 0 :(得分:0)
生成的C代码是递归关系,它描述了时域中的过滤器行为。每个索引均指的是经过滤波的输入信号的样本(您可能会从ADC获得的信号)。
您通过以下方式“破坏”代码: