braintools.input.Triangular#

class braintools.input.Triangular(amplitude, frequency, duration, t_start=None, t_end=None, bias=False)#

Composable triangular wave input generator.

Creates a triangular (linear ramping) waveform that linearly increases and decreases between peak values. This class is composable with other Input objects.

The triangular wave ramps linearly between -amplitude and +amplitude.

Parameters:
  • amplitude (float) – Peak amplitude of the triangular wave.

  • frequency (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 triangular wave starts. Before this, output is 0. Default is 0.

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

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

amplitude#

Peak amplitude of the triangular wave

Type:

float

frequency#

Frequency of oscillation in Hz

Type:

Quantity

t_start#

Start time of the triangular wave

Type:

float or Quantity

t_end#

End time of the triangular wave

Type:

float or Quantity

bias#

Whether DC bias is applied

Type:

bool

Examples

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

Simple triangular wave:

>>> tri = Triangular(2.0, 3 * u.Hz, 1000 * u.ms)
>>> signal = tri()

Slow ramp for I-V curve measurements:

>>> ramp = Triangular(
...     amplitude=100.0,
...     frequency=0.5 * u.Hz,  # 2 second period
...     duration=4000 * u.ms
... )

Clipped triangular wave:

>>> tri = Triangular(5.0, 4 * u.Hz, 600 * u.ms)
>>> clipped = tri.clip(-3.0, 3.0)  # Trapezoidal shape

Triangular wave with envelope:

>>> from braintools.input import GaussianPulse
>>> tri = Triangular(2.0, 10 * u.Hz, 1000 * u.ms)
>>> envelope = GaussianPulse(1.0, 500 * u.ms, 100 * u.ms, 1000 * u.ms)
>>> modulated = tri * envelope

Testing adaptation with slow ramps:

>>> adaptation_test = Triangular(
...     amplitude=20.0,
...     frequency=1 * u.Hz,
...     duration=5000 * u.ms
... )

Triangular wave with positive bias:

>>> positive_tri = Triangular(
...     amplitude=3.0,
...     frequency=5 * u.Hz,
...     duration=800 * u.ms,
...     bias=True  # Ramps between 0 and 6
... )

Create sawtooth approximation:

>>> # Combine triangular with step for asymmetric ramp
>>> tri = Triangular(1.0, 2 * u.Hz, 1000 * u.ms)
>>> from braintools.input import Step
>>> step = Step([0, 0.5], [0 * u.ms, 250 * u.ms], 1000 * u.ms)
>>> asymmetric = tri + step

Windowed triangular stimulation:

>>> windowed_tri = Triangular(
...     amplitude=4.0,
...     frequency=2 * u.Hz,
...     duration=3000 * u.ms,
...     t_start=500 * u.ms,
...     t_end=2500 * u.ms
... )

Notes

  • Ramps linearly between -amplitude and +amplitude

  • With bias=True, ramps between 0 and 2*amplitude

  • Peaks occur at 0, 0.5/frequency, 1/frequency, etc.

  • More suitable than sawtooth for symmetric ramping

  • Can be combined with other Input classes using +, -, *, /

See also

Sawtooth

Sawtooth wave generator

Sinusoidal

Sinusoidal wave generator

triangular

Functional API for triangular wave

__init__(amplitude, frequency, duration, t_start=None, t_end=None, bias=False)[source]#

Initialize the Input base class.

Parameters:

duration (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – The total duration of the input.

Methods

__init__(amplitude, frequency, duration[, ...])

Initialize the Input base class.

apply(func)

Apply a custom function to the input.

clip([min_val, max_val])

Clip the input values to a range.

generate()

Generate the triangular wave using the functional API.

repeat(n_times)

Repeat the input pattern n times.

scale(factor)

Scale the input by a factor.

shift(time_shift)

Shift the input in time.

smooth(tau)

Apply exponential smoothing to the input.

Attributes

dt

Get the time step from global environment.

n_steps

Get the number of time steps.

shape

Get the shape of the input array.