Hough Spiker Algorithm
- hough_spiker(signal: ndarray, window_length: int, cutoff: float | ndarray, width: int | None = None, 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'] = 'hann', pass_zero: bool | str = True, scale: bool = True, fs: float | None = None) tuple[ndarray, ndarray, ndarray, ndarray][source]¶
Perform Hough Spiker Algorithm (HSA) encoding on the input signal.
HSA is a simple, parameter-free technique for converting non-negative analog signals (scaled to [0, 1]) into unipolar spike trains that can be accurately reconstructed via convolution with the same FIR filter used during encoding. It iteratively scans the signal with a sliding window of length equal to the FIR filter and emits a positive spike (+1) if the entire signal segment is greater than or equal to the filter coefficients pointwise. Upon detection, the filter is subtracted from the segment, effectively removing the detected pattern for subsequent scans.
Note
HSA requires non-negative inputs; automatic shifting and normalization to [0, 1] is applied per feature.
The FIR filter is designed using scipy.signal.firwin with the specified cutoff, window type, etc.
For multi-feature signals, the same filter shape is applied across all features, but scaling is performed independently per feature based on its amplitude.
Refer to the Hough Spiker (HSA) Encoding for a detailed explanation of the HSA.
Code Example
import numpy as np from spikify.encoders.temporal.deconvolution import hough_spiker signal = np.array([0.1, 0.2, 4.1, 1.0, 3.0, 0.3, 0.1]) window_length = 3 cutoff = 0.1 encoded_signal, fir_coeffs, shift, norm = hough_spiker(signal, window_length, cutoff)
- Parameters:
signal (numpy.ndarray) – Input signal to encode (1D or 2D: time × features or channels).
window_length (int) – Length of the FIR filter (number of coefficients).
cutoff (float | numpy.ndarray) – Cutoff frequency(ies) for the FIR filter design (normalized 0 to 1, where 1 = Nyquist). Scalar or an array of cutoff frequencies (that is, band edges).
width (int | None) – Transition width for FIR filter design (optional, used with certain window types).
window_type (str) – Window function for FIR filter design (e.g., ‘hann’, ‘hamming’, ‘blackman’, ‘boxcar’).
pass_zero (bool | str) – Whether the filter should be low-pass (True) or high-pass (False/’highpass’).
scale (bool) – Set to True to scale the coefficients so that the frequency response is exactly unity at a certain frequency.
fs (float | None) – Sampling frequency (used for physical frequency units in cutoff; optional).
- Returns:
spikes: A numpy array representing the encoded spike train. (values in {0, +1})
fir_bank: Final filter coefficients used (window_length, features or channels).
shift: Per-feature shift values subtracted to make signal non-negative, shape (features or channels,).
norm: Per-feature normalization values used to scale signal to [0, 1], shape (features or channels,).
- Return type:
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]
- Raises:
ValueError – If the input signal is empty or if the window_length is greater than the signal lenght.