• Not Answered

Compiler/TMS320F28069M: IQmath problem

Part Number: TMS320F28069M

Tool/software: TI C/C++ Compiler

Hi all!

I have a problem with the #include <IQmathLib.h> library. Currently I'm using a Launchpad F28069M, and the idea is that I need to calculate the sine and cosine for some variables in radians. But the IQmath lybrary is not that easy to understand.

My angles values are expressed as a 2*pi*w, and i have to update w several times during  a period of time (w will be between 10 and 10000). (This is in order to apply a FFT in my code)

I hope someone has an example of how  to apply the sine and cosine applying the IQmath lib so I can adapt it to my code.

Thanks in advance for the help!


5 Replies

  • Hi Maria,

    For examples of the basic IQmath functions I can do no better than point to the code examples in the quickstart guide (attached). The sine and cosine functions expect inputs in radians, and you have to keep within the numeric range of your chosen IQ format.  For example, with w = 10000 you'll be passing in a value of 62832, so your IQ format will need at least 16 bits of range (2^16 = 65536).  This will restrict you to IQ15 or less.

    Is your input data (w) already in IQ format?




  • In reply to Richard Poley:

    Dear Richard

    Thanks for your repply, there is an easier way to do it? i tried with math.h and it does not matter what value I put i have the same answer, also tried some IQmath examples and they also give me some numbers at the output value that are really big and make no sense to me (even changing them from IQ to float) then I tried also CLAmath without success.

    The main idea is only to generate a sine and cosine function in terms of a variable wp with amplitude 1. Then I want to have this value:

    sin(2*pi*w) and cos(2*pi*w)

    The variables I have are not in IQ format yet, but I would really appreciate if you could tell me an easier way to do it (without getting that into details with IQmath that is a bit complicated)

    Thanks in advance for your help

    Best regards


    Hi Maria,

    It should be fairly straightforward to do this.  Once you have added the IQmath library to your project, here's what you might try in your program:

    // variables
    _iq twopi = _IQ(6.283185307f);
    _iq sval = _IQ(0.0f);
    _iq cval = _IQ(0.0f);
    _iq ref = _IQ(0.0f);
    _iq inc = _IQ(0.01f);
    _iq angle = _IQ(0.0f);
    long i;



    for (i=0; i<9999; i++)
    angle = _IQmpy(twopi, ref);
    sval = _IQsin(angle);
    cval = _IQcos(angle);
    ref += inc;


    If I set a break-point on the last line ("ref += inc;") it's stepping through the angles nicely.  You would change "inc" to change the frequency of the sine/cosine outputs, which would obviously be in global _IQ format (I was using IQ24).  The attachment is what I see in the watch window.

    An alternative approach which does not involve IQmath is to use the FastRTS library which you can find in controlSUITE.  The sine and cosine functions have approximately the same cycle counts as their IQmath counterparts, and you will be able to keep everything in floating-point if that's what you want.

    I hope this helps, but do post back if you have further questions.



  • In reply to Richard Poley:

    Dear Richard

    Thanks for the repply, I dont understand what happened but now I have 33 errors related to the #include <IQmathCPP.h> library. The error looks like this

    And I cant try the code you sent me. This error appears the moment I call the include function.

    Thanks in advance for the help.




    Hi Maria,

    Regret I can't really see what's going wrong from the errors.  Those warnings are from the C++ version of the library header file.

    If I'm right, your project is the ADC SOC example in controlSUITE, which is likely at this location on your hard drive:


    I've attached a slightly modified main source file for this example.  The only changes I've made are to add the IQ math header file at the top, and copy in the lines of code from my last post.  It's working correctly on my machine.  

    Can you change your own source file to look like this and let me know if it builds please?

    (Note: you may get a couple of warnings when you build the project but these can be ignored).