Kaiser
openseize.filtering.fir.Kaiser
Bases: FIR
A callable Type I FIR Filter using the parametric Kaiser window.
A parameterized window allows for Kaiser filters to be designed to meet the stricter of user supplied pass or stop band attenuation criteria. Given this increased flexibility compared to general cosine windows (Hamming, Hann etc), Kaiser filters are the recommended FIR filter design in Openseize.
Attributes:
Name | Type | Description |
---|---|---|
|
see FIR Base for attributes |
Examples:
>>> # design a low pass filter with a max ripple of 1 dB and minimum
... # attenuation of 40 dB
>>> kaiser = Kaiser(fpass=300, fstop=350, fs=5000, gpass=1,
... gstop=40)
>>> kaiser.btype
'lowpass'
>>> kaiser = Kaiser(fpass=600, fstop=400, fs=1800, gpass=0.5,
... gstop=40)
>>> rect.btype
'highpass'
>>> rect = Rectangular(fpass=[400, 1000], fstop=[200, 1200],
... fs=4000)
>>> rect.btype
'bandpass'
>>> rect = Rectangular(fpass=[200, 1200], fstop=[400, 1000],
... fs=5000)
>>> rect.btype
'bandstop'
References
- Ifeachor E.C. and Jervis, B.W. (2002). Digital Signal Processing: A Practical Approach. Prentice Hall
- Oppenheim, A.V. and Schafer, R.W. (2009) "Discrete-Time Signal Processing" 3rd Edition. Pearson.
Source code in openseize/filtering/fir.py
__init__(fpass, fstop, fs, gpass=1.0, gstop=40.0)
Initialize this Kaiser windowed FIR.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpass |
Union[float, Tuple[float, float]]
|
The pass band edge frequency in the same units as fs OR a 2-el sequence of edge frequencies that are monotonically increasing and in [0, fs/2]. |
required |
fstop |
Union[float, Tuple[float, float]]
|
The stop band edge frequency in the same units as fs OR a 2-el sequence of edge frequencies that are monotonically increasing and in [0, fs/2]. |
required |
fs |
int
|
The sampling rate of the digital system. |
required |
gpass |
float
|
The maximum allowable ripple in the pass band in dB. Default of 1.0 dB is ~ 11% amplitude ripple. |
1.0
|
gstop |
float
|
The minimum attenuation required in the stop band in dB. Default of 40 dB is a 99% amplitude attenuation. |
40.0
|
Source code in openseize/filtering/fir.py
numtaps()
property
Returns the number of taps needed to meet the stricter of the pass and stop band criteria.
Source code in openseize/filtering/fir.py
Bases and Mixins
FIR Base
Bases: abc.ABC
, mixins.ViewInstance
, FIRViewer
Base class for finite 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. |
nyq |
float
|
The nyquist rate of the digital system, fs/2. |
width |
float
|
The minimum transition width between the pass and stopbands. |
coeffs |
np.ndarray
|
A 1-D numpy array of filter coeffecients. |
Notes
This FIR ABC defines the common and expected methods of all concrete FIR filters in the openseize.filtering.fir module. Inheritors must override abstract methods & properties of this base to be instantiable.
btype()
property
Returns the string band type of this filter.
ftype()
property
Returns the string name of this FIR filter.
pass_attenuation()
property
Converts the max passband ripple, gpass, into a pass band attenuation in dB.
cutoff()
property
Returns an ndarray of the -6 dB points of each transition band.
__call__(data, chunksize, axis=-1, mode='same', **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
|
mode |
str
|
A numpy convolve mode; one of 'full', 'same', 'valid'.
|
'same'
|
kwargs |
Any valid keyword argument for 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
|