Package fixpoint_widgets

This package contains widgets and fixpoint descriptions for simulating filter designs with fixpoint arithmetics and for converting filter designs to Verilog using the migen library. These Verilog netlists can be synthesized e.g. on an FPGA.

Hardware implementations for discrete-time filters usually imply fixpoint arithmetics but this could change in the future as floating point arithmetics can be implemented on FPGAs using dedicated floating point units (FPUs).

Filter topologies are defined in the corresponding classes and can be implemented in hardware. The filter topologies use the order and the coefficients that have been determined by a filter design algorithm from the pyfda.filter_widgets package for a target filter specification (usually in the frequency domain). Filter coefficients are quantized according to the settings in the fixpoint widget.

Each fixpoint module / class contains a widget that is constructed using helper classes from fixpoint_widgets.fixpoint_helpers. The widgets allow entering fixpoint specifications like word lengths and formats for input, output and internal structures (like an accumulator) for each class. It also contains a reference to a picture showing the filter topology.

The configuration file pyfda.conf lists which fixpoint classes (e.g. FIR_DF and IIR_DF1) can be used with which filter design algorithm. tree_builder parses this file and writes all fixpoint modules into the list fb.fixpoint_widgets_list.

The widgets are selected and instantiated in the widget input_widgets.input_fixpoint_specs.

The input widget pyfda.input_widgets.input_fixpoint_specs constructs a combo box from this list with references to all successfully imported fixpoint modules. The currently selected fixpoint widget (e.g. FIR_DF) is imported from Package fixpoint_widgets together with the referenced picture.

First, a filter widget is instantiated as self.fx_filt_ui (after the previous one has been destroyed).

Next, fx_filt_ui.construct_fixp_filter() constructs an instance fixp_filter of a fixpoint filter class (of e.g. pyfda.fixpoint_widgets.fir_df).

The widget’s methods

  • response = fx_filt_ui.fx_filt.run_sim(stimulus)

  • fx_filt_ui.fx_filt.to_verilog()

are used for bit-true simulations and for generating Verilog code for the filter.

input_widgets.input_fixpoint_specs

A fixpoint filter for a given filter design is selected in this widget

Widget for simulating fixpoint filters and generating Verilog Code

class pyfda.input_widgets.input_fixpoint_specs.Input_Fixpoint_Specs(parent=None, objectName='input_fixpoint_spec_inst')[source]

Create the widget that holds the dynamically loaded fixpoint filter UI

dict2ui()[source]

Called during __init__() and from process_sig_rx().

Update UI from fb.fil[0][‘fx_sim’], fb.fil[0][‘qfrmt’] and the fx filter dict fb.fil[0][‘fxq’]. This affects the visibility and the fx settings of input, output and dyn. filter widget via their dict2ui() methods. The setting of the self.cmb_qfrmt combobox influencing float / fixpoint number format is updated as well.

embed_fixp_img(img_file: str) QPixmap[source]

Embed img_file in png format as self.img_fixp

Parameters:

img_file (str) – path and file name to image file

Returns:

self.img_fixp – pixmap containing the passed img_file

Return type:

QPixmap object

emit(dict_sig: dict = {}, sig_name: str = 'sig_tx') None

Emit a signal self.<sig_name> (defined as a class attribute) with a dict dict_sig using Qt’s emit().

  • Add the keys ‘id’ and ‘class’ with id resp. class name of the calling instance if not contained in the dict

  • If key ‘ttl’ is in the dict and its value is less than one, terminate the signal. Otherwise, reduce the value by one.

  • If the sender has passed an objectName, add it with the key “sender_name” to the dict.

exportHDL()[source]

Synthesize HDL description of filter

fx_filt_init()[source]

Wrapper around self.fx_filt_ui.init_filter() to catch errors. Initialize fix-point filter, reset registers and overflow counters

TODO: - Update the fxqc_dict containing all quantization information

Returns:

error – 0 for sucessful fx widget construction, -1 for error

Return type:

int

fx_sim_calc_response(dict_sig) None[source]
  • Read fixpoint stimulus from dict_sig in integer format

  • Pass it to the fixpoint filter which calculates the fixpoint response

  • Store the result in fb.fx_results and return. In case of an error, fb.fx_results == None

Return type:

None

load_fx_filter() None[source]

A new filter has been loaded, create fixpoint filter from scratch.

(Re-)Read list of available fixpoint filters for a given filter class every time a new filter has been designed or loaded.

Then try to import the fixpoint designs in the list and populate the fixpoint implementation combo box self.cmb_fx_wdg with successfull imports.

process_sig_rx(dict_sig: dict = None) None[source]

Process signals coming in via sig_rx from other widgets.

Trigger fx simulation:

  1. fx_sim’: ‘init’: Start fixpoint simulation by sending ‘fx_sim’:’start_fx_response_calculation’

  2. Store fixpoint response in fb.fx_result and return to initiating routine

process_sig_rx_local(dict_sig: dict = None) None[source]

Process signals coming in from input and output quantizer subwidget and emit {‘fx_sim’: ‘specs_changed’} in the end.

qfrmt2ui()[source]

Triggered by by a change of index of the combo box self.cmb_qfrmt.

  • Update UI (fixpoint format, visibility of fixpoint widgets) from combobox self.cmb_qfrmt to fb.fil[0][‘fx_sim’] and fb.fil[0][‘qfrmt’].

  • Update fixpoint widget settings via self.dict2ui()

  • Emit {‘fx_sim’: ‘specs_changed’}.

resize_img() None[source]

Triggered when self (the widget) is selected or resized. The method resizes the image inside QLabel to completely fill the label while keeping the aspect ratio.

The parent InputTabWidget defines the available width (minus some offset due to margins etc.), unfortunately self.width() cannot be used as a measure as it expands with the parent but doesn’t shrink.

pyfda.input_widgets.input_fixpoint_specs.classes = {'Input_Fixpoint_Specs': 'Fixpoint'}

display name

Type:

Dict with class name

pyfda.fixpoint_widgets.fir_df