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.

TMS320F28069: Raising numbers to powers efficiently

Part Number: TMS320F28069


Hello All,

The standard math library "pow()" function compiles into a large amount of code.  I'm not trying to use it in an rtos, so execution time is not an issue, but my program code space is not sufficient to allow it.

I'm using the IQMath library for the vast majority of DSP work in this project, and I've found it to be efficient in space and time.  However, I don't see a function in there that will allow me to raise a number to a power.  Am I just missing it?

One of the terms of the calculation is:  10^(20/40)

Programmatically, it looks like this:  x = pow( 10, (20/40) );

This will compile and do it's job OK, but I don't have enough free memory to use it.

Is there a better way to approach this?

Thanks,

robin

  • Robin,

    You are correct that there is no power function in the IQ math library.  What you can try is to make a change of base to 'e' and then use a natural logarithm. 

    I haven't tried bit, but your code would look something like:

    result = IQexp(10 * IQlog(20/40));

    These two functions consume 218 words of program space.

    Regards,

    Richard

  • Hi Richard,

    Thanks for your reply.

    Please forgive me, I'm weak in the math department, but this equation:

    result = IQexp(10 * IQlog(20/40));

    seems to have a different result from this equation:

    result = 10^(20/40)

    e.g.

    10^(20/40) = 3.162

    IQexp(10 * IQlog(20/40)) = 0.0009766

    Also, I'm getting crashes when implementing the log function in code.  Running in C, I use _IQlog(20/40).  There are no compiler errors or warnings, but execution screeches to a halt when it reaches this line of code.

    Line 4689 of IQMathLib.h replaces _IQlog() with log().  log() is found in math.h, and it's defined to use double floats.  I've tried using doubles versus _iq types, but haven't been able to get either to run with the 20/40 expression.  Nor do they run when using 0.5 in place of the 20/40 expression.

    Oddly, the line does run when I enter the number 10 in place of the 0.5, but it comes up with the wrong result.  The result of log(10.0) should be 2.303, but I'm getting -0.6931 (which, curiously,  is the natural log of 2).

    So;

    1. Am I applying the math incorrectly?
    2. Any idea why I'm not seeing the expected result from the log() function?

    Thanks,

    robin

  • Hi Robin,

    Sorry for the delay.  The math is sound, but I'm hitting some unexpected code issues too.  Still working on it and will get back to you as soon as I can.

    Thanks for your patience.

    Regards,

    Richard

  • Hi Robin,

    The difference in the calculations is that one computes 10^(0.5) = 3.162, while the other computes (0.5)^10 = 0.0009766. You asked for the former. The method is correct; I just put the modulus and exponent the wrong way round in my reply.

    The variable declarations and code I have is:

    _iq result;
    _iq modulus = _IQ(10.0);
    _iq expnt = _IQ(0.5);

    main()
    {
    result = _IQexp(_IQmpy(expnt, _IQlog(modulus)));

    This is working fine on my machine. Can you try it and let me know what you find please?

    You should see the result 3.162277281. If you're getting something else it's likely to be the IQ math tables not being loaded in the right place in your linker file. The _IQNexp() function uses a look-up table held in internal ROM at address 0x3FEAf0. Check section 3.3 in the IQmath User's Guide for details of how to configure the table.

    Regards,

    Richard
  • Hi Richard,

    It's working well.

    Thanks for the help.

    robin