After checking the audio path in Part 1, I started detection with a loudness threshold. It was inexpensive to run and gave me a way to find out whether a learned model was needed. The threshold became a more capable DSP detector, but its promising early results did not hold up on days I had not used for tuning.

Stage 1: a threshold, a duration gate, and a background that moves

The first stage tracks ambient noise with a slow percentile-follower over ~60 seconds of frame energy. It treats that rolling noise floor as the background. An event must exceed the background by a fixed margin and last long enough to exclude a brief sound such as a door slam:

frame_rms > background + MARGIN_DB   sustained for >= MIN_DURATION_S

The background estimate adapts to two substantial changes: daytime traffic is much louder than night-time traffic, and opening the window changes the recorded level. A fixed threshold cannot accommodate both well. The relative gate uses the same 7 dB margin at 2am and at rush hour, measured above the current background rather than an absolute level.

I adjusted the initial parameter guesses against an hour of levels recorded at the window. Offline replay used the same detector code as the device, avoiding discrepancies from a separate implementation.

Two bugs that only showed up in real audio

That first hour exposed an interaction between event detection and the interval intended to prevent double-counting.

The strongest candidate lasted 11.5 seconds at 27 dB above background, yet the log recorded a 1.8-second event. A faint precursor had crossed the threshold 2.9 seconds earlier and started the 90-second refractory window intended to avoid counting one vehicle twice. The main siren then arrived inside that window and was ignored.

An approaching siren can begin faint and masked before becoming loud and sustained. The detector was therefore mishandling a relevant event shape, and recording the wrong duration and peak level: the very fields that later filtering would use.

The fix was two changes: bridge short gaps between above-threshold runs into one excursion before applying the duration gate, and measure the refractory window from the end of an event rather than its start. Same hour, same audio: 5 events became 10, and the strongest one was finally described correctly.

Checking the fix revealed another problem. A host-side Python replica disagreed with the C firmware on one event: a frame 0.01 dB from the threshold rounded to opposite sides under float32 and float64. Investigating that difference exposed a fault in both implementations. Bridging could join two one-frame spikes 1.5 seconds apart into an event whose elapsed span passed the duration gate, despite containing only 0.2 seconds of above-threshold energy. Two brief bangs could therefore qualify as a sustained event.

What the duration gate measures

I changed the gate to count frames actually above threshold rather than the elapsed time between the first and last ones. This retained gap bridging without allowing the gaps themselves to satisfy the duration requirement.

Loudness alone can't tell you what a siren is

Three days of unattended collection produced 199 clips, including 41 sirens. Recall appeared essentially perfect in these checks, while precision was 21%: about four in five uploaded clips were not sirens.

Clip counts spiked overnight, so I considered adding an absolute loudness floor alongside the relative gate. It would have reduced the corpus from 199 clips to 80 and made the daily curve look more plausible.

Before changing the code, I rendered spectrograms of the nine loudest night clips. Three contained clear wails, quiet in absolute terms against an empty road at 2am. The nine loudest clips across the whole corpus contained no sirens, only vehicle passes and impulsive bangs. These checks gave me little reason to expect another loudness threshold to separate sirens from other sounds.

The labelled sirens instead shared a recognisable spectral pattern:

  • a narrow fundamental that sweeps, roughly 700 → 1700 Hz
  • harmonics at 2f₀ and 3f₀ moving in lockstep with it, often brighter than the fundamental itself
  • the sweep repeats on a 1.5–5 second cycle
  • it persists for many seconds, not one

Engine noise was the closest false-positive because it also forms a harmonic stack. In these clips its fundamental was lower (150–350 Hz) and drifted rather than sweeping. Rain and wind were broadband without the harmonic structure, making them easier to separate using these features.

I added a harmonic-sum score over candidate fundamentals, checking span, sweep rate and periodicity. It needed only a few thousand multiply-accumulates per frame, within the ESP32-S3's budget, and was easy to inspect while labels were scarce. On a visual check, 12/12 top-scoring clips were clear wails and 0/12 bottom-scoring clips were sirens; ambiguous examples fell in the middle.

These spectrograms show the difference in two real labelled clips from the corpus:

Side-by-side spectrograms of a real labelled siren clip showing a repeating diagonal sweep, versus a real labelled traffic clip showing only faint broadband noise
Real clips from the corpus, both unedited. Left: labelled siren, 2026-08-04 07:19 — the repeating 700–1700 Hz sweep is the whole detection signal. Right: labelled other (traffic), 2026-08-04 05:16 — no sweep, no harmonic stack, just quiet broadband noise.

A promising result without the held-out check

By early August, DSP v3 combined the loudness gate and harmonic-sweep score. Against the 121 labels then available, it achieved 97.1% precision at 91.7% recall. That cleared the pre-registered requirement of ≥90% precision at ≥90% recall on non-distant clips. Under the rule I had set, DSP would ship if it met that requirement, without adding ML. I treated the result as sufficient to close that question.

The same entry still called for "another ~50 labels, ideally from a day not yet touched, scored by v3 without further changes." That held-out check did not run as intended. The tool joining scores to labels read only the first three days of a growing scores file, silently dropping every later label from subsequent evaluations.

Backfilling the missing scores and re-running the same tool eight days later reversed the decision:

SetDaysClipsPrecisionRecall
In-sample (v3 tuned here)Aug 1–312294.6%89.7%
Held-out (never touched)Aug 4–65581.2%81.2%
Grouped bar chart: precision and recall both drop when the DSP detector is scored on held-out days it was never tuned against
The exact numbers, plotted: precision and recall both fall on data v3 never saw. Held-out sirens weren't quieter or harder — the model had simply overfit.

Loudness did not explain the drop. Held-out sirens had a marginally higher median margin, 21.2 dB vs 20.2 dB in-sample, and the non-siren distributions matched to within 0.1 dB. That does not rule out every difference between the days, but the result was consistent with overfitting to the spectrogram shapes used for tuning. The original write-up had left generalisation unresolved.

Checking the evaluation path

The early result met the numerical rule on the available data, but the promised held-out check was missing. The join bug made later evaluations appear to include new labels when they did not. Freezing an acceptance rule was not enough; I also needed to verify which data reached the evaluator.

What this settles, and what it reopens

DSP v3 remained the baseline for learned approaches. It was cheap, deployable from the start, and needed zero labelled data for its initial version. The later results did not establish that DSP could never work; they showed that my in-sample result was insufficient to settle the choice. Parts 4 and 5 compare learned models against the same baseline on held-out data.

First, I needed a way to collect labels without favouring one detector over another. Part 3 covers that sampling design.