Snapback filter
Kalman filters are a common way to estimate the current state of a system when all you have are noisy measurements. They use a model of the system’s behavior to predict the current state, then blend that prediction with measurements, while tracking the uncertainty of both the measurements and the model. By choosing the right blend of measurements and predictions from past data, they can produce estimates that are more accurate than the measurements alone.
In the PhobGCC, the measured stick positions have a slightly noisy signal, but getting a good estimate of the actual stick position wouldn’t be hard on its own. The main issue is removing unwanted snapback oscillations. So the PhobGCC heavily modifies the Kalman filter to exclude measurements when it thinks the stick is undergoing snapback, with other changes to improve behavior in other situations.
For a thorough introduction to Kalman filters, see kalmanfilter.net.
Filter components
Section titled “Filter components”Current position measurement
Section titled “Current position measurement”When determining the final estimated stick position, the filter weights the current measured position by the smaller of two values:
- Radius weight: the radius of the stick position to the sixth power. This makes the stick respond quickly to full stick inputs. The weight stays very close to 0, then rises very suddenly near the edge. The filter can assume snapback isn’t happening when the stick is near the rim, because by definition snapback only happens when the stick is released.
- Motion weight: 1 when the stick isn’t moving or accelerating along that axis, dropping gradually to 0 as the velocity or acceleration reaches a threshold. This makes the stick respond reasonably quickly to small inputs. The assumption is that problematic snapback outside the deadzone will always have velocity or acceleration (or both) above these thresholds, while small manual stick movements will never come close to them.
Together, these cover both cases: a small input will always be slow compared to snapback, and any input near the rim, even a fast one, will never be snapback.
Prediction of future motion
Section titled “Prediction of future motion”The prediction based on past motion is weighted as the complement of the current position measurement’s weight.
This prediction isn’t designed to be as accurate as possible, though. It’s just an estimate of the desired velocity:
- The velocity estimate is reduced by a damping factor. This is a parameter you can adjust to tame snapback on controllers with particularly strong snapback.
- The velocity estimate is itself a heavily filtered version of the current velocity, built
from three parts:
- The current velocity is weighted by the radius of the stick position squared, so it’s mostly ignored near the center (though less so than the stick position weight).
- The previous filtered velocity is weighted as the complement of the current velocity’s weight, with an extra decay factor to help prevent unwanted slow overshoots when the stick returns to center.
- The disagreement between the previous measured and filtered stick positions is lightly weighted into the filtered velocity. This improves responsiveness without causing overshooting.
Results
Section titled “Results”Smash inputs
Section titled “Smash inputs”For smash inputs, the filter ignores the first part of the stick’s travel, because the stick is moving fast and isn’t near the gate yet, and then it catches up. This means the filtered stick position spends only a very short time in the tilt region, which makes dashbacks, pivots, and wiggling out of tumble more reliable.
Small tilt inputs
Section titled “Small tilt inputs”For small tilt inputs, the stick stays very responsive, because humanly possible stick movements can’t approach the extreme speeds and accelerations of snapback. By closely following the stick when it moves slowly, the PhobGCC stays responsive for small inputs, which helps with fast tilts, turnarounds, and slight DI.
Releasing the stick
Section titled “Releasing the stick”When the stick is released, the high velocity and acceleration of snapback make the filter drastically reduce the weight of the current stick position. This lets it effectively ignore the oscillation and dampen the overshoot.
Thanks to this combination, the PhobGCC’s analog stick filter stays highly responsive for Melee while taming snapback.
Reading the code
Section titled “Reading the code”The filter’s code is well commented and available in the PhobGCC-SW repository.
Documentation licensed under CC BY-SA 4.0, adapted from phobgcc.com.