gpt4 book ai didi

c++ - 带通 FIR 滤波器

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:17:04 26 4
gpt4 key购买 nike

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

效果很好,可以切断所需的 strip 。但是,当我尝试以较小的步幅更改上限或下限时,在某些限制值上我听到了错误的结果 - 频率衰减或偏移(与当前限制不对应)的声音。

计算脉冲响应的函数:

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)Fl - 下限傅-上限

以及简单的过滤功能:

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));

但是结果是错误的。我需要标准化拍子吗?

最佳答案

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

...This Windowed FIR Filter C Code has two parts, the first is the calculation of the impulse response for a rectangular window (low pass, high pass, band pass, or notch). Then a window (Kaiser, Hanning, etc) is applied to the impulse response. There are several windows to choose from...

关于c++ - 带通 FIR 滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27817159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com