Phase Encoding Algorithm

phase(signal: ndarray, num_bits: int) ndarray[source]

Perform Phase Encoding (PE) on the input signal.

This function encodes the input signal by calculating the phase angles of the normalized signal and quantizing these angles into a binary spike train representation. The encoding process uses a specified number of bits to determine the level of quantization.

Note

  • PE requires normalized input signals between 0 and 1. If the input signal contains negative values, they are shifted to be non-negative and then normalized.

Refer to the Phase Encoding (PE) for a detailed explanation of the Phase Encoding Algorithm.

Code Example:

import numpy as np
from spikify.encoders.temporal.global_referenced import phase
signal = np.array([0.1, 0.2, 0.3, 1.0, 0.5, 0.3, 0.1, 0.2])
num_bits = 4
encoded_signal = phase(signal, num_bits)
Parameters:
  • signal (numpy.ndarray) – The input signal to be encoded. This should be a numpy ndarray.

  • num_bits (int) – The number of bits to use for encoding.

Returns:

A 1D numpy array representing the phase-encoded spike train.

Return type:

numpy.ndarray

Raises:

ValueError – If the input signal is empty or if the number of bits is not appropriate for the signal length.