Step Forward Algorithm

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

Perform Step-Forward (SF) encoding on the input signal.

This function takes a continuous signal and converts it into a spike train using a dynamically updated baseline signal and threshold-based approach. A spike is generated when the signal exceeds or drops below the dynamically adjusted baseline (base) by the specified threshold.

Refer to the Step Forward (SF) Encoding for a detailed explanation of the SF encoding algorithm.

Code Example:

import numpy as np
from spikify.encoders.temporal.contrast import step_forward
signal = np.array([0.1, 0.3, 0.4, 0.2, 0.5, 0.6])
threshold = 0.2
encoded_signal = step_forward(signal, threshold)
Parameters:
  • signal (numpy.ndarray) – The input signal to be encoded. This should be a numpy ndarray.

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

Returns:

A numpy array representing the encoded spike train.

Return type:

numpy.ndarray

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

  • TypeError – If the threshold parameter is of invalid dimension.