Filters
Zero-phase IIR filtering and decimation.
All filters use Butterworth SOS design (scipy.signal.butter + sosfiltfilt) for numerical stability and zero group-delay distortion — appropriate for offline SHM analysis where phase matters.
Zero-phase vs causal
zero_phase=True (default) applies the filter twice (forward + backward), doubling the effective order and producing exactly zero phase shift. Set zero_phase=False for causal (real-time) processing.

dspkit.filters.lowpass(x, fs, cutoff, order=4, zero_phase=True)
Butterworth lowpass filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
Input signal. |
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
cutoff
|
float
|
-3 dB cutoff frequency [Hz]. |
required |
order
|
int
|
Filter order. With |
4
|
zero_phase
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
|
Source code in dspkit/filters.py
dspkit.filters.highpass(x, fs, cutoff, order=4, zero_phase=True)
Butterworth highpass filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
cutoff
|
float
|
-3 dB cutoff frequency [Hz]. |
required |
order
|
int
|
|
4
|
zero_phase
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
|
Source code in dspkit/filters.py
dspkit.filters.bandpass(x, fs, low, high, order=4, zero_phase=True)
Butterworth bandpass filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
low
|
float
|
Lower -3 dB cutoff [Hz]. |
required |
high
|
float
|
Upper -3 dB cutoff [Hz]. |
required |
order
|
int
|
Order of each lowpass/highpass section (total order = 2 * order). |
4
|
zero_phase
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
|
Source code in dspkit/filters.py
dspkit.filters.bandstop(x, fs, low, high, order=4, zero_phase=True)
Butterworth bandstop (band-reject) filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
low
|
float
|
Lower edge of the stop band [Hz]. |
required |
high
|
float
|
Upper edge of the stop band [Hz]. |
required |
order
|
int
|
|
4
|
zero_phase
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
|
Source code in dspkit/filters.py
dspkit.filters.notch(x, fs, freq, q=30.0, zero_phase=True)
IIR notch filter at a single frequency.
Common uses: remove mains hum (50 or 60 Hz) or a known harmonic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
freq
|
float
|
Notch frequency [Hz]. |
required |
q
|
float
|
Quality factor. Higher Q → narrower notch. Typical values: 10 (broad) to 50 (narrow). Default 30. |
30.0
|
zero_phase
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(N))
|
|
Source code in dspkit/filters.py
dspkit.filters.decimate(x, fs, target_fs, zero_phase=True)
Downsample a signal with an anti-aliasing lowpass filter.
The decimation factor must be a positive integer (fs / target_fs).
For non-integer ratios, use scipy.signal.resample_poly directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Original sampling frequency [Hz]. |
required |
target_fs
|
float
|
Target sampling frequency [Hz]. Must satisfy |
required |
zero_phase
|
bool
|
If |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
x_decimated |
ndarray
|
Downsampled signal. |
target_fs |
float
|
Actual output sampling frequency (same as |