Notch
openseize.filtering.iir.Notch
Bases: IIR
A callable second order digital Notch IIR filter.
This IIR achieves a -3 dB attenuation at the transition band edges centered on a single rejection frequency.
Attributes:
Name | Type | Description |
---|---|---|
|
see IIR Base for attributes |
Examples:
>>> # design a Notch filter around 60 Hz with a 8 Hz transition
>>> notch = Notch(fstop=60, width=8, fs=5000)
>>> # print the pass and stop bands
>>> notch.fpass
array([56., 64.])
>>> notch.fstop
array([60, 60])
Source code in openseize/filtering/iir.py
__init__(fstop, width, fs)
Initialize this Second Order Notch IIR.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fstop |
float
|
The stop frequency at which the filter reaches maximum attenuation in the same units as fs. |
required |
width |
float
|
The width of the trasition band centered on the stop frequency in the same units as fs. |
required |
fs |
float
|
The sampling rate of the digital system. |
required |
Source code in openseize/filtering/iir.py
Bases and Mixins
IIR Base
Bases: abc.ABC
, IIRViewer
, mixins.ViewInstance
Base class for infinite impulse response filters.
Attributes:
Name | Type | Description |
---|---|---|
fpass |
np.ndarray
|
1-D numpy array of start and stop edge frequencies of this filter's passband(s). |
fstop |
np.ndarray
|
1-D numpy array of start and stop edge frequencies of this filter's stopband(s). |
gpass |
float
|
Maximum ripple in the passband(s) in dB. |
gstop |
float
|
Minimum attenuation in the stopbands in dB. |
fs |
int
|
The sampling rate of the digital system. |
fmt |
A scipy filter coeffecient format specification. Must be one of:
|
|
nyq |
float
|
The nyquist rate of the digital system, fs/2. |
coeffs |
np.ndarray
|
A numpy array of filter coeffecients. |
Notes
This IIR ABC defines the common and expected methods of all concrete IIR filters in the openseize.filtering.iir module. Inheritors must override abstract methods and properties of this base to be instantiable.
btype()
property
Returns the string band type of this IIR filter.
ftype()
property
Returns the string name of this IIR filter.
__call__(data, chunksize, axis=-1, dephase=True, zi=None, **kwargs)
Apply this filter to an ndarray or producer of ndarrays.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[Producer, np.ndarray]
|
The data to be filtered. |
required |
chunksize |
int
|
The number of samples to hold in memory during filtering. |
required |
axis |
int
|
The axis of data along which to apply the filter. If data is multidimensional, the filter will be independently applied along all slices of axis. |
-1
|
dephase |
bool
|
Removes the delay introduced by this filter by running the filter in the forward and reverse directions of data's samples. |
True
|
zi |
Optional[np.ndarray]
|
Initial conditions for this filter. The shape depends on the fmt attribute. For 'sos' format, zi has shape nsections x (...,2,...) where (...,2,...) has the same shape as data but with 2 along axis. For more information see lfilter_zi and sosfilt_zi in scipy's signal module. This argument is ignored if dephase is True. |
None
|
kwargs |
Keyword arguments are passed to the producer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Union[Producer, np.ndarray]
|
Filtered result with type matching input 'data' parameter. |
Viewer Mixin
A collection of common plotting methods for both IIR, FIR and Parks-McClellan filters.
All filters in openseize have the ability to plot their impulse response and frequency response to a matplotlib figure called the Viewer. This mixin is inherited by specific IIR, FIR and ParksMcClellan Viewers in this file. Each of these specific viewers is inherited by the corresponding filter type (i.e. IIR, FIR, ParksMcClellan) in the openseize filtering module.
plot(size=(8, 6), gridalpha=0.3, worN=2048, rope=-100, axarr=None, show=True)
Plots the impulse and frequency response of this filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
Tuple[int, int]
|
tuple The figure size to display for the plots. Default is 8 x 6. |
(8, 6)
|
gridalpha |
float
|
float in [0, 1] The alpha transparency of each subplots grid. Default is 0.3 |
0.3
|
worN |
int
|
int The number of frequencies to compute the gain and phase responses over. Default is 2048 frequencies. |
2048
|
rope |
float
|
float For plotting, all values below this region of practical equivalence will be set to this value. Default is -100 dB. Any filter response smaller than this will be set to -100 for plotting. |
-100
|
axarr |
Optional[Sequence[plt.Axes]]
|
A Matplotlib axis array. An optional axis array to plot the impulse and frequency responses to. Default None means a new axis is created. |
None
|