AnyLearn
All lessons
Roboticsadvanced

The Mathematics of Coupled Oscillators

How a handful of phase oscillators produce coordinated gaits: limit cycles and why they resist disturbance, phase coupling that locks oscillators into fixed relationships, and the travelling waves that swim a robot.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 8

The phase oscillator

The mathematical core of a CPG is simpler than the biology suggests. Start with the simplest possible oscillator.

Represent one rhythmic unit by a single variable, its phase θ\theta, a number that advances continuously and wraps around at 2π2\pi. Its dynamics are one equation:

θ˙=ω\dot{\theta} = \omega

The phase advances at constant rate ω\omega, the intrinsic frequency. Output any periodic function of the phase, typically a sinusoid, and you have a rhythm.

The reason to work with phase rather than the output signal directly is that phase makes relationships between oscillators expressible. Two oscillators are in step if their phases match, in antiphase if they differ by π\pi, and locomotion is largely about maintaining such relationships.

A phase alone has no amplitude, so practical CPGs use an amplitude-phase formulation, adding a second variable r whose dynamics converge to a target amplitude. That gives independent control of how fast the rhythm runs and how large the resulting motion is, which maps directly onto frequency and stride length.

Everything that follows is built from coupling these units together.

Full lesson text

All 8 steps on one page, for reading, reference, and search.

Show

1. The phase oscillator

The mathematical core of a CPG is simpler than the biology suggests. Start with the simplest possible oscillator.

Represent one rhythmic unit by a single variable, its phase θ\theta, a number that advances continuously and wraps around at 2π2\pi. Its dynamics are one equation:

θ˙=ω\dot{\theta} = \omega

The phase advances at constant rate ω\omega, the intrinsic frequency. Output any periodic function of the phase, typically a sinusoid, and you have a rhythm.

The reason to work with phase rather than the output signal directly is that phase makes relationships between oscillators expressible. Two oscillators are in step if their phases match, in antiphase if they differ by π\pi, and locomotion is largely about maintaining such relationships.

A phase alone has no amplitude, so practical CPGs use an amplitude-phase formulation, adding a second variable r whose dynamics converge to a target amplitude. That gives independent control of how fast the rhythm runs and how large the resulting motion is, which maps directly onto frequency and stride length.

Everything that follows is built from coupling these units together.

2. Limit cycles and why they matter

The amplitude equation is where the robustness comes from, and it is worth seeing why.

A typical form drives the amplitude toward a target R:

r¨=a(a4(Rr)r˙)\ddot{r} = a\left(\frac{a}{4}(R - r) - \dot{r}\right)

The details matter less than the behaviour: whatever amplitude the system starts at, it converges smoothly to R and stays there.

Combined with the advancing phase, the system's trajectory in state space settles onto a closed loop, a circle of radius R traversed at rate ω\omega. That closed orbit is a limit cycle, and it is attracting: perturb the state off it and the dynamics bring it back.

Contrast this with tracking a stored trajectory. If a disturbance knocks a trajectory-tracking robot off its reference, the controller must detect the error and drive it to zero, and the reference itself keeps advancing on its own clock regardless of what the robot is doing.

A limit cycle system has no reference to fall behind. Push it and it returns to the orbit, having naturally adjusted its phase rather than accumulating a tracking error.

This is stability as a property of the system's dynamics rather than as a job assigned to a controller, and it is why CPG-driven robots tolerate rough terrain without special handling.

3. Coupling

One oscillator gives rhythm. Locomotion needs coordination, and coordination comes from coupling.

Add to each oscillator's phase equation a term depending on its neighbours' phases:

θ˙i=ωi+jwijsin(θjθiϕij)\dot{\theta}_i = \omega_i + \sum_{j} w_{ij} \sin(\theta_j - \theta_i - \phi_{ij})

Three ingredients control everything.

wijw_{ij} is the coupling strength: how hard oscillator j pulls on oscillator i.

ϕij\phi_{ij} is the desired phase bias: the relationship the coupling drives toward.

The sine term is the error. When the actual phase difference θjθi\theta_j - \theta_i equals ϕij\phi_{ij}, the sine is zero and the coupling does nothing. Otherwise it pushes to correct the difference, in the direction that reduces it.

So the coupling is a restoring force on phase relationships. Given enough coupling strength relative to the spread of intrinsic frequencies, the oscillators lock into the specified relative phases and run at a common frequency.

That locking is the whole mechanism. A gait is nothing more than a set of phase relationships between limbs, and the coupling parameters encode it.

4. Gaits as phase relationships

The claim becomes concrete when you write out the quadruped gaits. Number the legs left front, right front, left hind, right hind, and give each leg's phase as a fraction of the cycle.

Trot        LF 0.0   RF 0.5   LH 0.5   RH 0.0
            diagonal pairs move together

Pace        LF 0.0   RF 0.5   LH 0.0   RH 0.5
            lateral pairs move together

Bound       LF 0.0   RF 0.0   LH 0.5   RH 0.5
            front pair, then hind pair

Walk        LF 0.0   RF 0.5   LH 0.25  RH 0.75
            one foot lifted at a time

Every gait is the same oscillator network with different phase biases. Nothing else changes: not the equations, not the number of oscillators, not the amplitude dynamics.

This is a large simplification of the control problem. Switching gait means interpolating a handful of numbers, and because the coupling drives smoothly toward the new relationships, the transition is continuous rather than a discontinuous jump between two stored trajectories.

