# This file is part of librefdatool. librefdatool is free software: you can # redistribute it and/or modify it under the terms of the GNU General Public # License as published by the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Copyright (C) 2013 Javier D. Garcia-Lasheras # import numpy as np from numpy import pi, log10 from scipy import signal from matplotlib import pyplot as plt from matplotlib import mlab class control: '''This class acts as control interface for filter parameters, such as structure realization, fixed-point approximation... Note (limited to FIR filters) ''' def __init__(self): '''This method provides initial filter parameters, executing each set command with default values when a new filter object is intantiated. ''' self.setBus() self.setScaling() self.setStructure() self.setModel() self.setTrace() self.setWorkspace() self.setToolchain() def setBus(self, busX=[1,15], busY=[1,15], busC=[1,15]): '''assign the different bus width: The value is given as a pair of natural numbers [p,q]: - p is the number of bits representing the integer part. - q is the number of bits representing the fractional part There are three different configurable buses: * busX: Input bit width * busY: Output bit width * busC: Coefficient bit width ''' self.busX = busX self.busY = busY self.busC = busC def setScaling(self, scalingX=16, scalingC=16): '''assign the different FP scaling factor: * scalingX: Input FP scaling factor (power of two exponent) * scalingC: Coefficient FP scaling factor (power of two exponent) ''' self.scalingX = scalingX self.scalingC = scalingC def setStructure(self, structure='firfilt'): '''assign filter structure or realization. Availability depends on python-to-HDL toolchain selection. TBD: only "firfilt" structure is available Future structures are type I/II direct forms, transposed... ''' self.structure = structure def setTrace(self, trace=False): '''assign activation state for VCD file tracer. If true, a *.vcd file will be generated by simulation process. This file can be analyzed with third party tools such as GTKWave. ''' self.trace = trace def setModel(self, model='myhdl'): '''assign HDL model, this is, the languaje for the toolchain. When not selected the native/default value, it relies on languaje conversion cogeneration & Icarus cosimulation. For myhdl toolchain, valid values are [myhdl, verilog, vhdl, vhdl2] TBD: this mechanism still has to be adapted for toolchain selection and including migen an other tools (maybe GHDL for cosimulation). ''' self.model = model def setWorkspace(self, workspace='.'): '''assign workspace folder for filter design and analysis. By default, the path is the one where the librefdatool is called. In this path, output files will be generated: * VHDL, Verilog converted files * VCD simulation files ''' self.workspace = workspace def setToolchain(self, toolchain='myhdl'): '''Choose python-to-HDL toolchain. By default, MyHDL is the toolchain in use. TBD: migen toolchain will be developed in the near future ''' self.toolchain = toolchain