Main Routines

pyfda.pyfda_dirs

pyfda.tree_builder

pyfda.pyfda_lib

pyfda.filter_factory

Dynamic parameters and settings are exchanged via the dictionaries in this file. Importing filterbroker.py runs the module once, defining all module variables which have a global scope like class variables and can be imported like

>>> import filter_factory as ff
>>> myfil = ff.fil_factory
class pyfda.filter_factory.FilterFactory[source]

This class implements a filter factory that (re)creates the globally accessible filter instance fil_inst from module path and class name, passed as strings.

call_fil_method(method, fil_dict, fc=None)[source]

Instantiate the filter design class passed as string fc with the globally accessible handle fil_inst. If fc = None, use the previously instantiated filter design class.

Next, call the design method passed as string method of the instantiated filter design class.

Parameters:
  • method (string) – The name of the design method to be called (e.g. ‘LPmin’)
  • fil_dict (dictionary) – A dictionary with all the filter specs that is passed to the actual filter design routine. This is usually a copy of fb.fil[0] The results of the filter design routine are written back to the same dict.
  • fc (string (optional, default: None)) – The name of the filter design class to be instantiated. When nothing is specified, the last filter selection is used.
Returns:

err_code

one of the following error codes:
-1:filter design operation has been cancelled by user
0:filter design method exists and is callable
16:passed method name is not a string
17:filter design method does not exist in class
18:filter design error containing “order is too high”
19:filter design error containing “failure to converge”
99:unknown error

Return type:

int

Examples

>>> call_fil_method("LPmin", fil[0], fc="cheby1")

The example first creates an instance of the filter class ‘cheby1’ and then performs the actual filter design by calling the method ‘LPmin’, passing the global filter dictionary fil[0] as the parameter.

create_fil_inst(fc, mod=None)[source]

Create an instance of the filter design class passed as a string fc from the module found in fb.filter_classes[fc]. This dictionary has been collected by tree_builder.py.

The instance can afterwards be globally referenced as fil_inst.

Parameters:
  • fc (str) – The name of the filter design class to be instantiated (e.g. ‘cheby1’ or ‘equiripple’)
  • mod (str (optional, default = None)) – Fully qualified name of the filter module. When not specified, it is read from the global dict fb.filter_classes[fc]['mod']
Returns:

err_code

one of the following error codes:
-1:filter design class was instantiated successfully
0:filter instance exists, no re-instantiation necessary
1:filter module not found by FilterTreeBuilder
2:filter module found by FilterTreeBuilder but could not be imported
3:filter class could not be instantiated
4:unknown error during instantiation

Return type:

int

Examples

>>> create_fil_instance('cheby1')
>>> fil_inst.LPmin(fil[0])

The example first creates an instance of the filter class ‘cheby1’ and then performs the actual filter design by calling the method ‘LPmin’, passing the global filter dictionary fil[0] as the parameter.

pyfda.filter_factory.fil_factory = <pyfda.filter_factory.FilterFactory object>

Class instance of FilterFactory that can be accessed in other modules

pyfda.filter_factory.fil_inst = None

Instance of current filter design class (e.g. “cheby1”), globally accessible

>>> import filter_factory as ff
>>> ff.fil_factory.create_fil_instance('cheby1') # create instance of dynamic class
>>> ff.fil_inst.LPmin(fil[0]) # design a filter

pyfda.filterbroker

Dynamic parameters and settings are exchanged via the dictionaries in this file. Importing filterbroker.py runs the module once, defining all module variables which have a global scope like class variables and can be imported like

>>> import filterbroker as fb
>>> myfil = fb.fil[0]

The entries in this file are only used as initial / default entries and to demonstrate the structure of the global dicts and lists. These initial values are also handy for module-level testing where some useful settings of the variables is required.

Notes

Alternative approaches for data persistence could be the packages shelve or pickleshare More info on data persistence and storing / accessing global variables:

pyfda.filterbroker.base_dir = ''

Project base directory

pyfda.filterbroker.clipboard = None

Handle to central clipboard instance

pyfda.filterbroker.design_filt_state = 'changed'

“ok”, “changed”, “error”, “failed”

Type:State of filter design
pyfda.filterbroker.filter_classes = {'Bessel': {'mod': 'pyfda.filter_designs.bessel', 'name': 'Bessel'}, 'Butter': {'mod': 'pyfda.filter_designs.butter', 'name': 'Butterworth'}, 'Cheby1': {'mod': 'pyfda.filter_designs.cheby1', 'name': 'Chebychev 1'}, 'Cheby2': {'mod': 'pyfda.filter_designs.cheby2', 'name': 'Chebychev 2'}, 'Ellip': {'mod': 'pyfda.filter_designs.ellip', 'name': 'Elliptic'}, 'EllipZeroPhz': {'mod': 'pyfda.filter_designs.ellip_zero', 'name': 'EllipZeroPhz'}, 'Equiripple': {'mod': 'pyfda.filter_designs.equiripple', 'name': 'Equiripple'}, 'Firwin': {'mod': 'pyfda.filter_designs.firwin', 'name': 'Windowed FIR'}, 'MA': {'mod': 'pyfda.filter_designs.ma', 'name': 'Moving Average'}, 'Manual_FIR': {'mod': 'pyfda.filter_designs.manual', 'name': 'Manual'}, 'Manual_IIR': {'mod': 'pyfda.filter_designs.manual', 'name': 'Manual'}}

The keys of this dictionary are the names of all found filter classes, the values are the name to be displayed e.g. in the comboboxes and the fully qualified name of the module containing the class.

pyfda.pyfda_io_lib