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.

Using DSPLIB in Fixed Point

Hi,

I use C5535 to develop some algorithm, which need "log", "sqrt" and "power",

but I find they have to change to Q15 format from fixed point integer,

and transform back after using DSPLIB, for example to get sqrt(100):

//test root "sqrt_16()" by using int <-> q15 conversion
    temp_x = 100;

    temp_f = 1;
    temp_f /= temp_x;  //turn integer value to reciprocal
    temp_f *= 32768;  //convert to Q15 from integer

    temp_log_in = (short)temp_f;

    sqrt_16(&temp_log_in, &temp_log_out, 1);

    temp_f2 = temp_log_out;
    temp_f2 /= 32768;  //convert to integer from Q15
    temp_y = 1;
    temp_y /= temp_f2;  //get output integer value from reciprocal

It cost too much CPU cycle, and the result will not be precise when input value get much bigger.

Is there any good solution to transfer integer to Q15, or using these DSPLIB more efficient?

Best regards

Eddie

  • I will give you a more detailed answered later,  but just to be on the same page lets review what is q15

    You can look at wikipedia  (https://en.wikipedia.org/wiki/Q_%28number_format%29

  • Somehow the rest of my posting was deleted

     

    Look at the library user’s guide (http://www.ti.com/lit/ug/spru422j/spru422j.pdf ) and see what are the format of the function sqrt_16 and the data format that it needs

     

    Look at the definition of the data type (section 3.1.2) and see what DATA type means and what short and unsigned short means

     

    Then go to the definition of the function sqrt_16 and see what is the format of the input and the output values

     

    Now, depends on your knowledge of the values that you want to do sqrt, you may or may not convert it to DATA format. You may choose a different way to convert numbers. In this example they did it by going to 1/100 (so they know what is the format of 1/x) and then manipulate the binary point. If you have better understanding of the range of your numbers or the format of the numbers you can write more efficient code

     

    Ran

  • Hi! Ran,

    Thanks for your kindly help!

    I finally understood how to manipulate Q format value in integer DSP world.

    With regards,

    Eddie