iir_design_helper¶
Basic IIR Bilinear Transform-Based Digital Filter Design Helper
Copyright (c) March 2017, Mark Wickert All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.
-
sk_dsp_comm.iir_design_helper.
IIR_bpf
(f_stop1, f_pass1, f_pass2, f_stop2, Ripple_pass, Atten_stop, fs=1.0, ftype='butter', status=True)[source]¶ Design an IIR bandpass filter using scipy.signal.iirdesign. The filter order is determined based on f_pass Hz, f_stop Hz, and the desired stopband attenuation d_stop in dB, all relative to a sampling rate of fs Hz.
Parameters: - f_stop1 : ndarray of the numerator coefficients
- f_pass : ndarray of the denominator coefficients
- Ripple_pass :
- Atten_stop :
- fs : sampling rate in Hz
- ftype : Analog prototype from ‘butter’ ‘cheby1’, ‘cheby2’,
‘ellip’, and ‘bessel’
Returns: - b : ndarray of the numerator coefficients
- a : ndarray of the denominator coefficients
- sos : 2D ndarray of second-order section coefficients
Examples
>>> fs = 48000 >>> f_pass = 8000 >>> f_stop = 5000 >>> b_but,a_but,sos_but = IIR_hpf(f_stop,f_pass,0.5,60,fs,'butter') >>> b_cheb1,a_cheb1,sos_cheb1 = IIR_hpf(f_stop,f_pass,0.5,60,fs,'cheby1') >>> b_cheb2,a_cheb2,sos_cheb2 = IIR_hpf(f_stop,f_pass,0.5,60,fs,'cheby2') >>> b_elli,a_elli,sos_elli = IIR_hpf(f_stop,f_pass,0.5,60,fs,'ellip')
Mark Wickert October 2016
-
sk_dsp_comm.iir_design_helper.
IIR_bsf
(f_pass1, f_stop1, f_stop2, f_pass2, Ripple_pass, Atten_stop, fs=1.0, ftype='butter', status=True)[source]¶ Design an IIR bandstop filter using scipy.signal.iirdesign. The filter order is determined based on f_pass Hz, f_stop Hz, and the desired stopband attenuation d_stop in dB, all relative to a sampling rate of fs Hz.
Mark Wickert October 2016
-
sk_dsp_comm.iir_design_helper.
IIR_hpf
(f_stop, f_pass, Ripple_pass, Atten_stop, fs=1.0, ftype='butter', status=True)[source]¶ Design an IIR highpass filter using scipy.signal.iirdesign. The filter order is determined based on f_pass Hz, f_stop Hz, and the desired stopband attenuation d_stop in dB, all relative to a sampling rate of fs Hz.
Parameters: - f_stop :
- f_pass :
- Ripple_pass :
- Atten_stop :
- fs : sampling rate in Hz
- ftype : Analog prototype from ‘butter’ ‘cheby1’, ‘cheby2’,
‘ellip’, and ‘bessel’
Returns: - b : ndarray of the numerator coefficients
- a : ndarray of the denominator coefficients
- sos : 2D ndarray of second-order section coefficients
Examples
>>> fs = 48000 >>> f_pass = 8000 >>> f_stop = 5000 >>> b_but,a_but,sos_but = IIR_hpf(f_stop,f_pass,0.5,60,fs,'butter') >>> b_cheb1,a_cheb1,sos_cheb1 = IIR_hpf(f_stop,f_pass,0.5,60,fs,'cheby1') >>> b_cheb2,a_cheb2,sos_cheb2 = IIR_hpf(f_stop,f_pass,0.5,60,fs,'cheby2') >>> b_elli,a_elli,sos_elli = IIR_hpf(f_stop,f_pass,0.5,60,fs,'ellip')
Mark Wickert October 2016
-
sk_dsp_comm.iir_design_helper.
IIR_lpf
(f_pass, f_stop, Ripple_pass, Atten_stop, fs=1.0, ftype='butter', status=True)[source]¶ Design an IIR lowpass filter using scipy.signal.iirdesign. The filter order is determined based on f_pass Hz, f_stop Hz, and the desired stopband attenuation d_stop in dB, all relative to a sampling rate of fs Hz.
Parameters: - f_pass : Passband critical frequency in Hz
- f_stop : Stopband critical frequency in Hz
- Ripple_pass : Filter gain in dB at f_pass
- Atten_stop : Filter attenuation in dB at f_stop
- fs : Sampling rate in Hz
- ftype : Analog prototype from ‘butter’ ‘cheby1’, ‘cheby2’,
‘ellip’, and ‘bessel’
Returns: - b : ndarray of the numerator coefficients
- a : ndarray of the denominator coefficients
- sos : 2D ndarray of second-order section coefficients
Notes
Additionally a text string telling the user the filter order is written to the console, e.g., IIR cheby1 order = 8.
Examples
>>> fs = 48000 >>> f_pass = 5000 >>> f_stop = 8000 >>> b_but,a_but,sos_but = IIR_lpf(f_pass,f_stop,0.5,60,fs,'butter') >>> b_cheb1,a_cheb1,sos_cheb1 = IIR_lpf(f_pass,f_stop,0.5,60,fs,'cheby1') >>> b_cheb2,a_cheb2,sos_cheb2 = IIR_lpf(f_pass,f_stop,0.5,60,fs,'cheby2') >>> b_elli,a_elli,sos_elli = IIR_lpf(f_pass,f_stop,0.5,60,fs,'ellip')
Mark Wickert October 2016
-
sk_dsp_comm.iir_design_helper.
freqz_cas
(sos, w)[source]¶ Cascade frequency response
Mark Wickert October 2016
-
sk_dsp_comm.iir_design_helper.
freqz_resp_cas_list
(sos, mode='dB', fs=1.0, Npts=1024, fsize=(6, 4))[source]¶ A method for displaying cascade digital filter form frequency response magnitude, phase, and group delay. A plot is produced using matplotlib
freq_resp(self,mode = ‘dB’,Npts = 1024)
A method for displaying the filter frequency response magnitude, phase, and group delay. A plot is produced using matplotlib
freqz_resp(b,a=[1],mode = ‘dB’,Npts = 1024,fsize=(6,4))
b = ndarray of numerator coefficients a = ndarray of denominator coefficents- mode = display mode: ‘dB’ magnitude, ‘phase’ in radians, or
- ‘groupdelay_s’ in samples and ‘groupdelay_t’ in sec, all versus frequency in Hz
Npts = number of points to plot; default is 1024
fsize = figure size; defult is (6,4) inches
Mark Wickert, January 2015
-
sk_dsp_comm.iir_design_helper.
freqz_resp_list
(b, a=array([1]), mode='dB', fs=1.0, Npts=1024, fsize=(6, 4))[source]¶ A method for displaying digital filter frequency response magnitude, phase, and group delay. A plot is produced using matplotlib
freq_resp(self,mode = ‘dB’,Npts = 1024)
A method for displaying the filter frequency response magnitude, phase, and group delay. A plot is produced using matplotlib
freqz_resp(b,a=[1],mode = ‘dB’,Npts = 1024,fsize=(6,4))
b = ndarray of numerator coefficients a = ndarray of denominator coefficents- mode = display mode: ‘dB’ magnitude, ‘phase’ in radians, or
- ‘groupdelay_s’ in samples and ‘groupdelay_t’ in sec, all versus frequency in Hz
Npts = number of points to plot; default is 1024
fsize = figure size; defult is (6,4) inches
Mark Wickert, January 2015
-
sk_dsp_comm.iir_design_helper.
sos_zplane
(sos, auto_scale=True, size=2, tol=0.001)[source]¶ Create an z-plane pole-zero plot.
Create an z-plane pole-zero plot using the numerator and denominator z-domain system function coefficient ndarrays b and a respectively. Assume descending powers of z.
Parameters: - sos : ndarray of the sos coefficients
- auto_scale : bool (default True)
- size : plot radius maximum when scale = False
Returns: - (M,N) : tuple of zero and pole counts + plot window
Notes
This function tries to identify repeated poles and zeros and will place the multiplicity number above and to the right of the pole or zero. The difficulty is setting the tolerance for this detection. Currently it is set at 1e-3 via the function signal.unique_roots.
Examples
>>> # Here the plot is generated using auto_scale >>> sos_zplane(sos) >>> # Here the plot is generated using manual scaling >>> sos_zplane(sos,False,1.5)