PedestrianDynamics / PedestrianDynamics/PedPy
Jitter removal with Savitzky-Golay filter
@awestphal1 is already working on this.
Since Sep 7, 2026.
- Dominant language
- Pascal
- Stars
- 35
- Forks
- 18
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 2
Description
Summary
Implement a Savitzky-Golay filter to reduce positional jitter in pedestrian trajectories. The filter should smooth each pedestrian's x/y coordinates independently while preserving trajectory metadata and frame alignment.
Background / Context
Trajectory data from recordings and simulations can contain small frame-to-frame position fluctuations. Unlike a simple moving average, a Savitzky-Golay filter fits local polynomials to preserve trajectory curvature and peak shape better while still suppressing noise.
Providing a built-in smoothing utility lets users reduce this noise consistently before computing derived quantities such as speed and acceleration, without manually manipulating the underlying DataFrame.
Technical Details
- Add the filtering functionality in the preprocessing API.
- Use
scipy.signal.savgol_filter(or equivalent) as the underlying implementation; addscipyusage in line with the existingscipy~=1.15,<2.0dependency (no new dependency needed). - Accept configurable window length (frames) and polynomial order parameters.
- Smooth
X_COLandY_COLindependently for eachID_COL, ordered byFRAME_COL. - Preserve the original pedestrian IDs, frame numbers, and
TrajectoryDataframe rate. - Validate that window length is odd, positive, greater than the polynomial order, and does not exceed the number of frames available for a given pedestrian; raise an appropriate PedPy custom exception otherwise.
- Define and document boundary behavior for trajectories shorter than the window length.
- Export the public API from
pedpy/__init__.pyand add it to__all__if applicable. - Add unit tests under
tests/unit_tests/for normal operation, multiple pedestrians, boundary/short trajectories, and invalid parameter combinations.
Acceptance Criteria
- Users can apply a Savitzky-Golay filter with configurable window length and polynomial order to a
TrajectoryDatainstance or the trajectory of a specific pedestrian(s) (by ID) - Coordinates are smoothed independently per pedestrian and never use samples from another pedestrian
- Output retains all original IDs, frames, non-coordinate columns, and trajectory metadata.
- Boundary behavior is analyzed and implemented & documented:
- apply filter where possible, remove other data (trajectory may become shorter).
- adaptive window size at border
- take inspiration from scipy
- If window size is larger than trajectory, keep the original trajectory and warn the user
- Use an existing implementation, e.g. scipy
- Invalid window sizes (<=0, even) and invalid polynomial order raise a PedPy custom exception with a useful error message.
- Unit tests cover single- and multi-pedestrian trajectories, boundary frames, and invalid input.
- The new public API is documented.
- Describe how the window size may be chosen and influence on the result
- Describe how the polynomial order should be chosen
- Describe border behavior.
- Describe in which scenarios the Savitzky-Golay may be used to remove jitter from trajectories.
- Describe pre-conditions, when the filter may be applied, e.g., window size vs length of trajectory.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.