Low-pass and high-pass
One cutoff splits a recording in two: below ~300 Hz the slow field potentials (LFP), above it
the spikes. dspk.ops.filter.iir designs the filter for the recording’s sample rate and runs it
on the device (Butterworth, order 5, zero phase by default).
import numpy as np
import dspkfrom plating import signals
s = signals.synthetic()CUTOFF = 300.0low = dspk.ops.filter.iir(s.data, s.sample_rate, "lowpass", CUTOFF)high = dspk.ops.filter.iir(s.data, s.sample_rate, "highpass", CUTOFF)
# What each should keep: everything slow (LFP, the common artefact, the 60 Hz hum) or the spikesslow = s.components["lfp"] + s.components["common"] + s.components["hum"]ch = s.loudest_channelfor name, got, want in (("low-pass", low, slow), ("high-pass", high, s.components["spikes"])): r = np.corrcoef(got[ch], want[ch])[0, 1] print(f"{name}: correlation with what it should keep {r:.3f}")
The whole script is playground/02_filtering/01_lowpass_highpass.py. Run it with uv run python playground/02_filtering/01_lowpass_highpass.py.