diff options
author | Artem Pisarenko <artem.k.pisarenko@gmail.com> | 2021-01-17 00:25:21 +0600 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2021-01-17 00:07:12 +0100 |
commit | 3de68c1c88f72d32eccdd5ff0ceb7d52b53b5d4d (patch) | |
tree | d6572f257fb28bd5465e30f680be579c0037a718 /gnuradio-runtime/lib/math | |
parent | c9b01b8409b5fcfa12154898bfedc45fed7f5354 (diff) |
runtime: simplify math fxpt sine/cosine calculation
Algorithm improved in order to eliminate getting output values
outside of range [-1.0, 1.0)
Fixes #2993
Signed-off-by: Artem Pisarenko <artem.k.pisarenko@gmail.com>
Diffstat (limited to 'gnuradio-runtime/lib/math')
-rw-r--r-- | gnuradio-runtime/lib/math/gen_sine_table.py | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/gnuradio-runtime/lib/math/gen_sine_table.py b/gnuradio-runtime/lib/math/gen_sine_table.py index b84f9b2f3e..ae31b6b81a 100644 --- a/gnuradio-runtime/lib/math/gen_sine_table.py +++ b/gnuradio-runtime/lib/math/gen_sine_table.py @@ -11,14 +11,9 @@ import math import sys -def wrap (x): - if x >= 2**31: - return x - 2**32 - return x - def gen_approx_table (f, nentries, min_x, max_x): """return a list of nentries containing tuples of the form: - (m, c, abs_error). min_x and max_x specify the domain + (m, c). min_x and max_x specify the domain of the table. """ r = [] @@ -27,9 +22,8 @@ def gen_approx_table (f, nentries, min_x, max_x): a = (i * incx) + min_x b = ((i + 1) * incx) + min_x m = (f(b)-f(a)) / (b-a) - c = (3.0*a+b)*(f(a)-f(b))/(4.0*(b-a)) + (f((a+b)/2.0) + f(a))/2.0 - abs_error = c+m*a-f(a) - r.append ((m, c, abs_error)) + c = f(a) + r.append ((m, c)) return r def scaled_sine (x): @@ -45,19 +39,13 @@ def gen_sine_table (): max_x = 2**32-1 t = gen_approx_table (scaled_sine, nentries, min_x, max_x) - max_error = 0 - for e in t: - max_error = max (max_error, abs (e[2])) - # sys.stdout.write ('static const int WORDBITS = 32;\n') # sys.stdout.write ('static const int NBITS = %d;\n' % (nbits,)) - sys.stdout.write (' // max_error = %22.15e\n' % (max_error,)) - # sys.stdout.write ('static const double sine_table[%d][2] = {\n'% (nentries,)) for e in t: - sys.stdout.write (' { %22.15e, %22.15e },\n' % (2.0 * e[0], e[1])) + sys.stdout.write (' { %22.15e, %22.15e },\n' % (e[0], e[1])) # sys.stdout.write ('};\n') |