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.

CC2640R2F: AOA SDK 3.20 - What is the rational for the approximation and logic of the ita2 and AOA_iatan2sc functions

Part Number: CC2640R2F


Hi,

Is there any documents that provide details about the implementation of the angle calculation in the functions ita2(y,x) and AOA_iatan2sc(x,y)?

I am currently using simplelink_cc2640r2_sdk_3_20_00_21.

1. Specifically, what kind of approximation is made in ita2(y,x) and what is the error rate?

2. I do not understand the logic in the function AOA_iatan2sc(x,y). Within each pie of the octant a specific formula is used, could you explain the rational behind the logic?

3. Does TI plan to release a new SDK any time soon?

Thanks,

David 

  • Hi David,

    Our SDK release cycle is quarterly. Assigning an expert to follow-up on the technical enquiries.

  • Hi David,

    Let me begin with a general explanation about the AOA_iatan2sc() function.

    This function has to compute arc-tangent value. It must be fast and small. As a result, we divide the trigonometric circle into 8 sectors (octants) and consider the arc-tangent value is linear within an octant. We chose a resolution of 32 samples per octant (i.e. 256 samples in total).

    So, we chose an octant using the if/then/else blocks. Once in the right octant, we do the linear approximation (using the function iat2()). This function returns a value between 0 and 64 (so we divide by 2 to be between 0 and 32). An offset value is added to the value returned by iat2() to take in consideration the octant used (sometimes we add iat2() to the "beginning" of the octant, sometimes we subtract iat2() to the "end" of the octant).

    If we focus a bit on iat2(): this function is responsible of all the imprecision added by the computation (i.e. you have to optimize this function if you want to increase the precision of the computation). If you want, this function could basically do {return (y*64)/x ;} (however, this is way less precise due to rounding errors ==> the max error would be 3.88, while here the max error is 3.39) 

    The values passed to iat2() have to meet the three following constraints:

    - x = 0 is forbidden (divide by 0 is not recommended...)

    - x and y must be negative (this to increase the precision of the calculation: you have 128 values in the negative range, only 127 in the positive range).

    - verify  -x > -y (if not we are out of range and have a value over 64)

    Finally, these constraints explain why AOA_iatan2sc() is calling iat2() sometimes with a "-" before the parameters, before by inverting the two parameters.

    In summary:

    We approximate a circle by one of its chords (we use one chord for each octant). We have 256 samples to cover the full circle (360 degrees). The maximum error done is (3.39 / 2)*360/256 degrees (i.e. 2.4 degrees)

    I hope this will help,

  • Thank you Clément for the detailed clarification.

    There is however a few things I do not clearly understand regarding the iat2 function.

    1) In SDK 3.20, approximation for arctan is done by ita2(y,x)=(32.y+x/2)/x.2=(64.y+x)/x=(64.y)/x+1

    When looking at the raw IQ data, it seems that y/x can be greater than 1 which means that the result of the function is not always less or equal to 64?

    2) I looked closer at the logic of the  AOA_iatan2sc() but I do not get it right somehow.

    For example, if we consider the second section of the octant where X ≥ 0, Y ≥ 0 and X ≤ Y, the angle is determined using -iat2(-x, -y)/2 + 2*32.

    if α is the angle determined by (x,y) then I would expect the following:

    (-x,-y)

    corresponds to

    α + π

    iat2(-x, -y)/2

    corresponds to

    (α + π)/2

    2.(iat2(-x, -y)/2 - π/2)

    corresponds to

    α + π - π = α

    3) In the AOA_iatan2sc() function, I understand  that 32 corresponds to π/4. But is the result of iat2 already scaled down from radian to signed integer?

    In that case what is the original approximation method used?

    Kind regards,

    David

  • Hi,

    1) You always ensure the condition -y > -x (i.e. y < x) so y/x cannot be greater than 1.

    2) in the following formula (-iat2(-x, -y)/2 + 2*32) the term "/2" is due to the iat2() function (it returns a value between 0 and 64, we want to have a value between 0 and 32).

    3) The results returned by iat2() is neither in radian neither in degrees. When iat2() returns 64, it corresponds to π/4 (i.e. 45 degrees). Same kind of remark applies to AOA_iatan2sc() function: when AOA_iatan2sc() returns 32, it corresponds to π/4 (i.e. 45 degrees). That is why, in the function AOA_AngleComplexProductComp() we use a constant to finally get an angle in degrees (for details, please have a look to the angleconst)

    I hope this will help,

    Regards,

  • Hi Clément,

    I am still processing your feedback but I see a discrepancy between the code in SDK3.20 and your explanation.

    From what I can see, the current implementation of iat2() is indeed ((y*32+(x/2))/x)*2 = 64(y/x) +1 and not 64(y/x)?

    Regards,

    David

  • Hi David,

    As the calculation is made with integers, by default the result of the division is truncated. As we wanted to round the result we used the fact that, for integer calculation in C, ((a+b/2)/b) returns the round result of (a/b).

    So yes, you are right, in some cases, the function iat2() returns (64*(y/x) +1) but it is only when this is required for rounding the result. If you think in "casual math" (where we expect a rounded result), then the function does return 64*(y/x)


    Regards,