You are on page 1of 36

Program-5

Aim:-
To generate sinusoidal signal using DSK-6713 processor.

Coding:-
/* DSP program generate the sine wave using lookup table */
/* and produces an output stream. Output data are sent to host files */
/* using RTDX channels. Interface CCstudio with VB and display */
/* the wave on VB graph screen */
/***************************************************************************/

#include <std.h>

#include <log.h>
#include <rtdx.h>

#include "rtdxsinecfg.h"

#include "target.h"

#define BUFSIZE 64
#define BUFFERLENGTH 64
#define MINVOLUME 1

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];
int out_buffer[BUFFERLENGTH];

Int volume=0;

/* RTDX channels */
RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);

Jai Kumar Soni


/*
* ======== main ========
*/
Void main()
{
sample *input = inp_buffer;
Uns size = BUFSIZE;
int sin_table[8] = {0,707,1000,707,0,-707,-1000,-707};
int i=0,loop=0;

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

// LOG_printf(&trace,"\n Sine Wave Example Started");

/* enable volume control input channel */

RTDX_enableInput(&control_channel);

while (TRUE)
{
/* Read a new volume when the hosts send it */
if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel, input, size*sizeof(sample));

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

out_buffer[i]= sin_table[loop];

Jai Kumar Soni


i++;
if (i== BUFFERLENGTH)
i=0;
if (++loop >7)
loop = 0;

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));

while(RTDX_writing)
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}

}
}

Output :-

Jai Kumar Soni


Program-6

Aim:-
To generate square wave signal using DSK-6713 processor.

Coding:-
/* DSP program generate the Square wave using lookup table */
/* and produces an output stream. Output data are sent to host files */
/* using RTDX channels. Interface CCstudio with VB and display */
/* the wave on VB graph screen through RTDX channel */
/***************************************************************************/

#include <std.h>

#include "rtdxsqurecfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#include <log.h>
#include <rtdx.h>
#include "target.h"

#define BUFSIZE 64
#define BUFFERLENGTH 64
#define table_size 8 //size of table=48

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];
sample out_buffer[BUFFERLENGTH];

Int volume=0;

/* RTDX channels */
RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);

Jai Kumar Soni


int data_table[table_size]; //data table array
sample *input = inp_buffer;
Uns size = BUFSIZE;
int i=0,j=0;

/*
* ======== main ========
*/
Void main()
{

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

// LOG_printf(&trace,"\n Square Wave Example Started");

/* enable volume control input channel */


RTDX_enableInput(&control_channel);

while (TRUE)
{

/* Read a new volume when the hosts send it */


if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel, input, size*sizeof(sample));

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

for(i=0; i<=table_size/2; i++) //set 1st half of buffer

Jai Kumar Soni


{
data_table[i] = 0x7FFF; //with max value (2^15)-1
}
for(i=table_size/2;i<table_size;i++) //set 2nd half of buffer
{
data_table[i] = -0x8000; //with -(2^15)
}
i = 0;

for(i=0; i<table_size/2; i++)


{
out_buffer[j] = data_table[i]; //output to buffer
j++;
if(j==BUFFERLENGTH) j=0;
}
for(i=table_size/2;i<table_size;i++)
{
out_buffer[j] = data_table[i]; //output to buffer
j++;
if(j==BUFFERLENGTH) j=0;
}
i=0;

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));
printf("hello");

while(RTDX_writing){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}

}
}

Jai Kumar Soni


Output :-

Jai Kumar Soni


Program-7

Aim:-
To generate triangular wave signal using DSK-6713 processor.

Coding:-
/* DSP program generate the Triangular wave using lookup table */
/* and produces an output stream. Output data are sent to host files */
/* using RTDX channels. Interface CCstudio with VB and display */
/* the wave on VB graph screen through RTDX channel */
/***************************************************************************/

#include <std.h>
#include"rtdxtrangcfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#include <log.h>
#include <rtdx.h>
#include "target.h"

#define BUFSIZE 64
#define BUFFERLENGTH 64

/* Length of sine wave table */


#define TABLE_SIZE 24

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];

Int volume=0;
// = MINVOLUME; /* the scaling factor for volume control */

Jai Kumar Soni


/* RTDX channels */
RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);

int out_buffer[256];
int loop=0;
int i=0;
sample *input = inp_buffer;
Uns size = BUFSIZE;
int trang_table[TABLE_SIZE]=
{ 0, 2000, 4000, 6000, 8000, 10000, 12000, 10000, 8000, 6000,
4000, 2000, 0, -2000, -4000, -6000, -8000, -10000,-12000,-10000,
-8000, -6000 ,-4000, -2000 };//table values
int out_buffer[256]; //output buffer

