Skip to content
Oakfield Operator Calculus Function Reference Site

Potential & Stimulus Operators

All stimulus operators take a destination field and an options table; most support scale_by_dt (bool) to scale writes by the simulation timestep.

Most spatial stimuli support alternate coordinate mappings (2D, angle, radial). Applies to: stimulus_sine, stimulus_standing, stimulus_chirp, stimulus_gaussian_pulse, stimulus_spectral_lines, stimulus_checkerboard, stimulus_gabor, stimulus_digamma_square, digamma_square_warp.

ParameterTypeDefaultDescription
coord_modeenum "axis"Coordinate mode: axis, angle, radial, separable
coord_axisenum "x"Axis for coord_mode = "axis"
coord_combineenum "multiply"Separable combine rule: multiply, add
coord_angledouble 0.0Angle for coord_mode = "angle" (radians)
origin_x, origin_ydouble 0.0Coordinate origin for 2D mappings
spacing_x, spacing_ydouble 1.0Coordinate spacing for 2D mappings
coord_center_x, coord_center_ydouble 0.0Radial coordinate center (units)
coord_velocity_x, coord_velocity_ydouble 0.0Radial center velocity (units/s)

Wavevector overrides (for stimulus_sine, stimulus_chirp, stimulus_spectral_lines, stimulus_gabor):

ParameterTypeDefaultDescription
kx, kydouble 0.0Wavevector components (rad/unit)
use_wavevectorboolean falseUse kx/ky instead of wavenumber + coordinate mapping
ParameterTypeDefaultDescription
amplitudedouble Peak output amplitude (before dt scaling)
wavenumberdouble Spatial wavenumber k (rad/unit)
omegadouble Angular frequency (rad/s)
phasedouble 0.0Phase offset (radians)
time_offsetdouble 0.0Shift time by constant before evaluation
nominal_dtdouble 0.0Fixed timestep for fixed_clock = true
fixed_clockboolean falseLock evolution to nominal_dt
scale_by_dtboolean trueMultiply write by dt
rotationdouble 0.0Complex phase rotation on output (radians)

sim_add_stimulus_operator(ctx, field, opts)

Generate a travelling sinusoidal wave. Fundamental building block for wave propagation, oscillating forcing, and harmonic analysis.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_sine".

u(x,t)=Asin(kxωt+ϕ)u(x, t) = A \cdot \sin(k \cdot x - \omega \cdot t + \phi)

where:

  • AA is the amplitude
  • kk is the wavenumber
  • ω\omega is the angular frequency
  • ϕ\phi is the phase offset

Phase velocity: vp=ω/kv_p = \omega / k

ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_sine"
amplitudedouble unboundedPeak amplitude (required)
wavenumberdouble unboundedSpatial wavenumber k (required)
omegadouble unboundedAngular frequency (required)
phasedouble 0.0unboundedPhase offset (radians)
time_offsetdouble 0.0unboundedTemporal shift
rotationdouble 0.0unboundedComplex phase rotation
nominal_dtdouble 0.0≥0Fixed timestep
fixed_clockboolean falseUse nominal_dt
scale_by_dtboolean trueScale by dt

Plus all shared coordinate mapping parameters.

-- Basic travelling wave
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_sine",
amplitude = 0.3,
wavenumber = 1.0,
omega = 0.6
})
-- Standing-like behavior (omega = 0)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_sine",
amplitude = 0.5,
wavenumber = 2.0,
omega = 0.0,
phase = math.pi / 4
})
-- 2D wavevector specification
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_sine",
amplitude = 0.4,
use_wavevector = true,
kx = 0.5,
ky = 0.5,
omega = 1.0
})

sim_add_stimulus_operator(ctx, field, opts)

Generate a standing-wave sinusoid with fixed nodes and antinodes. Models resonant cavity modes and stationary vibration patterns.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_standing".

u(x,t)=Asin(kx+ϕ)cos(ωt)u(x, t) = A \cdot \sin(k \cdot x + \phi) \cdot \cos(\omega \cdot t)

Equivalently, this is the superposition of two counter-propagating waves:

