Damped Harmonic Oscillator

JJ Ben-Joseph headshot JJ Ben-Joseph

What is a damped harmonic oscillator?

A damped harmonic oscillator is a simple model of a vibrating system that loses energy over time. In this calculator, the system is a single mass attached to a spring and a damper (dashpot). The spring stores energy, the mass carries kinetic energy, and the damper removes energy as heat or friction.

This model appears in many contexts: a car suspension, a building in an earthquake, a microphone diaphragm, or an RLC electrical circuit. By adjusting the parameters and playing the animation, you can see how displacement, velocity, and the different energy components evolve with time.

Model equation and key formulas

The motion of the mass is described by a second‑order differential equation. The calculator uses the standard linear mass–spring–damper model with optional sinusoidal forcing:

m xt + c dt x + k x = F 0 sin ( ω d t )

Here, m is mass (kg), c is damping coefficient (kg/s), k is spring constant (N/m), x is displacement (m), F0 is forcing amplitude (N), and ωd is the driving angular frequency (rad/s). When F0 = 0, the system performs free vibration. When the forcing is non‑zero, you see forced vibration and resonance effects.

Two important derived quantities are the natural frequency and damping ratio:

ωn = k m ,   ζ = c 2 m k

The damping ratio ζ tells you the qualitative behavior:

  • ζ<1: underdamped – oscillatory motion with decaying amplitude.
  • ζ=1: critically damped – fastest return to equilibrium without oscillation.
  • ζ>1: overdamped – slow, non‑oscillatory return to equilibrium.

The calculator also tracks energy terms:

  • Kinetic energy: E_k=12mv2
  • Spring potential energy: E_s=12kx2
  • Dissipated energy in the damper, obtained by integrating the power P=cv2 over time.

Parameters and how to use the simulator

Use the input fields above to configure the system:

  • Mass (m, kg) – Effective mass that is moving. Larger mass makes the motion slower and reduces natural frequency.
  • Spring constant (k, N/m) – Stiffness of the spring. A larger k increases the natural frequency and makes the system resist displacement more strongly.
  • Damping coefficient (c, kg/s) – Strength of the viscous damper. Increasing c reduces oscillation amplitude and speeds up decay, but very high damping leads to a slow, heavily overdamped response.
  • Initial displacement (x₀, m) – Starting offset from equilibrium. This sets the initial spring energy.
  • Initial velocity (v₀, m/s) – Starting speed of the mass. This sets initial kinetic energy.
  • Forcing amplitude (F₀, N) – Peak magnitude of the external sinusoidal force. Set F₀ = 0 for free vibration.
  • Drive frequency (ωd, rad/s) – Angular frequency of the external force. When ωd is near ωn, you will see resonance in the response.
  • Time step (Δt, s) – Size of the numerical integration step. Smaller values increase accuracy and stability but require more computation.

After choosing values, select Play to run the simulation, Pause to stop it, and Reset to return to the initial conditions. The plots show displacement and velocity over time, along with kinetic, spring, and dissipated energies. Use the CSV download to export the time‑series for analysis in tools such as Excel, Python, or MATLAB.

Worked example

Suppose you model a 1 kg mass on a spring with k = 20 N/m and c = 0.5 kg/s, with initial displacement x₀ = 0.1 m and zero initial velocity, and no external forcing (F₀ = 0). The calculator computes:

  • ωn=2014.47 rad/s
  • ζ=0.521200.056 (underdamped)

The displacement will oscillate with a frequency slightly less than ωn, and the amplitude will gradually decrease due to damping. In the energy plot, the sum of kinetic and spring energies decays monotonically as energy is transferred to the damper (dissipated energy curve increases).

If you now set F₀ to a non‑zero value and choose ωd close to 4.47 rad/s, the steady‑state amplitude of motion will grow, demonstrating resonance. Increasing c reduces the resonant peak and broadens the frequency response.

Comparison of damping regimes

