braintools.input.sawtooth#
- braintools.input.sawtooth(amplitude, frequency, duration, t_start=None, t_end=None, bias=False)#
Generate sawtooth wave current input.
Creates a sawtooth waveform that ramps up linearly and then drops sharply. Useful for testing reset dynamics, asymmetric responses, and ramp sensitivity.
- Parameters:
amplitude (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Peak amplitude of the sawtooth 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 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.
- Returns:
current – The sawtooth wave current array with shape (n_timesteps,).
- Return type:
ndarray or Quantity
- Raises:
AssertionError – If frequency is not in Hz units.
Examples
>>> import brainunit as u >>> import brainstate >>> brainstate.environ.set(dt=0.1 * u.ms)
Simple sawtooth at 2 Hz
>>> current = sawtooth( ... amplitude=10 * u.pA, ... frequency=2 * u.Hz, ... duration=2000 * u.ms ... )
Slow ramp for threshold detection
>>> current = sawtooth( ... amplitude=50 * u.pA, ... frequency=0.5 * u.Hz, # 2 second ramp ... duration=4000 * u.ms ... )
Sawtooth with positive bias
>>> current = sawtooth( ... amplitude=5 * u.nA, ... frequency=10 * u.Hz, ... duration=500 * u.ms, ... bias=True # Ramps from 0 to 10 nA ... )
Windowed sawtooth stimulation
>>> current = sawtooth( ... amplitude=8 * u.pA, ... frequency=5 * u.Hz, ... duration=2000 * u.ms, ... t_start=400 * u.ms, ... t_end=1600 * u.ms ... )
Fast sawtooth for reset testing
>>> current = sawtooth( ... amplitude=20 * u.pA, ... frequency=20 * u.Hz, ... duration=250 * u.ms ... )
Repeated ramp protocol
>>> current = sawtooth( ... amplitude=100 * u.pA, ... frequency=1 * u.Hz, ... duration=10000 * u.ms ... )
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