Mass-spring-damper PID calculator
Position control of a mass on a spring and damper with a PID controller, the way Simulink's PID Controller block does it. Type your gains and see the closed-loop poles, the step response, overshoot and settling time, and the force the controller needs, against a pulse reference. Or pick the damping and speed you want and get Kp, Ki and Kd. Free, no sign-up, runs in your browser.
It opens on the brief of Skill-Lync's mass-spring-damper project (m = 3.6 kg, k = 400 N/m, c = 100 N s/m). The third tab checks the gains in your report and names the slips Skill-Lync found when it read 225 of them.
Simulink PID Controller block (parallel form, filter N) · Routh-Hurwitz · stepinfo definitions · Åström and Murray · Updated 20 Nov 2026
Reference pulse and force limit
Defaults: gains from the Design tab (ζ 0.7, ωn 10 rad/s, α 5), the PID block's default filter N = 100 and the project's reference: amplitude 1, period 10 s, 50 % width.
The gains place the ideal PID loop's poles at ζ and ωn plus a real pole at α ζ ωn (α ≥ 5 keeps it out of the way). A filter N moves them slightly; the chart uses the derivative setting below.
Type the gains from your Simulink model. Leave the derivative on "Derivative block" if you built the PID from Gain, Integrator and Derivative blocks.
- Plant: ωn = 10.54 rad/s, ζ = 1.318 (overdamped), poles -4.845, -22.93; 400 N holds the mass 1 m from rest against the spring.
- Closed loop stable. Poles -6.762 ± 6.715j, -57.13 ± 24.3j; the slowest complex pair has ζ = 0.71.
- Unit step: overshoot 6.05 %, rise time 0.09 s, 2 % settling 0.466 s (stepinfo definitions).
- First pulse: inside 2 % of the reference 0.466 s after it switches on, out of the 5 s it stays on.
- Peak force 9,364 N, 265 g on the 3.6 kg mass. The derivative kick at each edge alone is about Kp + Kd × N = 9,364 N; the derivative on the position only removes it.
What does the mass-spring-damper project ask?
"Obtain the transfer function of a mass spring damper system and use it in the model. Add a PID controller to adjust the force on mass so that its position follows a reference signal", with m = 3.6 kg, k = 400 N/m and c = 100 N s/m, and a pulse reference of amplitude 1 and period 10 s. It is the controls project of Skill-Lync's Matlab and Simulink Basics course. Skill-Lync fetched 287 public reports on mass-spring-damper systems on 20 Nov 2026 (263 carry the project's exact title); 225 were distinct and 134 quote the brief's values.
So the plant on its own is overdamped, with poles at -4.845, -22.93: it never overshoots and never oscillates. Its static gain is 1/k = 2.5 mm per newton, so holding the mass 1 m from rest takes 400 N against the spring. Everything the controller adds, it adds by force.
The closed loop and when it is stable
Simulink's PID Controller block, in its default parallel form, is
with N the derivative filter coefficient (100 by default; N → ∞ is an ideal derivative). With an ideal derivative the closed-loop characteristic equation is a cubic:
Routh's condition for a cubic gives the stability test you can do on paper:
A stable loop with Ki > 0 tracks a constant reference with zero steady error. Without Ki it settles short, at Kp/(k + Kp) of the reference: Kp = 100 leaves the mass at 0.2 m for a 1 m step.
How do you choose Kp, Ki and Kd?
Pick the closed-loop poles and match coefficients. A dominant pair at damping ζ and natural frequency ωn, plus a faster real pole at p:
For ζ = 0.7, ωn = 10 rad/s and p = 5 × ζ ωn = 35 s⁻¹: Kp = 1,724 N/m, Ki = 12,600 N/(m s), Kd = 76.4 N s/m. The poles land at -7 ± 7.141j, -35, and a unit step overshoots 7.0 % (the zeros the PID adds push it above the 4.6 % a pure second-order pair at ζ = 0.7 would give) and settles to 2 % in 0.46 s. With the block's filter N = 100 the numbers barely move: 6.0 % and 0.47 s.
The Design tab does this for any ζ, ωn and α and simulates the result.
Why place() gives Kp = 0 and a negative Kd
104 of the 225 reports (46 %) design the gains with K = place(A, B, P) on the two-state model, then set Kp = K(1), Kd = K(2) and pick Ki by trial. place() returns state-feedback gains: the K in u = −Kx that puts the poles of A − BK where you asked.
The scripts ask for one of two ωn: the plant's own √(k/m) (46 reports) or 2π × 1 Hz (38), usually with ζ = 0.5 (74):
| Script asks for | "Kp" = K(1) | "Kd" = K(2) | Settles at |
|---|---|---|---|
| ωn = √(k/m) = 10.54, ζ = 0.5 | 0 | -62.05 | 0 × r |
| ωn = √(k/m), ζ = 0.9 | 0 | -31.69 | 0 × r |
| ωn = 2π × 1 Hz = 6.28, ζ = 0.5 | -257.88 | -77.38 | -1.81 × r |
Asking for ωn = √(k/m) is asking for the plant's own stiffness, so K(1) = 0 (MATLAB prints something like −1.5 × 10⁻¹³). Any ζ below the plant's 1.318 asks for less damping than the damper already gives, so K(2) is negative. And because u = −Kx pulls the state back to zero and never sees the reference, the gains used as Kp and Kd give the PD loop exactly the poles you asked for, with a steady position of
which is 0 when Kp = 0: the mass does not follow the reference at all. With the 1 Hz version, Kp = −257.9 and the mass settles at −1.81 m for a +1 m reference. All the tracking then comes from the Ki chosen by trial, and Ki moves the poles. In the 78 place() reports whose ζ and ωn could be read, every "Kp" was ≤ 0 and every "Kd" negative. Of the 32 where Ki could be read too, 9 left Ki = 0, 2 chose a Ki that makes the loop unstable (with the 1 Hz gains Ki must stay below 893; one report used 1,020), and 11 of the 21 stable ones overshoot more than 25 %. Ki = 2,000 with the ζ = 0.5 gains gives a pair at ζ = 0.22 and 98.3 % overshoot.
To keep the place() design, use it as state feedback and scale the reference so the steady position is right:
That puts the poles where you asked and settles exactly on the reference, as long as m, c and k are exact. Add integral action, or design the PID poles directly as above, if they are not.
The derivative kick: why the force spikes at every edge
With the derivative on the error, every step of the reference is differentiated. An ideal derivative turns a step Δr into an impulse, which hits the mass with a velocity jump; the PID block's filter turns it into a tall, narrow spike:
For the gains above and the 1 m pulse, the filtered spike is 9,364 N at each edge, 265 g on a 3.6 kg mass. A Derivative block built from separate blocks is worse: Simulink computes Δu/Δt between time steps, so the spike's height depends on the step size, and the docs warn about exactly this at discontinuities. Putting the derivative on the measured position only (the PID Controller (2DOF) block with setpoint weight c = 0, Åström and Murray's "γ is normally zero") keeps the same poles and cuts the peak to 1,743 N, with 17.2 % overshoot instead of 6.0 %. Only 1 of the 225 reports mention the filter coefficient.
How much force do your gains need?
The project has no actuator limit, so any gain works on screen. Of the 47 reports whose three gains could be read, 46 give a stable loop; with the block's default filter, 36 of them need more than 1 kN for a 1 m step and 13 more than 10 kN (median 3,241 N). Only 16 reports mention saturation, a force limit or windup. Limit the force to ±600 N on the design above and the overshoot grows from 6.0 % to 33.7 %, because the integral keeps winding up while the force is capped; clamping the integrator (Simulink's "clamping" anti-windup, which stops integrating while the output is saturated and the error pushes the same way) brings it back to 4.7 %. Try it under "Reference pulse and force limit".
Which slips does the check tab catch?
- Gains from place() used as Kp and Kd: a zero or negative Kp and a negative Kd. The tab tells you which ζ and ωn they came from and where the mass settles.
- Ki = 0: the steady position is Kp/(k + Kp) of the reference.
- An unstable Ki: the Routh limit (c + Kd)(k + Kp)/m.
- A ζ that no longer describes the loop once Ki is added.
- Overshoot and settling claims that do not match the gains (68 reports mention overshoot, 34 settling time, 37 steady-state error).
- Forces no actuator can give, and the derivative kick of a Derivative block.
- Text copied from MathWorks' Simscape example (16 reports say "The initial velocity for the mass is 10 meters per second"): that example has its own model; the project's brief does not set an initial velocity.
What this calculator does not cover
- Simulink's solver. The calculator integrates with fixed-step RK4 between the edges of the pulse; Simulink's variable-step solvers agree on smooth parts but can differ right at an edge with an unfiltered Derivative block.
- Friction, backlash and a real actuator. The plant is linear. The force limit is a hard clamp with no actuator dynamics.
- Discrete-time PID. A sampled controller with a slow sample time adds phase lag the continuous model does not show.
- Robustness. The design assumes m, c and k are exact; it reports no gain or phase margins.
Modelling a plant, designing a controller and proving it with a simulation is the daily work of a controls or model-based development engineer. The mass-spring-damper project is part of Skill-Lync's Matlab and Simulink Basics course.
Frequently asked questions
How do I find PID gains for a mass-spring-damper system?
Choose where the closed-loop poles should be and match coefficients. With an ideal PID the loop is m s³ + (c + Kd) s² + (k + Kp) s + Ki, so for a pair at ζ, ωn and a third pole at p: Kd = m(2ζωn + p) − c, Kp = m(ωn² + 2ζωn p) − k, Ki = m ωn² p. For m = 3.6 kg, c = 100 N s/m, k = 400 N/m, ζ = 0.7, ωn = 10 rad/s and p = 35: Kp = 1,724, Ki = 12,600, Kd = 76.4, about 7.0 % overshoot and 0.46 s settling.
Why does place() give a zero or negative Kp and Kd?
place(A, B, p) returns state-feedback gains for u = −Kx: K1 = m ωn² − k and K2 = 2ζωn m − c. If you ask for ωn = √(k/m) you get K1 = 0, and any ζ below 1.318 (the plant's own damping) gives a negative K2. They are not PID gains: used as Kp and Kd, the loop has the poles you asked for but the mass settles at Kp/(k + Kp) times the reference, 0 for Kp = 0.
What is the transfer function of a mass-spring-damper system?
X(s)/F(s) = 1/(m s² + c s + k), from m x'' + c x' + k x = F with zero initial conditions. For m = 3.6 kg, c = 100 N s/m and k = 400 N/m: 1/(3.6 s² + 100 s + 400), poles at −4.85 and −22.93, natural frequency 10.54 rad/s, damping ratio 1.318 (overdamped) and a static gain of 2.5 mm per newton.
Why is there a spike in the force when the reference changes?
Derivative action on the error differentiates the step in the reference. An ideal derivative gives an impulse of Kd × Δr; Simulink's PID Controller block, with its default filter N = 100, gives a peak of about (Kp + Kd N) × Δr, 9,364 N for the gains above. Putting the derivative on the measured position only (the 2DOF block with c = 0) cuts the peak to 1,743 N without changing the closed-loop poles.
How do I check if my PID loop is stable?
Look at the closed-loop poles, or for the ideal PID on this plant use Routh's condition for the cubic: (c + Kd)(k + Kp) > m Ki with every coefficient positive. For Kp = −257.9 and Kd = −77.4 (place() with ωn = 2π) Ki must stay below 893; Ki = 1,020 is unstable.
What reference signal does the project use?
A Pulse Generator with amplitude 1 and period 10 s; the reports quote a 50 % pulse width, so the reference is 1 for 5 s and 0 for 5 s. Note that Simulink's default pulse width is 5 %, not 50 %. With the position in metres that is a 1 m step up and back every 10 s.
Related on Skill-Lync
- Student project: position control of a mass-spring-damper system
- DC motor speed control calculator (the same PID block on a motor: speed loop, voltage demand, place() gains)
- Damped pendulum calculator
- Ride frequency calculator
- Adaptive cruise control calculator
- SOC estimation simulator
- MATLAB and Simulink project ideas
- All free engineering tools
Sources
- MathWorks, Simulink PID Controller block reference: parallel form P + I/s + D N s/(s + N), defaults P = 1, I = 1, D = 0, N = 100, zero initial conditions; anti-windup "clamping" (integration stops when the sum of the block components exceeds the output limits and the integrator input and saturation input have the same sign) and back-calculation. PID Controller (2DOF): u = P(b r − y) + I/s (r − y) + D N/(1 + N/s) (c r − y), b and c default 1.
- MathWorks, Pulse Generator block (time based; defaults amplitude 1, period 10 s, pulse width 5 %, phase delay 0); Derivative block (Δu/Δt between time steps, with warnings about discontinuous inputs); place (state-feedback gain K for u = −Kx; no pole repeated more than rank(B) times); stepinfo (rise time 10-90 %, 2 % settling threshold).
- MathWorks, Simscape example Mass-Spring-Damper with Controller (the source of "The initial velocity for the mass is 10 meters per second").
- K. J. Åström and R. M. Murray, Feedback Systems, Princeton (2008): Routh-Hurwitz for a cubic (Exercise 4.16), the derivative impulse on a setpoint step (Sec. 10.1) and setpoint weighting (Sec. 10.5, "γ is normally zero to avoid large transients"). Their filter N (2-20) is a different parameter from Simulink's N.
- Skill-Lync, 287 public mass-spring-damper reports, read 20 Nov 2026: gains, place() scripts, ζ and ωn, Ki and claims; responses recomputed for the brief's plant.
- Skill-Lync, scripts/verify/msd.py: rebuilds the closed loops with python-control, integrates the pulse responses with scipy (Radau, tolerance 10⁻¹⁰, with and without a force limit and anti-windup), checks the ideal-derivative step against the exact LTI response and place() against control.place; the page checks itself against it at build time.