u=A2[sin(kxωt)+sin(kx+ωt)]u = \frac{A}{2}[\sin(kx - \omega t) + \sin(kx + \omega t)]
  • Nodes: Points where sin(kx+ϕ)=0\sin(kx + \phi) = 0 (always zero)
  • Antinodes: Points where sin(kx+ϕ)=1|\sin(kx + \phi)| = 1 (maximum oscillation)

Same as stimulus_sine:

ParameterTypeDefaultDescription
typestring Must be "stimulus_standing"
amplitudedouble Peak amplitude (required)
wavenumberdouble Spatial wavenumber (required)
omegadouble Angular frequency (required)
phasedouble 0.0Controls node/antinode placement

Plus timing and coordinate parameters.

-- Basic standing wave
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_standing",
amplitude = 0.4,
wavenumber = 0.8,
omega = 0.8,
phase = 0.25
})
-- Half-wavelength shifted nodes
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_standing",
amplitude = 0.5,
wavenumber = 1.0,
omega = 1.0,
phase = math.pi / 2
})

sim_add_stimulus_operator(ctx, field, opts)

Generate a sinusoid with time-varying frequency and/or wavenumber. Models frequency sweeps, dispersive waves, and time-frequency analysis signals.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_chirp".

u(x,t)=Asin((k0+k˙t)x(ω0+ω˙t)t+ϕ)u(x, t) = A \cdot \sin\left((k_0 + \dot{k}t) \cdot x - (\omega_0 + \dot{\omega}t) \cdot t + \phi\right)

where:

  • k0k_0 is the initial wavenumber
  • k˙\dot{k} is kdot (wavenumber rate)
  • ω0\omega_0 is the initial angular frequency
  • ω˙\dot{\omega} is wdot (frequency rate)

Instantaneous frequency: f(t)=ω0+ω˙t2πf(t) = \frac{\omega_0 + \dot{\omega}t}{2\pi}

ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_chirp"
amplitudedouble unboundedPeak amplitude (required)
wavenumberdouble unboundedInitial wavenumber (required)
omegadouble unboundedInitial angular frequency (required)
kdotdouble 0.0unboundedWavenumber rate (rad/unit/s)
wdotdouble 0.0unboundedFrequency rate (rad/s²)
phasedouble 0.0unboundedPhase offset
rotationdouble 0.0unboundedComplex phase rotation
time_offsetdouble 0.0unboundedTemporal shift

Plus timing and coordinate parameters.

-- Linear frequency chirp
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_chirp",
amplitude = 0.5,
wavenumber = 1.0,
omega = 0.3,
kdot = 0.1,
wdot = 0.2
})
-- Spatial chirp only
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_chirp",
amplitude = 0.4,
wavenumber = 0.5,
omega = 1.0,
kdot = 0.5,
wdot = 0.0
})

sim_add_stimulus_operator(ctx, field, opts)

Generate a pure Gaussian envelope without carrier oscillation. Models localized pulses, initial conditions, and smooth spatial masks.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_gaussian_pulse".

1D:

u(x,t)=Aexp((xx0vt)22σ2)u(x, t) = A \cdot \exp\left(-\frac{(x - x_0 - v \cdot t)^2}{2\sigma^2}\right)

2D separable:

u(x,y,t)=Aexp((xx0vxt)22σx2(yy0vyt)22σy2)u(x, y, t) = A \cdot \exp\left(-\frac{(x - x_0 - v_x t)^2}{2\sigma_x^2} - \frac{(y - y_0 - v_y t)^2}{2\sigma_y^2}\right)
ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_gaussian_pulse"
amplitudedouble unboundedPeak amplitude (required)
center_x, center_ydouble 0.0unbounded1D/2D center position
sigma_x, sigma_ydouble 1.0>01D/2D standard deviations
velocity_x, velocity_ydouble 0.0unbounded1D/2D velocities
time_offsetdouble 0.0unboundedTemporal shift
rotationdouble 0.0unboundedComplex phase rotation

Plus timing parameters.

-- Static 1D Gaussian
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_gaussian_pulse",
coord_center_x = 128,
sigma_x = 30,
amplitude = 1.0
})
-- Moving pulse
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_gaussian_pulse",
coord_center_x = 0,
sigma_x = 10,
amplitude = 0.5,
velocity_x = 2.0
})
-- 2D elliptical Gaussian
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_gaussian_pulse",
amplitude = 0.8,
coord_mode = "separable",
coord_center_x = 128,
coord_center_y = 128,
sigma_x = 20,
sigma_y = 40
})

