📄 main.c
字号:
//IIR 19阶butterworth低通滤波器
//采样频率fs=40k,截止频率fc=10k
//吴臻志作于2006/12/8
#include <c6x.h>
#include "math.h"
#define N 20
#define Length 128
float input[Length],output[Length];
const float b[N] = {
1.532234455e-005,0.0002911245683, 0.002620120998, 0.01484735217, 0.05938940868,
0.1781682223, 0.415725857, 0.7720623016, 1.158093452, 1.415447593,
1.415447593, 1.158093452, 0.7720623016, 0.415725857, 0.1781682223,
0.05938940868, 0.01484735217, 0.002620120998,0.0002911245683, 1.532234455e-005
};
const float a[N] = {
1,-1.341377151e-015, 2.582051277,-3.020413399e-015, 2.629014969,
-2.643519736e-015, 1.364365935,-1.157850946e-015, 0.3901539147,-2.727497971e-016,
0.06217307225,-3.461429587e-017, 0.005333174486,-2.247626948e-018,0.0002255303698,
-6.607450878e-020,3.915039997e-006,-6.698137419e-022,1.784284365e-008,-9.904767921e-025
};
void filter(){
int n,j;
float temp;
float x[N],y[N];
//采样频率fs=40k,截止频率fc=10k
for (j=0;j<N;j++){
x[j]=y[j]=0;
}
for (n=0;n<Length;n++){
temp=0;
x[0]=input[n];
for (j=0;j<N;j++){
temp=temp+x[j]*b[j];
}
for (j=1;j<N;j++){
temp=temp-y[j]*a[j];
}
y[0]=temp;
//record values
output[n]=y[0];
//refresh state
for (j=N-1;j>0;j--){
x[j]=x[j-1];
y[j]=y[j-1];
}
}
while(1);
}
void test1(){
int n;
for (n=0;n<Length;n++){
input[n]=0;
}
input[Length/2]=1e034;
}
void test2(){
int n;
for (n=0;n<Length;n++){
input[n]=sin(2*3.1415926*n*9000/40000)+sin(2*3.1415926*n*11000/40000);
}
}
void main(){
test2();
filter();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -