Package plot_widgets

Package providing widgets for plotting various time and frequency dependent filter properties

plot_tab_widgets

Create a tabbed widget for all plot subwidgets in the list fb.plot_widgets_list. This list is compiled at startup in pyfda.tree_builder.Tree_Builder, it is kept as a module variable in pyfda.filterbroker.

class pyfda.plot_widgets.plot_tab_widgets.PlotTabWidgets(parent=None, objectName='plot_tab_widgets_inst')[source]
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.

eventFilter(source, event)[source]

Filter all events generated by the QTabWidget. Source and type of all events generated by monitored objects are passed to this eventFilter, evaluated and passed on to the next hierarchy level.

This filter stops and restarts a one-shot timer for every resize event. When the timer generates a timeout after 500 ms, current_tab_redraw() is called by the timer.

log_rx(dict_sig=None)[source]

Enable self.sig_rx.connect(self.log_rx) above for debugging.

plot_hf

The Plot_Hf class constructs the widget to plot the magnitude frequency response |H(f)| of the filter either in linear or logarithmic scale. Optionally, the magnitude specifications and the phase can be overlayed.

class pyfda.plot_widgets.plot_hf.Plot_Hf[source]

Widget for plotting |H(f)|, frequency specs and the phase

align_y_axes(ax1, ax2)[source]

Sets tick marks of twinx axes to line up with total number of ax1 tick marks

calc_hf()[source]

(Re-)Calculate the complex frequency response H_cmplx(W) (complex) for W = 0 … 2 pi:

draw()[source]

Re-calculate |H(f)| and draw the figure

draw_inset()[source]

Construct / destruct second axes for an inset second plot

draw_phase(ax)[source]

Draw phase on second y-axis in the axes system passed as the argument

init_axes()[source]

Initialize and clear the axes (this is run only once)

plot_spec_limits(ax)[source]

Plot the specifications limits (F_SB, A_SB, …) as hatched areas with borders.

process_sig_rx(dict_sig=None)[source]

Process signals coming from the navigation toolbar and from sig_rx

redraw()[source]

Redraw the canvas when e.g. the canvas size has changed

update_view()[source]

Draw the figure with new limits, scale etc without recalculating H(f)

pyfda.plot_widgets.plot_hf.classes = {'Plot_Hf': '|H(f)|'}

display name

Type:

Dict containing class name

plot_phi

Widget for plotting phase frequency response phi(f)

class pyfda.plot_widgets.plot_phi.Plot_Phi[source]
calc_resp()[source]

(Re-)Calculate the complex frequency response H(f)

draw()[source]

Main entry point: Re-calculate |H(f)| and draw the figure

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.

init_axes()[source]

Initialize and clear the axes - this is only called once

process_sig_rx(dict_sig=None)[source]

Process signals coming from the navigation toolbar and from sig_rx

redraw()[source]

Redraw the canvas when e.g. the canvas size has changed

unit_changed()[source]

Unit for phase display has been changed, emit a ‘view_changed’ signal and continue with drawing.

update_view()[source]

Draw the figure with new limits, scale etc without recalculating H(f)

pyfda.plot_widgets.plot_phi.classes = {'Plot_Phi': 'φ(f)'}

display name

Type:

Dict containing class name

plot_tau_g

Widget for plotting the group delay

class pyfda.plot_widgets.plot_tau_g.Plot_tau_g[source]

Widget for plotting the group delay

calc_tau_g()[source]

(Re-)Calculate the complex frequency response H(f)

init_axes()[source]

Initialize the axes and set some stuff that is not cleared by ax.clear() later on.

process_sig_rx(dict_sig=None)[source]

Process signals coming from the navigation toolbar and from sig_rx

redraw()[source]

Redraw the canvas when e.g. the canvas size has changed

update_view()[source]

Draw the figure with new limits, scale etc without recalculating H(f)

plot_pz

Widget for plotting poles and zeros

class pyfda.plot_widgets.plot_pz.Plot_PZ[source]
draw_Hf(r=2, Hf_visible=True)[source]

Draw the magnitude frequency response around the UC

draw_pz()[source]

(re)draw P/Z plot

init_axes()[source]

Initialize and clear the axes (this is only run once)

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

Process signals coming from the navigation toolbar and from sig_rx

redraw()[source]

Redraw the canvas when e.g. the canvas size has changed

update_view()[source]

Draw the figure with new limits, scale etcs without recalculating H(f) – not yet implemented, just use draw() for the moment

zplane(b=None, a=1, z=None, p=None, k=1, pn_eps=0.001, analog=False, plt_ax=None, plt_poles=True, style='equal', anaCircleRad=0, lw=2, mps=10, mzs=10, mpc='r', mzc='b', plabel='', zlabel='')[source]

