资源简介
本程序用c语言实现FIR滤波器设计,采用的凯撒窗函数法,滤波器阶数、阻带宽度、阻带衰减等都可以通过修改相关系数达到特定的需要,同时通过调整相关系数可以实现带通,带阻,低通,高通等功能。
代码片段和文件信息
/*******************************************
function name: kaiser.cpp
The function is to get the order of the kaiser filter and the length of the transform sequence bn
L is the length of the transform sequence Fs is the sampling ratefs is the stop band fp is the -3db band
N is the length of the sn xn is the result after filtering.
kaiser window stopband attenuation is -50db
Author: Shi Yongbiao
Date: 19/04/2016
*****************************************/
#include
#include
#include
int order(intdoubledoubledoubledoubledouble);
void My_Convolution(double *double *double *intint);
void kaiserord(double *int int int *);
void mdefir1(intintdoubledoubledoubleintdouble *double *int*);
int max(intint);
int min(intint);
void kaiser(double *bndouble *xnint ibandint N int Ldouble fldouble fhdouble fsdouble fpdouble Fs) //
{
/*iwindow:=1: rectangular window
=2: Hamming window
=3: Hanning window
int *w;
int n=5;//n must odd
w=(double*)malloc(sizeof(double)*n);
int *b;
b=(double*)malloc(sizeof(double)*n);
*/
int xi;
int *p=&x; /*L is the length of the wnorder of the filter is L-1*/
double *wn;
wn=(double*) malloc(sizeof(double)*L);
bn=(double*) malloc(sizeof(double)*L);
for(i=0;i {
wn[i]=0;
bn[i]=0;
}
mdefir1(LibandflfhFs1bnwnp);// get h[n]
free(wn);
}
void mdefir1(int lint ibanddouble fldouble fhdouble fsint iwindow
double *bndouble *wnint *ierror)
{
/*----------------------------------------------------------------------
Subroutine mdesfir: To Design FIR Filter By Windowed Fourier Series.
fl:low cut-off frequency. fh:high cut-off(For BPBS). flfhfs in Hz
Digital filter coefficients are returned in b(l)
h(z)=b(0)+b(1)z^(-1)+ ... +b(l-1)z^(-l+1)
Input parameters:
l : the length of FIR filter. l must be odd.
iband: iband=1 low pass FIR filter.
iband=2 high pass FIR filter.
iband=3 band pass FIR filter.
iband=4 band stop FIR filter.
flnfhn: the edge frequency desiredin normalized form0.<=flnfhn<=.5
|--- | --- | --- |-- --
| | | | | | | | | |
| | | | | | | | | |
--|------ -|-------- -|----------- --|--------------
0 fln 0 fln 0 fln fhn 0 fln fhn
fhn=* fhn=*
iband=1 LP iband=2 HP iband=3 BP iband=4 BS
iwindow: window type desired.
iwindow=1: rectangular window =2: triangular window
=3: cosin window =4: Hanning window
=5: Hamming window =6: Blackman window
=7: Papoulis window .
w: l dimensioned real work array.
- 上一篇:blockly的积木转C++
- 下一篇:C语言最小二乘法多项式拟合
评论
共有 条评论