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.

Mathematical Power in Fixed point

Other Parts Discussed in Thread: TMS320F2808, CONTROLSUITE

I would like to Implement Mathematical Power in the most easy and efficient way , I'm using C2000 (TMS320F2808) – for example à Y = 2x^3 + 3x^5 + 6x^4… In C we can use pow function from include math library , but in C2000 it's not working because the dsp is fixed point. 

  • Saman,

    What format is 'x' in?  Is it just an integer?  You will need to be careful about overflow.  I'd expect 'x' to be a fractional format, maybe an IQmath format (see IQmath available in ControlSuite).

    If the exponents are all postive integers, it is a simple matter to write a power function.  Basically, you just loop and multiply 'x' by itself the required number of times.  In pseudo-code:

    if(exponent == 0)
    {
      x = 1;
    }
    else if(exponent == 1)
    {
       // do nothing.  x = x.
    }
    else
    {
       x0 = x;
       for(i=0; i<exponent-1; i++)
       {
          x = x*x0;
       }
    }

    Something like the above.  This can work for IQmath format as well.  You'd just replace x=x*x0 with x=_IQmpy(x, x0).  If the exponents are real numbers (e.g., x^1.8), then you will need to do something else, probably compute in floating point.

    ----------

    If you are using IQmath, you might also try exploiting the properties of logarithms:

    z = x^y   ==>

    ln(z) = y*ln(x)

    e^ln(z) = e^[y*ln(x)]

    z = e^[y*ln(x)]

    The IQmath library has IQNexp() and IQNlog() functions that will allow you to compute the right-hand side of the above:

    z = IQNexp(_IQmpy(y, IQNlog(x));

     

    If the exponents are all fractional, then the logarithm approach is the way to go.  If the exponents are (positive) integers, then the looping method is probably best for reasonably small exponents.  As the exponents get larger and larger however, at some point the looping becomes inefficient and the logarithm approach is better.  You will have to determine which method is best for your particular situation.

    I vaguely recall another method called "Horner's Method."  http://en.wikipedia.org/wiki/Horner's_method.  The wikipedia article is not completely clear on how to implement it, but it can give you a starting point if you want to research it more yourself.

    Regards,

    David

     

    Regards,

    David