You are on page 1of 6

31508121008

IIR FILTER: (LPF & HPF)


#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
const signed int filter_Coeff[]=
{
//12730,-12730,12730,2767,-18324,21137 /*HPF 2500*/
//312,312,312,32767,-27943,24367/*LPF 800*/
//1455,1455,1455,32767,-23140,21735/* LPF 2500*/
//9268,-9268,9268,32767,-7395,18367/*HPF 4000*/
7215,-7215,7215,32767,5039,6171,/* HPF 7000*/
};
DSK6713_AIC23_Config config ={
0x0017,/* 0 DSK6713_AIC23_LEFTINVOL Leftline input channel volume*/\
0x0017,/* 1 DSK6713_AIC23_RIGHTINVOL Rightline input channel volume*/\
0x00d8,/* 2 DSK6713_AIC23_LEFTHPVOL LEFT CHANNEL HEADPHONE
volume*/\
0x00d8,/* 3 DSK6713_AIC23_RIGHTHPVOL Right Channel Headphone Volume*/\
0x0011,/*4 DSK6713_AIC23_ANAPATH Analog audio path control*/\
0x0000,/*5 DSK6713_AIC23_DIGPATH Digital audio path control*/\
0x0000,/*6 DSK6713_AIC23_POWERDOWN Powerdowncontrol*/\
0x0043,/*7 DSK6713_AIC23_DIGIF digital audio interface format*/\
0x0081,/*8 DSK6713_AIC23_SAMPLERATE sampleratecontrol*/\
0x0001,/* 9DSK6713_AIC23_DIGACT Digital Interface Activation*/\
};
/*main()-Main code routine ,initializes BSL and generates tone*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input, l_output, r_output;
/*initialize BSL,must be calle first*/
DSK6713_init();
/*start the codec*/
hCodec = DSK6713_AIC23_openCodec(0,&config);
/* set codec sampling frequency*/
DSK6713_AIC23_setFreq(hCodec,3);

31508121008

while(1)
{ /*Read the sample to the left channel*/
while (!DSK6713_AIC23_read(hCodec,&l_input));
/*Read the sample to the right channel*/
while (!DSK6713_AIC23_read(hCodec,&r_input));
l_output = IIR_FILTER(&filter_Coeff,l_input);
r_output = l_output;
/*send the sample to the left channel*/
while(!DSK6713_AIC23_write(hCodec,l_output));
/*send the sample to the right channel*/
while(!DSK6713_AIC23_write(hCodec,r_output));
}
/* close the codec*/
DSK6713_AIC23_closeCodec(hCodec);
}
signed int IIR_FILTER(const signed int *h,signed int x1)
{
static signed int x[6]={0,0,0,0,0,0};/*x(n),x(n-1),x(n-2). must be static*/
static signed int y[6]= {0,0,0,0,0,0};/*y(n),y(n-1),y(n-2). must be static*/
int temp=0;
temp =(short int)x1;/*copy input to temp*/
x[0]=(signed int) temp;/*copy input to x[stages][0]*/
temp = ( (int)h[0]*x[0]);/*B0 *x(n) */
temp += ( (int)h[1]*x[1]);/*B1/2 *x(n-1) */
temp += ( (int)h[1]*x[1]);/*B1/2 *x(n-1) */
temp += ( (int)h[2]*x[2]);/*B2 *x(n-2) */
temp -= ( (int)h[4]*y[1]);/*A1/2 *y(n-1) */
temp -= ( (int)h[4]*y[1]);/*A1/2 *y(n-1) */
temp -= ( (int)h[5]*y[2]);/*A2 *y(n-2) */
/*divide temp by coefficients [a0]*/
temp >>=15;
if(temp>32767)
{
temp=32767;
}
else if (temp<-32767)

31508121008

{
temp = -32767;
}
y[0]=temp;
/*shuffle values along one place for next time*/
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1]=x[0];
/*teemp is used as input next time through*/
return (temp<<2);
}

31508121008

FIR FILTER (LPF,HPF,BPF,BSF):


