1

I am generating a LUT dividing 0-2PI into 512 fragments and then finding sine of these values and storing them as Q1.31 values.

Example:

LUT[0] = 0

LUT[1] = sin((1/512) * 2*PI) * (2^31)
..
..

LUT[511] = sin((511/512) * 2*PI) * (2^31)

My inputs are also values in the Q1.31 format.

My question is how do I go about using the LUT i.e. what is the algorithm to find the offset values in the table when I get a random value as an input to figure out the sine value

Example:

int sample_input = 0.125 * (2^31) //0.125radians in Q31 format = 268435456
RuD
  • 93
  • 1
  • 6

1 Answers1

0

Note that 0.125radians * (2^31) approach is not suitable for angles > 1 radian. Probably, you wanted to normalize angle (0.125radians/2Pi) * (2^31)
Anyway, you'll need to map 2^31 range to 2^9 - so just divide by 2^22. Example:

Angle = 0.125 radians.
0.125 /(2*Pi) * 2^31 = 42 722 829
42 722 829 / 2^22 = 10
Result = Lut[10] = 262 874 923
MBo
  • 77,366
  • 5
  • 53
  • 86
  • could you please elaborate on your answer, with an example maybe? – RuD Feb 09 '15 at 10:23
  • My inputs are in Q31 format like I mentioned in the question. So 0.125 is 268435456. I assume there is a condition on the inputs to be less than 1rad. How would the algorithm change then? – RuD Feb 09 '15 at 11:21
  • I think the normalization is done at a later stage in the code. – RuD Feb 09 '15 at 11:29
  • See edit (result is the same). If input value is limited by 1 radian, it would be better to fill LUT with this range for higher precision. – MBo Feb 09 '15 at 11:33