Regime Damping ratio (ζ) Qualitative motion Typical use cases
Underdamped 0 < ζ < 1 Oscillatory with decaying amplitude Suspensions, lightly damped structures, acoustics
Critically damped ζ = 1 Fastest return to equilibrium without overshoot Precision positioning, some control systems
Overdamped ζ > 1 Slow, non‑oscillatory response Highly damped supports, shock isolation where oscillation is undesirable

Interpreting results and using the CSV

Focus on the following when reading the plots:

  • Decay rate – Faster decay indicates higher damping ratio. Compare different values of c while keeping m and k fixed.
  • Resonant amplification – For forced vibration, vary ωd around ωn. Large steady‑state amplitudes near resonance reveal how sensitive the system is to that frequency.
  • Energy balance – In free vibration (F₀ = 0), the total mechanical energy decreases monotonically as the damper dissipates energy.

With the CSV export, you can compute additional quantities such as frequency spectra, phase plots (x versus v), or compare multiple parameter sets programmatically.

Assumptions and limitations

This simulator is designed for education and preliminary insight, not for certified engineering design. The underlying model assumes:

  • Linear spring (Hooke’s law): force is proportional to displacement, valid only for small deflections.
  • Linear viscous damping: damping force is proportional to velocity, which may not hold for dry friction or complex materials.
  • Single degree of freedom: only one mass coordinate is modeled; real structures may have many coupled modes.
  • Small displacements: geometric nonlinearities and contact effects are ignored.
  • SI units: inputs and outputs are interpreted in kilograms, meters, seconds, and newtons.
  • Numerical integration: the motion is computed with a time‑stepping algorithm. Very large Δt values can cause inaccurate or unstable results; if the response looks erratic, reduce Δt and rerun.

Always check whether this simplified model is appropriate for your application before drawing design‑level conclusions.

1. Real‑world motivation

From automobile suspensions to seismically isolated buildings, countless machines rely on the balance between inertia, spring stiffness, and damping. A traditional damped harmonic oscillator calculator reports only a displacement value, concealing how energy sloshes between kinetic and elastic stores while friction steals a portion every cycle. This interactive version keeps the original purpose of computing motion but augments it with a canvas that shows a block bobbing on a spring. As you adjust parameters like mass or forcing amplitude, the animation and energy bars update instantly, clarifying why an overly soft shock absorber leads to bouncy rides or why a lightly damped bridge oscillates for minutes after a gust of wind.

2. Variables and assumptions

The model treats a single degree‑of‑freedom system consisting of mass m , spring constant k , and viscous damping coefficient c . Position x and velocity v are measured along the spring’s axis with the equilibrium at x =0. Optional sinusoidal forcing F ( t ) = F_0 sin ( ω_d t ) can drive the oscillator. Initial conditions x_0 and v_0 set the starting state. Air resistance and structural damping are modeled with the single coefficient c ; nonlinear effects, large deflections, and temperature‑dependent stiffness are ignored. All quantities use SI units: kilograms, newtons, meters, and seconds. Input validation rejects non‑finite or negative mass and spring values, and the time step Δt is clamped between 0.001 and 0.1 s to maintain numerical stability.

3. Governing equations

The dynamics follow Newton’s second law applied to the mass: m d v d t = F ( t ) - c v - k x . Introducing d x d t = v yields a first‑order system:

d x d t = v , d v d t = F ( t ) - c v - k x m . Kinetic and potential energies are E_k = 1 2 m v 2 and E_p = 1 2 k x 2 , while the power dissipated by damping is P_d = c v 2 . The work performed by the driving force accumulates as W = F ( t ) v dt , allowing an energy balance check E_k + E_p + E_d - ( E_0 + W ) .

4. Numerical scheme

The simulator advances the state with a classical fourth‑order Runge–Kutta method. For each step of size Δt , four derivative estimates sample the forces at the beginning, two midpoints, and the end. The weighted average s ( t + Δt ) = s ( t ) + Δt 6 ( k_1 + 2 k_2 + 2 k_3 + k_4 ) updates position and velocity simultaneously. RK4 offers a good compromise between speed and accuracy; the local error scales with Δt 5 , so halving the step roughly reduces the global error by a factor of sixteen. Nevertheless, very stiff systems with large k or c may require smaller steps to avoid overshoot. The code clamps the user‑selected Δt and recomputes the trajectory whenever inputs change, debounced by 400 ms to prevent excessive re‑simulation during typing.

