FIR Filter Low pass/High pass (LP/HP) Using Windowing technique

AIM:    To verify FIR filters using Code Composer Studio.

SOFTWARE REQUIREMENTS:

Operating System – Windows XP

Constructor - Simulator

Software – Code Composer 3.1v,6713DSK  Diagnostics

HARDARE REQUIREMENTS:

TMS320C67XXDSP KIT  / example TMS320C6713DSP KIT 

USB cable  

Power Supply +5v  

Theory:

DESIGNING AN FIR FILTER :

Following are the steps to design linear phase FIR filters Using Windowing Method.

I.  Clearly specify the filter specifications.

Eg: Order  = 30;

Sampling Rate  = 8000 samples/sec

Cut off Freq.  = 400 Hz.

 

II.  Compute the cut-off frequency Wc

Eg: Wc = 2*pie* fc / Fs

= 2*pie* 400/8000

= 0.1*pie

 

III.  Compute the desired Impulse Response h d (n) using particular Window.

Eg: b_rect1=fir1(order, Wc , 'high',boxcar(31));

 

IV.  Convolve input sequence with truncated Impulse Response x (n)*h (n).

1. Rectangular window (High pass)

PROGRAM CODE:

#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
//float filter_coeff[ ]={0.021665,0.022076,0.020224,0.015918,0.009129,
//   -0.000000,-0.011158,-0.023877,-0.037558,-0.051511,
//    -0.064994,-0.077266,-0.087636,-0.095507,-0.100422,
//    0.918834,-0.100422,-0.095507,-0.087636,-0.077266,
//   -0.064994,-0.051511,-0.037558,-0.023877,-0.011158,
//   -0.000000,0.009129,0.015918,0.020224,0.022076,
//               0.021665};
                                //FIR High pass Rectangular filter pass band range 400Hz- 3.5KHz


//float filter_coeff[ ]={0.000000,-0.013457,-0.023448,-0.025402,-0.017127,
//   -0.000000,0.020933,0.038103,0.043547,0.031399,
//   0.000000,-0.047098,-0.101609,-0.152414,-0.188394,
//   0.805541,-0.188394,-0.152414,-0.101609,-0.047098,
//   0.000000,0.031399,0.043547,0.038103,0.020933,
//   -0.000000,-0.017127,-0.025402,-0.023448,-0.013457,
//               0.000000};
                             /|/FIR High pass Rectangular filter pass band range 800Hz-3.5KHz


float filter_coeff[ ]={-0.020798,-0.013098,0.007416,0.024725,0.022944,
          -0.000000,-0.028043,-0.037087,-0.013772,0.030562,
            0.062393,0.045842,-0.032134,-0.148349,-0.252386,
            0.686050,-0.252386,-0.148349,-0.032134,0.045842,
            0.062393,0.030562,-0.013772,-0.037087,-0.028043,
           -0.000000,0.022944,0.024725,0.007416,-0.013098,
            -0.020798}:
                           //FIR High pass Rectangular filter pass band range 1200Hz-3.5KHz


//static short int  in_buffer[100];

DSK6713_AIC23_Config config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001};

void main( )
{
 DSK6713_AIC23_CodecHandle hCodec;
 Uint32 l_input, r_input,l_output, r_output;
 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(&filter_coeff ,l_input);
              r_output=l_output;
               
      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;
static short int  in_buffer[100];
in_buffer[0] = x;

for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];

for(i=0;i<32;i++)
output = output + h[i] * in_buffer[i];
//output = x;
return(output);
}

 

Expected Output: observed the output in CRO with respect to input signal, it pass the signal at range of frequency 1200-3.5KHz,and attenuate at other than pass band frequency

 

2. Rectangular window (Lowpass)

PROGRAM CODE:

#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"

//float filter_coeff[ ]={-0.008982,-0.017782,-0.025020,-0.029339,-0.029569,
//       -0.024895,-0.014970,0.000000,0.019247,0.041491,
//        0.065053,0.088016,0.108421,0.124473,0.134729,
//        0.138255,0.134729,0.124473,0.108421,0.088016,
//        0.065053,0.041491,0.019247,0.000000,-0.014970,
//       -0.024895,-0.029569,-0.029339,-0.025020,-0.017782,
//       -0.008982};
                                                    //FIR Low pass Rectangular Filter pass band range 0-500Hz

//float filter_coeff[ ]={-0.015752,-0.023869,-0.018176,0.000000,0.021481,
//        0.033416,0.026254,-0.000000,-0.033755,-0.055693,
//       -0.047257,0.000000,0.078762,0.167080,0.236286,
//        0.262448,0.236286,0.167080,0.078762,0.000000,
//       -0.047257,-0.055693,-0.033755,-0.000000,0.026254,
//        0.033416,0.021481,0.000000,-0.018176,-0.023869,
//       -0.015752};
                                                  //FIR Low pass Rectangular Filter pass band range 0-1000Hz


float filter_coeff[ ]={-0.020203,-0.016567,0.009656,0.027335,0.011411,
      -0.023194,-0.033672,0.000000,0.043293,0.038657,
                 -0.025105,-0.082004,-0.041842,0.115971,0.303048,
       0.386435,0.303048,0.115971,-0.041842,-0.082004,
      -0.025105,0.038657,0.043293,0.000000,-0.033672,
      -0.023194,0.011411,0.027335,0.009656,-0.016567,
                                                             -0.020203};
                                               //FIR Low pass Rectangular Filter pass band range 0-1500Hz

//static short int  in_buffer[100];

DSK6713_AIC23_Config config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001};

void main( )
{
 DSK6713_AIC23_CodecHandle hCodec;
 Uint32 l_input, r_input,l_output, r_output;
 DSK6713_init();
 hCodec = DSK6713_AIC23_openCodec(0, &amp;config);

 DSK6713_AIC23_setFreq(hCodec, 1);

 while(1)
 {
      while(!DSK6713_AIC23_read(hCodec, &amp;l_input));

   while(!DSK6713_AIC23_read(hCodec, &amp;r_input));
   
     l_output=(Int16)FIR_FILTER(&amp;filter_coeff ,l_input);
              r_output=l_output;
               
      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;
static short int  in_buffer[100];
in_buffer[0] = x;

for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];

for(i=0;i<32;i++)
output = output + h[i] * in_buffer[i];
//output = x;
return(output);
}

               

Expected Output: observed the output in CRO for low pass filter with respect to input signal, it pass the signal at range of pass band frequency 0-1500KHz, and attenuate at other than pass band frequency