Hi,
I met a very urgent issue with implementation of LMS algorithm on DSK6713.
I need to Implementation noise control on with DSK6713 with a loudspeaker, mikrophone and headphone. First of all I dont know if I must use the DSP/BIOS to realize the real time performance, because I am not sure if the board is fast enough.
I write my program like this:
#include "tonecfg.h"
#include "math.h"
/*
* The 6713 DSK Board Support Library is divided into several modules, each
* of which has its own include file. The file dsk6713.h must be included
* in every program that uses the BSL. This example also includes
* dsk6713_aic23.h because it uses the AIC23 codec module.
*/
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdlib.h"
#define size 30000 //signal number
#define M 40 //filter order
#define mu 0.00000000005 //convergence factor 0 < mu < 1/rho
// Function prototypes
void sinewave();
/* 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
0x000d, // 8 DSK6713_AIC23_SAMPLERATE Sample rate control//// 0x000d/ 0x000c:8kHz, 0x0001: 48kHz.
0x0001 // 9 DSK6713_AIC23_DIGACT Digital interface activation
};
//define of the vectors and matrix
Int32 xs[size];
Uint32 Error[size];
Int32 y[size];
float g[size];
//Generation of sine wave in the area between 1V to -1V, in a*sampla rate(8kHz) Hz.
void sinewave()
{
Int16 i=0;
float a=0.01;
for (i=0; i<size;i++)
{
xs[i]=23405*sin(2*3.14*a*i);
}
}
//main rutine
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Int16 i, j, k, n;
//coefficients of the transfer function
float a1 = 0.009246;
float a2 = 0.1731;
float a3 = 4.266;
float a4 = 0.5043;
float a5 = 13.22;
float a6 = 9.292;
float b2 = 1.255;
float b3 = 0.04594;
float b4 = 0.3459;
float b5 = 0.01714;
float b6 = 0.02187;
float b7 = 0.08492;
//define of the variables
float Buffer1[M];
float Buffer2[M];
float Product[M];
float W[2][M];
//read the sine wave from the function
sinewave();
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
//transfer function
for (n=6; n<size; n++)
{
g[n]=a1*(float)xs[n-1]-a2*(float)xs[n-2]-a3*(float)xs[n-3]+a4*(float)xs[n-4]+a5*(float)xs[n-5]-a6*(float)xs[n-6]+b2*g[n-1]-b3*g[n-2]-b4*g[n-3]+b5*g[n-4]+b6*g[n-5]-b7*g[n-6];
}
for (n=M; n<=size; n++)
{
//input of the error
while (!DSK6713_AIC23_read (hCodec, &Error[n]));
//stock the output signal in Buffer1 with size of M
for(k=n; k>=n-M+1; k--)
{
Buffer1[n-k]=g[k];
Buffer2[n-k]=(float)xs[k];
}
//Product of the Error and input
for (i=0; i<M; i++)
{
Product[i]=(float)Error[n]*Buffer1[i]*2*mu;
}
//Iteration of W, W is a Matrix with two culonms, which will be alternately filled
if(n%2 == 0)
{
for(j=0; j<M; j++)
{
W[1][j]=W[0][j]+Product[j];
}
for(i=0; i<M; i++)
{
y[n]=W[1][i]*Buffer2[i];
}
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, xs[n]));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, y[n]));
}
else
{
for(j=0;j<M;j++)
{
W[0][j]=W[1][j]+Product[j];
}
for(i=0; i<M; i++)
{
y[n]=W[0][i]*Buffer2[i];
}
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, xs[n]));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, y[n]));
}
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
However after debug and I run the code, I cant get what I want. What Particularly strange is in the left chennel I got a sinewave with a different frequency as it should be. What I made at began is a sinewave with a frequency with 80 Hz, but I got a sinewave with a frequency of about 20 Hz. I did a lot of checks, and found that from the second for-loop in the main on, the algorithm changes always the frequency. But I just cant understand why??
Could any body help me?