Filter Latency and EMA Explorer
Try Start with Moving average window size (N) at 10, Sample rate (Hz) at 100 and EMA smoothing factor (alpha) at 0.1, then increase alpha.
Observe The moving-average latency begins at 45.0 ms; the EMA value begins at 94.9 ms and falls as alpha rises.
Explain Moving average window size (N) sets delay to (N - 1) / 2 samples. The EMA time constant is -1 / ln(1 - alpha) samples; each sample count is divided by Sample rate (Hz) and multiplied by 1000 to obtain the displayed milliseconds.
Calculate smoothing delays
Reset
Technical boundaries. The comparison assumes the stated window-based noise-reduction estimates and four bytes per stored moving-average value. The EMA row labeled Low-frequency group delay actually computes a time constant; true low-frequency group delay is (1 − alpha) / alpha samples.
Try It: Filter Latency and EMA Explorer
viewof filterWindowSize = Inputs. range ([2 , 64 ], {
value : 10 ,
step : 1 ,
label : "Moving average window size (N)"
})
viewof sampleRateHz = Inputs. range ([1 , 1000 ], {
value : 100 ,
step : 1 ,
label : "Sample rate (Hz)"
})
viewof emaAlpha = Inputs. range ([0.01 , 0.99 ], {
value : 0.1 ,
step : 0.01 ,
label : "EMA smoothing factor (alpha)"
})
maLatencySamples = (filterWindowSize - 1 ) / 2
maLatencyMs = (maLatencySamples / sampleRateHz) * 1000
emaTimeSamples = - 1 / Math . log (1 - emaAlpha)
emaLatencyMs = (emaTimeSamples / sampleRateHz) * 1000
maNoiseReduction = Math . sqrt (filterWindowSize)
emaEquivWindow = 2 / emaAlpha - 1
emaNoiseReduction = Math . sqrt (emaEquivWindow)
html `<div style="background: var(--bs-light, #f8f9fa); padding: 20px; border-radius: 8px; border-left: 4px solid #3498DB; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: #2C3E50; margin-top: 0;">Filter Comparison Results</h4>
<table style="width: 100%; border-collapse: collapse; margin-top: 10px;">
<tr style="background: #eaf2f8;">
<td style="padding: 8px; border-bottom: 1px solid #d4e5f7; font-weight: bold; color: #2C3E50;" colspan="3">Moving Average (N= ${ filterWindowSize} )</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;">Latency</td>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #3498DB; font-weight: bold;"> ${ maLatencySamples. toFixed (1 )} samples = ${ maLatencyMs. toFixed (1 )} ms</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;">Noise reduction</td>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #3498DB; font-weight: bold;"> ${ maNoiseReduction. toFixed (2 )} x</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;">Memory</td>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;"> ${ filterWindowSize} floats = ${ filterWindowSize * 4 } bytes</td>
</tr>
<tr style="background: #eaf2f8;">
<td style="padding: 8px; border-bottom: 1px solid #d4e5f7; font-weight: bold; color: #2C3E50;" colspan="3">Exponential MA (alpha= ${ emaAlpha. toFixed (2 )} )</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;">Low-frequency group delay</td>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #16A085; font-weight: bold;"> ${ emaTimeSamples. toFixed (1 )} samples = ${ emaLatencyMs. toFixed (1 )} ms</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;">Equivalent MA window</td>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #16A085; font-weight: bold;">~ ${ emaEquivWindow. toFixed (0 )} samples</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #2C3E50;">Noise reduction</td>
<td style="padding: 8px; border-bottom: 1px solid #eee; color: #16A085; font-weight: bold;">~ ${ emaNoiseReduction. toFixed (2 )} x</td>
</tr>
<tr>
<td style="padding: 8px; color: #2C3E50;">Memory</td>
<td style="padding: 8px; color: #2C3E50;">One previous output; implementation storage is additional</td>
</tr>
</table>
<p style="margin-top: 15px; color: #555; font-size: 13px; font-style: italic;">
MA group delay = (N−1)/2 samples. EMA time constant = −1/ln(1−alpha) samples. Lower alpha = smoother but slower. Try alpha=0.5 for fast response, alpha=0.05 for heavy smoothing.
</p>
</div>`
Correction: The displayed −1/ln(1−alpha) value is the EMA time constant, not its low-frequency group delay. The group delay tends to (1−alpha)/alpha samples. At alpha = 0.1, these are about 9.49 and 9 samples; at alpha = 0.5, they are about 1.443 and 1 sample.
Back to the chapter