CHEBY2
The Chebyshev Type II filter, also known as the inverse Chebyshev filter, is designed to have a flat response in the passband and ripple in the stopband.
Compared to Type I, Type II filters have no ripple in the passband and a slower roll-off near the cutoff frequency, but they provide better attenuation further into the stopband for a given order.
Excel Usage
=CHEBY2(N, rs, Wn, btype, filter_output_form, analog, fs)
N(int, required): The order of the filter.rs(float, required): The minimum attenuation required in the stop band (dB).Wn(list[list], required): Critical frequency or frequencies.btype(str, optional, default: “lowpass”): The type of filter.filter_output_form(str, optional, default: “ba”): Type of output representation.analog(bool, optional, default: false): When True, return an analog filter.fs(float, optional, default: null): The sampling frequency of the digital system.
Returns (list[list]): Filter coefficients or representation as a 2D array.
Example 1: Low-pass (b, a)
Inputs:
| N | rs | Wn | btype |
|---|---|---|---|
| 2 | 40 | 0.1 | lowpass |
Excel formula:
=CHEBY2(2, 40, 0.1, "lowpass")
Expected output:
| Result | ||
|---|---|---|
| 0.0101759 | -0.0184072 | 0.0101759 |
| 1 | -1.93697 | 0.93892 |
Example 2: Band-stop (SOS)
Inputs:
| N | rs | Wn | btype | filter_output_form | |
|---|---|---|---|---|---|
| 2 | 20 | 0.2 | 0.4 | bandstop | sos |
Excel formula:
=CHEBY2(2, 20, {0.2,0.4}, "bandstop", "sos")
Expected output:
| Result | |||||
|---|---|---|---|---|---|
| 0.420673 | -0.343526 | 0.420673 | 1 | -0.00116017 | 0.344412 |
| 1 | -1.53157 | 1 | 1 | -1.4681 | 0.641703 |
Python Code
Show Code
import numpy as np
from scipy.signal import cheby2 as scipy_cheby2
def cheby2(N, rs, Wn, btype='lowpass', filter_output_form='ba', analog=False, fs=None):
"""
Chebyshev Type II digital and analog filter design (stopband ripple).
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.cheby2.html
This example function is provided as-is without any representation of accuracy.
Args:
N (int): The order of the filter.
rs (float): The minimum attenuation required in the stop band (dB).
Wn (list[list]): Critical frequency or frequencies.
btype (str, optional): The type of filter. Valid options: Lowpass, Highpass, Bandpass, Bandstop. Default is 'lowpass'.
filter_output_form (str, optional): Type of output representation. Valid options: Numerator/Denominator, Pole-Zero, Second-Order Sections. Default is 'ba'.
analog (bool, optional): When True, return an analog filter. Default is False.
fs (float, optional): The sampling frequency of the digital system. Default is None.
Returns:
list[list]: Filter coefficients or representation as a 2D array.
"""
try:
if isinstance(Wn, list):
wn_flat = [float(v) for row in Wn for v in row]
wn_val = wn_flat[0] if len(wn_flat) == 1 else wn_flat
else:
wn_val = float(Wn)
result = scipy_cheby2(
int(N),
float(rs),
wn_val,
btype=btype,
analog=bool(analog),
output=filter_output_form,
fs=float(fs) if fs is not None else None
)
if filter_output_form == 'ba':
b, a = result
max_len = max(len(b), len(a))
return [b.tolist() + [""] * (max_len - len(b)), a.tolist() + [""] * (max_len - len(a))]
elif filter_output_form == 'zpk':
z, p, k = result
max_len = max(len(z), len(p), 1)
return [z.tolist() + [""] * (max_len - len(z)), p.tolist() + [""] * (max_len - len(p)), [float(k)] + [""] * (max_len - 1)]
else: # sos
return result.tolist()
except Exception as e:
return f"Error: {str(e)}"Online Calculator
The order of the filter.
The minimum attenuation required in the stop band (dB).
Critical frequency or frequencies.
The type of filter.
Type of output representation.
When True, return an analog filter.
The sampling frequency of the digital system.