Skip to content

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 dspk
from plating import signals
s = signals.synthetic()
CUTOFF = 300.0
low = 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 spikes
slow = s.components["lfp"] + s.components["common"] + s.components["hum"]
ch = s.loudest_channel
for 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}")

Low-pass and high-pass

The whole script is playground/02_filtering/01_lowpass_highpass.py. Run it with uv run python playground/02_filtering/01_lowpass_highpass.py.