DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Design and Apply IIR Filters in Python with SciPy

A practical guide to designing SciPy IIR filters: set the right frequency units, use second-order sections, select online or offline filtering, and check the realized response.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To design an IIR filter in SciPy, choose a filter family and frequency requirements, create the filter as second-order sections (SOS), apply it with a function suited to online or offline processing, and verify its measured frequency response. For most practical digital filters, output='sos' is the safer coefficient format than a single numerator-and-denominator polynomial.

Choose a design method from your requirements

SciPy’s scipy.signal module includes filter-design functions such as iirfilter, iirdesign, and family-specific functions such as butter. The choice depends on whether you already know the filter order or instead need to meet passband and stopband limits. See the SciPy iirdesign reference and the SciPy signal-processing tutorial.

As an Amazon Associate I earn from qualifying purchases.

Set an order and cutoff

Use a family function or iirfilter when you want to specify the family, filter type, order, and critical frequency or frequencies. For example, a low-pass Butterworth design can be created with butter. In that interface, Wn is the critical frequency at which the gain reaches 1/√2 of the passband gain, approximately −3 dB; it is not necessarily the edge of a flat passband.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Specify passband and stopband targets

Use iirdesign when you have passband and stopband edges and acceptable deviations for each. This is a specification-led approach: state what the filter must preserve and what it must attenuate, then inspect whether the resulting design achieves those targets. The SciPy tutorial’s elliptic low-pass example illustrates explicit ripple constraints and a trade between order and attenuation; that example is not a universal ranking of filter families.

#1 Best Overall
Sale
Digital Signal Processing, 4/e
  • the book is suitable for undergraduate and graduate courses and provides balanced coverage of both theory and practical applications.
  • Digital Signal Processing, 4/e

Make frequency units explicit

The meaning of a digital cutoff depends on whether you pass fs. Without fs, SciPy interprets Wn on a normalized scale where 1 is the Nyquist frequency (half the sampling rate). When fs is supplied, Wn uses the same frequency units as fs. This distinction is documented in the SciPy butter reference.

For example, with samples taken at 1000 Hz, a 100 Hz cutoff is expressed directly as Wn=100, fs=1000. Omitting fs would require a normalized value instead: 100 Hz divided by the 500 Hz Nyquist frequency, or 0.2. Mixing those conventions can produce a valid filter that targets the wrong frequency.

Design in second-order sections

For general-purpose digital filtering, request SOS coefficients. A single transfer-function representation (ba) expresses the filter as high-degree numerator and denominator polynomials. At high orders or in narrow bands, converting roots into those polynomials can be sensitive to floating-point precision and may produce an unstable or incorrect filter. SciPy discusses this issue in the Butterworth design reference and recommends SOS-oriented functions in its filtering reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A practical Butterworth example using frequencies in hertz is:

from scipy import signal

fs = 1000.0  # samples per second
sos = signal.butter(
    N=4,
    Wn=100.0,
    btype="lowpass",
    fs=fs,
    output="sos",
)

This creates a fourth-order low-pass design with a 100 Hz critical frequency. The order and cutoff here are example choices, not values that suit every signal. SciPy can also return transfer-function coefficients (ba) or zeros, poles, and gain (zpk); SOS is a robust default, not a claim that it is optimal for every performance constraint. SOS can have some additional computational cost, so validate the implementation if processing speed is critical.

Apply the filter: one pass or forward and backward

Choose the filtering function based on whether the data are processed as they arrive or are available as a complete offline record. The two approaches have different phase and boundary behavior.

Online or causal processing with sosfilt

sosfilt applies the sections in one pass. This is the appropriate form when preserving causal, streaming behavior matters; the filter’s phase delay remains part of the output. For continuous streams, state handling across successive blocks matters: treating each block as a fresh signal can create discontinuities at block boundaries. Consult the SciPy sosfilt reference for the function’s state interface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Offline processing with sosfiltfilt

sosfiltfilt filters forward and then backward, cancelling phase shift in the resulting offline signal. It is not a drop-in option for real-time causal processing: it requires future samples and edge handling. Forward-backward filtering also doubles the effective filter order, changing the magnitude response as well as the phase behavior. The SOS function exposes padding type and length to manage boundaries; consult its SciPy reference when choosing those settings. For most tasks, SciPy recommends this SOS form over filtfilt because second-order sections have fewer numerical problems.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify the realized frequency response

A successful design call only means SciPy produced coefficients; it does not prove those coefficients meet the application’s requirements. Inspect the response with tools such as freqz or freqz_sos, then compare the actual passband and stopband behavior to the targets. The SciPy freqz reference documents response analysis.

  • Check passband flatness or allowed ripple where the signal should remain.
  • Check stopband attenuation where interference or unwanted components should be reduced.
  • Examine transition width and filter order against the constraints of the design.
  • Consider phase behavior and whether one-pass or forward-backward processing fits the use case.
  • Test boundary behavior on representative records, especially when using forward-backward filtering.

Keep the design requirements, chosen coefficient representation, filtering method, and response check together in code or documentation. That makes it easier to distinguish a frequency-unit mistake from a specification mismatch or an unsuitable processing mode.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.