DSPRelated.com
Forums

Filter implementation on DSK6416

Started by bhar...@gmail.com July 28, 2008
Hello All,

I am new to DSP programming and am experiencing some difficulties implementing filters on a fixed point DSP (TMS320C6416).

To keep it simple, I started trying to implement a single pole low pass filter with a corner frequency of 500 Hz while sampling at 96kHz.

I have obtained the quantized filter coefficients using Matlab's fdatool.

I have then written down type 1 direct form equations for the filter using the coefficients.

I am using C to program the DSP. Further, I am using the AIC23 codec API (came with the board) to perform the ADC and DAC operations.

Since the task comprises of iterating the difference equations, the program I ended up with is relatively simple. However, when the load the compiled code on the DSP and run the program, all I see is that the output is reflecting the input signal. As I sweep the frequency of the input sine wave, the amplitude of the output signal stays constant till it attenuates as it gets closer to the Nyquist rate.

I would appreciate any advice on this issue.

Below is a copy of my code:
#include "tonecfg.h"
#include
#include
#include
#include "dsk6416.h"
#include "dsk6416_aic23.h"

/* Codec configuration settings */

DSK6416_AIC23_Config config = {
0x0017, // 0 DSK6416_AIC23_LEFTINVOL Left line input channel volume
0x0017, // 1 DSK6416_AIC23_RIGHTINVOL Right line input channel volume
0x00d8, // 2 DSK6416_AIC23_LEFTHPVOL Left channel headphone volume
0x00d8, // 3 DSK6416_AIC23_RIGHTHPVOL Right channel headphone volume
0x0011, // 4 DSK6416_AIC23_ANAPATH Analog audio path control
0x0000, // 5 DSK6416_AIC23_DIGPATH Digital audio path control
0x0000, // 6 DSK6416_AIC23_POWERDOWN Power down control
0x0043, // 7 DSK6416_AIC23_DIGIF Digital audio interface format
0x0001, // 8 DSK6416_AIC23_SAMPLERATE Sample rate control
0x0001 // 9 DSK6416_AIC23_DIGACT Digital interface activation
};

// Filter coefficients

Int16 num[2] = {528,528};
Int16 den[2] = {32767,-31713}; // Assume length(num)=length(den)

void main()
{

DSK6416_AIC23_CodecHandle hCodec;

// Define union to get input

union{Uint32 combo;Int16 channel[2];}input;

// Declaration of I/O and state variables

Int16 x;
Int16 v[2]={0,0};
Int16 y;

// Define union to send output

union{Uint32 combo;Int16 channel[2];}oput;
// Initialize the DSP board

DSK6416_init();

/* Start the codec */

hCodec = DSK6416_AIC23_openCodec(0, &config);
DSK6416_AIC23_setFreq(hCodec,(Uint32)DSK6416_AIC23_FREQ_96KHZ);
while(1){

// Read in a value from ADC

DSK6416_AIC23_read(hCodec,&input.combo);

x = input.channel[0];

// Input x in an Int16 number

// Update state vector

v[0] = x - (Int16)((den[1]*v[1])>>15);

// Build the output

y = (Int16)((num[0]*v[0])>>15) + (Int16)((num[1]*v[1])>>15);

// Shift state vecor

v[1] = v[0];
// y=x;

oput.channel[0] = y;
oput.channel[1] = y;
DSK6416_AIC23_write(hCodec,oput.combo);

}
}
bhargava,

I do not see anything in your code to throttle the filter update rate to 96khz.

The way I usually produce a low pass filter is:

correction set to 0
start timer for 96Khz
start loop
wait timer expire (your 96khz)
restart timer
input sample
sample + correction = output
correction set to (output-sample * (factor for 500hz))
end loop

R. Williams

---------- Original Message -----------
From: b...@gmail.com
To: c...
Sent: Mon, 28 Jul 2008 10:28:09 -0400
Subject: [c6x] Filter implementation on DSK6416

> Hello All,
>
> I am new to DSP programming and am experiencing some difficulties
> implementing filters on a fixed point DSP (TMS320C6416).
>
> To keep it simple, I started trying to implement a single pole low
> pass filter with a corner frequency of 500 Hz while sampling at 96kHz.
>
> I have obtained the quantized filter coefficients using Matlab's fdatool.
>
> I have then written down type 1 direct form equations for the filter
> using the coefficients.
>
> I am using C to program the DSP. Further, I am using the AIC23 codec
> API (came with the board) to perform the ADC and DAC operations.
>
> Since the task comprises of iterating the difference equations, the
> program I ended up with is relatively simple. However, when the load
> the compiled code on the DSP and run the program, all I see is that
> the output is reflecting the input signal. As I sweep the frequency of
> the input sine wave, the amplitude of the output signal stays constant
> till it attenuates as it gets closer to the Nyquist rate.
>
> I would appreciate any advice on this issue.
>
> Below is a copy of my code:
>
> #include "tonecfg.h"
> #include
> #include
> #include #include "dsk6416.h"
> #include "dsk6416_aic23.h"
>
> /* Codec configuration settings */
>
> DSK6416_AIC23_Config config = {
> 0x0017, // 0 DSK6416_AIC23_LEFTINVOL Left line input channel
> volume 0x0017, // 1 DSK6416_AIC23_RIGHTINVOL Right line input
> channel volume 0x00d8, // 2 DSK6416_AIC23_LEFTHPVOL Left channel
> headphone volume 0x00d8, // 3 DSK6416_AIC23_RIGHTHPVOL Right
> channel headphone volume 0x0011, // 4 DSK6416_AIC23_ANAPATH
> Analog audio path control 0x0000, // 5 DSK6416_AIC23_DIGPATH
> Digital audio path control 0x0000, // 6 DSK6416_AIC23_POWERDOWN
> Power down control 0x0043, // 7 DSK6416_AIC23_DIGIF Digital
> audio interface format 0x0001, // 8 DSK6416_AIC23_SAMPLERATE Sample
> rate control 0x0001 // 9 DSK6416_AIC23_DIGACT Digital
> interface activation };
>
> // Filter coefficients
>
> Int16 num[2] = {528,528};
> Int16 den[2] = {32767,-31713}; // Assume length(num)=length(den)
>
> void main()
> {
>
> DSK6416_AIC23_CodecHandle hCodec;
>
>
> // Define union to get input
>
> union{Uint32 combo;Int16 channel[2];}input;
>
> // Declaration of I/O and state variables
>
> Int16 x;
> Int16 v[2]={0,0};
> Int16 y;
>
> // Define union to send output
>
> union{Uint32 combo;Int16 channel[2];}oput;
>
> // Initialize the DSP board
>
> DSK6416_init();
>
> /* Start the codec */
>
> hCodec = DSK6416_AIC23_openCodec(0, &config);
> DSK6416_AIC23_setFreq(hCodec,(Uint32)DSK6416_AIC23_FREQ_96KHZ);
>
> while(1){
>
> // Read in a value from ADC
>
> DSK6416_AIC23_read(hCodec,&input.combo);
>
> x = input.channel[0];
>
>
> // Input x in an Int16 number
>
> // Update state vector
>
> v[0] = x - (Int16)((den[1]*v[1])>>15);
>
> // Build the output
>
> y = (Int16)((num[0]*v[0])>>15) + (Int16)((num[1]*v[1])>>15);
>
> // Shift state vecor
>
> v[1] = v[0];
>
> // y=x;
>
> oput.channel[0] = y;
> oput.channel[1] = y;
>
> DSK6416_AIC23_write(hCodec,oput.combo);
>
> }
>
> }
------- End of Original Message -------