5. Worked example

Consider a 1 kg mass attached to a spring with k =20 N/m and damping c =0.5 kg/s. Starting from x_0 =0.1 m and v_0 =0, with no external forcing, the simulator predicts oscillations that decay with a time constant τ = 2 c ≈ 4 s. Running the animation with Δt =0.02 s shows the block initially move toward the origin, overshoot, and settle after a few cycles. The energy bars reveal kinetic energy peaking as the block passes equilibrium and shrinking as damping converts it to heat. Downloading the CSV confirms the analytic period of about 1.4 s derived from ω_d = k m - c 2 4 m 2 .

6. Comparison table

The table contrasts the baseline oscillator above with two variations: increased damping and a driven case. Values are extracted from the simulation after five seconds.

Scenario c (kg/s) F₀ (N) Max |x| (m) Energy drift (J)
Baseline 0.5 0 0.10 ≈0
Heavier damping 2.0 0 0.04 ≈0
Driven 0.5 1.0 0.12 <0.001

Doubling the damping coefficient reduces the peak displacement to 4 cm, while a modest sinusoidal drive at the natural frequency slightly increases the amplitude without introducing significant numerical energy error.

7. How to read the animation

The canvas displays a horizontal spring anchored to the left wall with a colored block on the right. The block’s position corresponds to the instantaneous displacement, scaled to fit the viewport. A blue trail traces its recent path. Beneath the canvas, striped orange, blue, and gray bars show kinetic energy, spring potential energy, and cumulative dissipated energy, respectively, with text labels so color perception is unnecessary. The caption narrates time, displacement, velocity, and the small energy‑balance error. Focus the canvas with the keyboard and press the space bar to toggle play and pause. The hidden “Simulation summary” div mirrors these numbers for screen readers.

8. Limitations

Several idealizations keep the model tractable. Damping is purely viscous and linear, whereas real shock absorbers can exhibit velocity‑squared or hysteretic behavior. The spring obeys Hooke’s law without yielding or coil bind. Forcing is limited to a single sinusoid; arbitrary waveforms or impacts are not included. The system moves only in one dimension, ignoring torsional or lateral modes. Numerical integration assumes the parameters remain constant and may lose accuracy for extremely stiff or poorly scaled inputs. Despite these simplifications, the simulator captures the essential trade‑offs that govern many engineering designs.

9. Suggested extensions

Ambitious users could extend the code to include nonlinear damping, piecewise spring behavior, or multiple degrees of freedom coupled in series. Plotting velocity versus displacement would generate a phase‑space portrait that highlights spiraling toward rest. Another extension is to add a second mass and spring, exploring resonance and modal beating. Because the project uses only vanilla JavaScript, editing the source to experiment with control strategies or feedback loops is straightforward. For related explorations, see the Mass‑Spring Oscillation Calculator, compare electrical analogs with the RLC Circuit Damping Calculator, or examine motion without springs in the Projectile Motion Calculator.

10. References

Standard treatments of damped oscillations appear in H. Goldstein, C. Poole, and J. Safko, Classical Mechanics, and R. C. Hibbeler, Engineering Mechanics: Dynamics. These texts discuss linear systems, energy methods, and the effect of damping on resonance. The numerical technique follows the RK4 algorithm described in any introductory computational physics resource.

Enter parameters and press Play.
Simulation summary will appear here.

Kinetic energy

Spring potential energy

Dissipated energy

Resonance Arena Mini-Game

React to changing drive frequencies by dialing in damping fast enough to keep the steady-state amplitude below the damage threshold. Each round translates the response curve into an arcade-style targeting challenge.

Keep amplitude inside safe band

Click to Play, tune damping in time, and survive all 80 seconds.

Best run: 0

Embed this calculator

Copy and paste the HTML below to add the Damped Harmonic Oscillator – Interactive Simulation to your website.