Plot the poles and zeros in the complex z-plane either from the coefficients (b,`a) of a discrete transfer function `H`(`z) (zpk = False) or directly from the zeros and poles (z,p) (zpk = True).

When only b is given, an FIR filter with all poles at the origin is assumed.

Parameters:
  • b (array_like) – Numerator coefficients (transversal part of filter) When b is not None, poles and zeros are determined from the coefficients b and a

  • a (array_like (optional, default = 1 for FIR-filter)) – Denominator coefficients (recursive part of filter)

  • z (array_like, default = None) – Zeros When b is None, poles and zeros are taken directly from z and p

  • p (array_like, default = None) – Poles

  • analog (boolean (default: False)) – When True, create a P/Z plot suitable for the s-plane, i.e. suppress the unit circle (unless anaCircleRad > 0) and scale the plot for a good display of all poles and zeros.

  • pn_eps (float (default : 1e-2)) – Tolerance for separating close poles or zeros

  • plt_ax (handle to axes for plotting (default: None)) – When no axes is specified, the current axes is determined via plt.gca()

  • plt_poles (Boolean (default : True)) – Plot poles. This can be used to suppress poles for FIR systems where all poles are at the origin.

  • style (string (default: 'scaled')) – Style of the plot, for style == ‘scaled’ make scale of x- and y- axis equal, style == ‘equal’ forces x- and y-axes to be equal. This is passed as an argument to the matplotlib ax.axis(style)

  • mps (integer (default: 10)) – Size for pole marker

  • mzs (integer (default: 10)) – Size for zero marker

  • mpc (char (default: 'r')) – Pole marker colour

  • mzc (char (default: 'b')) – Zero marker colour

  • lw (integer (default: 2)) – Linewidth for unit circle

  • plabel (string (default: '')) – This string is passed to the plot command for poles and zeros and can be displayed by legend()

  • zlabel (string (default: '')) – This string is passed to the plot command for poles and zeros and can be displayed by legend()

Returns:

z, p, k

Return type:

ndarray

Notes

pyfda.plot_widgets.plot_pz.classes = {'Plot_PZ': 'P / Z'}

display name

Type:

Dict containing class name

plot_impz

Widget for plotting impulse and general transient responses

class pyfda.plot_widgets.plot_impz.Plot_Impz(objectName='plot_impz_inst')[source]

Construct a widget for plotting impulse and general transient responses

calc_auto(autorun: bool = None) None[source]

Triggered when checkbox “Autorun” is clicked or specs have been edited, requiring a recalculation.

When Autorun has been pushed (but_auto_run.isChecked() == True) and calculation is required, automatically run impz_init().

calc_fft()[source]

(Re-)calculate FFTs of stimulus self.X, quantized stimulus self.X_q and response self.Y using the window function from self.ui.win_dict[‘win’].

draw(arg=None)[source]

(Re-)draw the figure without recalculation. When triggered by a signal- slot connection from a button, combobox etc., arg is a boolean or an integer representing the state of the widget. In this case, needs_redraw is set to True.

draw_data(plt_style: str, ax: object, x: ndarray, y: ndarray, bottom: float = 0, label: str = '', plt_fmt: dict = {}, mkr_fmt: dict = {}, **args)[source]

Plot x, y data (numpy arrays with equal length) in a plot style defined by plt_style.

Parameters:
  • plt_style (str) – one of “line”, “stem”, “steps”, “dots”

  • ax (matplotlib axis) – Handle to the axis where signal is to be plotted

  • x (array-like) – x-axis: time or frequency data

  • y (array-like) – y-data

  • bottom (float) – Bottom line y-coordinate for stem plot. The default is 0.

  • label (str) – Plot label

  • plt_fmt (dict) – Line styles (color, linewidth etc.) for plotting (default: None).

  • mkr_fmt (dict) – Marker styles

  • args (dict) – additional keys and values. As they might not be compatible with every plot style, they have to be added individually

Returns:

handle – This provides a handle to the properties of line and marker (optionally) which are displayed by legend

Return type:

A lines.Line2D() objects or tuple with two of them

draw_freq()[source]

(Re-)draw the frequency domain mplwidget

draw_time(N_start=0, N_end=0)[source]

(Re-)draw the time domain mplwidget

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.

file_io() None[source]

