Filters
Butterworth, Chebyshev I or Bessel, as low-pass, high-pass, band-pass or band-stop.
y = dspk.ops.filter.iir(x, 30_000.0, "bandpass", (300.0, 6000.0), order=5)pipeline.add(PipelineStage::bandpass(300.0, 6_000.0)); // also highpass, lowpass, bandstop{"op": "iir", "band": "bandpass", "cutoff": [300.0, 6000.0], "order": 5}Filter → IIR, with presets for spikes, LFP, EMG, ECG, EEG and mains.
Zero phase or causal. mode="forward_backward" (the default) runs the filter forward and back, as
scipy.signal.sosfiltfilt, so nothing shifts in time, and the magnitude response applies twice.
mode="forward" is causal, as sosfilt, and is what streaming needs.
Takes out one frequency, as scipy.signal.iirnotch. The notch is freq / q Hz wide at −3 dB.
y = dspk.ops.filter.notch(x, 30_000.0, 60.0, 30.0)pipeline.add(PipelineStage::notch(60.0, 30.0));{"op": "notch", "freq": 60.0, "q": 30.0}Filter → Notch.
Taps you give, causal (as scipy.signal.lfilter(taps, 1, x)) or centred on each sample. Design taps
with firwin.
taps = dspk.ops.filter.firwin(101, 250.0, sample_rate=30_000.0)y = dspk.ops.filter.fir(x, taps, centered=True)pipeline.add(PipelineStage::fir(taps)); // causal{"op": "fir", "taps": [0.2, 0.2, 0.2, 0.2, 0.2], "centered": true}Filter → FIR.
Gaussian smoothing
Section titled “Gaussian smoothing”Zero phase, as scipy.ndimage.gaussian_filter1d, with the kernel cut at 4 standard deviations.
y = dspk.ops.filter.gaussian_smooth(x, 30.0) # sigma in samplespipeline.add(PipelineStage::gaussian_smooth(30.0));{"op": "gaussian_smooth", "sigma_samples": 30.0}Smooth → Gaussian.
Running median
Section titled “Running median”Over an odd width of at most 31 samples. With the default edge it is scipy.signal.medfilt.
y = dspk.ops.filter.median(x, 31)pipeline.add(PipelineStage::median(31));{"op": "median", "width": 31}Smooth → Median.
Teager–Kaiser energy
Section titled “Teager–Kaiser energy”x[t]**2 - x[t-1] * x[t+1]: large where the signal is both large and fast, so spikes stand out from
slow waves.
energy = dspk.ops.filter.teager_kaiser(x)pipeline.add(PipelineStage::teager_kaiser());{"op": "teager_kaiser"}Transform → Teager–Kaiser.
Template subtraction
Section titled “Template subtraction”Removes a known waveform at each event, such as stimulation artefacts, aligned and scaled per event.
Python only: subtract_template.
Worked examples: Filtering.