Bessel滤波器c语言实现
时间: 2023-05-12 11:03:31 浏览: 62
以下是Bessel滤波器的C语言实现代码:
```c
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
double bessel(double x, int n) {
double sum = 0.0;
double t = 1.0;
double u = 1.0;
int i, j;
for (i = 0; i <= n; i++) {
t = 1.0;
for (j = 1; j <= i; j++) {
t *= x / j;
}
u = t * t;
sum += u;
}
return sum;
}
void bessel_filter(double *input, double *output, int length, double cutoff, int order, double sample_rate) {
double wc = 2.0 * PI * cutoff / sample_rate;
double b0 = bessel(wc, order);
double b1 = 0.0;
double b2 = 0.0;
double a1 = 0.0;
double a2 = 0.0;
double w0 = 2.0 * PI * cutoff;
double alpha = sin(w0) / (2.0 * exp(log(2.0) / 2.0) * bessel(wc, order - 1));
double cosw0 = cos(w0);
double a = 1.0 + alpha;
b0 /= a;
b1 = 0.0 - b0 * cosw0;
b2 = b0;
a1 = 0.0 - alpha * cosw0;
a2 = 1.0 - alpha;
int i;
double x1 = 0.0;
double x2 = 0.0;
double y1 = 0.0;
double y2 = 0.0;
for (i = 0; i < length; i++) {
double x0 = input[i];
double y0 = b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
output[i] = y0;
x2 = x1;
x1 = x0;
y2 = y1;
y1 = y0;
}
}
int main() {
double input[] = {1.0, 2.0, 3.0, 4.0, 5.0};
double output[5];
bessel_filter(input, output, 5, 2.0, 4, 10.0);
int i;
for (i = 0; i < 5; i++) {
printf("%f\n", output[i]);
}
return 0;
}
```
这是一个Bessel滤波器的实现,可以用于信号处理中。
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)