FIR and IIR filter design and application — mirrors scipy.signal.
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
Design a 51-tap Hamming-windowed low-pass FIR and check its DC and Nyquist gain.
Pass high frequencies by setting pass_zero: false. DC gain should be near 0, Nyquist near 1.
lfilter is causal (has phase delay); filtfilt applies the filter twice for zero-phase output.
Design a 4th-order Butterworth IIR filter. butter returns both SOS form (numerically preferred) and ba form.
Filter a noisy 50 Hz signal to remove 300 Hz interference. Zero-phase output is closer to the clean reference.
A 2nd-order Butterworth high-pass attenuates DC and passes high frequencies.
All Butterworth filters have exactly −3 dB gain at the cutoff frequency, regardless of order.
| Function | Description | Mirrors |
|---|---|---|
firwin(n, cutoff, opts?) | FIR design (windowed-sinc) | scipy.signal.firwin |
butter(N, Wn, type?) | Butterworth IIR design | scipy.signal.butter |
freqz(b, a?, worN?) | FIR/IIR frequency response | scipy.signal.freqz |
sosfreqz(sos, worN?) | SOS frequency response | scipy.signal.sosfreqz |
lfilter(b, a, x) | Causal FIR/IIR filter | scipy.signal.lfilter |
filtfilt(b, a, x) | Zero-phase filter | scipy.signal.filtfilt |
sosfilt(sos, x) | Causal SOS filter | scipy.signal.sosfilt |
sosfiltfilt(sos, x) | Zero-phase SOS filter | scipy.signal.sosfiltfilt |