C编程FIR滤波器的实现 [英] FIR filter implementation in C programming

查看:1032
本文介绍了C编程FIR滤波器的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何用c语言编程实现FIR滤波器。

Can anyone tell me how to implement an FIR filter using c programming language.

推荐答案

设计一个FIR滤波器的的一个简单的话题,但实施一个已经设计的滤波器(假设你已经拥有了FIR系数)是不是太糟糕。该算法被称为卷积。这里有一个天真的实现...

Designing an FIR filter is NOT a simple topic, but implementing an already-designed filter (assuming you already have the FIR coefficients) isn't too bad. The algorithm is called convolution. Here's a naive implementation...

void convolve (double *p_coeffs, int p_coeffs_n,
               double *p_in, double *p_out, int n)
{
  int i, j, k;
  double tmp;

  for (k = 0; k < n; k++)  //  position in output
  {
    tmp = 0;

    for (i = 0; i < p_coeffs_n; i++)  //  position in coefficients array
    {
      j = k - i;  //  position in input

      if (j >= 0)  //  bounds check for input buffer
      {
        tmp += p_coeffs [k] * p_in [j];
      }
    }

    p_out [i] = tmp;
  }
}

基本上,卷积确实的输入信号的一个移动加权平均值。权重是滤波器系数,其被假定为总和为1.0。如果权重之和为1.0之外的东西,你得到一些放大/衰减以及过滤。

Basically, the convolution does a moving weighted average of the input signal. The weights are the filter coefficients, which are assumed to sum to 1.0. If the weights sum to something other than 1.0, you get some amplification/attenuation as well as filtering.

顺便说一句 - 这是可能的这个函数的系数阵向后 - 我没有双重检查,它是因为我想过这些事情,而

BTW - it's possible this function has the coefficients array backwards - I haven't double-checked and it's a while since I thought about these things.

有关如何计算FIR系数为特定的过滤器,还有背后的数学了相当数量的 - 你真的需要数字信号处理一本好书。 这其中是免费提供的PDF,但我不知道它有多好。我有<一个href=\"http://www.amazon.co.uk/Digital-Filter-Designers-Handbook-Algorithms/dp/0070538069/ref=sr_1_2?ie=UTF8&qid=1361437667&sr=8-2\">Rorabaugh和<一个href=\"http://www.amazon.co.uk/Introduction-Signal-Processing-$p$pntice-Series/dp/0132091720/ref=sr_1_sc_2?s=books&ie=UTF8&qid=1361437726&sr=1-2-spell\">Orfandis,双方发表在90年代中期,但这些事情没有真正得到过时。

For how you calculate the FIR coefficients for a particular filter, there's a fair amount of mathematics behind that - you really need a good book on digital signal processing. This one is available free for a PDF, but I'm not sure how good it is. I have Rorabaugh and Orfandis, both published in the mid nineties but these things don't really get obsolete.

这篇关于C编程FIR滤波器的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