A robot contact test records a short sensor pulse at sample 2. A dashboard displays the largest reading in a three-sample window, and a review compares the dashboard's first threshold crossing with the raw sensor clock. If the dashboard uses a centered window, the displayed crossing can precede the raw pulse because the calculation includes a later sample.
Check the window on a single pulse
For an odd window of length three, a centered maximum at sample i considers i-1, i, and i+1. The trailing version should consider i-2, i-1, and i. In this one-dimensional SciPy example, origin=1 shifts the same three-sample filter to the trailing position. Constant padding supplies zero wherever a window goes outside this test record.
import numpy as np
from scipy.ndimage import maximum_filter
raw = np.array([0, 0, 9, 0, 0])
centered = maximum_filter(raw, size=3, mode="constant", cval=0)
trailing = maximum_filter(
raw, size=3, origin=1, mode="constant", cval=0,
)
assert centered.tolist() == [0, 9, 9, 9, 0]
assert trailing.tolist() == [0, 0, 9, 9, 9]
The assertions passed with SciPy 1.18.1 and NumPy 2.5.5. With a threshold of 5, the centered result is already above threshold at sample 1. The trailing result first crosses at 2 and stays high through sample 4 because the pulse is still in the window. That longer display interval describes the window's memory. The raw channel still contains a one-sample pulse.
Keep raw time and filtered time available
A centered window can support retrospective plots where the samples on both sides are available. A live indicator that must use only readings already received needs a trailing window or an equivalent streaming calculation. Keep the raw event timestamp separate from the duration of the filtered indicator. Declare the sample rate and window length so readers can translate that duration into time.
Check startup and clip boundaries as well as a pulse in the middle. Zero is an appropriate fixture baseline here. With signed measurements, that padding can become the maximum whenever all observed values in a partial window are negative. A report can withhold results until the full window is available or use a padding value justified by the signal. For arrays with several channels, apply the window along the time dimension and verify that an event on one channel leaves the others unchanged.
Sources
SciPy maximum_filter reference for window origin and boundary settings
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.maximum_filter.html
SciPy maximum_filter1d reference for filtering along one selected axis
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.maximum_filter1d.html