3 # Copyright 2004 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
31 def gen_approx_table (f, nentries, min_x, max_x):
32 """return a list of nentries containing tuples of the form:
33 (m, c, abs_error). min_x and max_x specify the domain
37 incx = float (max_x - min_x) / nentries
38 for i in range (nentries):
39 a = (i * incx) + min_x
40 b = ((i + 1) * incx) + min_x
42 c = (3*a+b)*(f(a)-f(b))/(4*(b-a)) + (f((a+b)/2) + f(a))/2
43 abs_error = c+m*a-f(a)
44 r.append ((m, c, abs_error))
48 return math.sin (x * math.pi / 2**31)
50 def gen_sine_table ():
58 t = gen_approx_table (scaled_sine, nentries, min_x, max_x)
62 max_error = max (max_error, abs (e[2]))
64 # sys.stdout.write ('static const int WORDBITS = 32;\n')
65 # sys.stdout.write ('static const int NBITS = %d;\n' % (nbits,))
67 sys.stdout.write (' // max_error = %22.15e\n' % (max_error,))
69 # sys.stdout.write ('static const double sine_table[%d][2] = {\n'% (nentries,))
72 sys.stdout.write (' { %22.15e, %22.15e },\n' % (2 * e[0], e[1]))
74 # sys.stdout.write ('};\n')
76 if __name__ == '__main__':