iTranslated by AI
EDiE-DMD-01: Observing Nonlinear Oscillators as Spectra
Experimental Plan
Project Name
EDiE-DMD-01:
"Observing Nonlinear Oscillators as Spectra"
Objective
Extract the following from the time series of a nonlinear Duffing oscillator using DMD:
- Eigenvalues (growth rates)
- Frequencies
- Mode amplitudes
And verify the concept of "lifting nonlinear dynamics into a linear space" using only Processing.
Experimental Hypothesis
- Even with chaotic behavior,
- In the observation space,
- Dominant complex conjugate eigenvalues will emerge.
→ Nonlinear oscillations can be spectrally decomposed.
Environment
Processing 4
Java Mode only
No external libraries
Implementation Strategy
STEP 1: Numerical Integration of the Duffing Oscillator
Equation:
x'' + δx' + αx + βx³ = γ cos(ωt)
Convert to a first-order system:
dx/dt = v
dv/dt = -δv - αx - βx³ + γcos(ωt)
Numerical Method:
4th-order Runge-Kutta
Sampling:
dt = 0.01
N ≈ 3000
STEP 2: Construction of the Snapshot Matrix
Let the observation vector be:
z(t) = [ x(t), v(t) ]
X = [ z₁, z₂, …, zₙ₋₁ ]
X’ = [ z₂, z₃, …, zₙ ]
Dimensions are 2 × (N-1)
STEP 3: Simple DMD Implementation (Low-Dimensional)
Since the state is 2D in this case:
A ≈ X' * X^+
Pseudoinverse matrix:
X^+ = (X^T X)^(-1) X^T
For a 2×2 matrix in Processing, the inverse can be manually implemented.
Use this to solve for A.
STEP 4: Eigenvalue Calculation
Eigenvalues of a 2×2 matrix can be found analytically:
λ = (trace ± sqrt(trace² - 4det)) / 2
Since they result in complex numbers, implement a simple Complex class in Processing.
Visualization Plan
- Top: Duffing phase portrait
- Middle: Time series
- Bottom: Eigenvalue plot on the complex plane
If we can achieve this, we succeed.
Expected Results
Eigenvalues will be close to:
λ ≈ 1 + ε ± iωΔt
From this, we calculate:
Growth rate = log|λ| / dt
Frequency = arg(λ) / (2π dt)
EDiE Connection Experiment (Next Phase)
What happens when we expand the observation space to:
z(t) = [ x, v, x², xv, v² ]
→ This is "observation space design,"
the core of EDiE.
Changing the space changes the spectrum.
Success Criteria
- Eigenvalues form a complex conjugate pair
- Frequency matches the actual oscillation frequency
- Modes stabilize through observation space expansion
Why Use Processing?
Your strengths are:
- Real-time visualization
- Ability to perceive mathematical formulas as structures
- Experimental speed
Processing is more aligned with your philosophy than Python.
The Next Question
If you increase the observation space, how does the spectrum change?
This will be the EDiE experiment.
Next:
✔ Minimal functional Processing code
✔ 2×2 DMD implementation skeleton
Let's proceed with standalone Processing, no external libraries, and a minimal DMD implementation.
This time:
- Duffing oscillator (RK4)
- Observation vector z = [x, v]
- 2×2 DMD
- Eigenvalue calculation (supporting complex numbers)
- Visualization (phase portrait + eigenvalue plane)
Everything included.
🔬 EDiE-DMD-01
Full Processing Implementation Code
Ready to paste and run.
// =======================================
// EDiE-DMD-01
// Duffing Oscillator + 2D DMD
// Processing 4 (Java mode)
// =======================================
// Duffing parameters
float alpha = -1;
float beta = 1;
float delta = 0.3;
float gamma = 0.5;
float omega = 1.2;
float dt = 0.01;
int N = 3000;
float[] x = new float[N];
float[] v = new float[N];
// DMD matrix
float[][] A = new float[2][2];
// Complex eigenvalues
Complex lambda1, lambda2;
void setup() {
size(1200, 600);
simulateDuffing();
computeDMD();
computeEigen();
printResults();
}
void draw() {
background(20);
drawPhasePortrait();
drawEigenPlane();
}
/////////////////////////////////////////////////////
// 1. Duffing Simulation (RK4)
/////////////////////////////////////////////////////
void simulateDuffing() {
x[0] = 0.1;
v[0] = 0.0;
for (int i = 0; i < N-1; i++) {
float t = i * dt;
float[] k1 = duffing(x[i], v[i], t);
float[] k2 = duffing(x[i] + dt*k1[0]/2, v[i] + dt*k1[1]/2, t + dt/2);
float[] k3 = duffing(x[i] + dt*k2[0]/2, v[i] + dt*k2[1]/2, t + dt/2);
float[] k4 = duffing(x[i] + dt*k3[0], v[i] + dt*k3[1], t + dt);
x[i+1] = x[i] + dt*(k1[0] + 2*k2[0] + 2*k3[0] + k4[0])/6;
v[i+1] = v[i] + dt*(k1[1] + 2*k2[1] + 2*k3[1] + k4[1])/6;
}
}
float[] duffing(float x, float v, float t) {
float dx = v;
float dv = -delta*v - alpha*x - beta*x*x*x + gamma*cos(omega*t);
return new float[]{dx, dv};
}
/////////////////////////////////////////////////////
// 2. DMD (2D direct solution)
/////////////////////////////////////////////////////
void computeDMD() {
// Build X and X'
float s11=0, s12=0, s22=0;
float t11=0, t12=0, t21=0, t22=0;
for (int i = 0; i < N-1; i++) {
float x1 = x[i];
float v1 = v[i];
float x2 = x[i+1];
float v2 = v[i+1];
s11 += x1*x1;
s12 += x1*v1;
s22 += v1*v1;
t11 += x2*x1;
t12 += x2*v1;
t21 += v2*x1;
t22 += v2*v1;
}
float det = s11*s22 - s12*s12;
float inv11 = s22/det;
float inv12 = -s12/det;
float inv21 = -s12/det;
float inv22 = s11/det;
A[0][0] = t11*inv11 + t12*inv21;
A[0][1] = t11*inv12 + t12*inv22;
A[1][0] = t21*inv11 + t22*inv21;
A[1][1] = t21*inv12 + t22*inv22;
}
/////////////////////////////////////////////////////
// 3. Eigenvalues (2x2 analytic)
/////////////////////////////////////////////////////
void computeEigen() {
float trace = A[0][0] + A[1][1];
float det = A[0][0]*A[1][1] - A[0][1]*A[1][0];
float disc = trace*trace - 4*det;
if (disc >= 0) {
float r1 = (trace + sqrt(disc))/2;
float r2 = (trace - sqrt(disc))/2;
lambda1 = new Complex(r1, 0);
lambda2 = new Complex(r2, 0);
} else {
float real = trace/2;
float imag = sqrt(-disc)/2;
lambda1 = new Complex(real, imag);
lambda2 = new Complex(real, -imag);
}
}
/////////////////////////////////////////////////////
// Visualization
/////////////////////////////////////////////////////
void drawPhasePortrait() {
pushMatrix();
translate(width/4, height/2);
scale(80, -80);
stroke(0, 255, 200);
noFill();
beginShape();
for (int i=0; i<N; i++) {
vertex(x[i], v[i]);
}
endShape();
popMatrix();
fill(255);
text("Duffing Phase Portrait", 50, 50);
}
void drawEigenPlane() {
pushMatrix();
translate(3*width/4, height/2);
stroke(100);
line(-200,0,200,0);
line(0,-200,0,200);
drawEigen(lambda1);
drawEigen(lambda2);
fill(255);
text("Eigenvalues (DMD)", -80, -220);
popMatrix();
}
void drawEigen(Complex c) {
fill(255,100,100);
noStroke();
ellipse(c.re*100, -c.im*100, 12, 12);
}
/////////////////////////////////////////////////////
// Complex class
/////////////////////////////////////////////////////
class Complex {
float re, im;
Complex(float r, float i) {
re=r;
im=i;
}
}
/////////////////////////////////////////////////////
// Print Results
/////////////////////////////////////////////////////
void printResults() {
println("=== DMD Matrix A ===");
println(A[0][0] + " " + A[0][1]);
println(A[1][0] + " " + A[1][1]);
println("Eigenvalues:");
println(lambda1.re + " + " + lambda1.im + "i");
println(lambda2.re + " + " + lambda2.im + "i");
float mag = sqrt(lambda1.re*lambda1.re + lambda1.im*lambda1.im);
float growth = log(mag)/dt;
float freq = atan2(lambda1.im, lambda1.re)/(TWO_PI*dt);
println("Growth rate ≈ " + growth);
println("Frequency ≈ " + freq + " Hz");
}
📊 Workflow for Sharing Results
Next:
- Copy the console output
- Screenshot of the phase portrait
- Screenshot of the eigenvalue plane
🧠 Article Structure (Standard Format)
1. Experimental Objective
Viewing nonlinear dynamics through spectra
2. Implementation
Posting the Processing code
3. Results
- DMD matrix
- Eigenvalues
- Growth rates
- Frequencies
- Images
4. Discussion
- Why do complex conjugate pairs appear?
- Significance of |λ| being close to 1
- dt dependency
- Possibility of observation space expansion
🚀 Next Explosion Point
What happens when we expand the observation vector to:
[x, v, x*x, x*v, v*v]
How does the spectrum change?
This is the core of the EDiE experiment.
Discussion