อนุพันธ์ อัตราการเปลี่ยนแปลง และการอินทิเกรตเชิงตัวเลข

Derivatives of position, velocity and acceleration; numerical integration of sensor data

Last updated:

Why it matters

Everything a drone does involves change over time. Position changes into velocity, velocity into acceleration, attitude changes at the rate the gyroscope measures, and battery charge falls with the current drawn. Calculus describes this from two sides: the derivative, which says how fast a quantity is changing, and the integral, which says how much has accumulated.

In practice we rarely have a formula for the function. We have sensor samples taken at intervals. This page therefore focuses on numerical methods, estimating derivatives and integrals from data, and on the limits you need to know before trusting the result.

The derivative is a rate of change

The average rate of change over an interval is the change in the quantity divided by the change in time, Δx/Δt. If altitude rises 12 m in 4 s, the average climb rate is 3 m/s. The derivative dx/dt is this rate as the interval shrinks towards zero. On a graph it is the slope of the tangent line (the straight line that touches the curve at one point) at that instant.

The quantities of motion form a chain:

QuantityRelationSI unitRelated drone sensor
Position xstarting quantitymGNSS, barometer
Velocity vv = dx/dtm/sGNSS (Doppler), optical flow
Acceleration aa = dv/dtm/s2IMU accelerometer
Angle θ and rate ωω = dθ/dtrad/sIMU gyroscope
Charge Q and current II = dQ/dtA (= C/s)Power-module current sensor

The unit of a derivative is always the unit of the quantity divided by the unit of time. Checking units is the quickest way to catch a wrong formula.

Estimating a derivative from samples

With samples xk spaced Δt apart, two estimates are common:

  • Forward difference, vk ≈ (xk+1 − xk)/Δt. It needs only the newest sample, so it suits real-time use.
  • Central difference, vk ≈ (xk+1 − xk−1)/(2Δt). Its error shrinks with Δt2 rather than Δt, so it is more accurate, but it needs the next sample. It suits post-flight log analysis.

Test them on a known function, x(t) = 2t2, whose true derivative 4t equals 12 at t = 3. With Δt = 0.5 the forward difference gives 13.0 and the central difference gives exactly 12.0 (it is exact for quadratics). Reducing Δt to 0.1 brings the forward difference to 12.2.

Differentiation amplifies noise

Real data carries noise, small random fluctuations that do not come from real motion. Dividing a difference by a very small Δt magnifies it. If barometric altitude has noise with a standard deviation of 0.1 m and is logged at 50 Hz (Δt = 0.02 s), the forward-difference velocity has a standard deviation of about √2 × 0.1 / 0.02 ≈ 7.1 m/s, larger than the climb rate of most drones. The remedies are to filter before differentiating, use a longer Δt, or fuse with other sensors in an estimator such as a Kalman filter. This is why the D term of a PID controller almost always has a low-pass filter.

The integral is accumulation

The definite integral of f(t) from t = a to t = b is the area under the graph of f over that interval. Physically it is a running total: the area under a velocity curve is distance, and the area under a current curve is charge used. From samples, the area is estimated in two main ways:

  • Rectangle (Euler) rule: the value at the start of each step times Δt. It is the simplest, and it is what an autopilot does each cycle because its Δt is tiny.
  • Trapezoidal rule: the mean of the two ends of each step times Δt. It is more accurate when Δt is long.

For v(t) = t2 from 0 to 3 s the true area is 9. With Δt = 1 s the left rectangle sum gives 0 + 1 + 4 = 5, while the trapezoidal rule gives 0.5 + 2.5 + 6.5 = 9.5, much closer.

Worked example: counting charge used

Autopilots estimate remaining capacity by integrating current, a method called coulomb counting. Assume a drone with a 5000 mAh battery logs current every 60 s for 5 minutes:

Time (s)060120180240300
Current (A)182022211918

Apply the trapezoidal rule step by step:

  • Step 1: (18 + 20)/2 × 60 = 1140 A·s
  • Step 2: (20 + 22)/2 × 60 = 1260 A·s
  • Step 3: (22 + 21)/2 × 60 = 1290 A·s
  • Step 4: (21 + 19)/2 × 60 = 1200 A·s
  • Step 5: (19 + 18)/2 × 60 = 1110 A·s

The total is 6000 A·s, or 6000 C. Since 1 Ah = 3600 A·s, that is 6000/3600 ≈ 1.667 Ah, about 1667 mAh, or roughly 33% of the 5000 mAh pack. The mean current is 6000/300 = 20 A. A real autopilot samples current many times per second, so its figure is far more precise, but the principle is the same. If the current sensor is miscalibrated by 5%, the "mAh used" figure is off by 5% for the whole flight, so calibrate the sensor before relying on it.

Accumulated error

Integration accumulates not only the true signal but also any constant sensor bias. Suppose (assumed) a gyroscope has a bias of 0.5 degrees per second and heading is computed from gyro integration alone: after one minute the heading is off by 0.5 × 60 = 30 degrees. With an accelerometer bias b = 0.05 m/s2, velocity error grows as b·t and position error as ½·b·t2. At t = 10 s that is 0.5 m/s and 2.5 m. At t = 60 s it is 3 m/s and 90 m. The position error grows with the square of time.

That is why drone navigation never relies on the IMU alone. It fuses GNSS, barometer and compass to correct the accumulated error. The same reasoning explains why the I term of a PID controller must be limited to prevent integral windup.

Common pitfalls

  • Wrong Δt. Log samples are rarely perfectly evenly spaced. Compute Δt from each row's actual timestamp, not from the nominal logging rate.
  • Forgetting time units. Many autopilot logs use microseconds. Divide by 106 first.
  • Differentiating raw noisy data. The result swings wildly. Filter first or use a longer interval.
  • Trusting long integrations. A small bias becomes a large error. An external reference must correct it regularly.
  • Mixing degrees and radians. Gyro rates are usually in rad/s. Integrating them and reading the result as degrees is wrong by a factor of about 57.
  • Confusing mAh with Wh. Integrating current gives charge (mAh); integrating power gives energy (Wh). They differ by the voltage.

Continue in the lessons

Key references

  1. Stroud, K. A., & Booth, D. J. (2020). Engineering mathematics (8th ed.). Bloomsbury.
  2. Kreyszig, E. (2011). Advanced engineering mathematics (10th ed.). Wiley.
  3. Strang, G., & Herman, E. (2016). Calculus volume 1. OpenStax. link
  4. Groves, P. D. (2013). Principles of GNSS, inertial, and multisensor integrated navigation systems (2nd ed.). Artech House. link

Used in courses

How to cite this page

Drone Institute, Rangsit University. (2026). อนุพันธ์ อัตราการเปลี่ยนแปลง และการอินทิเกรตเชิงตัวเลข. In UAS Technology Knowledge Hub (B.Tech.). https://rsu-uat.pk-research.work/en/kb/new/math-calculus-rates/