Moving Window Algorithm

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

Perform Moving Window (MW) encoding on the input signal.

This function takes a continuous signal and converts it into a spike train using a moving window and threshold-based approach. A spike is generated when the signal exceeds the calculated base plus or minus a specified threshold.

Refer to the Moving Window (MW) Encoding for a detailed explanation of the Moving Window encoding algorithm.

Code Example:

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

  • window_length (int) – The size of the sliding window for calculating the signal base mean.

  • 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.