Real-time signal monitoring requires lightweight, stateful primitives that track envelope, periodicity, and energy without buffering entire waveforms. Three composable detectors cover the most common needs: holding the peak magnitude for VU-style metering, counting sign reversals to estimate frequency, and smoothing instantaneous power to approximate RMS level. All three operate in O(1) time and O(1) memory per sample, making them suitable for tight interrupt service routines.
Let
When
A zero crossing occurs at sample
The instantaneous fundamental frequency of a periodic signal can be estimated from the cumulative count
A one-pole IIR filter is applied to
The RMS envelope is:
This is structurally identical to an exponential moving average applied to the squared signal.
| Detector | Time per sample | State words |
|---|---|---|
| Peak Hold | O(1) — 1 mul, 1 compare, 1 abs | 1 scalar |
| Zero-Crossing Counter | O(1) — 1 compare, 1 abs | 1 scalar + 1 uint32 |
| RMS Envelope | O(1) — 1 MAC + 1 sqrt | 1 scalar |
No buffers, no windows, no dynamic allocation.
| n | ||||
|---|---|---|---|---|
| 0 | 0.8 | 0.8 | 0.0 | 0.8 |
| 1 | 0.0 | 0.0 | 0.4 | 0.4 |
| 2 | 0.0 | 0.0 | 0.2 | 0.2 |
| 3 | 0.0 | 0.0 | 0.1 | 0.1 |
| n | prev sign | curr sign | crossed | C | |
|---|---|---|---|---|---|
| 0 | +1 | 0 | + | no | 0 |
| 1 | -1 | + | - | yes | 1 |
| 2 | +1 | - | + | yes | 2 |
| 3 | -1 | + | - | yes | 3 |
- Decay = 0 collapses the peak hold to the instantaneous absolute value; decay must be in
$(0, 1]$ for meaningful hold behavior. - Zero-crossing sign comparison must treat
$x = 0$ consistently; a sample at exactly zero with$h = 0$ can cause spurious double-counts if not handled. The hysteresis guard mitigates this. - RMS Envelope with very small
$\alpha$ responds slowly to changes in signal level; with$\alpha$ near 1 it approaches the instantaneous absolute value squared. - The RMS detector returns 0 at initialization (
$E_0 = 0$ ) and converges to the true RMS from below for positive-power signals.
- The peak hold decay parameter maps directly to a time constant:
$\tau = -T_s / \ln(d)$ , bridging the gap between digital and analog VU meter release times. - A bilateral zero-crossing counter can distinguish positive-going from negative-going edges, enabling half-wave frequency estimation.
- The RMS envelope is the special case of an exponential moving average applied to
$x^2$ ; replacing the squaring with$|x|$ yields a mean-absolute-value envelope.
- VU meters and compressor side-chains use peak hold with a configurable release time.
- Zero-crossing rate is a low-cost voiced/unvoiced classifier in speech processing.
- RMS envelope tracks AC signal levels in power monitoring, audio dynamic processing, and vibration analysis.
- All three detectors compose naturally into a signal statistics block for real-time diagnostics.
- RMS Envelope is structurally equivalent to the Exponential Moving Average (EMA) filter applied to
$x^2$ , sharing the same one-pole recurrence. - Zero-crossing detection is a degenerate form of edge detection in discrete sequences, related to sign-change detection in root-finding algorithms.
- Zolzer, U., "DAFX: Digital Audio Effects", 2nd ed., Wiley, 2011 — Chapter 2 (dynamics processing, envelope followers).
- Proakis, J. & Manolakis, D., "Digital Signal Processing", 4th ed., Prentice Hall, 2007 — Section 1.4 (zero-crossing rate).
- Smith, J.O., "Introduction to Digital Filters with Audio Applications", W3K Publishing, 2007 — online.