On this page

Signal Filtering & Noise Suppression

A resistive overlay picks up noise from backlight inverters, switching supplies and ambient EMI. The pico_sdk_touch digitizer runs the fuller conditioning chain; the constants below are the ones in pico_sdk_touch/main.c.

Five stage coordinate filter chain used by the Touch2USB digitizer firmware raw SPI ADC 1. Median filter rejects single-sample spikes 2. Screen remap and clamp scales calibrated ADC limits 3. Exponential moving average alpha = 3/8 low-pass smoothing 4. Jitter threshold suppresses moves under 12 px 5. HID report dispatch release guard 40 ms on lift-off
The digitizer runs the full conditioning chain, so spikes, jitter and a bouncing pen never reach the host.

1. Five-sample median filter

Each axis is read NUM_SAMPLES (5) times per cycle, the samples are sorted and the middle value is kept, so a single high or low spike cannot reach the rest of the pipeline.

2. Screen remap and clamp

The median value is mapped onto the panel’s screen range with the calibration constants, and the result is clamped to 0 to 799 horizontally and 0 to 479 vertically. See XPT2046 and calibration.

3. Exponential moving average

The mapped coordinate is low-pass filtered to smooth motion without adding noticeable lag:

S_t = alpha * Y_t + (1 - alpha) * S_(t-1)

where alpha = EMA_ALPHA_NUM / EMA_ALPHA_DEN, that is 3/8 = 0.375. A lower alpha smooths more but adds lag; a higher one is more responsive but noisier.

4. Jitter threshold

A report is sent only when the smoothed coordinate has moved at least JITTER_THRESHOLD (12 px) on either axis, so a finger held still does not make the cursor tremble.

5. Release guard

On lift-off the interrupt line can float high briefly in the middle of a slow drag. The firmware therefore confirms pen-up only after PENIRQ has stayed high for RELEASE_GUARD_MS (40 ms), which stops a drag ending early.

The mouse target keeps a lighter filter, since a relative cursor tolerates more noise than an absolute digitizer. See PlatformIO Arduino mouse target.