Applies a digital Butterworth lowpass-filter to an XY data object. [1]
For filtering, the scipy.filter.butter and the scipy.signal.filtfilt functions are
used. This function provides a convenience access to both functions, directly
applying the filter to all non-NaN sequences in all columns.
Parameters:
xy (XY) – Floodlight XY Data object.
order (int, optional) – The order of the filter. Corresponds to the argument N from the scipy.
signal.butter function. Default is 3
Wn (Numeric, optional) – The normalized critical cutoff frequency. Corresponds to the argument Wn
from the scipy.signal.butter function. Default is 1.
remove_short_seqs (bool, optional) – If True, sequences that are too short for the filter with the specified settings
are replaced with np.nan. If False, they are kept unfiltered. Default is False.
kwargs – Optional arguments {‘padtype’, ‘padlen’, ‘method’, ‘irlen’} that can be passed
to the scipy.signal.filtfilt function.
Returns:
xy_filtered – XY object with position data filtered by designed Butterworth low pass filter.
The values of the input data are assumed to be numerical. Missing data is assumed
to be either np.nan or None. The Butterworth-filter requires a minimum signal length
depending on the settings. A signal is a sequence of data in the XY-object that is
not interrupted by missing values. The minimum signal length is defined as
\(3 \cdot (order + 1)\). The treatment of signals shorter than the minimum
signal length are specified with the remove_short_sequence-argument, where True
will replace these sequences with np.nan and False will keep the sequences in the
data unfiltered.
Applies a FIR lowpass-filter to an XY data object.
For filtering, the scipy.signal.firwin and the scipy.signal.filtfilt functions are
used. This function provides a convenience access to both functions, directly
applying the filter to all non-NaN sequences in all columns.
Parameters:
xy (XY) – Floodlight XY Data object.
numtaps (int, optional) – Length of the FIR filter (number of coefficients, i.e. the filter order + 1).
numtaps must be odd for a Type I filter. Corresponds to the argument
numtaps from the scipy.signal.firwin function. Default is 21.
cutoff (Numeric, optional) – The cutoff frequency of the filter in Hz. Corresponds to the argument cutoff
from the scipy.signal.firwin function. Default is 1.
window (str, optional) – Desired window to use for the FIR filter design. Corresponds to the argument
window from the scipy.signal.firwin function. Default is
"hamming".
remove_short_seqs (bool, optional) – If True, sequences that are too short for the filter with the specified settings
are replaced with np.nans. If False, they are kept unfiltered. Default is False.
kwargs – Optional arguments {‘padtype’, ‘padlen’, ‘method’, ‘irlen’} that can be passed
to the scipy.signal.filtfilt function.
Returns:
xy_filtered – XY object with position data filtered by the designed FIR lowpass filter.
The values of the input data are assumed to be numerical. Missing data is assumed
to be either np.nan or None. The FIR filter requires a minimum signal length
depending on the settings. A signal is a sequence of data in the XY-object that is
not interrupted by missing values. The minimum signal length is defined as
\(3 \cdot numtaps\). The treatment of signals shorter than the minimum
signal length are specified with the remove_short_seqs-argument, where True
will replace these sequences with np.nan and False will keep the sequences in the
data unfiltered.
Applies a forward Kalman filter to an XY data object. [3]
Uses a constant-velocity motion model where the state vector consists of
position and velocity. Only positions are observed. The filter smooths noisy
position data by combining predictions from the motion model with the
observed measurements.
Parameters:
xy (XY) – Floodlight XY Data object. Must have framerate set.
process_noise (float, optional) – Process noise intensity (acceleration variance in m²/s⁴) that controls
how much the model trusts the constant-velocity prediction. Larger
values allow faster changes in velocity. Default corresponds to
\(\sigma_a = 1\,\mathrm{m/s^2}\), which is a conservative smoothing
prior.
measurement_noise (float, optional) – Measurement noise variance (in m²) controlling how much the model
trusts the observed positions. Larger values produce smoother output.
Default is 0.04, corresponding to 0.20 m RMSE, a conservative
estimate for common optical [4] and local [5] tracking systems
during high-dynamic situations.
Returns:
xy_filtered – XY object with position data filtered by the Kalman filter.
The Kalman filter requires xy.framerate to be set in order to compute
the time interval between frames.
The default noise parameters assume positions are given in meters. If
positions use a different unit (e.g. centimeters), the noise parameters
must be adjusted accordingly (e.g. measurement_noise=20.0**2 for
20 cm RMSE in centimeter units).
Unlike butterworth_lowpass() and
savgol_lowpass(), the Kalman filter
handles missing data (NaN) natively. When an observation is missing, the
filter runs a predict-only step, maintaining its internal state (velocity
estimate, covariance) across gaps. Frames with missing input data remain
NaN in the output — no gap-filling is performed.
Applies a Savitzky-Golay lowpass-filter to an XY data object. [2]
For filtering, the scipy.filter.savgol function is used. This function
provides a convenient access to the function, directly applying the filter to all
non-NaN sequences in all columns.
Parameters:
xy (XY) – Floodlight XY Data object.
window_length (int, optional) – The length of the filter window. Corresponds to the argument window_length
from the scipy.filter.savgol function. Default is 5.
poly_order (Numeric, optional) – The order of the polynomial used to fit the samples. poly_order must be less
than window_length. Default is 3. Corresponds to the argument poly_order
from the scipy.filter.savgol function. Default is 5.
remove_short_seqs (bool, optional) – If True, sequences that are too short for the filter with the specified settings
are removed from the data. If False, they are kept unfiltered. Default is False.
kwargs – Optional arguments {‘deriv’, ‘delta’, ‘mode’, ‘cval’} that can be passed to
the scipy.signal.savgol function.
Returns:
xy_filtered – XY object with position data filtered by designed Savitzky-Golay low pass
filter.
The values of the input data are assumed to be numerical. Missing data is assumed
to be either np.nan or None. The Savitzky-Golay-filter requires a minimum signal
length depending on the settings. A signal is a sequence of data in the XY-object
that is not interrupted by missing values. The minimum signal length is defined as
the window_length. The treatment of signals shorter than the minimum signal
length are specified with the remove_short_sequence-argument, where True will
replace these sequences with np.nan and False will keep the sequences in the data
unfiltered.
For filtering, the scipy.signal.wiener function is used. This function provides a
convenient access to the function, directly applying the filter to all non-NaN
sequences in all columns.
Parameters:
xy (XY) – Floodlight XY Data object.
window_size (int, optional) – Size of the local window used for noise estimation and filtering. Corresponds
to the argument mysize from the scipy.signal.wiener function.
Default is 5.
noise (float, optional) – Noise power estimate. If None, the noise power is estimated locally from the
data within the window. Corresponds to the argument noise from the
scipy.signal.wiener function. Default is None.
remove_short_seqs (bool, optional) – If True, sequences that are too short for the filter with the specified settings
are replaced with np.nan. If False, they are kept unfiltered. Default is False.
Returns:
xy_filtered – XY object with position data filtered by the Wiener filter.
The values of the input data are assumed to be numerical. Missing data is assumed
to be either np.nan or None. The Wiener filter requires a minimum signal length
depending on the settings. A signal is a sequence of data in the XY-object that is
not interrupted by missing values. The minimum signal length is defined as
the window_size. The treatment of signals shorter than the minimum signal
length are specified with the remove_short_seqs-argument, where True will
replace these sequences with np.nan and False will keep the sequences in the
data unfiltered.