#include <stdio.h> #include <math.h> #define pi 3.1415 #define N 11 //N为滤波器的阶数+1 #define LEN 512 int inputdata[LEN]; //假设数据的长度为512 int outputdata[LEN]; long int yn; const int B[N] = {166, 0, -1374, 0, 9453, 16279, 9453, 0, -1374, 0, 166}; int main(void) { int f1,f2,fs,i,j,n; int *a; f1=100; //频率分量1(Hz) f2=300; //频率分量2(Hz) fs=800; //采样频率(Hz) for(n=0;n<LEN;n++) { inputdata[n]=sin(2*pi*f1*n/fs) + sin(2*pi*f2*n/fs); //产生信号 } for(j=0;j<LEN;j++) //根据公式来进行滤波 { a=&inputdata[j]; yn=0; for(i=0;i<N;i++) { yn=yn+B[i]*(*a++); } outputdata[j]=yn>>16; //滤波后信号 } while(1); } 分别修改此低通FIR滤波器为高通、带通、带阻滤波器
时间: 2024-04-28 10:25:15 浏览: 16
1. 高通FIR滤波器:
将原始滤波器的系数数组B中的所有偶数项变为负数即可。修改后的系数数组B为:
const int B[N] = {-166, 0, 1374, 0, -9453, 16279, -9453, 0, 1374, 0, -166};
2. 带通FIR滤波器:
在高通滤波器的基础上再添加一个低通滤波器,将两个滤波器的输出相加即可。修改后的系数数组B为:
const int B[N] = {83, 0, -687, 0, 4727, -8129, 4727, 0, -687, 0, 83};
3. 带阻FIR滤波器:
将带通滤波器的系数数组B中的奇数项变为负数即可。修改后的系数数组B为:
const int B[N] = {-83, 0, 687, 0, -4727, 8129, -4727, 0, 687, 0, -83};
相关问题
#include <iostream> #include <stdio.h> #include <math.h> #define N 5
这段代码是C++中的预处理指令,用于引入头文件和定义宏。具体解释如下:
1. `#include <iostream>`:引入iostream头文件,该头文件包含了C++中输入输出流的相关函数和对象,例如cout和cin。
2. `#include <stdio.h>`:引入stdio.h头文件,该头文件包含了C语言中的输入输出函数,例如printf和scanf。
3. `#include <math.h>`:引入math.h头文件,该头文件包含了数学函数的声明和定义,例如sqrt和pow。
4. `#define N 5`:定义一个宏常量N,并将其值设置为5。宏定义是一种在编译前进行文本替换的机制,这里将所有出现N的地方都替换为5。
这段代码的作用是引入所需的头文件和定义一个宏常量N,并没有实际的功能代码。
include <stdio.h>#include <stdlib.h>
这是一个C语言的标准头文件的引用,其中<stdio.h>包含了C语言的输入输出函数,而<stdlib.h>包含了一些通用的工具函数和内存分配函数。这些头文件在C语言中非常常见,几乎每个C程序都会用到它们。下面是一个简单的例子,展示了如何使用这两个头文件。
```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
char str[100];
printf("Enter an integer: ");
scanf("%d", &num);
printf("You entered %d.\n", num);
printf("Enter a string: ");
scanf("%s", str);
printf("You entered %s.\n", str);
return 0;
}
```
上面的程序使用了<stdio.h>中的printf和scanf函数,以及<stdlib.h>中的exit函数。输入一个整数和一个字符串,然后将它们输出到控制台上。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.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)