IIRDESIGN
The iirdesign function provides a high-level interface to design IIR filters by specifying the desired passband and stopband characteristics, rather than the filter order directly.
It constructs an analog or digital IIR filter of minimum order for a given basic type (Butterworth, Chebyshev I, Chebyshev II, or Elliptic).
Excel Usage
=IIRDESIGN(wp, ws, gpass, gstop, analog, ftype, filter_output_form, fs)
wp(list[list], required): Passband edge frequencies.ws(list[list], required): Stopband edge frequencies.gpass(float, required): The maximum loss in the passband (dB).gstop(float, required): The minimum attenuation in the stopband (dB).analog(bool, optional, default: false): When True, return an analog filter.ftype(str, optional, default: “ellip”): The type of IIR filter.filter_output_form(str, optional, default: “ba”): Type of output representation.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:
| wp | ws | gpass | gstop |
|---|---|---|---|
| 0.2 | 0.3 | 1 | 40 |
Excel formula:
=IIRDESIGN(0.2, 0.3, 1, 40)
Expected output:
| Result | ||||
|---|---|---|---|---|
| 0.0196744 | -0.017137 | 0.0332899 | -0.017137 | 0.0196744 |
| 1 | -3.03301 | 3.8118 | -2.2911 | 0.555357 |
Example 2: Band-pass (SOS)
Inputs:
| wp | ws | gpass | gstop | filter_output_form | ||
|---|---|---|---|---|---|---|
| 0.2 | 0.4 | 0.1 | 0.5 | 1 | 60 | sos |
Excel formula:
=IIRDESIGN({0.2,0.4}, {0.1,0.5}, 1, 60, "sos")
Expected output:
| Result | |||||
|---|---|---|---|---|---|
| 0.00366595 | 0 | -0.00366595 | 1 | -1.11784 | 0.808699 |
| 1 | 0.44536 | 1 | 1 | -0.77776 | 0.846087 |
| 1 | -1.86313 | 1 | 1 | -1.43271 | 0.887093 |
| 1 | -0.106599 | 1 | 1 | -0.605994 | 0.9492 |
| 1 | -1.76647 | 1 | 1 | -1.59091 | 0.968224 |
Python Code
Show Code
import numpy as np
from scipy.signal import iirdesign as scipy_iirdesign
def iirdesign(wp, ws, gpass, gstop, analog=False, ftype='ellip', filter_output_form='ba', fs=None):
"""
Complete IIR digital and analog filter design from passband and stopband specs.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.iirdesign.html
This example function is provided as-is without any representation of accuracy.
Args:
wp (list[list]): Passband edge frequencies.
ws (list[list]): Stopband edge frequencies.
gpass (float): The maximum loss in the passband (dB).
gstop (float): The minimum attenuation in the stopband (dB).
analog (bool, optional): When True, return an analog filter. Default is False.
ftype (str, optional): The type of IIR filter. Valid options: Butterworth, Chebyshev I, Chebyshev II, Cauer/Elliptic. Default is 'ellip'.
filter_output_form (str, optional): Type of output representation. Valid options: Numerator/Denominator, Pole-Zero, Second-Order Sections. Default is 'ba'.
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:
def to_val(v):
if isinstance(v, list):
flat = [float(x) for row in v for x in row]
return flat[0] if len(flat) == 1 else flat
return float(v)
wp_val = to_val(wp)
ws_val = to_val(ws)
result = scipy_iirdesign(
wp_val,
ws_val,
float(gpass),
float(gstop),
analog=bool(analog),
ftype=ftype,
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
Passband edge frequencies.
Stopband edge frequencies.
The maximum loss in the passband (dB).
The minimum attenuation in the stopband (dB).
When True, return an analog filter.
The type of IIR filter.
Type of output representation.
The sampling frequency of the digital system.