IIR Butter-worth Filter (LP/HP) on DSP processors

AIM:  To verify IIR Butter-worth Filter (LP/HP) using Code Composer Studio.

SOFTARE REQUIREMENTS:

Operating System – Windows XP

Constructor - Simulator

Software – Code Composer Studio3.1v,  6713DSK Diagnostics.

HARDARE REQUIREMENTS:

TMS320C6713DSP KIT  

USB cable  

Power Supply +5v The  

CRO (0-20MHz),

Function Generator (1-1MHz), Cables

PROCEDURE:  

1. Set 1v peak to peak in function generator, and connect this to 6713kit at Line in pin, connect CRO to kit at Line out pin.

2. Open code composer studio

3. create a new project ,give a meaningful name ,save into working folder, select target as TMS320C6713,and select output file type is execution. Out.

4. Click on file opennewsource file save it with .c extension in working folder and write C-code for desired task.

4. Filenew dsp \bios configuration file select DSK6713.cdB. save it with .cdb extension in working folder.

5. Add .cdb file to project [pathright click on dsp\ Bios configuration select .cdb file] and choose .cdb file.

6. Add the library file ‘dsk6713bsl.lib’ to the current project. [Path c.\ccstudio\c600\dsk6713\lib\dsk6713bst.lib]

7. Under working folder include 3-header files

  “dsk6713.h”

  “dsk6713_aic23.h”

  “Filtercfg.h”(pathc:\ccstudio\c6000\dsk6713\include.)

8. Compile the program.

9. Build the program.

10. Connect the kit and load the program then run.

11. In the CRO we can verify the output signal with input signal.

 

1. Butterworth (High pass)

PROGRAM CODE:

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

//const signed int filter_coeff[ ] = {20539,-20539,20539,32767,-18173,13406};
             //IIR_BUTTERWORTH_HP FILTER  pass band range 2.5kHz-11KHz
//const signed int filter_coeff[ ] = {15241,-15241,15241,32761,-10161,7877};
              //IIR_BUTTERWORTH_HP FILTER pass band range 4kHz-11KHz
const signed int filter_coeff[ ] = { 7215,-7215,7215,32767,5039,6171};
                //IIR_BUTTERWORTH_HP FILTER pass band range 7kHz-11Khz

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, 3);

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

   while(!DSK6713_AIC23_read(hCodec, &r_input));
   
     l_output=IIR_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 IIR_FILTER(const signed int * h, signed int x1)
{
   static signed int x[6] = {0,0,0,0,0,0};

static signed int y[6] = {0,0,0,0,0,0};

int temp=0;

temp = (short int)x1;

x[0] = (signed int) temp;  

temp = ( (int)h[0] * x[0]);
 
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[2] * x[2]);
 
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[5] * y[2]);
 
   temp >>=15;
 
 if ( temp > 32767 )
 {
   temp = 32767;
 }    
  else if ( temp < -32767)
  {
    temp = -32767;
  }
  y[0] = temp;

  y[2] = y[1];
  y[1] = y[0];

  x[2] = x[1];
  x[1] = x[0];

  return (temp<<2);
}  

Expected Output: Observed the output in CRO with respect to input signal, it pass the signal at range of pass band frequency 7-11KHz, and attenuate at other than pass band frequency.

2. Butterworth(Low pass)

PROGRAM CODE:

 

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

//const signed int filter_coeff[] = {2366,2366,2366,32767,-18179,13046};
             //IIR_BUTTERWORTH_LP FILTER pass band range 0-2.5kHZ
//const signed int filter_coeff[] = {312,312,312,32767,-27943,24367};
            //IIR_BUTTERWORTH_LP FILTER pass band range 0-800Hz
const signed int filter_coeff[] = {15241,15241,15241,32761,10161,7877};
                 //IIR_BUTERWORTH_LP FILTER pass band range 0-8kHz



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, 3);

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

   while(!DSK6713_AIC23_read(hCodec, &r_input));
   
     l_output=IIR_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 IIR_FILTER(const signed int * h, signed int x1)
{
   static signed int x[6] = {0,0,0,0,0,0};

static signed int y[6] = {0,0,0,0,0,0};

int temp=0;

temp = (short int)x1;

x[0] = (signed int) temp;  

temp = ( (int)h[0] * x[0]);
 
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[2] * x[2]);
 
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[5] * y[2]);

   temp >>=15;
 
 if ( temp > 32767 )
 {
   temp = 32767;
 }    
  else if ( temp < -32767)
  {
    temp = -32767;
  }
  y[0] = temp;

  y[2] = y[1];
  y[1] = y[0];

  x[2] = x[1];
  x[1] = x[0];

  return (temp<<2);
}

 

Expected Output: Observed the output in CRO with respect to input signal, it pass the signal at range of pass band frequency 0-8KHz, and attenuate at other than pass band frequency.