脑电信号频域分析butterworth滤波器代码
时间: 2023-04-04 21:01:47 浏览: 181
以下是脑电信号频域分析butterworth滤波器代码的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323846
void butterworth_filter(double *input, double *output, int n, double fc, int fs)
{
double w = 2 * PI * fc / fs;
double a = tan(w / 2);
double a2 = a * a;
double b = 1 / (1 + sqrt(2) * a + a2);
double b1 = 2 * b;
double b2 = b;
double a1 = 2 * b * (a2 - 1);
double a2 = b * (1 - sqrt(2) * a + a2);
double x1 = , x2 = , y1 = , y2 = ;
for (int i = ; i < n; i++) {
output[i] = b * input[i] + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
x2 = x1;
x1 = input[i];
y2 = y1;
y1 = output[i];
}
}
int main()
{
int n = 100;
double fs = 100;
double fc = 50;
double *input = (double *)malloc(n * sizeof(double));
double *output = (double *)malloc(n * sizeof(double));
for (int i = ; i < n; i++) {
input[i] = sin(2 * PI * i * 10 / fs) + sin(2 * PI * i * 100 / fs);
}
butterworth_filter(input, output, n, fc, fs);
for (int i = ; i < n; i++) {
printf("%f\n", output[i]);
}
free(input);
free(output);
return ;
}
```
阅读全文