Check status of file_io widget:

  • if no file is loaded, do nothing and return 0, disable cmb_file_io and the option to transfer the number of samples to N

  • else map the file data to self.stim_wdg.x_file to make it accessible

    from the stimulus widget. If cmb_file_io == `use, disable the widget to modify stimuli

impz()[source]

Calculate floating point / fixpoint response and redraw it

Triggered by:

  • self.impz_init() (floating point)

  • Fixpoint widget, requesting “start_fx_response_calculation”

    via process_rx_signal() (fixpoint filter)

impz_finish()[source]

Do some housekeeping, resetting and drawing when self.impz() has finished:

  • Calculate step error if selected

  • Check for complex stimulus or response

  • Calculate simulation time

  • Draw the signals

  • Reset Run Icon to normal state, reset needs_calc flag

  • Update File IO save combo boxes

impz_init(arg=None) None[source]

Initialize transient simulation.

Parameters:

arg (bool or None)

Return type:

None

Triggered by:

  • _construct_UI() during initialization

  • Pressing “Run” button, passing button state as a bool

  • self.ui.cmb_sim_select when changing between fixpoint and float mode

  • self.calc_auto() when activating “Autorun”

  • Autorun (when something relevant in the UI has been updated)

  • signal {'fx_sim' : 'specs_changed'}

The following tasks are performed:

  • Enable energy scaling for impulse stimuli when requirements are met

  • check for and enable fixpoint settings

  • resize stimulus widget

  • when triggered by but_run or when Auto`== pressed and `self.needs_calc == True, continue with calculating stimulus / response

  • When in fixpoint mode, initialize quantized stimulus x_q and input quantizer and emit {‘fx_sim’:’init’}

process_sig_rx(dict_sig=None)[source]

Process signals coming from - the navigation toolbars (time and freq.) - local widgets (impz_ui) and - plot_tab_widgets() (global signals)

process_sig_rx_f(dict_sig=None)[source]

Special treatment for signals coming from FREQ plot navigation toolbar

process_sig_rx_t(dict_sig=None)[source]

Special treatment for signals coming from TIME plot navigation toolbar

redraw()[source]

Redraw the currently visible canvas (but not the plot!) when e.g. the canvas size has changed

resize_stim_tab_widget()[source]

Resize active tab of stimulus Tab widget to fit the height of the contained widget. This is triggered by: - initialization in _construct_UI() - changed tab in the stimulus tab widget (signal-slot) - an ‘ui-changed’ - signal (process_signal_rx())

set_N_to_file_len() None[source]

Check status of file_io widget: - if no file is loaded, do nothing. This shouldn’t happen (check to be sure …) - else set N_end = len(file_data) in the UI

set_ui_level(ui_level)[source]

Sync time and frequency subwidget and set their ui display level

toggle_fx_settings(arg=None)[source]

arg can be the following arguments, triggered by:

  • arg None: from __init__(), impz_init() or process_sig_rx() when {dict_sig[‘fx_sim’] == ‘specs_changed’} was received. Read the state of fb.fil[0][‘fx_sim’] and update combobox correspondingly

  • arg int 0 or 1 from self.ui.cmb_sim_select when index was changed (signal-slot-connection), update fb.fil[0][‘fx_sim’] correspondingly, fire signal {‘fx_sim’: ‘specs_changed’} and start simulation

  • arg “fixpoint” or “float” from a direct call with (not used currently), update ui and combobox self.ui.cmb_sim_select correspondingly

When fixpoint simulation is selected, all corresponding widgets are made visible and fb.fil[0][‘fx_sim’] is set to True.

If fb.fil[0][‘fx_sim’] has been changed since last time, self.needs_calc is set to True and the run button is set to ‘changed’.

toggle_stim_options()[source]

Toggle visibility of stimulus options, depending on the state of the “Stimuli” button

zoom_home()[source]

Zoom to home settings

pyfda.plot_widgets.plot_impz.classes = {'Plot_Impz': 'y[n] / Y(f)'}

display name

Type:

Dict containing class name

plot_3d

Widget for plotting |H(z)| in 3D

class pyfda.plot_widgets.plot_3d.Plot_3D[source]

Class for various 3D-plots: - lin / log line plot of H(f) - lin / log surf plot of H(z) - optional display of poles / zeros

draw()[source]

Main drawing entry point: perform the actual plot

draw_3d()[source]

Draw various 3D plots

init_axes()[source]

Initialize and clear the axes to get rid of colorbar The azimuth / elevation / distance settings of the camera are restored after clearing the axes. See http://stackoverflow.com/questions/4575588/matplotlib-3d-plot-with-pyqt4-in-qtabwidget-mplwidget

process_sig_rx(dict_sig=None)[source]

Process signals coming from the navigation toolbar and from sig_rx

redraw()[source]

Redraw the canvas when e.g. the canvas size has changed

pyfda.plot_widgets.plot_3d.classes = {'Plot_3D': '3D'}

display name

Type:

Dict containing class name