sim_add_stimulus_operator(ctx, field, opts)

Generate harmonic series with configurable power weighting. Models multi-tone signals, harmonic oscillators, and comb-like spectra.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_spectral_lines".

u(x,t)=An=1Nnpsin(nkxnωt+ϕ)u(x, t) = A \sum_{n=1}^{N} n^{-p} \cdot \sin(n \cdot k \cdot x - n \cdot \omega \cdot t + \phi)

where:

  • NN is harmonic_count
  • pp is harmonic_power
  • Higher pp reduces high-frequency content

Special cases:

  • p=0p = 0: Equal amplitude harmonics
  • p=1p = 1: 1/n1/n amplitude decay (approaching square wave)
  • p=2p = 2: 1/n21/n² amplitude decay (faster rolloff)
ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_spectral_lines"
amplitudedouble unboundedPeak amplitude (required)
wavenumberdouble unboundedFundamental wavenumber
omegadouble unboundedFundamental frequency
phasedouble 0.0unboundedPhase offset
harmonic_countinteger 1≥1Number of harmonics
harmonic_powerdouble 0.0≥0Power weighting exponent

Plus timing and coordinate parameters.

-- Single fundamental
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_spectral_lines",
amplitude = 1.0,
wavenumber = 0.5,
harmonic_count = 1
})
-- Rich harmonic content
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_spectral_lines",
amplitude = 0.2,
harmonic_count = 4,
harmonic_power = 0.9,
fixed_clock = true
})
-- Square-wave approximation (odd harmonics with 1/n decay)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_spectral_lines",
amplitude = 0.5,
wavenumber = 1.0,
omega = 1.0,
harmonic_count = 8,
harmonic_power = 1.0
})

sim_add_stimulus_operator(ctx, field, opts)

Generate bandlimited waveforms using BLIT, PolyBLEP, or miniBLEP synthesis. Produces alias-free sawtooth, square, and triangle waves.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_fourier".

Sawtooth (ideal):

u(t)=A(tτmod10.5)u(t) = A \cdot \left(\frac{t}{\tau} \mod 1 - 0.5\right)

Square (ideal):

u(t)=Asign(sin(2πtτ))u(t) = A \cdot \text{sign}\left(\sin\left(\frac{2\pi t}{\tau}\right)\right)

Triangle (ideal):

u(t)=A(4tτmod10.51)u(t) = A \cdot \left(4 \left|\frac{t}{\tau} \mod 1 - 0.5\right| - 1\right)

The method parameter selects the anti-aliasing technique:

  • blit: Band-Limited Impulse Train
  • polyblep: Polynomial BLEP correction
  • miniblep: Minimum-phase BLEP
ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_fourier"
amplitudedouble unboundedWaveform amplitude (required)
frequencydouble >0Fundamental frequency in Hz (required)
shapeenum "saw"see belowWaveform shape
methodenum "polyblep"see belowAnti-aliasing method
dutydouble 0.5[0, 1]Duty cycle for square/triangle
phasedouble 0.0[0, 1)Initial phase in cycles
rotationdouble 0.0unboundedComplex phase rotation

Shape options: saw, square, triangle

Method options: blit, polyblep, miniblep

Plus timing parameters.

-- Bandlimited sawtooth at 440 Hz
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fourier",
amplitude = 0.8,
frequency = 440.0,
shape = "saw",
method = "polyblep"
})
-- Square wave with 25% duty cycle
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fourier",
amplitude = 0.5,
frequency = 220.0,
shape = "square",
duty = 0.25
})
-- Triangle wave
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fourier",
amplitude = 0.6,
frequency = 110.0,
shape = "triangle"
})

sim_add_stimulus_operator(ctx, field, opts)

Generate checker or stripe patterns. Works on complex fields with configurable periods and phase.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_checkerboard".

