Zero Crossing Step Forward Algorithm

zero_cross_step_forward(signal: ndarray, threshold: float | int | list[float | int] | ndarray) tuple[ndarray, ndarray][source]

Perform Zero-Crossing Step-Forward (ZCSF) encoding on the input signal.

This function generates a spike train based on the positive values of the input signal that exceed a specified threshold. Negative values of the signal are zeroed out (half-wave rectification), and only positive spikes are considered.

Refer to the Zero-Crossing Step-Forward (ZCSF) Encoding for a detailed explanation of the ZCSF encoding algorithm.

Code Example:

import numpy as np
from spikify.encoders.temporal.contrast import zero_cross_step_forward
signal = np.array([-0.2, 0.1, 0.5, 0.0, 1.2, 0.3])
threshold = 0.4
encoded_signal, thresholds = zero_cross_step_forward(signal, threshold)
Parameters:
  • signal (numpy.ndarray) – Input signal to encode (1D or 2D: time × features or channels).

  • threshold (float | int | list[float | int] | numpy.ndarray) – Threshold(s) for spike generation; scalar or 1D sequence matching features.

Returns:

  • spikes: A numpy array representing the encoded spike train. (values in {0, +1})

  • thresholds: Per-feature or channel thresholds used for encoding, returned for use in decoding, shape (features or channels,).

Return type:

tuple[numpy.ndarray, numpy.ndarray]

Raises:

ValueError – If the input signal is empty or if the threshold dimensions do not match the signal features.