A position log can produce a velocity curve that looks plausible while its scale is wrong. A Savitzky-Golay derivative fits a polynomial to a window of equally spaced samples. When the sample interval is omitted, SciPy uses a spacing of one. If positions are in millimeters, the result in that case is in millimeters per sample. To interpret it as millimeters per second, the derivative calculation needs the spacing in seconds. This distinction can be checked before applying the filter to a real robot run.
Start with a known velocity
The synthetic fixture below ran with SciPy 1.18.1 and NumPy 2.5.2. It uses a carriage position that increases by 5 mm each sample. The samples arrive every 0.02 seconds, so the represented speed is 250 mm/s. The initial position of 12 mm gives the fit a nonzero intercept without changing the slope. A quadratic fit can represent this straight line, and the five-sample window is small enough to inspect by hand. The point of this fixture is to isolate the unit conversion in the derivative. It is independent of a particular robot, sensor, controller, or drive.
import numpy as np
from scipy.signal import savgol_coeffs, savgol_filter
time_s = np.arange(9) * 0.02
position_mm = 12. + 250. * time_s
spacing_s = np.diff(time_s)
assert np.all(spacing_s > 0)
assert np.allclose(spacing_s, spacing_s[0])
dt_s = spacing_s[0]
per_sample = savgol_filter(position_mm, 5, 2, deriv=1)
per_second = savgol_filter(position_mm, 5, 2, deriv=1, delta=dt_s)
coeff = savgol_coeffs(5, 2, deriv=1, delta=dt_s, use='dot')
center = coeff @ position_mm[2:7]
assert np.allclose(per_sample, 5.)
assert np.allclose(per_second, 250.)
assert np.isclose(center, per_second[4])
missing = np.delete(time_s, 4)
assert not np.allclose(np.diff(missing), dt_s)
The first calculation returns 5 across the record. The second returns 250. The only change is the value of delta, with deriv set to one in both calls. The coefficient check asks SciPy for coefficients in dot-product order and applies them to the five input values centered on sample four, counting from zero. The coefficient calculation agrees with the center result from the full filter. A constant offset in position has no effect on the result in this fixture, because the derivative of the fitted line depends on its slope.
Check the clock before choosing delta
Compute differences between timestamps after putting them into the intended unit. A column named time may contain seconds, milliseconds, timer ticks, or sequence numbers. The units should come from the acquisition format or from the clock definition, and the log should identify the source of the timestamp. For an archived device log, differences in integer ticks can be formed before converting the intervals to seconds. The delta passed to a derivative should describe the sampling grid represented by the values the filter receives.
The fixture deletes one timestamp from the middle of the sequence. The remaining times still increase, but the gap between those neighboring values is twice the normal interval. A median interval can still equal the original value. Checking that median alone fails to detect the missing position on the sample grid. The array method uses one spacing across the window, so supplying the median cannot tell it which pair of samples is separated by the gap.
If a real log contains a gap or a rate change, decide whether to split it into contiguous intervals, resample it using a documented method, or fit against actual sample times with a method designed for irregular samples. The choice affects both the estimate and which points can legitimately be displayed. Keep coverage and segment boundaries with the output. Derivative values next to a repaired or missing section may need a separate label because the available measurements differ from those in the middle of a complete segment.
Keep units and window choices together
Window length counts samples. For five samples at 0.02 seconds, the first and last sample times in an interior window are separated by 0.08 seconds. A change in sampling rate changes that time span for the same number of samples, even if the derivative units are still correct after updating delta. Compare reports using both the window length and the physical time span. Also record the polynomial order, the derivative order, and the edge mode. An offline comparison may need to separate interior results from the ends of a run, where the calculation uses the documented edge handling. The linear fixture exercises units without estimating how much noise a particular configuration will reject.
A review can start with three checks. Confirm the measured axis and position unit. Confirm that the timestamps are strictly increasing and spaced closely enough for the chosen grid, with a tolerance that reflects the clock and acquisition process. Then compare the output on a known ramp with its expected physical units. A constant baseline and a ramp with the opposite slope are useful companion checks when reviewing sign or sensor direction. Keep the input sampling interval with the plotted and exported derivative. That gives a reader enough information to reproduce the scale and to judge whether two velocity curves are reasonably comparable.
Sources
SciPy, savgol_filter
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html
SciPy, savgol_coeffs
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_coeffs.html