Operator Calculus, Co.
Browse Studio documentation

GUI Examples

Examples of intermediate complexity that demonstrate useful patterns while remaining relatively readable.

1) Two-field FM synthesis

Combines a carrier and modulator so the carrier phase becomes

c(t)=Acei(ωct+0.5 sin⁡ωmt),c(t) = A_c e^{i(\omega_c t + 0.5\,\sin \omega_m t)},

giving a modulation index of 0.50.5 controlled by the mixer.

local N = 512
local dt = 0.001
local ctx = ooc.create()

ooc.set_timestep(ctx, dt)
ooc.set_visual_mode(ctx, "phase_portrait")

local carrier = ooc.add_field(ctx, {N}, {
    type = "complex_double",
    fill = {0, 0}
})

local mod = ooc.add_field(ctx, {N}, {
    type = "complex_double",
    fill = {0, 0}
})

ooc.add_stimulus_operator(ctx, carrier, {
    type = "stimulus_sine",
    amplitude = 0.2,
    wavenumber = 0.25,
    omega = 0.3,
    scale_by_dt = true
})

ooc.add_stimulus_operator(ctx, mod, {
    type = "stimulus_sine",
    amplitude = 0.1,
    wavenumber = 0.5,
    omega = 0.05,
    scale_by_dt = false
})

ooc.add_mixer_operator(ctx, carrier, mod, carrier, {
    mode = "fm",
    rhs_gain = 0.5,
    scale_by_dt = true
})

local integrator = ooc.create_context_integrator(ctx, "rkf45", {
    initial_dt = dt,
    adaptive = true
})

ooc.set_integrator(ctx, integrator)

return ctx

Example output:

Phase portrait from two-field FM synthesis, with blue and orange looping traces around the center of a polar grid.

2) Dispersion Playground

Tune coefficient and order of a dispersion operator applied to a chirped stimulus.

local ctx = ooc.create()
local dt = 0.0125
local N = 512

ooc.set_timestep(ctx, dt)
ooc.set_visual_mode(ctx, "waveform")

local field = ooc.add_field(ctx, {N}, {
    type = "complex_double",
    fill = {0, 0}
})

ooc.add_stimulus_operator(ctx, field, {
    type = "stimulus_chirp",
    amplitude = 0.25,
    wavenumber = 0.07,
    omega = -0.27,
    phase = math.pi / 4,
    kdot = -0.096,
    wdot = 0.012,
    scale_by_dt = true
})

ooc.add_dispersion_operator(ctx, field, {
    coefficient = 0.75,
    order = 1.05,
    spacing = 0.02
})

local integrator = ooc.create_context_integrator(ctx, "rkf45", {
    initial_dt = dt
})

ooc.set_integrator(ctx, integrator)

return ctx

3) Phase modulation with feedback

Implements a phase modulation system with feedback, where the phase of field_2 is modulated by field_1, which in turn is influenced by field_2’s previous state through a mixer operator with feedback parameters.

local N = 768
local dt = 0.025

local ctx = ooc.create()

ooc.set_timestep(ctx, dt)
ooc.set_visual_mode(ctx, "phase_portrait")

local field_1 = ooc.add_field(ctx, {N}, {
    type = "complex_double",
    fill = {0.0, 0.0}
})

local field_2 = ooc.add_field(ctx, {N}, {
    type = "complex_double",
    fill = {0.0, 0.0}
})

ooc.add_mixer_operator(ctx, field_2, field_1, field_1, {
    mode = "linear",
    lhs_gain = 0,
    rhs_gain = 0
})

ooc.add_stimulus_operator(ctx, field_2, {
    type = "stimulus_sine",
    amplitude = 0.5,
    wavenumber = 1,
    omega = -0.43,
    spacing = 1,
    rotation = math.pi/2
})

ooc.add_stimulus_operator(ctx, field_2, {
    type = "stimulus_spectral_lines",
    amplitude = 0.2,
    wavenumber = 1,
    omega = 0.01,
    phase = 4.8,
    spacing = 1,
    harmonic_power = 0.9,
    harmonic_count = 2
})

ooc.add_stimulus_operator(ctx, field_1, {
    type = "stimulus_sine",
    amplitude = 1,
    wavenumber = 1,
    omega = -0.25,
    spacing = 0.18,
    rotation = 0
})

ooc.add_mixer_operator(ctx, field_2, field_1, field_1, {
    mode = "pm",
    lhs_gain = 1.0,
    rhs_gain = 1.0,
    feedback_decay = 1.0,
    feedback_strength = 1.8
})

local integrator = ooc.create_context_integrator(ctx, "rkf45", {
    initial_dt = dt
})

ooc.set_integrator(ctx, integrator)

return ctx

Example output:

Phase portrait from phase modulation with feedback, with blue and orange traces forming a ring around an open center.