braintools.input.square

Contents

braintools.input.square#

braintools.input.square(amplitude, frequency, duration, t_start=None, t_end=None, duty_cycle=0.5, bias=False)#

Generate square wave current input.

Creates a square wave that alternates between two levels at a specified frequency. Useful for testing step responses, synchronization, and driving rhythmic activity.

Parameters:
  • amplitude (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Peak amplitude of the square wave. Supports current units.

  • frequency (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Frequency of oscillation. Must be in Hz units.

  • duration (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Total duration of the signal. Supports time units.

  • t_start (Array | ndarray | bool | number | bool | int | float | complex | Quantity | None) – Time when square wave starts. Before this, output is 0. Default is 0.

  • t_end (Array | ndarray | bool | number | bool | int | float | complex | Quantity | None) – Time when square wave ends. After this, output is 0. Default is duration.

  • duty_cycle (float) – Fraction of period spent at high level (0 to 1). Default is 0.5 (symmetric square wave).

  • bias (bool) – If True, adds DC offset equal to amplitude (non-negative output). If False, alternates between +amplitude and -amplitude.

Returns:

current – The square wave current array with shape (n_timesteps,).

Return type:

ndarray or Quantity

Raises:

Examples

>>> import brainunit as u
>>> import brainstate
>>> brainstate.environ.set(dt=0.1 * u.ms)

Symmetric square wave at 2 Hz

>>> current = square(
...     amplitude=10 * u.pA,
...     frequency=2 * u.Hz,
...     duration=2000 * u.ms
... )

High-frequency pulse train

>>> current = square(
...     amplitude=5 * u.nA,
...     frequency=50 * u.Hz,
...     duration=500 * u.ms,
...     duty_cycle=0.2  # 20% on, 80% off
... )

Square wave with positive bias

>>> current = square(
...     amplitude=8 * u.pA,
...     frequency=10 * u.Hz,
...     duration=1000 * u.ms,
...     bias=True  # Alternates between 0 and 16 pA
... )

Windowed stimulation

>>> current = square(
...     amplitude=3 * u.nA,
...     frequency=5 * u.Hz,
...     duration=2000 * u.ms,
...     t_start=500 * u.ms,
...     t_end=1500 * u.ms
... )

Asymmetric pulse train (10% duty cycle)

>>> current = square(
...     amplitude=20 * u.pA,
...     frequency=1 * u.Hz,
...     duration=5000 * u.ms,
...     duty_cycle=0.1  # Short pulses
... )

Clock signal for synchronization

>>> current = square(
...     amplitude=1 * u.nA,
...     frequency=40 * u.Hz,
...     duration=250 * u.ms,
...     duty_cycle=0.5
... )

Notes

  • Without bias: alternates between +amplitude and -amplitude

  • With bias: alternates between 0 and 2*amplitude

  • Duty cycle controls the fraction of time at high level

  • Transitions are instantaneous (limited by dt resolution)