昨天自己设计了一个IIR滤波器,写了个测试程序:滤波器是一个低通的滤波器,要求滤除20KHZ以上的频率段,
程序如下:
#include "filter.h"
#include "iir.h"
#include "math.h"
float xn[400],yn[400],zn[400],rn[400];
#pragma DATA_SECTION(iir, "iirfilt");
IIR5BIQ16 iir=IIR5BIQ16_DEFAULTS;
#pragma DATA_SECTION(dbuffer,"iirfilt");
int dbuffer[2*IIR16_LPF_NBIQ];
const int coeff[5*IIR16_LPF_NBIQ]=IIR16_LPF_COEFF;
int i;
main ()
{
// int i;
float w1,w2,t;
/*************************************
下面是自己写的25K和15K频率的合成的波形
*************************************/
w1=2*3.1415926*25000;
for(i=0;i<400;i++)
{
xn=sin(w1*t);
t+=0.000001;
}
w2=2*3.1415926*15000;
for(i=0;i<400;i++)
{
yn=sin(w2*t);
t+=0.000001;
}
for(i=0;i<400;i++)
{
rn=xn+yn;
}
/******************************
下面是滤波程序
******************************/
iir.dbuffer_ptr=dbuffer;
iir.coeff_ptr=(int *)coeff;
iir.qfmat=IIR16_LPF_QFMAT;
iir.nbiq=IIR16_LPF_NBIQ;
iir.isf=IIR16_LPF_ISF;
iir.init(&iir);
for(i=0;i<400;i++)
{
iir.input=(rn);
iir.calc(&iir);
zn=iir.output;
}
while(1)
{};
}
滤波头的设计是:
>> eziir16
ezIIR FILTER DESIGN SCRIPT
Butterworth : 1
Chebyshev(Type 1) : 2
Chebyshev(Type 2) : 3
Elliptic : 4
Select Any one of the above IIR Filter Type : 1
Low pass : 1
High Pass : 2
Band Pass : 3
Band Stop : 4
Select Any one of the above Response : 1
Enter the Sampling frequency : 96000
Enter the Pass band Ripples in dB(RP) : 1
Enter the stop band Rippled in dB(RS) : 20
Enter the pass band corner frequency(FP) : 20000
Enter the stop band corner frequency(FS) : 21000
Enter the name of the file for coeff storage : filter.h
Q format of the IIR filter coefficients:
6
Input Scaling value:
0.8763
Number of Biquads:
23
生成的头文件的代码是:
#define IIR16_COEFF {\
0,8,0,6,6,\
-1,16,12,25,12,\
-1,16,12,25,12,\
-2,16,13,25,13,\
-2,16,13,25,13,\
-3,16,13,26,13,\
-4,17,13,26,13,\
-5,17,13,27,13,\
-6,17,14,27,14,\
-8,17,14,28,14,\
-9,18,14,28,14,\
-11,18,15,29,15,\
-14,19,15,30,15,\
-16,20,15,31,15,\
-19,20,16,32,16,\
-22,21,17,33,17,\
-26,22,17,34,17,\
-30,23,17,35,17,\
-34,24,18,36,18,\
-40,25,18,36,18,\
-46,27,17,34,17,\
-52,28,11,23,11,\
-60,30,13320,26640,13320}
#define IIR16_ISF 56
#define IIR16_NBIQ 23
#define IIR16_QFMAT 6
但是自己在测试的时候发现输出的zn的波形不是和yn相似??请问为什么?