Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

signal.butter

Designs an Nth-order digital or analog Butterworth filter. It supports low-pass, high-pass, band-pass, and band-stop designs and returns coefficients as polynomials, zero-pole-gain values, or second-order sections.

Since
1.2.0

How it works

butter computes an Nth-order Butterworth filter from its critical frequency or frequencies. It can design digital or analog low-pass, high-pass, band-pass, or band-stop filters, and returns polynomial, zero-pole-gain, or second-order-section coefficients according to output.

Syntax

scipy.signal.butter(N, Wn, btype='lowpass', analog=False, output='ba', fs=None)

Parameters

NameTypeDescription
NintThe filter order.
Wnarray_likeThe critical frequency or frequencies. A scalar is used for low-pass and high-pass filters; a length-2 sequence is used for band-pass and band-stop filters.
btype{‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’}, optionalThe filter type: 'lowpass', 'highpass', 'bandpass', or 'bandstop'. Default: 'lowpass'.
analogbool, optionalIf true, design an analog filter; otherwise design a digital filter. Default: False.
output{‘ba’, ‘zpk’, ‘sos’}, optionalCoefficient representation: 'ba', 'zpk', or 'sos'. Default: 'ba'.
fsfloat, optionalSampling frequency of the digital system.

Returns

If output='ba', returns (b, a): numerator and denominator polynomials. If output='zpk', returns (z, p, k): zeros, poles, and system gain. If output='sos', returns an array of second-order sections.

Key points

  • The function designs an Nth-order Butterworth filter and returns coefficients in the representation selected by output.
  • Use one critical frequency for low-pass or high-pass filters, and a two-element sequence for band-pass or band-stop filters.
  • Each critical frequency marks the Butterworth response's -3 dB point relative to the passband.
  • btype selects low-pass, high-pass, band-pass, or band-stop behavior.
  • analog=True produces an analog design; the default produces a digital design.
  • The default output is polynomial coefficients for compatibility, while second-order sections are advised for ordinary filtering.

Common mistakes

  • With a digital filter and no fs, critical frequencies use normalized units: 1 corresponds to the Nyquist frequency.
  • When fs is supplied, express digital critical frequencies in the same units as the sampling frequency.
  • High-order or narrow-band filters can be numerically problematic in transfer-function form; prefer second-order sections.

Example: Low-pass filtering with second-order sections

import numpy as np
from scipy import signal

fs = 1000.0
sos = signal.butter(4, 100.0, btype="lowpass", fs=fs, output="sos")
t = np.arange(0, 1, 1 / fs)
x = np.sin(2 * np.pi * 20 * t) + np.sin(2 * np.pi * 250 * t)
y = signal.sosfilt(sos, x)
print(y.shape, sos.shape)

Designs a fourth-order digital low-pass Butterworth filter with a 100 Hz cutoff and applies its numerically stable second-order-section representation.

When to use it

Digital low-pass filtering

Remove frequencies above a chosen cutoff from sampled data.

Digital band-stop filtering

Suppress a narrow frequency range such as mains interference.

Analog filter design

Create a continuous-time prototype for analog circuit or control analysis.

Stable second-order-section filtering

Filter with higher-order designs while reducing coefficient-related numerical issues.

Interview questions

QWhat does Wn represent?

Wn is the critical frequency, or the two critical frequencies for band-pass and band-stop designs. For a Butterworth filter, it is the frequency where the gain reaches the passband value divided by 2, commonly called the -3 dB point.

Follow-up: How do digital frequency units change when fs is provided? Without fs, frequencies are normalized to the Nyquist frequency; with fs, Wn uses the same units as fs.

QWhat can output return?

output="ba" returns numerator and denominator polynomial coefficients, output="zpk" returns zeros, poles, and gain, and output="sos" returns second-order sections. The default is ba, but the documentation recommends sos for general-purpose filtering.

Follow-up: Why is sos preferable for difficult designs? Cascaded second-order sections generally avoid the numerical sensitivity that can make high-order transfer-function coefficients unstable or inaccurate.

QHow do you choose between analog and digital designs?

Set analog=True to design an analog filter; otherwise the result is digital. Digital designs use the sampling frequency when fs is specified, while analog designs interpret Wn as angular frequencies.

Follow-up: What filter types can be selected? btype supports low-pass, high-pass, band-pass, and band-stop designs.

  • scipy.signal.sosfilt
  • scipy.signal.sosfreqz
  • scipy.signal.freqz
  • scipy.signal.zpk2sos

Source: scipy.signal.butter — SciPy v1.16.0 Manual. Checked 2026-10-15.