firexample.c

来自「自己写的一个低通滤波器设计的例子」· C语言 代码 · 共 32 行

C
32
字号
   窗口法设计FIR滤波器比较简单,由于有8个窗口可选择,能满足一般应用的要求。考虑到查看频谱的方便,用DFT来计算FIR滤波器的幅频特性。因为用DFT可以计算出任意点的频谱。取DFT的长度为200,显示归一化频谱的范围从-100dB到0dB。改变设计参数截止频率和过渡带宽,可看到设计的滤波器也随之改变。当滤波器过渡带宽小于0.05时,要考虑增加一些数组的尺寸。

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>

void InitGraphic(void);
void PlotTimeSequ(float *x,int n,float scale,int space,int y1);
void PlotLog(float *x,int n,float scale,int space);
void DFT(int n,float *x,int N,float *y);
int FIR(int window_type,float FH,float DF,float *h);

void main(void)
{
float h[200],y[200];
int i,n,k,N=200;
InitGraphic();

n=FIR(2,0.2,0.1,h);/*DF>0.05*/

PlotTimeSequ(h,n,80,4,130);

DFT(n,h,N,y);

PlotLog(y,N,1.5,2,400);
setcolor(11);
outtextxy(200,440,"Please press any key---");
getch();
closegraph();
return;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?