带通FIR滤波器

时间:2015-01-07 10:20:16

标签: c++ audio filter signal-processing

我需要制作一个简单的带通音频滤波器。 现在我使用了这个简单的C ++类:http://www.cardinalpeak.com/blog/a-c-class-to-implement-low-pass-high-pass-and-band-pass-filters

效果很好,切断了所需的乐队。但是当我尝试用小步长改变上限或下限时,在某些极限值上我听到了错误的结果 - 衰减或频率偏移(不对应电流限制)声音。

计算脉冲响应的函数:

void Filter::designBPF()
{
    int n;
    float mm;

    for(n = 0; n < m_num_taps; n++){
        mm = n - (m_num_taps - 1.0) / 2.0;
        if( mm == 0.0 ) m_taps[n] = (m_phi - m_lambda) / M_PI;
        else m_taps[n] = (   sin( mm * m_phi ) -
                             sin( mm * m_lambda )   ) / (mm * M_PI);
    }

    return;
}

其中

m_lambda = M_PI * Fl / (Fs/2);
m_phi = M_PI * Fu / (Fs/2);

Fs - 采样率(44.100) F1 - 下限 福 - 上限

简单的过滤功能:

float Filter::do_sample(float data_sample)
{
    int i;
    float result;

    if( m_error_flag != 0 ) return(0);

    for(i = m_num_taps - 1; i >= 1; i--){
        m_sr[i] = m_sr[i-1];
    }   
    m_sr[0] = data_sample;

    result = 0;
    for(i = 0; i < m_num_taps; i++) result += m_sr[i] * m_taps[i];

    return result;
}

我是否需要使用任何窗口功能(Blackman等)?如果是,我该怎么做? 我试图将我的冲动响应乘以布莱克曼窗口:

m_taps[n] *= 0.42 - 0.5 * cos(2.0 * M_PI * n / double(N - 1)) +
                0.08 * cos(4.0 * M_PI * n / double(N - 1));

但结果是错误的。 我是否需要规范水龙头?

2 个答案:

答案 0 :(得分:1)

我找到了一个很好的免费实现FIR滤波器: http://www.iowahills.com/A7ExampleCodePage.html

  

...这个窗口FIR滤波器C代码有两部分,第一部分是   计算矩形窗口的脉冲响应(低   传球,高传,带传球或缺口)。然后是一扇窗户(凯撒,汉宁,   等)应用于脉冲响应。有几个窗户   选择......

答案 1 :(得分:0)

y[i] = waveform[i] × (0.42659071 – 0.49656062cos(w) + 0.07684867cos(2w))

where w = (2)i/n and n is the number of elements in the waveform

Try this I got the code from: http://zone.ni.com/reference/en-XX/help/370592P-01/digitizers/blackman_window/

I hope this helps.

相关问题