问题描述
我正在生成一个将0-2PI分成512个片段的LUT,然后找到这些值的正弦值并将其存储为Q1.31值。
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.
示例:
LUT[0] = 0
LUT[1] = sin((1/512) * 2*PI) * (2^31)
..
..
LUT[511] = sin((511/512) * 2*PI) * (2^31)
我的输入也是Q1.31格式的值。
My inputs are also values in the Q1.31 format.
我的问题是如何使用LUT,即当我得到一个随机值作为输入来找出正弦值时,如何在表中查找偏移值
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
示例:
int sample_input = 0.125 * (2^31) //0.125radians in Q31 format = 268435456
推荐答案
请注意, 0.125radians *(2 ^ 31)
方法不适用于大于1弧度的角度。可能您想对角度
(0.125radians / 2Pi)*(2 ^ 31)
进行归一化将2 ^ 31的范围映射到2 ^ 9-因此只需除以2 ^ 22。
示例:
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
这篇关于如何使用定点算法在正弦查找表(LUT)中查找偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!