FREQZ

This function computes the complex frequency response of a digital filter defined by numerator and denominator coefficients.

For filter transfer function

H(z) = \frac{\sum_{m=0}^{M} b_m z^{-m}}{\sum_{n=0}^{N} a_n z^{-n}}

it evaluates H(e^{j\omega}) on a frequency grid and returns frequency, magnitude, and phase so response behavior can be analyzed directly in Excel.

Excel Usage

=FREQZ(b, a, wor_n, whole, fs, include_nyquist)
  • b (list[list], required): Numerator (feed-forward) filter coefficients.
  • a (list[list], optional, default: [[1]]): Denominator (feedback) filter coefficients.
  • wor_n (int, optional, default: 512): Number of frequency points to evaluate.
  • whole (bool, optional, default: false): If True, compute response over the whole unit circle.
  • fs (float, optional, default: 6.283185307179586): Sampling frequency in frequency units (radians per sample by default).
  • include_nyquist (bool, optional, default: false): If True and wor_n is an integer, include the Nyquist frequency endpoint.

Returns (list[list]): A 2D array with rows for frequency, magnitude response, and phase response.

Example 1: Frequency response for a simple low-pass filter on default grid

Inputs:

b a wor_n
1 1 1 -0.5 16

Excel formula:

=FREQZ({1,1}, {1,-0.5}, 16)

Expected output:

Result
0 0.19635 0.392699 0.589049 0.785398 0.981748 1.1781 1.37445 1.5708 1.76715 1.9635 2.15984 2.35619 2.55254 2.74889 2.94524
4 3.83605 3.43491 2.95836 2.50777 2.11663 1.78561 1.50525 1.26491 1.05546 0.869597 0.701632 0.547095 0.40241 0.264635 0.131251
0 -0.2873 -0.538017 -0.738334 -0.893173 -1.01319 -1.10805 -1.18498 -1.24905 -1.30377 -1.35165 -1.39448 -1.43359 -1.47002 -1.50459 -1.53798
Example 2: Frequency response with custom number of points

Inputs:

b a wor_n
1 0 -1 1 16

Excel formula:

=FREQZ({1,0,-1}, {1}, 16)

Expected output:

Result
0 0.19635 0.392699 0.589049 0.785398 0.981748 1.1781 1.37445 1.5708 1.76715 1.9635 2.15984 2.35619 2.55254 2.74889 2.94524
0 0.390181 0.765367 1.11114 1.41421 1.66294 1.84776 1.96157 2 1.96157 1.84776 1.66294 1.41421 1.11114 0.765367 0.390181
0 1.37445 1.1781 0.981748 0.785398 0.589049 0.392699 0.19635 0 -0.19635 -0.392699 -0.589049 -0.785398 -0.981748 -1.1781 -1.37445
Example 3: Frequency response over full unit circle

Inputs:

b a whole wor_n
0.2 0.2 0.2 0.2 0.2 1 true 16

Excel formula:

=FREQZ({0.2,0.2,0.2,0.2,0.2}, {1}, TRUE, 16)

Expected output:

Result
0 0.392699 0.785398 1.1781 1.5708 1.9635 2.35619 2.74889 3.14159 3.53429 3.92699 4.31969 4.71239 5.10509 5.49779 5.89049
1 0.852395 0.482843 0.0702307 0.2 0.235916 0.0828427 0.113291 0.2 0.113291 0.0828427 0.235916 0.2 0.0702307 0.482843 0.852395
0 -0.785398 -1.5708 -2.35619 0 -0.785398 -1.5708 0.785398 0 -0.785398 1.5708 0.785398 0 2.35619 1.5708 0.785398
Example 4: Frequency response including Nyquist endpoint

Inputs:

b a wor_n include_nyquist
1 -1 1 16 true

Excel formula:

=FREQZ({1,-1}, {1}, 16, TRUE)

Expected output:

Result
0 0.20944 0.418879 0.628319 0.837758 1.0472 1.25664 1.46608 1.67552 1.88496 2.0944 2.30383 2.51327 2.72271 2.93215 3.14159
0 0.209057 0.415823 0.618034 0.813473 1 1.17557 1.33826 1.48629 1.61803 1.73205 1.82709 1.90211 1.9563 1.98904 2
0 1.46608 1.36136 1.25664 1.15192 1.0472 0.942478 0.837758 0.733038 0.628319 0.523599 0.418879 0.314159 0.20944 0.10472 0

Python Code

Show Code
import numpy as np
from scipy.signal import freqz as scipy_freqz

def freqz(b, a=[[1]], wor_n=512, whole=False, fs=6.283185307179586, include_nyquist=False):
    """
    Compute the frequency response of a digital filter.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.freqz.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        b (list[list]): Numerator (feed-forward) filter coefficients.
        a (list[list], optional): Denominator (feedback) filter coefficients. Default is [[1]].
        wor_n (int, optional): Number of frequency points to evaluate. Default is 512.
        whole (bool, optional): If True, compute response over the whole unit circle. Default is False.
        fs (float, optional): Sampling frequency in frequency units (radians per sample by default). Default is 6.283185307179586.
        include_nyquist (bool, optional): If True and wor_n is an integer, include the Nyquist frequency endpoint. Default is False.

    Returns:
        list[list]: A 2D array with rows for frequency, magnitude response, and phase response.
    """
    try:
        def flatten_numeric(x):
            if not isinstance(x, list):
                return [float(x)]
            values = []
            for row in x:
                if isinstance(row, list):
                    for v in row:
                        values.append(float(v))
                else:
                    values.append(float(row))
            return values

        b_vals = flatten_numeric(b)
        a_vals = flatten_numeric(a)

        if len(b_vals) == 0:
            return "Error: b must contain at least one numeric coefficient"
        if len(a_vals) == 0:
            return "Error: a must contain at least one numeric coefficient"

        w, h = scipy_freqz(
            b_vals,
            a_vals,
            worN=int(wor_n),
            whole=bool(whole),
            fs=float(fs),
            include_nyquist=bool(include_nyquist)
        )

        return [
            w.tolist(),
            np.abs(h).tolist(),
            np.angle(h).tolist()
        ]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Numerator (feed-forward) filter coefficients.
Denominator (feedback) filter coefficients.
Number of frequency points to evaluate.
If True, compute response over the whole unit circle.
Sampling frequency in frequency units (radians per sample by default).
If True and wor_n is an integer, include the Nyquist frequency endpoint.