braintools.input.Sinusoidal#
- class braintools.input.Sinusoidal(amplitude, frequency, duration, t_start=None, t_end=None, bias=False)#
Composable sinusoidal input generator.
Creates a sinusoidal waveform with specified amplitude and frequency. This class is composable, allowing mathematical operations with other Input objects to create complex stimulation protocols.
The sinusoidal waveform is defined as:
\[I(t) = A \sin(2\pi f t)\]where A is amplitude and f is frequency.
- Parameters:
amplitude (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Peak amplitude of the sinusoidal 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 sinusoid starts. Before this, output is 0. Default is 0.t_end (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – Time when sinusoid 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 around 0 (default).
- frequency#
Frequency of oscillation in Hz
- Type:
Quantity
Examples
>>> import brainunit as u >>> import brainstate >>> brainstate.environ.set(dt=0.1 * u.ms)
Create simple sinusoidal input:
>>> sine = Sinusoidal(1.0, 10 * u.Hz, 1000 * u.ms) >>> signal = sine()
Create amplitude-modulated signal:
>>> from braintools.input import Ramp >>> carrier = Sinusoidal(1.0, 100 * u.Hz, 500 * u.ms) >>> envelope = Ramp(0, 1, 500 * u.ms) >>> am_signal = carrier * envelope
Create frequency beats by combining sinusoids:
>>> sine1 = Sinusoidal(1.0, 10 * u.Hz, 1000 * u.ms) >>> sine2 = Sinusoidal(1.0, 11 * u.Hz, 1000 * u.ms) >>> beats = sine1 + sine2 # 1 Hz beat frequency
Create complex waveform with harmonics:
>>> fundamental = Sinusoidal(1.0, 5 * u.Hz, 2000 * u.ms) >>> third = Sinusoidal(0.3, 15 * u.Hz, 2000 * u.ms) >>> fifth = Sinusoidal(0.2, 25 * u.Hz, 2000 * u.ms) >>> complex_wave = fundamental + third + fifth
Test resonance with windowed sinusoid:
>>> resonance = Sinusoidal( ... amplitude=2.0, ... frequency=8 * u.Hz, # Theta frequency ... duration=5000 * u.ms, ... t_start=1000 * u.ms, ... t_end=4000 * u.ms ... )
Create phase-shifted sinusoids:
>>> sine1 = Sinusoidal(1.0, 10 * u.Hz, 1000 * u.ms) >>> # Shift by 250ms (90 degrees for 10Hz) >>> sine2 = sine1.shift(25 * u.ms) >>> quadrature = sine1 + sine2
Sinusoid with positive bias (rectified):
>>> positive_sine = Sinusoidal( ... amplitude=5.0, ... frequency=5 * u.Hz, ... duration=2000 * u.ms, ... bias=True # Oscillates between 0 and 10 ... )
Notes
Phase starts at 0 (sine wave starts at 0)
Frequency should be less than Nyquist frequency (1/(2*dt))
With bias=True, output ranges from 0 to 2*amplitude
Without bias, output ranges from -amplitude to +amplitude
Can be combined with other Input classes using +, -, *, /
See also
SquareSquare wave generator
ChirpFrequency sweep generator
NoisySinusoidalSinusoid with additive noise
sinusoidalFunctional API for sinusoidal input
- __init__(amplitude, frequency, duration, t_start=None, t_end=None, bias=False)[source]#
Initialize the Input base class.
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 sinusoidal input 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
dtGet the time step from global environment.
n_stepsGet the number of time steps.
shapeGet the shape of the input array.