本帖最后由 hanl 于 2011-7-21 10:07 编辑
我用C语言实现一个butterworth低通滤波器,现在遇到问题,please help me!
实现过程:
1、采样频率10KHz,通带边界频率2KHz,通带波纹小于1dB,阻带边界频率3KHz,阻带衰减大于40dB。
2、用
matlab求出滤波器系数b,a
- >> Fp = 2000;
- >> Fs = 3000;
- >> F = 10000;
- >> T = 1/F;
- >> Ap = 1;
- >> As = 40;
- >> Wp = Fp*T*2;
- >> Ws = Fs*T*2;
- >> [n,Wc] = buttord(Wp,Ws,Ap,As);
- >> [b,a] = butter(n,Wc)
- b =
- 0.0021 0.0186 0.0745 0.1739 0.2609 0.2609 0.1739 0.0745 0.0186 0.0021
- a =
- 1.0000 -1.0893 1.6925 -1.0804 0.7329 -0.2722 0.0916 -0.0174 0.0024 -0.0001
- >>
复制代码3、差分方程: y(0) = b(0)*x(0) + b(1)*x(1) +...+ b(9)*x(9) - {a(1)*y(1) + a(2)*y(2) +...+ a(9)*y(9)}
4、程序:
- double a[L] = {1.0000, -1.0893, 1.6925, -1.0804, 0.7329, -0.2722, 0.0916, -0.0174, 0.0024, -0.0001};
- double b[L] = {0.0021, 0.0186, 0.0745, 0.1739, 0.2609, 0.2609, 0.1739, 0.0745, 0.0186, 0.0021};
- read(&input); //输入范围:-10V~+10V ,量化范围 0~65535
- x[0] = input-32767;
- for (i=0; i<=L-1; i++)
- {
- b_sum = b[i]*x[i] + b_sum;
- a_sum = a[i+1]*y[i+1] + a_sum;
- }
- y[0] = b_sum - a_sum;
- output = y[0];
- for (i=L-1; i>=1; i--)
- {
- x[i] = x[i-1];
- y[i] = y[i-1];
- }
- write(output);
复制代码5、测试结果
a、无输入
(单位:0.1ms)
b、输入1KHz正弦波,峰峰值 4V
(单位:0.1ms)
到此,不知道哪里出了问题,请高人赐教
一周热门 更多>