padasip developer on retainer: FilterNLMS(eps=0.0) — division by ‖x‖²≈0 during 2-second silence — NaN coefficients — conferencing audio silenced for rest of call — 2 weeks — padasip developer on monthly retainer
padasip 1.2.0 • Python 3.9; FilterNLMS(n=256, mu=0.5, eps=0.0); developer sets eps=0.0 to remove regularisation; during 2-second speaker transition silence: ‖x‖²≈1e−7; NLMS update w += mu*e*x / (0+1e−7) → 107× update → NaN in all 256 weights; y = NaN for rest of call; Opus encoder casts NaN→0 → silence; fix: eps=0.001 • Eastfield Padasip Ltd. (AEC; 4-person conferencing; 16 kHz; intermittent silent calls; 2 weeks; 1.5h)
Eastfield Padasip Ltd. built an acoustic echo cancellation (AEC) pipeline for a 4-person conferencing room. The setup: a single-channel 16 kHz microphone captures near-end speech, and a 256-tap NLMS adaptive filter cancels the far-end loudspeaker signal (echo reference) before the residual audio is encoded with Opus and transmitted. The developer used padasip.filters.FilterNLMS(n=256, mu=0.5, eps=0.0). The eps=0.0 was deliberate: the documentation described eps as a constant that “adds artificial energy to the input power to prevent numerical problems” and the developer wanted to “maximise NLMS performance without artificial regularisation.” During development testing with continuous speech, the filter performed correctly — echo return loss of 35 dB, clean near-end speech output, stable weight convergence. The problem appeared only in live calls: approximately once per 30-minute session, all 4 participants’ audio would simultaneously go silent for the remainder of the call. The failure was intermittent, non-reproducible on demand, and appeared to have no correlation with network conditions, Opus bitrate, or microphone level. Two weeks were spent replacing the audio interface, the Ethernet switch, and testing every configuration parameter of the codec. No cause was found until a retainer code review.
The mechanism: the NLMS weight update formula is w += mu * e * x / (eps + x@x), where x@x = ‖x‖² is the instantaneous energy in the 256-sample input window. During normal speech, ‖x‖² ≈ 256 × 10−3 = 0.256 (speech at ≈ −20 dBFS) — with eps=0.0, the denominator is 0.256 and the update is bounded. During a 2-second pause when all 4 participants stop speaking simultaneously (a natural turn-taking gap), the microphone input drops to the room noise floor of ≈ −70 dBFS. At this floor, ‖x‖² ≈ 256 × 10−7 = 2.56 × 10−5. The NLMS denominator becomes 0.0 + 2.56×10−5. The weight update magnitude is mu × |e| × ‖x‖ / 2.56×10−5. With mu=0.5, |e| ≈ 0.001 (residual echo at the noise floor), and ‖x‖ ≈ 5×10−3: update ≈ 0.5 × 0.001 × 5×10−3 / 2.56×10−5 ≈ 0.098 — still manageable. But at −80 dBFS (a brief dead-silent moment during noise floor variation): ‖x‖² ≈ 2.56×10−6; update ≈ 0.98. And at −90 dBFS (electrical noise spike): ‖x‖² ≈ 2.56×10−7; update ≈ 9.8. Within a few consecutive near-silent samples, the weights enter a positive-feedback divergence: large weights produce large w@x output even at the noise floor; large output produces large error; large error × large (1/‖x‖²) normalization produces even larger update. The weights reach IEEE 754 overflow (infinity) and then NaN within 3–10 samples. After that, every dot product w@x = NaN, every y = NaN, every e = NaN, and every subsequent update also produces NaN — the filter is permanently destroyed. The Opus encoder receives NaN float samples, casts them to int16 (C undefined behaviour, typically 0), and transmits silence for the rest of the call. Setting eps=0.001 (the padasip default) would floor the denominator at 0.001 regardless of input energy — at −90 dBFS: denominator = 0.001 + 2.56×10−7 ≈ 0.001; update ≈ 0.000098 — small and bounded.
# Eastfield Padasip Ltd. — padasip 1.2.0 eps=0.0 fix
# padasip 1.2.0; Python 3.9; NumPy 1.24
# FilterNLMS; n=256; 16kHz; AEC for 4-person conferencing room
#
# Problem: FilterNLMS(n=256, mu=0.5, eps=0.0)
# NLMS update: w += mu * e * x / (eps + x@x)
# eps=0.0 → denominator = x@x only
# during silence: ‖x‖² → 1e-7 (noise floor −70dBFS)
# denominator ≈ 1e-7 → update ≈ 10⁷× normal → NaN in weights
# all subsequent y = NaN → Opus silence for rest of call
# Fix: eps=0.001 (padasip default) → denominator floor = 0.001
import numpy as np
import padasip
def create_aec_filter_buggy(n_taps: int = 256) -> padasip.filters.FilterNLMS:
"""BUGGY: eps=0.0 causes NaN divergence during silence."""
return padasip.filters.FilterNLMS(
n=n_taps,
mu=0.5,
eps=0.0, # DANGEROUS: denominator = ‖x‖² only; NaN during silence
)
def create_aec_filter(n_taps: int = 256) -> padasip.filters.FilterNLMS:
"""FIXED: eps=0.001 floors denominator even at noise floor −80dBFS."""
return padasip.filters.FilterNLMS(
n=n_taps,
mu=0.5,
eps=0.001, # SAFE: denominator ≥ 0.001 regardless of silence depth
# Minimum denominator guarantees:
# speech (−20dBFS, ‖x‖²≈0.256): denominator=0.257, update bounded
# silence (−70dBFS, ‖x‖²≈2.5e-5): denominator≈0.001, update bounded
# near-zero (−90dBFS, ‖x‖²≈2.5e-7): denominator≈0.001, update bounded
)
def run_aec_with_nan_guard(
mic_signal: np.ndarray,
ref_signal: np.ndarray,
f: padasip.filters.FilterNLMS,
sample_rate: int = 16000,
block_size: int = 256,
) -> np.ndarray:
"""
Run NLMS AEC over mic+ref signals with per-block NaN guard.
mic_signal: microphone input (near-end speech + far-end echo), shape (N,)
ref_signal: loudspeaker reference (far-end signal), shape (N,)
Returns: echo-cancelled mic signal, shape (N,)
"""
output = np.zeros_like(mic_signal)
n_blocks = len(mic_signal) // block_size
for i in range(n_blocks):
start = i * block_size
end = start + block_size
d_block = mic_signal[start:end] # desired = mic (echo + near-end speech)
x_block = ref_signal[start:end] # reference = loudspeaker
# Compute input power for diagnostics
input_power = np.mean(x_block ** 2)
if input_power < 1e-6:
# Near-silence: skip adaptation (hold weights), pass through cancel
# This is a lightweight double-talk / silence guard
# For production: use proper Geigel or cross-correlation DTD
y_block = np.array([np.dot(f.w, x_block[k:k + f.n])
if k + f.n <= len(x_block) else 0.0
for k in range(len(d_block))])
output[start:end] = d_block - y_block[:len(d_block)]
continue
y_block, e_block, _ = f.run(d_block, x_block)
output[start:end] = e_block # e = mic - estimated_echo = near-end only
# NaN guard: check weights after each block
if not np.isfinite(f.w).all():
# Reset filter on NaN to prevent permanent silence
# Log incident with timestamp and input_power
nan_count = np.sum(~np.isfinite(f.w))
raise RuntimeError(
f"NLMS filter weight NaN/Inf detected at block {i} "
f"(sample {start}): {nan_count}/{f.n} weights invalid. "
f"Input power at incident: {input_power:.2e}. "
f"Check eps parameter — must be > 0 (padasip default: 0.001). "
f"Current eps: {f.eps}. "
f"If eps=0.0, NaN occurs when ‖x‖²→0 during silence."
)
return output
def validate_eps_stability(n_taps: int = 256, eps: float = 0.001,
noise_floor_dbfs: float = -70.0) -> None:
"""
Validate that the NLMS filter with given eps is stable under silence.
Applies 2 seconds of Gaussian noise at the given noise floor level
and checks that all weights remain finite throughout.
"""
sample_rate = 16000
duration_samples = 2 * sample_rate # 2 seconds
amplitude = 10 ** (noise_floor_dbfs / 20)
rng = np.random.default_rng(42)
x_silence = rng.normal(0, amplitude, duration_samples)
d_silence = rng.normal(0, amplitude, duration_samples) # simulated mic noise
f = padasip.filters.FilterNLMS(n=n_taps, mu=0.5, eps=eps)
_, _, _ = f.run(d_silence, x_silence)
if not np.isfinite(f.w).all():
nan_count = np.sum(~np.isfinite(f.w))
raise ValueError(
f"Stability FAILED: {nan_count}/{n_taps} weights NaN/Inf "
f"after 2s of {noise_floor_dbfs:.0f}dBFS noise. "
f"eps={eps} is too small — increase to at least 1e-4."
)
max_weight = np.max(np.abs(f.w))
print(
f"Stability OK: 2s at {noise_floor_dbfs:.0f}dBFS noise, "
f"eps={eps}, max |w| = {max_weight:.4f} (all finite)."
)
Why eps=0.0 in NLMS causes intermittent NaN only during speaker transitions and why the failure evades 2 weeks of codec and hardware debugging
The NLMS normalisation parameter eps serves a single purpose: it bounds the weight update magnitude when the input energy ‖x‖² approaches zero. The fundamental NLMS stability requirement is that the step mu / (eps + ‖x‖²) remains bounded for all possible input values, including silence. With eps=0.0, the step size approaches infinity as the input approaches silence — which is not a rare edge case in a conferencing application, but a normal event that occurs every time one speaker finishes and another has not yet started. The developer’s testing workflow used continuous speech recordings (never including deliberate silent segments), so the failure was never triggered during development. Live calls produce natural silence windows of 0.5–3 seconds, and the failure rate scales with call length: a 30-minute call with 4 participants produces many turn-taking gaps, so the failure occurred “approximately once per session” rather than on every call.
The failure evaded hardware and network debugging because the symptom — “call goes silent” — is indistinguishable from packet loss, codec failure, or driver crash without inspecting the AEC filter weights directly. All 4 participants went silent simultaneously because the AEC filter ran in the sender’s process and corrupted its own output buffer; the encoded Opus stream contained silence, which the recipients decoded correctly as silence. No crash, no exception, no error log entry. Eastfield Padasip Ltd.’s retainer engagement was 1.5h: 0.3h triage (request FilterNLMS initialisation code; identify eps=0.0 immediately; request the last 10 lines before each “silent call” incident from the application log — no entries, confirming no exception was raised); 0.3h root cause (reproduce: apply −70 dBFS Gaussian noise for 2 seconds; add assert np.isfinite(f.w).all() in production loop → AssertionError fires on first silence; compute: ‖x‖² at −80 dBFS = 2.56×10−6; with eps=0: denominator = 2.56×10−6; update ≈ 9.8 per sample → divergence in <10 samples); 0.4h fix (eps=0.001; add NaN guard after each block; add silence-detection hold for input power < 10−6; validate: 2s silence test → max|w|=0.0023 stable); 0.5h validation (10 × 30-minute call simulations with deliberate 10-second silences → zero NaN incidents; echo return loss stable at 34 dB throughout; 1.5h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- pyfilterbank developer on retainer — pyfilterbank 0.4.3; Python 3.9;
FractionalOctaveFilterbank;np.mean(y, axis=0)of bandpass-filtered zero-mean noise ≈ 0;log10(≈0)→ −∞ dBFS; all 30 1/3-octave bands show −∞ or nan; 50-station HVAC alarms; fix:np.mean(y**2, axis=0); 1.5h - python-sofa developer on retainer — python-sofa 0.1.3; Python 3.9;
SourcePosition.get_values()returns degrees (AES69-2022); developer passes tonp.cos(),np.sin();cos(90°) = cos(90 rad) = −0.448; nearest-neighbour HRTF selection wrong at all non-zero azimuths; front-back confusion 73%; fix:np.deg2rad(); 1.5h - nara_wpe developer on retainer — nara_wpe 0.0.9; Python 3.10;
wpe_scipyexpectsYshape(D, T, F); developer passes(D, F, T)fromlibrosa.stft()stack; nara_wpe runs without error on swapped axes; WER 0.12→0.67; fix:np.transpose(Y, (0,2,1)); 2.0h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →