bundles / scipy latest / scipy / signal / _filter_design / cheby2
function
scipy.signal._filter_design:cheby2
source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_filter_design.py:3668
Signature
def cheby2(N, rs, Wn, btype = lowpass, analog = False, output = ba, fs = None)Summary
Chebyshev type II digital and analog filter design.
Extended Summary
Design an Nth-order digital or analog Chebyshev type II filter and return the filter coefficients.
Parameters
N: intThe order of the filter.
rs: floatThe minimum attenuation required in the stop band. Specified in decibels, as a positive number.
Wn: array_likeA scalar or length-2 sequence giving the critical frequencies. For Type II filters, this is the point in the transition band at which the gain first reaches -
rs.For digital filters,
Wnare in the same units asfs. By default,fsis 2 half-cycles/sample, so these are normalized from 0 to 1, where 1 is the Nyquist frequency. (Wnis thus in half-cycles / sample.)For analog filters,
Wnis an angular frequency (e.g., rad/s).btype: {'lowpass', 'highpass', 'bandpass', 'bandstop'}, optionalThe type of filter. Default is 'lowpass'. Note that the following legacy aliases should be avoided in new implementations:
'band', 'pass', 'bp' for 'bandpass'
'l', 'low', 'lp' for 'lowpass'
'h', 'high', 'hp' for 'highpass'
'bs', 'bands', 'stop' for 'bandstop'
analog: bool, optionalWhen True, return an analog filter, otherwise a digital filter is returned.
output: {'ba', 'zpk', 'sos'}, optionalType of output: numerator/denominator ('ba'), pole-zero ('zpk'), or second-order sections ('sos'). Default is 'ba' for backwards compatibility, but 'sos' should be used for general-purpose filtering.
fs: float, optionalThe sampling frequency of the digital system.
Returns
b, a: ndarray, ndarrayNumerator (b) and denominator (a) polynomials of the IIR filter. Only returned if
output='ba'.z, p, k: ndarray, ndarray, floatZeros, poles, and system gain of the IIR filter transfer function. Only returned if
output='zpk'.sos: ndarraySecond-order sections representation of the IIR filter. Only returned if
output='sos'.
Notes
The Chebyshev type II filter maximizes the rate of cutoff between the frequency response's passband and stopband, at the expense of ripple in the stopband and increased ringing in the step response.
Type II filters do not roll off as fast as Type I (cheby1).
The 'sos' output parameter was added in 0.16.0.
The current behavior is for ndarray outputs to have 64 bit precision (float64 or complex128) regardless of the dtype of Wn but outputs may respect the dtype of Wn in a future version.
Examples
Design an analog filter and plot its frequency response, showing the critical points:from scipy import signal import matplotlib.pyplot as plt import numpy as np✓
b, a = signal.cheby2(4, 40, 100, 'low', analog=True) w, h = signal.freqs(b, a)✓
plt.semilogx(w, 20 * np.log10(abs(h))) plt.title('Chebyshev Type II frequency response (rs=40)') plt.xlabel('Frequency [rad/s]') plt.ylabel('Amplitude [dB]')✗
Text(0, 0.5, 'Amplitude [dB]')
plt.margins(0, 0.1) plt.grid(which='both', axis='both')✓
plt.axvline(100, color='green') # cutoff frequency plt.axhline(-40, color='green') # rs✗
<matplotlib.lines.Line2D object at 0x7f3f69733380>
plt.show()
✓
t = np.linspace(0, 1, 1000, False) # 1 second sig = np.sin(2*np.pi*10*t) + np.sin(2*np.pi*20*t) fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)✓
ax1.plot(t, sig) ax1.set_title('10 Hz and 20 Hz sinusoids') ax1.axis([0, 1, -2, 2])✗
(np.float64(0.0), np.float64(1.0), np.float64(-2.0), np.float64(2.0))Design a digital high-pass filter at 17 Hz to remove the 10 Hz tone, and apply it to the signal. (It's recommended to use second-order sections format when filtering, to avoid numerical error with transfer function (``ba``) format):
sos = signal.cheby2(12, 20, 17, 'hp', fs=1000, output='sos') filtered = signal.sosfilt(sos, sig)✓
ax2.plot(t, filtered) ax2.set_title('After 17 Hz high-pass filter') ax2.axis([0, 1, -2, 2]) ax2.set_xlabel('Time [s]')✗
Text(0.5, 0, 'Time [s]')
plt.show()
✓
See also
Aliases
scipy.signal.cheby2