u(x,y)=Asign(sin(2πxPx)sin(2πyPy))eiϕcu(x, y) = A \cdot \text{sign}\left(\sin\left(\frac{2\pi x}{P_x}\right) \cdot \sin\left(\frac{2\pi y}{P_y}\right)\right) \cdot e^{i\phi_c}

where:

  • PxP_x, PyP_y are the periods
  • ϕc\phi_c is the complex phase rotation

Setting one period to infinity produces stripes along that axis.

ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_checkerboard"
amplitudedouble unboundedPattern amplitude (required)
period_xdouble 8.0>0X-axis period (samples)
period_ydouble 8.0>0Y-axis period (samples)
phasedouble 0.0unboundedScalar phase offset
complex_phasedouble 0.0unboundedComplex rotation (radians)
scale_by_dtboolean trueScale by dt
-- Standard checkerboard
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_checkerboard",
amplitude = 1.0,
period_x = 8,
period_y = 8
})
-- Rectangular cells with complex phase
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_checkerboard",
amplitude = 0.5,
period_x = 12,
period_y = 6,
complex_phase = 0.75
})
-- Vertical stripes (large period_y)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_checkerboard",
amplitude = 0.8,
period_x = 16,
period_y = 1000
})

sim_add_stimulus_operator(ctx, field, opts)

Generate a Gaussian-windowed sinusoid (Gabor function). Optimal for joint time-frequency localization and models neural receptive fields.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_gabor".

1D:

u(x,t)=Aexp((xx0vt)22σ2)sin(k(xx0)ωt+ϕ)u(x, t) = A \cdot \exp\left(-\frac{(x - x_0 - vt)^2}{2\sigma^2}\right) \cdot \sin(k(x - x_0) - \omega t + \phi)

2D with envelope rotation:

u(x,y,t)=Aexp(x22σx2y22σy2)sin(kxx+kyyωt+ϕ)u(x, y, t) = A \cdot \exp\left(-\frac{x'^2}{2\sigma_x^2} - \frac{y'^2}{2\sigma_y^2}\right) \cdot \sin(k_x x' + k_y y' - \omega t + \phi)

where (x,y)(x', y') are coordinates rotated by envelope_angle.

ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_gabor"
amplitudedouble unboundedPeak amplitude (required)
wavenumberdouble unboundedCarrier wavenumber
omegadouble 0.0unboundedCarrier frequency
phasedouble 0.0unboundedCarrier phase
center_x, center_ydouble 0.0unbounded1D/2D center
sigma_x, sigma_ydouble 1.0>01D/2D envelope widths
velocity_x, velocity_ydouble 0.0unbounded1D/2D velocities
envelope_angledouble 0.0unboundedEnvelope rotation (radians)
rotationdouble 0.0unboundedComplex output rotation
time_offsetdouble 0.0unboundedTemporal shift

Plus timing parameters.

-- 1D Gabor wavelet
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_gabor",
amplitude = 0.4,
sigma_x = 12.0,
wavenumber = 0.5
})
-- Moving Gabor pulse
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_gabor",
amplitude = 0.2,
omega = 0.5,
rotation = 0.3,
coord_center_x = 64,
sigma_x = 20,
velocity_x = 1.0
})
-- 2D oriented Gabor (receptive field model)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_gabor",
amplitude = 0.5,
coord_mode = "separable",
coord_center_x = 128,
coord_center_y = 128,
sigma_x = 15,
sigma_y = 30,
wavenumber = 0.3,
envelope_angle = math.pi / 4
})

sim_add_digamma_square_operator(ctx, field, opts)

Generate a digamma-based square wave driver. Uses the digamma function to produce bandlimited waveforms with reduced aliasing and controllable harmonics.

sim_add_digamma_square_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

The digamma square wave approximates:

u(x,t)=AIm[ψ(12+iHsin(kxωt+ϕ))]u(x, t) = A \cdot \text{Im}\left[\psi\left(\frac{1}{2} + iH\sin(kx - \omega t + \phi)\right)\right]

where ψ\psi is the digamma function and HH is the harmonics parameter controlling bandwidth.

Shape variants:

  • default: Standard square wave approximation
  • sawtooth: Asymmetric rising/falling
  • triangle: Linear interpolation between extrema
