Bens Spiker Algorithm
- bens_spiker(signal: ndarray, window_length: int, threshold: float) 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) – The length of the boxcar filter window.
threshold (float) – Threshold value used to detect spikes.
- Returns:
A 1D numpy array representing the detected spikes.
- Return type:
- 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.