How to find offset in a sine lookup table (LUT) using fixed point arithmetic

独自空忆成欢 提交于 2020-01-05 10:20:07

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/28406507/how-to-find-offset-in-a-sine-lookup-table-lut-using-fixed-point-arithmetic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!