This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LMS algorithms Problem with DSK6713



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?

  • Johnny,

    You have a complicated set of code that makes it harder to debug what is happening. It will be easier to debug if you simplify the code temporarily. For example, reduce the code to simply output your original unmodified sine wave so you can see if that can be done at the expected rate. Once you get that simple process working correctly, then you can start adding back in the rest of the code to see what the effects are - hint: add in as little as possible with each step, that way you will know most quickly when you have added in the part of the code that is affecting your output the most.

    Regards,
    RandyP
  • Hi,

    Thanks for your reply! I tried a lot, for example after only one for-loop:

    for(k=n; k>=n-M+1; k--)
    {
    Buffer1[n-k]=g[k];
    Buffer2[n-k]=(float)xs[k];
    }

    the frequency has already changed. I just cant understand why, it should not be.

    Do you know why?

    best regards

    Johnny

  • Johnny,

    This is not simple enough, yet. You have filled the xs array with a sine wave, which I assume is the sine wave you want to output at 80 Hz. Look at that array in the memory browser to see if you have the correct values there. Then, remove all the for-loops and output xs[n] to both the left and right channels.

    Regards,
    RandyP
  • Hi Randy,

    #define M=40;

    void sinewave()
    {
    Int16 i=0;
    float a=0.01;
    for (i=0; i<size;i++)
    {
    xs[i]=23405*sin(2*3.14*a*i);
    }
    }

    for (n=M; n<size; n++)
    {
    //The number of repetitions determines the output time!!
    /* 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, xs[n]));
    }
    I tried that, like what you said, without any for-loops, I can get the sinewave at 80 Hz.

    for (n=M; n<size; n++)
    {
    //stock the output signal in Buffer1 with size of M
    for(k=n; k>=n-M+1; k--)
    {
    Buffer2[n-k]=(float)xs[k];
    }
    //The number of repetitions determines the output time!!
    /* 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, xs[n]));
    }
    And when I add a for-loop in that, the frequency changed.
    That is unbelievable, cant find the reason!

    regards
    Johnny
  • Johnny,

    You have a solid datapoint with the first loop giving you the right result.

    1. Look at the outputs with an oscilloscope to see what you can determine from the data. You will want to compare the output of the 80Hz version and the 20Hz version to see what clues can come from the output data itself, if any.

    2. Confirm that the added k=n for-loop does not change the data in the xs array. If the data is changed, that would be a problem if I understand your code correctly.

    3. If the data in xs is unchanged but the output frequency is different, look for ways that could happen - what could change the output frequency (sending the same data multiple times, sending the data less often, sending corrupted data, 100s of possible reasons...)?

    4. Change some of the parameters of the added k=n for-loop and see how that affects the output frequency. For example, increase M to 60.

    Regards,
    RandyP
  • Hi Randy,
    thank you again for your reply!
    My friend find a reason, and it seems like right. He told me that the because the controller need time to finish the Buffer for-loop, and every time it take the same time to finish it, so it changed the original frequency average to a small one. And I have tried that to change the number of M, that proved the suppose, the frequency changed Inversely to the number of M.
    Problem now is how can I ensure the completion of the calculation within a certain period of time. I must implement a noise filtering with the LMS algorithm. After stuff of the buffer will be the signal calculated in LMS. How can I avoid the algorithm take too much time that it changes the frequency of the signal?
    Do you have any suggestions?

    regards,
    Johnny
  • Johnny,

    Go to TI.com and search for "DSP optimization" (no quotes). You will find some articles to read and some training material.

    Regards,
    RandyP