資源簡介
本程序通過直接法,實(shí)現(xiàn)了給定參數(shù)的IIR低通濾波器的設(shè)計。
本程序所設(shè)計的濾波器的參數(shù)與Matlab校準(zhǔn)過。
將需要的數(shù)據(jù)輸入.dat文件,實(shí)現(xiàn)自動處理。其輸出與Matlab一致。
詳細(xì)的設(shè)計過程,參看博客。
http://blog.csdn.net/thnh169/article/details/9076283

代碼片段和文件信息
#include?
#include?
#include?
#include?
#define?????pi?????((double)3.1415926)
typedef?struct?
{
????double?Real_part;
????double?Imag_Part;
}?COMPLEX;
struct?DESIGN_SPECIFICATION
{
????double?Cotoff;???
????double?Stopband;
????double?Stopband_attenuation;
};
int?Ceil(double?input)
{
?????if(input?!=?(double)((int)input))?return?((int)input)?+1;
?????else?return?((int)input);?
}
int?Complex_Multiple(COMPLEX?aCOMPLEX?b
?????????????????????????????????double?*Res_Realdouble?*Res_Imag)
{
???????*(Res_Real)?=??(a.Real_part)*(b.Real_part)?-?(a.Imag_Part)*(b.Imag_Part);
???????*(Res_Imag)=??(a.Imag_Part)*(b.Real_part)?+?(a.Real_part)*(b.Imag_Part); ???
?return?(int)1;?
}
?int?Complex_Division(COMPLEX?aCOMPLEX?b
? ??????????????????????????????????double?*Res_Realdouble?*Res_Imag)
{
????????*(Res_Real)?=??((a.Real_part)*(b.Real_part)?+?(a.Imag_Part)*(b.Imag_Part))/
???????????((b.Real_part)*(b.Real_part)?+?(b.Imag_Part)*(b.Imag_Part));
?*(Res_Imag)=??((a.Real_part)*(b.Imag_Part)?-?(a.Imag_Part)*(b.Real_part))/
???????????((b.Real_part)*(b.Real_part)?+?(b.Imag_Part)*(b.Imag_Part));
?return?(int)1;?
}
double?Complex_Abs(COMPLEX?a)
{
??????return?(double)(sqrt((a.Real_part)*(a.Real_part)?+?(a.Imag_Part)*(a.Imag_Part)));
}
double?IIRFilter??(double?*a?int?Lenth_a
???????????????????????????double?*b?int?Lenth_b
???????????????????????????double?Input_Data
???????????????????????????double?*Memory_Buffer)?
{
????int?Count;
????double?Output_Data?=?0;?
????int?Memory_Lenth?=?0;
????
????if(Lenth_a?>=?Lenth_b)?Memory_Lenth?=?Lenth_a;
????else?Memory_Lenth?=?Lenth_b;
????
????Output_Data?+=?(*a)?*?Input_Data;??//a(0)*x(n)?????????????
????
????for(Count?=?1;?Count?????{
????????Output_Data?-=?(*(a?+?Count))?*
???????????????????????(*(Memory_Buffer?+?(Memory_Lenth?-?1)?-?Count));???????????????????????????????????????
????}?
????
????//------------------------save?data--------------------------//?
????*(Memory_Buffer?+?Memory_Lenth?-?1)?=?Output_Data;
????Output_Data?=?0;
????//----------------------------------------------------------//?
????
????for(Count?=?0;?Count?????{????
????????Output_Data?+=?(*(b?+?Count))?*
???????????????????????(*(Memory_Buffer?+?(Memory_Lenth?-?1)?-?Count));??????
????}
????
????//------------------------move?data--------------------------//?
????for(Count?=?0?;?Count?????{
???? *(Memory_Buffer?+?Count)?=?*(Memory_Buffer?+?Count?+?1);
????}
????*(Memory_Buffer?+?Memory_Lenth?-?1)?=?0;
????//-----------------------------------------------------------//
????return?(double)Output_Data;?
}
int?Direct(?double?Cotoff
???????????double?Stopband
???????????double?Stopband_attenuation
???????????int?N
???????????double?*azdouble?*bz)
{
??????printf(“Wc?=??%lf??[rad/sec]?\n“?Cotof
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1358??2013-05-02?19:00??input.dat
?????文件???????9755??2013-05-02?15:25??IIR.c
-----------?---------??----------?-----??----
????????????????11113????????????????????2
評論
共有 條評論