This simulation models a damped harmonic oscillator where a key physical parameter, the restoring force constant (represented by
The simulation uses a set of ordinary differential equations (ODEs) solved numerically with odeint
or solve_ivp
from scipy
. The system’s behavior is governed by three interconnected variables:
-
Position (
$x$ ) and velocity ($v$ ): fast-evolving state of the oscillator. -
Theta (
$\theta$ ): adaptive parameter that changes slowly based on feedback from the system's energy, mimicking an adaptive rule.
The ODEs are defined as:
(Velocity is the rate of change of position)
(Damping and restoring force, where
(Feedback-driven adaptation, with
Two cases are simulated with configurable adaptation rates (epsilon_success
and epsilon_fail
), allowing flexible testing of slow and fast adaptation scenarios.
-
Default slow rate:
$\epsilon = 0.01$ (success) -
Default fast rate:
$\epsilon = 0.5$ (failure)
For large solve_ivp
with the 'BDF'
method is used to ensure numerical stability, with tight tolerances (rtol=1e-6
, atol=1e-8
).
- The
odeint
function uses an adaptive Runge-Kutta method (LSODA) for$\epsilon \leq 0.1$ . - For
$\epsilon > 0.1$ ,solve_ivp
with the'BDF'
method is used to handle stiff dynamics. - Both solvers use
rtol=1e-6
andatol=1e-8
to ensure numerical accuracy, particularly for higher frequencies or fast adaptation.
The instantaneous frequency of
- Hilbert transform (
scipy.signal.hilbert
) to obtain the analytic signal. - Phase unwrapping and numerical differentiation using
np.gradient
.
The instantaneous frequency is:
-
np.gradient
provides central differences for numerical stability. - The time window (
$t \in [60, 80]$ ) focuses on steady-state behavior. - For rapidly changing signals (large
$\epsilon$ , e.g., 0.5), the narrowband assumption of the Hilbert transform may introduce minor inaccuracies, triggering a warning. - Practical note: edge artefacts in the Hilbert transform. Even when focusing on a steady-state window (e.g., 60–80 s), the Hilbert transform can exhibit edge artefacts near the boundaries of the chosen segment due to the implicit periodic extension in FFT-based implementations. This is not mitigated in this simulation.
The damped theoretical frequency is calculated based on the steady-state
This is reported alongside the observed frequency to validate the simulation’s physical behavior.
The simulation demonstrates a key principle of adaptive systems: adaptation rate is critical for stability.
-
Slow adaptation (
$\epsilon$ small): smooth convergence to a stable state. -
Fast adaptation (
$\epsilon$ large): overshoot and unstable, sustained oscillations.
Parameter | Value | Description |
---|---|---|
0.05 | Damping coefficient controlling energy loss | |
0.5 | Target amplitude squared for |
|
0.05 | Regularization strength pulling |
|
1.0 | Baseline reference for |
|
0.01 (success), 0.5 (fail) | Adaptation rate | |
0–100, 500 points | Time array for simulation | |
Initial conditions |
|
Starting state |
Analysis window | 60–80 s | Time window for steady-state analysis |
0.01 | Threshold for |
For higher
The simulation generates three plots:
-
Stacked plot:
$\theta$ ,$x$ , and energy over time, with the 60–80s analysis window shaded. -
Phase space plot:
$x$ vs$v$ . - Instantaneous frequency plot: Frequency over the 60–80s window.
Console output includes:
- Status (Success/Fail based on
$\text{std}(\theta) < 0.01$ ). - Mean
$\theta$ , standard deviation of$\theta$ , observed frequency (from Hilbert transform), and damped theoretical frequency.
Behavior:
-
$\theta$ increases gradually and converges near 0.8962. -
$x$ shows damped oscillations, shrinking to a stable low-amplitude oscillatory state.
Energy:
Heuristic energy decays and flattens, confirming convergence.
Console Outputs:
- Mean
$\theta \approx 0.8962$ ,$\text{std}(\theta) < 0.01$ - Observed frequency
$\approx 0.1482$ Hz - Damped theoretical frequency
$\approx 0.1506$ Hz based on$\sqrt{0.8962 - \frac{0.05^2}{4}} / (2\pi)$ - Phase space: smooth inward spiral toward a stable limit cycle
Adjust epsilon_success
in code to explore different slow adaptation rates.
Behavior:
-
$\theta$ oscillates persistently, failing to settle. -
$x$ exhibits large, repeating oscillations.
Energy:
- Heuristic energy oscillates at a higher mean level, reflecting non-convergence.
Console Outputs:
- Mean
$\theta \approx$ 1.3244,$\text{std}(\theta) > 0.01$ - Observed frequency ~0.1979 Hz
- Damped theoretical frequency depends on mean
$\theta$ but is less reliable due to instability - Phase space: sustained wide loops, no contraction toward equilibrium
The console reports single mean values for (theta) and frequency, but plots show oscillatory behavior due to non-convergence. Adjust epsilon_fail to test different fast adaptation rates.
-
Small
$\epsilon$ (slow adaptation) → stable self-regulation -
Large
$\epsilon$ (fast adaptation) → unstable divergence
The adaptive oscillator admits equilibrium solutions analyzed using fixed-point and linear stability methods.
At equilibrium:
Gives:
From
$$\epsilon \big( (x^)^2 - a \big) - \gamma (\theta^ - \theta_0) = 0$$
So:
In practice,
Jacobian at $(x^, v^, \theta^*)$:
At $(x^, v^) = (0, 0)$:
Eigenvalues:
-
$\delta > 0$ and$\gamma > 0$ - Stability depends on
$\theta^* > 0$ - Small
$\epsilon$ →$\theta$ close to equilibrium → stable - Large
$\epsilon$ →$\theta$ oscillates → unstable
- Analytical stability requires positive
$\theta$ and moderate adaptation rate. -
Slow adaptation (
$\epsilon$ small) → stable self-regulation. -
Fast adaptation (
$\epsilon$ large) → oscillatory divergence. - Higher
$\theta_0$ (e.g., 2.0) requires increased$\gamma$ (e.g., 0.1) to stabilize slow adaptation by reducing$\theta$ variability.