计算FIR低通的C代码:
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <math.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- #define ORDER 10
- #define FC 0.15
- volatile double bb[32];
- volatile double wn[32];
- void dot(double *a,double *b);
- double sinc(double x)
- {
-
- if(x==0.0)
- {
- return 1.0;
- }
- else
- {
- return sin(M_PI*x)/(M_PI*x);
- }
- }
- void fir1(int32_t order,float fc)
- {
- int32_t i=0;
- int32_t N=order+1;
- int32_t M=(N-1)/2;
- int32_t k=0;
- for(i=0;i<N;i++)
- {
- k=i-M;
- wn[i]=(0.54-0.46*cos(2*M_PI*i/(order)));//窗函数
- bb[i]=2*fc*sinc(2*fc*k);//低通
- bb[i]=bb[i]*wn[i];//时域点乘
- }
-
- }
- int main(int argc, char *argv[]) {
- uint32_t i=0;
- fir1(ORDER,FC);
- for(i=0;i<(ORDER+1);i++)
- {
- printf("%3.17f\n",bb[i]);
- }
- return 0;
- }
|