cheby2
Builtin index · Signal processing
result = cheby2(order, atten_db, kind, cutoff, fs)
Input: order, atten_db, kind, cutoff, fs · Output: result
What it is
order: number; atten_db: number (dB); kind: string; cutoff: number or length-2 vector (Hz); fs: number (Hz).
Overloads
cutoff can be number or vector.
2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.
| Code | Input | Output | Description |
result = cheby2(order, atten_db, "low"/"high", cutoff, fs) | order numberorder: number.atten_db numberatten_db: number (dB)."low"/"high" —not documented yetcutoff number or vectorcutoff: number or length-2 vector (Hz).fs numberfs: number (Hz). | result number | A single Hz number. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 1000
lp = cheby2(4, 40, "low", 100, fs)
bp = cheby2(4, 40, "band", [80, 120], fs)
print("lowpass sections: {shape(lp.sos)[0]}") # lowpass sections: 2
print("bandpass sections: {shape(bp.sos)[0]}") # bandpass sections: 4
lowpass sections: 2 bandpass sections: 4
from signal-processing
fs = 1000
ep = ellip(4, 1, 40, "low", 100, fs)
c1 = cheby1(4, 1, "low", 100, fs)
c2 = cheby2(4, 40, "low", 100, fs)
print("ellip stable: {is_stable(ep)}, cheby1 stable: {is_stable(c1)}, cheby2 stable: {is_stable(c2)}")
fir = fir1(6, 100, kind="low", window="hamming", fs=fs)
b = fir.b
a = [1]
n = 0:1:255
t = n / fs
x = sin(2*pi*40*t) + sin(2*pi*300*t)
y = filter_ba(b, a, x)
y2 = lfilter(b, a, x) # lfilter is the same builtin under another name
print("filter_ba/lfilter agree: {max(abs(y - y2)) < 1e-12}")
lsq = firls(20, [0, 0.2, 0.3, 1.0], [1, 1, 0, 0]) # low-pass band edges/response
print("firls taps: {length(lsq.b)}")
gd = group_delay(fir, 256)
print("FIR group delay (should be ~order/2=3): {gd[10]}")
print("ellip filter has {length(poles(ep))} poles")
ep.fvtool() # 2x2 magnitude/phase/group-delay/impulse-response figure
pzplot(ep) # pole-zero plot with the unit circle and stability verdict
ellip stable: true, cheby1 stable: true, cheby2 stable: true filter_ba/lfilter agree: true firls taps: 21 FIR group delay (should be ~order/2=3): 3 ellip filter has 4 poles
from signal-processing
| Code | Input | Output | Description |
result = cheby2(order, atten_db, "band"/"stop", cutoff, fs) | order numberorder: number.atten_db numberatten_db: number (dB)."band"/"stop" —not documented yetcutoff number or vectorcutoff: number or length-2 vector (Hz).fs numberfs: number (Hz). | result vector | A length-2 [low, high] Hz vector. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 1000
lp = cheby2(4, 40, "low", 100, fs)
bp = cheby2(4, 40, "band", [80, 120], fs)
print("lowpass sections: {shape(lp.sos)[0]}") # lowpass sections: 2
print("bandpass sections: {shape(bp.sos)[0]}") # bandpass sections: 4
lowpass sections: 2 bandpass sections: 4
from signal-processing
fs = 1000
ep = ellip(4, 1, 40, "low", 100, fs)
c1 = cheby1(4, 1, "low", 100, fs)
c2 = cheby2(4, 40, "low", 100, fs)
print("ellip stable: {is_stable(ep)}, cheby1 stable: {is_stable(c1)}, cheby2 stable: {is_stable(c2)}")
fir = fir1(6, 100, kind="low", window="hamming", fs=fs)
b = fir.b
a = [1]
n = 0:1:255
t = n / fs
x = sin(2*pi*40*t) + sin(2*pi*300*t)
y = filter_ba(b, a, x)
y2 = lfilter(b, a, x) # lfilter is the same builtin under another name
print("filter_ba/lfilter agree: {max(abs(y - y2)) < 1e-12}")
lsq = firls(20, [0, 0.2, 0.3, 1.0], [1, 1, 0, 0]) # low-pass band edges/response
print("firls taps: {length(lsq.b)}")
gd = group_delay(fir, 256)
print("FIR group delay (should be ~order/2=3): {gd[10]}")
print("ellip filter has {length(poles(ep))} poles")
ep.fvtool() # 2x2 magnitude/phase/group-delay/impulse-response figure
pzplot(ep) # pole-zero plot with the unit circle and stability verdict
ellip stable: true, cheby1 stable: true, cheby2 stable: true filter_ba/lfilter agree: true firls taps: 21 FIR group delay (should be ~order/2=3): 3 ellip filter has 4 poles
from signal-processing
How it works
cheby2(order, atten_db, kind, cutoff, fs) — designs a digital Chebyshev Type II (inverse Chebyshev) filter: monotonic in the passband, equiripple in the stopband (at least atten_db dB down starting at the stopband edge), flatter passband than Type I at the cost of a wider transition band. Same kind/cutoff/fs conventions as butter; cutoff is the point in the transition band where the attenuation first reaches atten_db (matching MATLAB's/ SciPy's own cheby2(n, Rs, Wn)), the stopband-edge convention (mirroring cheby1's passband-edge one). Model kind "filter", field sos — same shape as butter/ ellip/cheby1, so every generic filter function works on a cheby2 design with no changes at all.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.