pyfda.filter_widgets package¶
Submodules¶
pyfda.filter_widgets.bessel module¶
Design Bessel filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) format
This class is re-instantiated dynamically every time the filter design method is selected, reinitializing instance attributes.
- API version info:
- 1.0:
initial working release
- 1.1:
copy
A_PB->A_PB2andA_SB -> ``A_SB2for BS / BP designsmark private methods as private
- 1.2:
new API using fil_save (enable SOS features)
- 1.3:
new public methods
destruct_UIandconstruct_UI(no longer called by__init__)- 1.4:
module attribute
filter_classescontains class name and combo box name instead of class attributenameFRMTis now a class attribute
- 2.0:
Specify the parameters for each subwidget as tuples in a dict where the first element controls whether the widget is visible and / or enabled. This dict is now called
self.rt_dict. When present, the dictself.rt_dict_addis read and merged with the first one.- 2.1:
Remove empty methods
construct_UIanddestruct_UIand attributesself.wdgandself.hdl- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- class pyfda.filter_widgets.bessel.Bessel[source]¶
Bases:
objectDesign Bessel filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) format
- FRMT = 'sos'¶
- ft¶
filter type
- info¶
filter variants
- pyfda.filter_widgets.bessel.classes = {'Bessel': 'Bessel'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.butter module¶
Design Butterworth filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) or second-order sections (sos) format
Attention: This class is re-instantiated dynamically every time the filter design method is selected, calling its __init__ method.
- API version info:
1.0: initial working release 1.1: - copy A_PB -> A_PB2 and A_SB -> A_SB2 for BS / BP designs
mark private methods as private
1.2: new API using fil_save (enable SOS features when available) 1.3: new public methods destruct_UI + construct_UI (no longer called by __init__) 1.4: module attribute filter_classes contains class name and combo box name
instead of class attribute name FRMT is now a class attribute
- 2.0: Specify the parameters for each subwidget as tuples in a dict where the
first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
- 2.1: Remove empty methods construct_UI and destruct_UI and attributes
self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
pyfda.filter_widgets.cheby1 module¶
Design Chebyshev 1 filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zpk (zeros, poles, gain) or second-order sections (sos) format.
Attention: This class is re-instantiated dynamically every time the filter design method is selected, calling its __init__ method.
- API version info:
1.0: initial working release 1.1: - copy A_PB -> A_PB2 and A_SB -> A_SB2 for BS / BP designs
mark private methods as private
1.2: new API using fil_save (enable SOS features when available) 1.3: new public methods destruct_UI + construct_UI (no longer called by __init__) 1.4: module attribute filter_classes contains class name and combo box name
instead of class attribute name FRMT is now a class attribute
- 2.0: Specify the parameters for each subwidget as tuples in a dict where the
first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
- 2.1: Remove empty methods construct_UI and destruct_UI and attributes
self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- pyfda.filter_widgets.cheby1.classes = {'Cheby1': 'Chebyshev 1'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.cheby2 module¶
Design Chebyshev 2 filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) or second-order sections (sos) format.
Attention: This class is re-instantiated dynamically everytime the filter design method is selected, calling the __init__ method.
- API version info:
1.0: initial working release 1.1: - copy A_PB -> A_PB2 and A_SB -> A_SB2 for BS / BP designs
mark private methods as private
1.2: new API using fil_save (enable SOS features when available) 1.3: new public methods destruct_UI + construct_UI (no longer called by __init__) 1.4: module attribute filter_classes contains class name and combo box name
instead of class attribute name FRMT is now a class attribute
- 2.0: Specify the parameters for each subwidget as tuples in a dict where the
first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
- 2.1: Remove empty methods construct_UI anddestruct_UI and attributes
self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- pyfda.filter_widgets.cheby2.classes = {'Cheby2': 'Chebyshev 2'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.common module¶
Common settings and some helper functions for filter design
- pyfda.filter_widgets.common.remezord(freqs, amps, rips, fs=1, alg='ichige')[source]¶
Filter parameter selection for the Remez exchange algorithm.
Calculate the parameters required by the Remez exchange algorithm to construct a finite impulse response (FIR) filter that approximately meets the specified design.
- Parameters:
freqs (list) – A monotonic sequence of band edges specified in Hertz. All elements must be non-negative and less than 1/2 the sampling frequency as given by the fs parameter. The band edges “0” and “f_S / 2” do not have to be specified, hence 2 * number(amps) - 2 freqs are needed.
amps (list) – A sequence containing the amplitudes of the signal to be filtered over the various bands, e.g. 1 for the passband, 0 for the stopband and 0.42 for some intermediate band.
rips (list) – A list with the peak ripples (linear, not in dB!) for each band. For the stop band this is equivalent to the minimum attenuation.
fs (float) – Sampling frequency
alg (string) – Filter length approximation algorithm. May be either ‘herrmann’, ‘kaiser’ or ‘ichige’. Depending on the specifications, some of the algorithms may give better results than the others.
- Return type:
numtaps, bands, desired, weight – See help for the remez function.
Examples
We want to design a lowpass with the band edges of 40 resp. 50 Hz and a sampling frequency of 200 Hz, a passband peak ripple of 10% and a stop band ripple of 0.01 or 40 dB.
>>> (L, F, A, W) = remezord([40, 50], [1, 0], [0.1, 0.01], fs = 200)
- pyfda.filter_widgets.common.remlplen_herrmann(fp, fs, dp, ds)[source]¶
Determine the length of the low pass filter with passband frequency fp, stopband frequency fs, passband ripple dp, and stopband ripple ds. fp and fs must be normalized with respect to the sampling frequency. Note that the filter order is one less than the filter length.
Uses approximation algorithm described by Herrmann et al.:
O. Herrmann, L.R. Raviner, and D.S.K. Chan, Practical Design Rules for Optimum Finite Impulse Response Low-Pass Digital Filters, Bell Syst. Tech. Jour., 52(6):769-799, Jul./Aug. 1973.
- pyfda.filter_widgets.common.remlplen_ichige(fp, fs, dp, ds)[source]¶
Determine the length of the low pass filter with passband frequency fp, stopband frequency fs, passband ripple dp, and stopband ripple ds. fp and fs must be normalized with respect to the sampling frequency. Note that the filter order is one less than the filter length. Uses approximation algorithm described by Ichige et al.: K. Ichige, M. Iwaki, and R. Ishii, Accurate Estimation of Minimum Filter Length for Optimum FIR Digital Filters, IEEE Transactions on Circuits and Systems, 47(10):1008-1017, October 2000.
This seems tol give the most accurate results of the three approximations.
- pyfda.filter_widgets.common.remlplen_kaiser(fp, fs, dp, ds)[source]¶
Determine the length of the low pass filter with passband frequency fp, stopband frequency fs, passband ripple dp, and stopband ripple ds. fp and fs must be normalized with respect to the sampling frequency. Note that the filter order is one less than the filter length.
Uses approximation algorithm described by Kaiser:
J.F. Kaiser, Nonrecursive Digital Filter Design Using I_0-sinh Window function, Proc. IEEE Int. Symp. Circuits and Systems, 20-23, April 1974.
pyfda.filter_widgets.delay module¶
Design a simple delay for demonstrating the effect of latency and for debugging
Attention: This class is re-instantiated dynamically every time the filter design method is selected, calling the __init__ method.
- API version info:
1.0: initial working release
- class pyfda.filter_widgets.delay.Delay[source]¶
Bases:
QWidget- FRMT = 'zpk'¶
- construct_UI()[source]¶
Create additional subwidget(s) needed for filter design: These subwidgets are instantiated dynamically when needed in select_filter.py using the handle to the filter instance, fb.fil_inst.
- dict2filter_params()[source]¶
Reload parameter(s) from filter dictionary (if they exist) and set corresponding UI elements. dict2filter_params() is called upon initialization and when the filter is loaded from disk.
- 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.
- info = '\n**Delay widget**\n\nallows entering the number of **delays** :math:`N` :math:`T_S`. It is treated as a FIR filter,\nthe number of delays is directly translated to a number of poles (:math:`N > 0`) \nor zeros (:math:`N < 0`).\n\nObviously, there is no minimum design algorithm or no design algorithm at all :-)\n\n '¶
- sig_tx¶
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- pyfda.filter_widgets.delay.classes = {'Delay': 'Delay'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.ellip module¶
Design ellip-Filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) format
Attention: This class is re-instantiated dynamically every time the filter design method is selected, calling its __init__ method.
- API version info:
1.0: initial working release 1.1: - copy A_PB -> A_PB2 and A_SB -> A_SB2 for BS / BP designs
mark private methods as private
1.2: new API using fil_save (enable SOS features when available) 1.3: new public methods destruct_UI + construct_UI (no longer called by __init__) 1.4: module attribute filter_classes contains class name and combo box name
instead of class attribute name FRMT is now a class attribute
- 2.0: Specify the parameters for each subwidget as tuples in a dict where the
first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
- 2.1: Remove empty methods construct_UI and destruct_UI and attributes
self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- class pyfda.filter_widgets.ellip.Ellip[source]¶
Bases:
object- FRMT = 'sos'¶
- info = '\n**Elliptic filters**\n\n(also known as Cauer filters) have the steepest rate of transition between the\nfrequency response’s passband and stopband of all IIR filters. This comes\nat the expense of a constant ripple (equiripple) :math:`A_PB` and :math:`A_SB`\nin both pass and stop band. Ringing of the step response is increased in\ncomparison to Chebyshev filters.\n\nAs the passband ripple :math:`A_PB` approaches 0, the elliptical filter becomes\na Chebyshev type II filter. As the stopband ripple :math:`A_SB` approaches 0,\nit becomes a Chebyshev type I filter. As both approach 0, it becomes a Butterworth\nfilter (butter).\n\nFor the filter design, the order :math:`N`, minimum stopband attenuation\n:math:`A_SB` and the critical frequency / frequencies :math:`F_PB` where the\ngain first drops below the maximum passband ripple :math:`-A_PB` have to be specified.\n\nThe ``ellipord()`` helper routine calculates the minimum order :math:`N` and the\ncritical passband frequency :math:`F_C` from pass and stop band specifications.\n\n**Design routines:**\n\n``scipy.signal.ellip()``, ``scipy.signal.ellipord()``\n\n '¶
- pyfda.filter_widgets.ellip.classes = {'Ellip': 'Elliptic'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.ellip_zero module¶
pyfda.filter_widgets.equiripple module¶
Design equiripple-Filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in coefficients format (‘ba’)
Attention: This class is re-instantiated dynamically every time the filter design method is selected, calling the __init__ method.
- API version info:
1.0: initial working release 1.1: mark private methods as private 1.2: new API using fil_save 1.3: new public methods destruct_UI + construct_UI (no longer called by __init__) 1.4: module attribute filter_classes contains class name and combo box name
instead of class attribute name FRMT is now a class attribute
- 2.0: Specify the parameters for each subwidget as tuples in a dict where the
first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
2.1: Remove method destruct_UI and attributes self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- class pyfda.filter_widgets.equiripple.Equiripple(objectName='equiripple_inst')[source]¶
Bases:
QWidget- FRMT = 'ba'¶
- construct_UI()[source]¶
Create additional subwidget(s) needed for filter design: These subwidgets are instantiated dynamically when needed in select_filter.py using the handle to the filter instance, fb.fil_inst.
- dict2filter_params()[source]¶
Reload parameter(s) from filter dictionary (if they exist) and set corresponding UI elements. dict2filter_params() is called upon initialization and when the filter is loaded from disk.
- 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.
- info = "\n**Equiripple filters**\n\nhave the steepest rate of transition between the frequency response’s passband\nand stopband of all FIR filters. This comes at the expense of a constant ripple\n(equiripple) :math:`A_PB` and :math:`A_SB` in both pass and stop band.\n\nThe filter-coefficients are calculated in such a way that the transfer function\nminimizes the maximum error (**Minimax** design) between the desired gain and the\nrealized gain in the specified frequency bands using the **Remez** exchange algorithm.\nThe filter design algorithm is known as **Parks-McClellan** algorithm, in\nMatlab (R) it is called ``firpm``.\n\nManual filter order design requires specifying the frequency bands (:math:`F_PB`,\n:math:`f_SB` etc.), the filter order :math:`N` and weight factors :math:`W_PB`,\n:math:`W_SB` etc.) for individual bands.\n\nThe minimum order and the weight factors needed to fulfill the target specifications\nis estimated from frequency and amplitude specifications using Ichige's algorithm.\n\n**Design routines:**\n\n``scipy.signal.remez()``, ``pyfda_lib.remezord()``\n "¶
- sig_tx¶
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- pyfda.filter_widgets.equiripple.classes = {'Equiripple': 'Equiripple'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.firwin module¶
pyfda.filter_widgets.ma module¶
Design Moving-Average-Filters (LP, HP) with fixed order, return the filter design in coefficients format (‘ba’) or as poles/zeros (‘zpk’)
Attention: This class is re-instantiated dynamically everytime the filter design method is selected, calling the __init__ method.
- API version info:
1.0: initial working release 1.1: mark private methods as private 1.2: - new API using fil_save & fil_convert (allow multiple formats,
save ‘ba’ _and_ ‘zpk’ precisely)
include method _store_entries in _update_UI
1.3: new public methods destruct_UI + construct_UI (no longer called by __init__) 1.4: module attribute filter_classes contains class name and combo box name
instead of class attribute name
FRMT is now a class attribute
- 2.0: Specify the parameters for each subwidget as tuples in a dict where the
first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
2.1: Remove method destruct_UI and attributes self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- class pyfda.filter_widgets.ma.MA(objectName='ma_inst')[source]¶
Bases:
QWidget- FRMT = ('zpk', 'ba')¶
- calc_ma(fil_dict, rt='LP')[source]¶
Calculate coefficients and P/Z for moving average filter based on filter length L = N + 1 and number of cascaded stages and save the result in the filter dictionary.
- construct_UI()[source]¶
Create additional subwidget(s) needed for filter design: These subwidgets are instantiated dynamically when needed in select_filter.py using the handle to the filter instance, fb.fil_inst.
- dict2filter_params()[source]¶
Reload parameter(s) from filter dictionary (if they exist) and set corresponding UI elements. load_dict() is called upon initialization and when the filter is loaded from disk.
- 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.
- info = '\n**Moving average filters**\n\ncan only be specified via their length and the number of cascaded sections.\n\nThe minimum order to obtain a certain attenuation at a given frequency is\ncalculated via the si function.\n\nMoving average filters can be implemented very efficiently in hard- and software\nas they require no multiplications but only addition and subtractions. Probably\nonly the lowpass is really useful, as the other response types only filter out resp.\nleave components at ``f_S/4`` (bandstop resp. bandpass) resp. leave components\nnear ``f_S/2`` (highpass).\n\n**Design routines:**\n\n``ma.calc_ma()``\n '¶
- sig_tx¶
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- pyfda.filter_widgets.ma.classes = {'MA': 'Moving Average'}¶
display name
- Type:
Dict containing class name
pyfda.filter_widgets.manual module¶
Dummy / template file for manual filter designs by entering P/Z or b/a. Targets for LP, HP, BP, BS are provided. Returns nothing.
Attention: This class is re-instantiated dynamically everytime the filter design method is selected, calling the __init__ method.
- API version info:
- 1.0:
initial working release
- 1.1:
mark private methods as private
- 1.2:
new API using fil_save
- 1.3:
new public methods destruct_UI + construct_UI (no longer called by __init__)
- 1.4:
module attribute filter_classes contains class name and combo box name instead of class attribute name
- 2.0:
Specify the parameters for each subwidget as tuples in a dict where the first element controls whether the widget is visible and / or enabled. This dict is now called self.rt_dict. When present, the dict self.rt_dict_add is read and merged with the first one.
- 2.1:
Remove empty methods construct_UI and destruct_UI and attributes self.wdg and self.hdl
- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- pyfda.filter_widgets.manual.classes = {'Manual_FIR': 'Manual', 'Manual_IIR': 'Manual'}¶
display name
- Type:
Dict containing class name
Module contents¶
pyfda.filter_widgets.bessel¶
Design Bessel filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) format
This class is re-instantiated dynamically every time the filter design method is selected, reinitializing instance attributes.
- API version info:
- 1.0:
initial working release
- 1.1:
copy
A_PB->A_PB2andA_SB -> ``A_SB2for BS / BP designsmark private methods as private
- 1.2:
new API using fil_save (enable SOS features)
- 1.3:
new public methods
destruct_UIandconstruct_UI(no longer called by__init__)- 1.4:
module attribute
filter_classescontains class name and combo box name instead of class attributenameFRMTis now a class attribute
- 2.0:
Specify the parameters for each subwidget as tuples in a dict where the first element controls whether the widget is visible and / or enabled. This dict is now called
self.rt_dict. When present, the dictself.rt_dict_addis read and merged with the first one.- 2.1:
Remove empty methods
construct_UIanddestruct_UIand attributesself.wdgandself.hdl- 2.2:
Rename filter_classes -> classes, remove Py2 compatibility
- class pyfda.filter_widgets.bessel.Bessel[source]¶
Design Bessel filters (LP, HP, BP, BS) with fixed or minimum order, return the filter design in zeros, poles, gain (zpk) format
- ft¶
filter type
- info¶
filter variants
- pyfda.filter_widgets.bessel.classes = {'Bessel': 'Bessel'}¶
display name
- Type:
Dict containing class name