C中波形文件的FIR滤波器函数

时间:2017-03-30 22:22:40

标签: c filter wave

我一直在尝试创建一个实现FIR过滤器的功能,该过滤器读取输入波形文件并将过滤后的波形文件输出到单独的文件中。我已经有工作函数从二进制过滤器文件中读取系数编号和值,以及读取波形文件并将数据存储到标题和数据中的函数,以及写入新的波形文件函数。我试图过滤波形文件并输出新文件,但波形文件没有像它应该的那样远程声音。这是我尝试过的:

int filter(char *filter_filename, char *input_wavefilename, char *output_wavefilename)
{
    // Variables
    int                         coeff_num,                              // Number of coefficients in filter file
                                i,                                      // Loop variable
                                j;                                      // Loop variable
    double                      *coeff_values;                          // Value of coefficient in filter file
    char                        *data,                                  // data of wavefile
                                *output_data,                           // New data to be writen the the filtered wavefile
                                *output_path = "output/question3/";     // Where the output file will be written to
                                pcm_wavefile_header_type    header;                                 // Header of the wavefile

    // Reading & Error checking the coefficients
    if(read_coefficients(&coeff_num, &coeff_values, filter_filename) != 0)
    {
        return -1;
    }

    // Reading & Error checking the wavefiles
    if (read_pcm_wavefile(&header, &data, input_wavefilename)!=0)
    {
        return -1;
     }

    // Variables
    int number_of_samples = header.Subchunk2Size/header.BlockAlign;
    char data_sample[number_of_samples];

    // Creating output data
    for(j = 0; j < number_of_samples; j++)
    {
        output_data[j] = 0;

        for(i = 0; i < coeff_num; i++)
        {
            output_data[j] += (char)coeff_values[i]*data[j-i];
        }
    }

    // Write wavefile
    write_pcm_wavefile(&header, output_data, output_wavefilename, output_path);

    // Freeing the data
    free(data);
    free(output_data);

    return 0; // Successful
}

谁能看到我做错了什么?

谢谢!

0 个答案:

没有答案