void main()
{

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

//LOG_printf(&trace,"\n Trangularwave example started");

/* enable volume control input channel */


RTDX_enableInput(&control_channel);

while (TRUE)
{

/* Read a new volume when the hosts send it */


if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel, input, size*sizeof(sample));

Jai Kumar Soni


/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

out_buffer[i] = trang_table[loop]; //output to buffer


i++;
if(i==BUFFERLENGTH) i=0; //if @ bottom reinit count
if (++loop > 23)
loop = 0;

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));
printf("hello");

while(RTDX_writing)
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}
}
}

Output :-

Jai Kumar Soni


Program-8

Aim:-
To perform linear convolution using DSK-6713 processor.

Coding:-
#include<stdio.h>
#include "linearcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "rtdx.h"
#include "target.h"

#define BUFSIZE 7

/* Codec configuration settings */


DSK6713_AIC23_Config config = {
0x0017, // 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume
0x0017, // 1 DSK6713_AIC23_RIGHTINVOL Right line 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 Power down control
0x0043, // 7 DSK6713_AIC23_DIGIF Digital audio interface format
0x0001, // 8 DSK6713_AIC23_SAMPLERATE Sample rate control
0x0001 // 9 DSK6713_AIC23_DIGACT Digital interface activation
};

Uint32 fs = DSK6713_AIC23_FREQ_32KHZ; //set sampling rate

Int volume =1; /* the scaling factor for volume control */

/* RTDX channels */

RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);
RTDX_CreateOutputChannel(D2A2_channel);

Jai Kumar Soni


typedef Int sample; /* representation of a data sample from A2D */

int m=4; /*Lenght of i/p samples sequence*/


int n=4; /*Lenght of impulse response Co-efficients */

int x[7]={1,2,3,4,0,0,0}; /*Input Signal Samples*/


int h[7]={1,2,3,4,0,0,0};
sample inp_buffer[7];

int out_buffer[10];

sample *input = inp_buffer;


int *output = out_buffer;
Uns size = BUFSIZE;
int i=0,j;

void main()
{

DSK6713_AIC23_CodecHandle hCodec;
//Int16 msec;

/* Initialize the board support library, must be called first */


DSK6713_init();

/* Start the codec */


hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq( hCodec, fs);

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

// LOG_printf(&trace,"hostio example started");

/* enable volume control input channel */


RTDX_enableInput(&control_channel);

while (TRUE) {
/* Read a new volume when the hosts send it */
if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION

Jai Kumar Soni


RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel,input, size*sizeof(sample));

/*
* Vector Scale: Scale the input signal by the volume factor to
* produce the output signal*/

while(size--)

for(i=0;i<m+n-1;i++)
{
out_buffer[i]=0;
for(j=0;j<=i;j++)
out_buffer[i]+=x[j]*h[i-j];
}

// for(i=0;i<m+n-1;i++)

// printf("%d\n",out_buffer[i]);

size = BUFSIZE;
input = inp_buffer;
output = out_buffer;

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));
while(RTDX_writing){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif

Jai Kumar Soni


}}}

Output :-

Jai Kumar Soni


Program-9

Aim:-
To design an FIR filter using DSK-6713 processor.

Coding:-
*Purpose ; This program explains FIR Filter. input is internally generated noise.The band
pass filter we designed is of the order 41.
*****************************************************************************
********************/

#include"fircfg.h"
#include"dsk6713.h"
#include "dsk6713_aic23.h"

#include "bp41.h"

#include "noise_gen.h"
#include "rtdx.h"
#include "target.h"
#include <math.h>
#define BUFSIZE 41
#define MINVOLUME 1
//delay samples
short fb; //feedback variable
shift_reg sreg;
short prn(void) ;

/* Codec configuration settings */


DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x01f9, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x01f9, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0012, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0001, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0002, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \

Jai Kumar Soni


0x0023, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */
};

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];
int out_buffer[BUFSIZE];
short buffercount = 0; //init buffer count
const short bufferlength =1024;
Int volume =1;
/* the scaling factor for volume control */
/* RTDX channels */

RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A_channel);
RTDX_CreateOutputChannel(D2A1_channel);
RTDX_CreateOutputChannel(D2A2_channel);

int *input = inp_buffer;


int *output =out_buffer;
Uns size = BUFSIZE;
int i;
int yn=0; //initialize filter's output
short yn_buffer[1024];