Animals switch gaits at particular speeds, and the same structure appears in CPG models: as drive changes, the stable phase configuration can shift, which is the subject of the next lesson.

5. From oscillators to motion

The pipeline is short, and each stage maps to a parameter you can set. Frequency sets speed, amplitude sets stride, and phase biases set the gait, with the limit cycle providing robustness underneath all of it.

flowchart TD
  A["One oscillator per joint or limb"] --> B["Phase advances at intrinsic frequency"]
  A --> C["Amplitude converges to target"]
  B --> D["Coupling terms pull phases toward desired biases"]
  C --> D
  D --> E["Network locks into a common frequency"]
  E --> F["Phase biases define the gait"]
  F --> G["Oscillator output becomes joint commands"]
  E --> H["Attracting limit cycle absorbs disturbances"]

6. Travelling waves for swimming

Swimming uses the same machinery with a different coupling topology, and the result is worth seeing because it explains the salamander.

Arrange oscillators in a chain along the body, each coupled to its immediate neighbours, and set a small constant phase lag between adjacent segments. Segment 2 lags segment 1 by a small amount, segment 3 lags segment 2 by the same amount, and so on.

The result is a travelling wave: the bending pattern propagates from head to tail, which is precisely how a lamprey or eel swims.

Two parameters carry the behaviour. The total phase lag across the body determines how many wavelengths fit along it, and setting it to about one full cycle produces roughly one wavelength on the body, matching what real anguilliform swimmers do. Reversing the sign of the lag reverses the wave direction and swims the robot backwards.

Standing waves come from the same chain with zero lag, so all segments bend in phase.

So one chain of coupled oscillators produces a travelling wave for swimming or a standing wave for walking, depending on a single parameter. That is the mathematical form of the evolutionary hypothesis: the same circuit, differently modulated, does both.

7. Implementing one

The whole controller is short enough to read.

import numpy as np

def cpg_step(theta, r, omega, R, W, PHI, a, dt):
    n = len(theta)
    dtheta = omega.copy()

    # phase coupling: pull toward the desired phase biases
    for i in range(n):
        for j in range(n):
            if W[i, j] != 0:
                dtheta[i] += W[i, j] * np.sin(theta[j] - theta[i] - PHI[i, j])

    # amplitude converges smoothly toward its target
    dr = a * (R - r)

    theta = (theta + dtheta * dt) % (2 * np.pi)
    r = r + dr * dt

    joint_cmd = r * np.cos(theta)      # output signal
    return theta, r, joint_cmd

The control interface is exactly three things. omega sets speed. R sets stride amplitude. PHI sets the gait.

Notice what is absent. There is no trajectory, no reference to track, no error to compute, no plan to store or re-plan. The commands emerge from integrating a small set of coupled differential equations, and the cost is a handful of arithmetic operations per timestep, cheap enough for a microcontroller.

That is the practical payoff of the whole formulation, and the next lesson shows it running on a real amphibious robot.

8. What the parameters control

A summary of the design surface, since tuning a CPG means choosing these.

ParameterControlsTypical use
Intrinsic frequencyCycle rateSpeed of locomotion
Target amplitudeMotion sizeStride length, turning by asymmetry
Phase bias matrixRelative timingWhich gait is produced
Coupling strengthHow rigidly phases lockRobustness versus flexibility
Chain phase lagWave along the bodySwimming versus standing wave
Amplitude gainConvergence speedHow fast transitions settle

Two gotchas that appear immediately in practice.

Coupling strength is a genuine trade-off. Too weak and the oscillators fail to lock, so the gait falls apart under load or when intrinsic frequencies differ. Too strong and the network becomes rigid, unable to be entrained by sensory feedback, which throws away one of the architecture's main advantages.

Turning comes from asymmetry, not steering. There is no steering input. You turn by making one side's amplitude larger than the other's, or by biasing the phase relationship between them, so direction is a modulation of the same rhythm rather than a separate control channel.

That pattern, everything as modulation of one running pattern, is what the next lesson demonstrates on hardware.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Why does a limit cycle give better disturbance rejection than trajectory tracking?
    • Limit cycles require no sensors to implement
    • The system returns to its orbit intrinsically, adjusting phase rather than accumulating tracking error against an advancing reference
    • Limit cycles are guaranteed to be energy optimal
    • Trajectory tracking cannot represent periodic motion
  2. In the phase coupling term, what happens when the actual phase difference equals the desired phase bias?
    • The oscillator amplitude is driven to zero
    • The coupling reverses sign to prevent overshoot
    • The sine term becomes zero and the coupling exerts no influence
    • The intrinsic frequency is overridden by the neighbour's frequency
  3. What distinguishes a trot from a pace in a CPG controller?
    • Only the phase biases differ; the equations and network are identical
    • The trot uses more oscillators than the pace
    • The pace requires a higher intrinsic frequency
    • The trot uses phase coupling while the pace uses amplitude coupling
  4. How does a chain of coupled oscillators produce swimming motion?
    • By synchronising all segments to zero phase difference
    • By oscillating alternate segments at different frequencies
    • By coupling only the head and tail segments together
    • By setting a small constant phase lag between adjacent segments, producing a travelling wave down the body
  5. Why can coupling strength be set too high?
    • It causes the intrinsic frequencies to drift apart
    • The network becomes too rigid to be entrained by sensory feedback
    • It makes the amplitude equation unstable
    • It prevents gait transitions from completing

Related lessons