braintools.input.Sawtooth#

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

Composable sawtooth wave input generator.

Creates a sawtooth waveform that ramps up linearly and then drops sharply. This class is composable with other Input objects.

The sawtooth ramps from -amplitude to +amplitude, then resets instantly.

Parameters:
  • amplitude (float) – Peak amplitude of the sawtooth 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 sawtooth wave starts. Before this, output is 0. Default is 0.

  • t_end (Array | ndarray | bool | number | bool | int | float | complex | Quantity | None) – Time when sawtooth 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, ramps from -amplitude to +amplitude.

amplitude#

Peak amplitude of the sawtooth wave

Type:

float

frequency#

Frequency of oscillation in Hz

Type:

Quantity

t_start#

Start time of the sawtooth wave

Type:

float or Quantity

t_end#

End time of the sawtooth 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 sawtooth wave:

>>> saw = Sawtooth(1.0, 2 * u.Hz, 2000 * u.ms)
>>> signal = saw()

Slow ramp for threshold detection:

>>> threshold_test = Sawtooth(
...     amplitude=50.0,
...     frequency=0.5 * u.Hz,  # 2 second ramp
...     duration=4000 * u.ms
... )

Combine with DC offset:

>>> from braintools.input import Constant
>>> saw = Sawtooth(3.0, 3 * u.Hz, 1000 * u.ms)
>>> offset = Constant([(2.0, 1000 * u.ms)])
>>> shifted_saw = saw + offset

Fast reset testing:

>>> reset_test = Sawtooth(
...     amplitude=20.0,
...     frequency=20 * u.Hz,
...     duration=250 * u.ms
... )

Repeated ramp protocol:

>>> ramp_protocol = Sawtooth(
...     amplitude=100.0,
...     frequency=1 * u.Hz,
...     duration=10000 * u.ms
... )

Sawtooth with positive bias:

>>> positive_saw = Sawtooth(
...     amplitude=5.0,
...     frequency=4 * u.Hz,
...     duration=500 * u.ms,
...     bias=True  # Ramps from 0 to 10
... )

Modulated sawtooth:

>>> from braintools.input import Sinusoidal
>>> saw = Sawtooth(2.0, 5 * u.Hz, 1000 * u.ms)
>>> modulation = Sinusoidal(0.5, 1 * u.Hz, 1000 * u.ms, bias=True)
>>> modulated = saw * modulation

Windowed sawtooth stimulation:

>>> windowed_saw = Sawtooth(
...     amplitude=8.0,
...     frequency=3 * u.Hz,
...     duration=2000 * u.ms,
...     t_start=400 * u.ms,
...     t_end=1600 * u.ms
... )

Create staircase by clipping sawtooth:

>>> saw = Sawtooth(10.0, 1 * u.Hz, 3000 * u.ms)
>>> # Clip to create discrete levels
>>> staircase = saw.apply(lambda x: u.math.round(x / 2) * 2)

Notes

  • Ramps linearly from -amplitude to +amplitude, then resets

  • With bias=True, ramps from 0 to 2*amplitude

  • The ramp is continuous, reset is instantaneous

  • Useful for finding thresholds and testing reset mechanisms

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

See also

Triangular

Triangular wave generator

Ramp

Single linear ramp

sawtooth

Functional API for sawtooth 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 sawtooth 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.