|
#include <stdio.h> // 添加标准输入输出库以支持打印
void test(float *in, float *out, int in_len, float *coef) {
int i, j;
int coef_len2, acc_length;
float acc;
int fir_length = 35;
int coef_start_idx = 0;
int in_ptr_idx;
int in_end_idx = in_len - 1;
coef_len2 = (fir_length + 1) / 2;
in_ptr_idx = coef_len2 - 1;
acc_length = coef_len2;
for (i = 0; i < in_len; i++) {
acc = coef[coef_start_idx] * in[in_ptr_idx];
for (j = 1; j < acc_length; j++) {
acc += coef[coef_start_idx + j] * in[in_ptr_idx - j];
}
out[i] = acc;
if (in_ptr_idx == in_end_idx) {
acc_length--;
coef_start_idx++;
} else if (acc_length < fir_length) {
acc_length++;
}
in_ptr_idx++;
}
}
// 添加main函数作为程序入口
int main() {
// 定义测试用的数组(长度适中以便演示)
float in[50] = {0}; // 输入数组,初始化为0
float out[50] = {0}; // 输出数组,初始化为0
float coef[35] = {0}; // 系数数组,初始化为0
// 为测试数组赋值(简单的测试数据)
for (int i = 0; i < 50; i++) {
in[i] = (float)i; // 输入数组赋值为0,1,2,...,49
}
coef[0] = 1.0f; // 简单设置一个系数值
// 调用测试函数
test(in, out, 50, coef);
// 打印部分结果以验证程序运行
printf("测试结果(前10个输出):\n");
for (int i = 0; i < 10; i++) {
printf("out[%d] = %.2f\n", i, out[i]);
}
return 0;
} |
|