Bens Spiker Algorithm

bens_spiker(signal: ndarray, window_length: int | list[int], threshold: float | list[float], window_type: Literal['barthann', 'brthan', 'bth', 'bartlett', 'bart', 'brt', 'blackman', 'black', 'blk', 'blackmanharris', 'blackharr', 'bkh', 'bohman', 'bman', 'bmn', 'boxcar', 'box', 'ones', 'rect', 'rectangular', 'cosine', 'halfcosine', 'exponential', 'poisson', 'flattop', 'flat', 'flt', 'hamming', 'hamm', 'ham', 'hann', 'han', 'lanczos', 'sinc', 'nuttall', 'nutl', 'nut', 'parzen', 'parz', 'par', 'taylor', 'taylorwin', 'triangle', 'triang', 'tri', 'tukey', 'tuk'] = 'boxcar') ndarray[source]

Perform spike detection using Bens Spiker Algorithm.

This function detects spikes in an input signal based on the comparison of cumulative errors calculated over a segment of the signal, which is filtered using a boxcar window. A spike is detected if the cumulative error between the filtered signal and the raw signal is below a certain threshold.

Refer to the Ben’s Spiker Encoding for a detailed explanation of the Ben’s Spiker algorithm.

Code Example:

import numpy as np
from spikify.encoding.temporal.deconvolution import bens_spiker
signal = np.array([0.1, 0.2, 0.3, 1.0, 0.5, 0.3, 0.1])
window_length = 3
threshold = 0.5
spikes = bens_spiker(signal, window_length, threshold)
Parameters:
  • signal (numpy.ndarray) – The input signal to be analyzed. This should be a numpy ndarray.

  • window_length (int | list[int]) – The length of the window type filter window. Can be a int or a list of ints.

  • threshold (float | list[float]) – Threshold value used to detect spikes. Can be a float or a list of floats.

Returns:

A numpy array representing the detected spikes.

Return type:

numpy.ndarray

Raises:
  • ValueError – If the input signal is empty or if the window length is greater than the signal length.

  • TypeError – If the signal is not a numpy ndarray.