Part Number: TMS320C6713B
Tool/software: TI C/C++ Compiler
Good afternoon sir,
Sir, am doing research on adaptive noise cancellation.
Iam implementing real time adaptive noise cancellation using the following code, here am taking desired signal is 500 hz and noise is 1000 hz. these two signal are taking from the function generator and give input into the TMS320C6713 line input, and from the line put to observe the adaptive output (Y) and error signal on CRO.
But, when am debug, and resume the weights of the filter was not obtained showing zero and Y also showing zero.
Sir, please help me how to solve this problem,
iam including code also sir, please help me sir. Sir iam using CCSv5.5 with TMS320C6713
* main.c
*/
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdlib.h"
#include "math.h"
#define NS 1000 // number of samples
#define beta 0.01 //rate of convergence
#define N 40
#define Fs 8000 //sampling frequency
short int adaptive_filter(short int ,short int );
// float delay[N];
// float w[N];
// float desired[NS], Y_out[NS], error[NS];
float D,yn,E;
//union{unsigned int uint; short channel[2];} AIC23_data;
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 */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_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;
Uint32 l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_48KHZ);
// DSK6713_AIC23_setFreq(hCodec, 8000);
while(1)
{
/* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec,&l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(short int)adaptive_filter(l_input,r_input);
r_output=l_output;
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output));
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
short int adaptive_filter(short l_input1,short r_input1) //ISR
{
long I, T;
float D, Y, E;
float w[N+1] = {0.0};
float X[N+1] = {0.0};
short output;
float dplusn=0, desired=0, noise=0;
for (T = 0; T < 40; T++)
{
// w[T] = 0; //init buffer weights
X[T] = 0; //init buffer for delay samples
}
desired = l_input1;
noise = r_input1;
D = desired + noise; //desired+noise
X[0] = noise; //noise as input to adapt FIR
Y = 0;
for (I = 0; I < N; I++) //to calculate out of adapt FIR
Y += (w[I] * X[I]); //output of adaptive filter
E = D - Y; //"error" signal=(d+n)-yn
for (I = N-1; I >= 0; I--) //to update weights and delays
{
w[I] = w[I] + (beta*E*X[I]); //update weights
if (I != 0) X[I] = X[I-1]; //update data sample
// delay[i] = delay[i-1]; //update delay samples
}
//output = ((short)desired);
output=((short)E); //error signal as overall output
// output=((short)yn); // adaptive controller signal
// output=((short)dplusn);//output (desired+noise)
// overall output result
return(output);
}