kopia lustrzana https://github.com/bristol-seds/pico-tracker
81 wiersze
2.2 KiB
Python
81 wiersze
2.2 KiB
Python
#!/bin/python
|
|
|
|
import numpy as np
|
|
import math
|
|
|
|
length = 512
|
|
|
|
def file_header(f):
|
|
print >>f, "/**"
|
|
print >>f, " * Autogenerated sine tables. See tools/ax25_lookup/ax25_lookup.py"
|
|
print >>f, " */"
|
|
print >>f, ""
|
|
|
|
def print_sintable(f, deviation_f, defonly):
|
|
f_resolution = 7.805347443
|
|
deviation = (deviation_f/f_resolution)
|
|
|
|
# Generate our sin table
|
|
quadrant_range = np.arange(0, np.pi/2, (np.pi/2)/length)
|
|
sintable = np.multiply(np.sin(quadrant_range), deviation)
|
|
|
|
# stringify
|
|
strings = [ "{0:0.0f}".format(x) for x in sintable ]
|
|
maxlen = max([ len(s) for s in strings ])
|
|
|
|
# stringify in equal parts
|
|
strings = [ "{0:>{width}.0f}".format(x, width=maxlen) for x in sintable ]
|
|
string = ", ".join(strings)
|
|
|
|
# lines
|
|
line_len = int(math.floor(78 / (maxlen+2))*(maxlen+2))
|
|
lines = [string[x:x+line_len].rstrip() for x in range(0, len(string), line_len)]
|
|
string = "\n ".join(lines)
|
|
|
|
print >>f, "/**"
|
|
print >>f, " * 1st quadrant sin lookup table for {0:0.1f}kHz deviation".format(deviation_f/1000.0)
|
|
print >>f, " *"
|
|
print >>f, " * Length: {0}".format(length)
|
|
print >>f, " * Frequency Resolution: {0:0.3f} Hz".format(f_resolution)
|
|
print >>f, " */"
|
|
if defonly:
|
|
print >>f, "uint16_t sintable_{0}_{1}hz[{0}];".format(length, deviation_f)
|
|
else:
|
|
print >>f, "uint16_t sintable_{0}_{1}hz[] = {{".format(length, deviation_f)
|
|
print >>f, " "+string
|
|
print >>f, "};"
|
|
print >>f, ""
|
|
|
|
|
|
|
|
source = open('src/ax25_sintable.c','w')
|
|
header = open('inc/ax25_sintable.h','w')
|
|
|
|
file_header(source)
|
|
file_header(header)
|
|
|
|
print >>source, "#include \"samd20.h\""
|
|
print >>source, ""
|
|
|
|
print_sintable(source, 1500, False)
|
|
print_sintable(source, 2500, False)
|
|
|
|
|
|
print >>header, "#ifndef AX25_SINTABLE_H"
|
|
print >>header, "#define AX25_SINTABLE_H"
|
|
print >>header, ""
|
|
print >>header, ""
|
|
|
|
print >>header, "#include \"samd20.h\""
|
|
print >>header, ""
|
|
|
|
print >>header, "#define AX25_SINTABLE_ORDER {0:d}".format(int(math.log(length, 2)))
|
|
print >>header, "#define AX25_SINTABLE_LENGTH {0:d}".format(length)
|
|
print >>header, ""
|
|
print >>header, ""
|
|
|
|
print_sintable(header, 1500, True)
|
|
print_sintable(header, 2500, True)
|
|
|
|
print >>header, "#endif /* AX25_SINTABLE_H */"
|