A force log can show a drop at the beginning and end after median filtering even when the recorded endpoints are high. The filter must decide what enters a window that extends beyond the captured trace. Two common choices, filling with zeros and repeating the nearest measurement, can produce different results without changing a single recorded sample.

Count the values in the endpoint window

Take seven synthetic force readings in newtons: 24, 20, 16, 12, 16, 20, and 24. A centered window of seven needs three values before the first reading. With zero padding, it contains three zeros followed by 24, 20, 16, and 12. The middle value after sorting is 12. With nearest extension, the same window contains three copies of the first value before those four readings. Its median is 24. The last reading has the same result in this symmetric example.

The middle output at index three is computed entirely from the recorded samples. The two edge rules therefore give the same middle value. This makes the test useful for isolating padding from other filter changes.

import numpy as np

from scipy.ndimage import median_filter

from scipy.signal import medfilt

force = np.array([24, 20, 16, 12, 16, 20, 24])

zero_pad = medfilt(force, kernel_size=7)

edge_repeat = median_filter(force, size=7, mode="nearest")

assert zero_pad[[0, -1]].tolist() == [12, 12]

assert edge_repeat[[0, -1]].tolist() == [24, 24]

assert zero_pad[3] == edge_repeat[3] == 20

The assertions pass with SciPy 1.18.1 and NumPy 2.5.5. The endpoint readings in this example differ by 12 newtons. That difference depends on the samples in the window and does not represent a general bias correction.

Choose a policy for the available evidence

Zero padding supplies artificial zero-force values outside the trace. It may be suitable where external evidence establishes a zero baseline, for example a recorded unloaded period. Repeating the endpoint assumes the last observed value persists across the missing part of the window. If the needed samples are unavailable, marking the affected outputs as edge estimates can make that limitation visible.

For a centered window of seven and a single contiguous trace, the first and last three outputs use some form of extension. Record that region alongside the filter size and edge policy. Check both ends before using a filtered trace to judge whether the gripper was loaded as recording began or remained loaded when it ended.

When logs are cut into shorter segments for processing, distinguish cuts made for storage from true acquisition boundaries. Windows at internal cuts can use neighboring recorded samples if those samples are available. If a cut marks a genuine acquisition gap, keep that gap visible in the results. Preserve the raw endpoint readings so another reviewer can reconstruct the window.

Sources

SciPy signal median filter reference for automatic zero padding

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html

SciPy image-processing median filter reference for configurable boundary extension

https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.median_filter.html