main()
{

int dly[N];
DSK6713_AIC23_CodecHandle hCodec;

/* Initialize the board support library, must be called first */


DSK6713_init();

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

/* Start the codec */


hCodec = DSK6713_AIC23_openCodec(0, &config);

/*set codec sampling frequency*/


DSK6713_AIC23_setFreq(hCodec,1);

Jai Kumar Soni


/* enable volume control input channel */
RTDX_enableInput(&control_channel);

while (TRUE) {
/* Read a new volume when the hosts send it */
if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

RTDX_read(&A2D_channel,input, size*sizeof(sample));

dly[0] = prn(); //input noise sequence


yn = 0; //initialize filter's output
for (i = 0; i< N; i++)
yn+=(h[i]*dly[i])>>15; //y(n)+=h(i)*x(n-i)
for (i = N-1; i > 0; i--) //start @ bottom of buffer
dly[i] = dly[i-1]; //data move to update delays

while (!DSK6713_AIC23_write(hCodec, ((short)yn))); //output filter

yn_buffer[buffercount] = yn; //filter's output into buffer


buffercount++; //increment buffer count
if(buffercount==bufferlength) //if buffer count = size
buffercount = 0; //reinitialize buffer count

sreg.regval = 0xFFFF; //shift register to nominal values


fb = 1; //initial feedback value

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

RTDX_write(&D2A1_channel,dly, size*sizeof(sample));
while(RTDX_writing){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif

Jai Kumar Soni


}

RTDX_write(&D2A2_channel,yn_buffer, size*sizeof(sample));

while(RTDX_writing){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}}}

short prn(void) //pseudorandom noise generation


{
short prnseq; //for pseudorandom sequence

if(sreg.bt.b0) //sequence {1,-1}


prnseq = -16000; //scaled negative noise level
else
prnseq = 16000; //scaled positive noise level
fb =(sreg.bt.b0)^(sreg.bt.b1); //XOR bits 0,1
fb ^=(sreg.bt.b11)^(sreg.bt.b13); //with bits 11,13 ->fb
sreg.regval<<=1; //shift register 1 bit to left
sreg.bt.b0 = fb; //close feedback path
return prnseq;

} //return sequence

Jai Kumar Soni


Output :-

Jai Kumar Soni


Program-10

Aim:-
To design an IIR filter using DSK-6713 processor.

Coding:-

#include "iirfiltercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include <rtdx.h>
#include "target.h"
#define BUFSIZE 31
#define MINVOLUME 1
typedef Int sample;

signed int filter_Coeff[] =


{
// 0.388513,-0.777027,0.388513,1.000000,-1.118450,0.645091
// 12730,-12730,12730,2767,-18324,21137 /*HP 2500 */
//312,312,312,32767,-27943,24367 /*LP 800 */
//1455,1455,1455,32767,-23140,21735 /*LP 1000 */
9268,-9268,9268,32767,-7395,18367 /*HP 4000*/
// 7215,-7215,7215,32767,5039,6171, /*HP 5000*/
};

Uint32 inp_buffer[BUFSIZE];
Uint32 out_buffer[BUFSIZE];
Int volume = MINVOLUME;

RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);
RTDX_CreateOutputChannel(D2A2_channel);
/* Codec configuration settings */
DSK6713_AIC23_Config config = { \

Jai Kumar Soni


0x001b, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x001b, /* 1 DSK6713_AIC23_RIGHTINVOL Right line 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 Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input, l_output;
Uint32 *input = inp_buffer;
Uint32 *output = out_buffer;
Uns size = BUFSIZE;

int j,m;

/* Initialize the board support library, must be called first */


DSK6713_init();

TARGET_INITIALIZE();
RTDX_enableInput(&control_channel);
RTDX_enableInput(&A2D_channel);
RTDX_enableOutput(&D2A1_channel);
RTDX_enableOutput(&D2A2_channel);
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);

while(1)
{

for(j=0;j<BUFSIZE;j++)
{

/* Read a sample to the left channel */


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

Jai Kumar Soni


/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));

l_output=IIR_FILTER(&filter_Coeff ,l_input);
//r_output=l_output;
out_buffer[j]=l_output;

RTDX_read(&A2D_channel, input, size*sizeof(sample));


if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/

#endif
}

j=0;
while(size--){

*output++ = out_buffer[j++];
}
size = BUFSIZE;
input = inp_buffer;
output = out_buffer;
/* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/
/* for(m=0;m<50000;m++)
{

RTDX_write(&D2A_channel, l_input, size*sizeof(sample));


}*/

for(m=0;m<50000;m++)
{

RTDX_write(&D2A2_channel, filter_Coeff, size*sizeof(sample));


}
for(m=0;m<50000;m++)

Jai Kumar Soni


{
RTDX_write(&D2A1_channel,out_buffer , size*sizeof(sample));
}
while(RTDX_writing){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif

}
/* Close the codec */
// DSK6713_AIC23_closeCodec(hCodec);
}}

signed int IIR_FILTER(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)
{
temp = -32767;
}
y[0] = temp ;

Jai Kumar Soni


/* Shuffle values along one place for next time */

y[2] = y[1]; /* y(n-2) = y(n-1) */


y[1] = y[0]; /* y(n-1) = y(n) */

x[2] = x[1]; /* x(n-2) = x(n-1) */


x[1] = x[0]; /* x(n-1) = x(n) */

/* temp is used as input next time through */

return (temp<<2);
}

Output :-

Jai Kumar Soni


Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni
Jai Kumar Soni

You might also like