Source code for hetero.stims.elem_funcs
import numpy as np
[docs]
def null(n_timesteps: int, **kwargs: dict) -> np.ndarray:
"""Generats a null (zero) stimulus.
Parameters
----------
n_timesteps : int
Number of timesteps to generate.
Returns
-------
np.ndarray of shape (n_timesteps, 1)
A zero 1-dimensional array.
"""
return np.zeros(size=(n_timesteps, 1), dtype=float)
[docs]
def sin(n_timesteps: int, h: float = 0.05,
freq: float = 10., phase: float = 0.) -> np.ndarray:
"""Generates a sinusoidal input of given frequency.
Parameters
----------
n_timesteps : int
Number of timesteps to generate.
h : float, optional
Time delta between two discrete timesteps, by default 0.05.
freq : float, optional
Oscillation frequency, by default 10.
phase : float, optional
Oscillation starting phase in radian, by default 0.
Returns
-------
np.ndarray of shape (n_timesteps, 1)
A 1-dimensional array.
"""
ts = np.linspace(0, n_timesteps*h, n_timesteps, endpoint=False)
return np.sin(2*np.pi*freq * ts + phase).reshape(n_timesteps, 1)
[docs]
def sign(n_timesteps: int, h: float = 0.05,
freq: float = 1., phase: float = 0.) -> np.ndarray:
"""Generates a signal that is the sign of a sinusoidal input of given frequency.
Parameters
----------
n_timesteps : int
Number of timesteps to generate.
h : float, optional
Time delta between two discrete timesteps, by default 0.05.
freq : float, optional
Oscillation frequency, by default 10.
phase : float, optional
Oscillation starting phase in radian, by default 0.
Returns
-------
np.ndarray of shape (n_timesteps, 1)
A 1-dimensional array.
"""
ts = np.linspace(0, n_timesteps*h, n_timesteps, endpoint=False)
return np.sign(np.sin(2*np.pi*freq * ts + phase)).reshape(n_timesteps, 1)