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.

CCS/TMS320C5505: Square root implementation

Part Number: TMS320C5505


Tool/software: Code Composer Studio

Hi Guys,


I want to write my own square root function is ccs for tms320c5505 ezdsp.

Input is audio signal signal.


I want to do square root of this input.

I cannot use sqrt_16 function in dsp library as it only finds square root of 16 bit number, but i need square root of 32 bit number.

Can anyone know how to write square root code for dsp. I am very much new to dsp.

  • Hi Satyajit,

    I've forwarded this to the C5000 software experts. Their feedback should be posted here.

    BR
    Tsvetolin Shulev
  • look "sqrtv" from Jeff Axelrod 1.00, A. Aboagye, 8/31/98, with N = 5 you get accuracy = 100 * 2/32767 = 0.0061% , it is very quick and
    you can change them to 32bit - with a little table and only 20 ASM_lines..
  • HI Lars,

    Thanks for reply.
    Where can I find "sqrtv" from Jeff Axelrod 1.00, A. Aboagye, 8/31/98.
  • Hi, ok, now it's named "from Li Yuan 01/30/2002" , but I've checked this this morning. It is no more
    then a chinese copy & paste of the version from Jeff Axelrod with large indexes (XAR5/XAR6) and a SI_Bug workaround.
    All coments are the same! You find it in dsplib/55x_src
    -make a long table until 2^31 - not only 30 and look at this, then you can make an unsigned version until 65000^2

    Lars
  • Hi,

    Actually I am very novice to dsp.
    I was trying to find dsplib/55x_src folder in my PC but did not get it.
    I found one src folder at location
    C:\ti\ccsv6\tools\compiler\c6000_7.4.18\lib\src
    but src folder it does not have "sqrtv" file

    Can you please tell me where can I get dsplib/55x_src
  • its part of csl - actual is 307 get it from ti's site
    but think the next question is "how to change to 32bit..."
    you know C55 ASM?
  • Hi,

    Thanks for reply.
    Actually I recently started working on dsp around 2 months back.
    I have only worked on c coding and not assembly.
    I am not much familiar with c55 asm.


    Below is the c code to generate the square root of sine wave. Firstly, I am converting the negative values to positive i.e. converting the range "-32767 to 32676" to "0 to 32767". Once the input is only positive, I am using square root function to get square root of input.

    signed short int generate_squareroot(signed short int input)
    {
    signed short int SquareRoot = 0;
    signed short int SquareRoot2 = 0;

    input = input >> 1;
    input = input + 0x3FFF;

    SquareRoot = input;
    sqrt_16(&SquareRoot, &SquareRoot2, 1); // take square root of sinusoid and store the squared root into SquareRoot
    return SquareRoot2;
    }


    But as you can see, the sqrt_16 can only take 16 bit input. If input is 16 bit, it can take any values from 0 to 32767. But once square root is done, the signal can take values from 0 to 181. As such, I am losing a lot precision when I square root.

    What I plan is to give input in the range 0 to 2^31 so that its square root can take values between 0 to 2^15.5

    Do you think is it possible
  • uint32_t root = 0;
    uint32_t Bit;

    for ( Bit = 0x80000000L; Bit > 0; Bit >>= 1 )
    {
    uint32_t trial = root + Bit;
    if ((uint64_t)trial * (uint64_t)trial < input)
    {
    root += Bit;
    }
    }
    return root;


    slow version...
  • Thank you very much for your timely assistance. I will try this and will get back to you.
    Thanks
  • HI,

    As per your suggestion, I tried below code. But it not seems to be working. Output is equal to input in below case.

    // Square root of 32 bit number
    signed long int generate_squareroot(signed long int input)
    {
    signed long int SquareRoot = 0;
    signed long int root = 0;
    signed long int Bit;
    signed long int trial =0;

    // convert input range from (-2^31)-(2^31) to (0)-(2^31)
    input = input >> 1;
    input = input + 0x3FFFFFFF;

    SquareRoot = input;

    for ( Bit = 0x40000000L; Bit > 0; Bit >>= 1 )
    {
    trial = root + Bit;
    if ((unsigned long long)trial * (unsigned long long)trial < SquareRoot)
    {
    root += Bit;
    }
    }
    return root;
    }