def make_twiddlefactors(pck, fn, dependencies, extraargs={}): # dependencies is not used fft_length = extraargs.get('N', None) width = extraargs.get('width', None) if fft_length is None: raise ValueError("N for twiddlefactors.v is not known.") if width is None: raise ValueError("width for twidlefactors.v is not known.") vs = [ cmath.exp(-i * 2j * cmath.pi / fft_length) for i in range(0, fft_length / 2) ] tfs = cs_to_dicts(vs, width, clean1=False) tf_dict = { 'N': fft_length, 'log_N': logceil(fft_length), 'width': width, 'tfs': tfs, } assert (fn == 'twiddlefactors.v.t') twiddlefactors_fn = 'twiddlefactors_{0}.v'.format(fft_length) in_fn = os.path.join(config.verilogdir, pck, fn) out_fn = os.path.join(config.builddir, pck, twiddlefactors_fn) out_dir = os.path.join(config.builddir, pck) if not os.path.exists(out_dir): os.makedirs(out_dir) format_template(in_fn, out_fn, tf_dict) return out_fn, {}
def make_twiddlefactors(pck, fn, dependencies, extraargs={}): # dependencies is not used fft_length = extraargs.get('N', None) width = extraargs.get('width', None) if fft_length is None: raise ValueError("N for twiddlefactors.v is not known.") if width is None: raise ValueError("width for twidlefactors.v is not known.") vs = [cmath.exp(-i*2j*cmath.pi/fft_length) for i in range(0, fft_length/2)] tfs = cs_to_dicts(vs, width, clean1=False) tf_dict = { 'N': fft_length, 'log_N': logceil(fft_length), 'width': width, 'tfs': tfs, } assert(fn == 'twiddlefactors.v.t') twiddlefactors_fn = 'twiddlefactors_{0}.v'.format(fft_length) in_fn = os.path.join(config.verilogdir, pck, fn) out_fn = os.path.join(config.builddir, pck, twiddlefactors_fn) out_dir = os.path.join(config.builddir, pck) if not os.path.exists(out_dir): os.makedirs(out_dir) format_template(in_fn, out_fn, tf_dict) return out_fn, {}
def generate_dit_files(fft_length, tf_width): """ Generate the fft files to perform an fft. Args: fft_length: Length of the FFT. tf_width: Number of bits in each real number of each twiddle factor. """ get_builddir() inputfiles = generate_math_files() inputfiles.append(copyfile('fft', 'butterfly.v')) log_fft_length = math.log(fft_length) / math.log(2) if log_fft_length != int(log_fft_length): raise ValueError("fft_length must be a power of two") log_fft_length = int(log_fft_length) # Generate the dit.v file dit_fn = 'dit_{0}'.format(fft_length) inputfiles.append( format_template('fft', 'dit.v.t', dit_fn, {'N': fft_length})) # Generate twiddle factor file. tf_fn = 'twiddlefactors_{0}'.format(fft_length) vs = [ cmath.exp(-i * 2j * cmath.pi / fft_length) for i in range(0, fft_length / 2) ] tfs = cs_to_dicts(vs, tf_width * 2, clean1=True) tf_dict = { 'N': fft_length, 'log_N': log_fft_length, 'tf_width': tf_width, 'tfs': tfs, } inputfiles.append( format_template('fft', 'twiddlefactors.v.t', tf_fn, tf_dict)) return inputfiles
def generate_dit_files(fft_length, tf_width): """ Generate the fft files to perform an fft. Args: fft_length: Length of the FFT. tf_width: Number of bits in each real number of each twiddle factor. """ get_builddir() inputfiles = generate_math_files() inputfiles.append(copyfile('fft', 'butterfly.v')) log_fft_length = math.log(fft_length)/math.log(2) if log_fft_length != int(log_fft_length): raise ValueError("fft_length must be a power of two") log_fft_length = int(log_fft_length) # Generate the dit.v file dit_fn = 'dit_{0}'.format(fft_length) inputfiles.append( format_template('fft', 'dit.v.t', dit_fn, {'N': fft_length})) # Generate twiddle factor file. tf_fn = 'twiddlefactors_{0}'.format(fft_length) vs = [cmath.exp(-i*2j*cmath.pi/fft_length) for i in range(0, fft_length/2)] tfs = cs_to_dicts(vs, tf_width*2, clean1=True) tf_dict = { 'N': fft_length, 'log_N': log_fft_length, 'tf_width': tf_width, 'tfs': tfs, } inputfiles.append( format_template('fft', 'twiddlefactors.v.t', tf_fn, tf_dict)) return inputfiles