資源簡介
本程序用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語言最小二乘法多項式擬合
評論
共有 條評論