ParameterTypeDefaultRangeDescription
amplitudedouble unboundedPeak amplitude (required)
wavenumberdouble unboundedSpatial wavenumber (required)
omegadouble unboundedAngular frequency (required)
phasedouble 0.0unboundedPhase offset
time_offsetdouble 0.0unboundedTemporal shift
harmonicsdouble 4.0[0.25, 12]Harmonic content control
shapeenum "default"see belowWaveform shape
backendenum "12_tail"see belowDigamma computation method
tolerancedouble 1e-12≥0Tolerance for adaptive backend
rotationdouble 0.0unboundedComplex phase rotation

Shape options: default, sawtooth, triangle

Backend options: 5_tail, 7_tail, 12_tail, adaptive, mortici

Plus timing parameters.

-- Basic digamma square wave
ooc.sim_add_digamma_square_operator(ctx, field, {
amplitude = 0.3,
wavenumber = 1.0,
omega = 0.6,
harmonics = 6.0
})
-- Sawtooth variant
ooc.sim_add_digamma_square_operator(ctx, field, {
amplitude = 0.5,
wavenumber = 0.8,
omega = 1.0,
shape = "sawtooth",
harmonics = 8.0
})
-- High-precision adaptive backend
ooc.sim_add_digamma_square_operator(ctx, field, {
amplitude = 0.4,
wavenumber = 1.0,
omega = 0.5,
backend = "adaptive",
tolerance = 1e-14
})

sim_add_digamma_square_warp_operator(ctx, field, warp, opts)

Generate a digamma square wave modulated by an external warp field. Enables complex pattern generation through field-driven modulation.

sim_add_digamma_square_warp_operator(ctx, field, warp, [options]) -> operator

Returns: Operator handle (userdata)

The warp field modulates the base digamma square wave:

u(x,t)=f(digamma_square(x,t),w(x)m+b)u(x, t) = f\left(\text{digamma\_square}(x, t), w(x) \cdot m + b\right)

where:

  • w(x)w(x) is the warp field value
  • mm is warp_mix
  • bb is warp_bias
  • ff is the mixing function determined by warp_mode

Warp modes:

  • sum: out=base+wm+b\text{out} = \text{base} + w \cdot m + b
  • multiply: out=base(wm+b)\text{out} = \text{base} \cdot (w \cdot m + b)
  • crossfade: out=(1m)base+mw\text{out} = (1 - m) \cdot \text{base} + m \cdot w
ParameterTypeDefaultRangeDescription
amplitudedouble unboundedPeak amplitude (required)
wavenumberdouble unboundedSpatial wavenumber (required)
omegadouble unboundedAngular frequency (required)
phasedouble 0.0unboundedPhase offset
time_offsetdouble 0.0unboundedTemporal shift
harmonicsdouble 4.0[0.25, 12]Harmonic content
warp_mixdouble 1.0unboundedWarp mixing factor
warp_biasdouble 0.0unboundedWarp bias
warp_modeenum "sum"see belowMixing strategy
shapeenum "default"see belowWaveform shape
backendenum "12_tail"see belowDigamma backend
tolerancedouble 1e-12≥0Adaptive tolerance
rotationdouble 0.0unboundedComplex rotation

Warp mode options: sum, multiply, crossfade

Shape options: default, sawtooth, triangle

Backend options: 5_tail, 7_tail, 12_tail, adaptive, mortici

Plus timing parameters.

-- Crossfade between digamma square and warp field
ooc.sim_add_digamma_square_warp_operator(ctx, field, warp, {
amplitude = 0.3,
wavenumber = 1.0,
omega = 0.6,
warp_mode = "crossfade",
warp_mix = 0.5,
harmonics = 8.0
})
-- Additive warp modulation
ooc.sim_add_digamma_square_warp_operator(ctx, field, warp, {
amplitude = 0.4,
wavenumber = 0.8,
omega = 1.0,
warp_mode = "sum",
warp_mix = 0.3,
warp_bias = 0.1
})
-- Multiplicative warp (AM-like)
ooc.sim_add_digamma_square_warp_operator(ctx, field, warp, {
amplitude = 0.5,
wavenumber = 1.0,
omega = 0.5,
warp_mode = "multiply",
warp_mix = 2.0
})