#include "xyzcfg.h"
#include "dsk6713.h"
#include"dsk6713_aic23.h"
float b[]={-0.0089819,-0.017782,-0.02502,-0.029339,-0.029569,-0.024895,-0.01497,5.3894e018,0.019247,0.041491,0.065053,0.088016,0.10842,0.12447,0.13473,0.13825,0.13473,0.12447,
0.10842,0.088016,0.065053,0.041491,0.019247,5.3894e-018,-0.01497,-0.024895,-0.029569,0.029339,-0.02502,-0.017782,-0.0089819};//fir low pass cutoff500hz
// high pass 400hz
{
4.963139549993e-005,0.0002226853416285,0.0005196103021507,0.0008311886295369,
0.0008450146941634,-6.518184994901e-018,-0.002478492169286,-0.007436948282182,
-0.01555596128135, -0.02707078700033, -0.0415379741771, -0.05774182200211,
-0.07380467577337, -0.08750533457613, -0.0967393446176, 0.8999976525254,
-0.0967393446176, -0.08750533457613, -0.07380467577337, -0.05774182200211,
-0.0415379741771, -0.02707078700033, -0.01555596128135,-0.007436948282182,
-0.002478492169286,-6.518184994901e-018,0.0008450146941634,0.0008311886295369,
0.0005196103021507,0.0002226853416285,4.963139549993e-005
};
// FIR--Bandpass bp = fir1(30,[0.25 0.75],'bandpass',kaiser(31,8));
Fs=8000;Fc1=1000;Fc2=3000;KAISER WINDOW
//{7.30259822279645e-20,0.000468265679545720,-8.19017388508424e19,1.03901074350716e-18,-2.95055859469454e-18,0.00967676443166421,1.10144517351165e-17,-6.19760576561239e-18,2.93396140565462e18,0.0569248086912406,-4.07450611115317e-17,1.48696940676016e-17,-2.38629771783738e17,-0.297730185442037,2.72959312612056e-17,0.499972248994170,2.72959312612056e-17,0.297730185442037,-2.38629771783738e-17,1.48696940676016e-17,-4.07450611115317e17,0.0569248086912406,2.93396140565462e-18,-6.19760576561239e-18,1.10144517351165e17,-0.00967676443166421,-2.95055859469454e-18,1.03901074350716e-18,8.19017388508424e-19,0.000468265679545720,7.30259822279645e-20}
//FIRbandstop bs = fir1(30,[0.25 0.75],'stop',kaiser(31,8));Fs=8000,Fc1=1000,Fc2=3000
KAISER WINDOW
//{1.94735952607905e-19,-0.000468265679545721,-4.55009660282458e-19,3.11703223052147e-18,1.63919921927474e-17,0.00967676443166420,-2.36023965752496e18,-6.19760576561239e-18,1.46698070282731e-17,-0.0569248086912406,6.79084351858861e17,-4.46090822028048e-17,5.96574429459345e-

31508121008

17,0.297730185442037,0,0.499972248994170,0,0.297730185442037, 5.96574429459345e-17,4.46090822028048e-17,6.79084351858861e-17,-0.0569248086912406 1.46698070282731e-17,6.19760576561239e-18,-2.36023965752496e-18,0.00967676443166420 1.63919921927474e17,-3.11703223052147e-18,-4.55009660282458e-19,-0.000468265679545721,


1.94735952607905e-19}

static short in_buffer[100];


DSK6713_AIC23_Config config={\
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline input channel volume*/\
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Rightline input channel volume*/\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL LEFT CHANNEL HEADPHONE volume*/\
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right Channel Headphone Volume*/\
0x0011, /*4 DSK6713_AIC23_ANAPATH Analog audio path control*/\
0x0000, /*5 DSK6713_AIC23_DIGPATH Digital audio path control*/\
0x0000, /*6 DSK6713_AIC23_POWERDOWN Powerdowncontrol*/\
0x0043, /*7 DSK6713_AIC23_DIGIF digital audio interface format*/\
0x0081, /*8 DSK6713_AIC23_SAMPLERATE sampleratecontrol*/\
0x0001 /* 9DSK6713_AIC23_DIGACT Digital Interface Activation*/\
};
/*main()-Main code routine ,initializes BSL and generates tone*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input,r_input,l_output,r_output,i;
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec,1);
while(1)
{

while(!DSK6713_AIC23_read(hCodec,&l_input));
while(!DSK6713_AIC23_read(hCodec,&r_input));
l_output = (Int16)FIR_FILTER(&b,l_input);
r_output = l_output;

31508121008

while(!DSK6713_AIC23_write(hCodec,l_output));
while(!DSK6713_AIC23_write(hCodec,r_output));
}
DSK6713_AIC23_closeCodec(hCodec);}
signed int FIR_FILTER(float *h,signed int x)
{
int i=0;
signed long output =0;
in_buffer[0] = x;/*new input at buffer [0]*/
for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];/*shuffle the buffer*/
for(i=0;i<32;i++)
output = output+ h[i]*in_buffer[i];
return(output);
}

You might also like