fixed cos sin
This commit is contained in:
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
# Generator for sin/cos fixed point LUT tables.
|
||||
import math
|
||||
|
||||
def generate_pi():
|
||||
print(f"#define COM_FIXED_PI (com_fixed_t){int(math.pi * (1 << 16))}\n")
|
||||
print(f"#define COM_FIXED_PI2 (com_fixed_t){int(math.pi*2 * (1 << 16))}\n")
|
||||
print(f"#define COM_FIXED_PIHALF (com_fixed_t){int(math.pi/2 * (1 << 16))}\n")
|
||||
|
||||
# Idea is to generate only one quadrant, as the values repeat later with different sign and order.
|
||||
def generate_sin_table(n_entries=128):
|
||||
r = []
|
||||
for n in range(n_entries):
|
||||
r += [math.sin(math.pi*n/(n_entries*2))]
|
||||
# r[n_entries-1]=1 # Make it converge to unit precisely
|
||||
print(f"static const uint16_t com_fixed_sin_lut[{n_entries}] =", "{", ",\n".join((str(int(a * (1 << 16))) for a in r)), "};\n")
|
||||
|
||||
generate_pi()
|
||||
generate_sin_table()
|
||||
Reference in New Issue
Block a user