Police, fire and ambulance sirens regularly pass my window, sometimes waking me in the middle of the night. I wanted to measure how often they passed and at what times, so I built a counter using an ESP32-S3 microcontroller and a MEMS microphone, listening at the window 24/7.

This first post in a six-part series covers the audio capture path. Before testing a detector or training a model, I needed to check that the microphone recorded loud sounds cleanly. Distortion here could leave every later stage working from plausible-looking but damaged data.

The hardware, and why I didn't reach for a camera

I considered listening for sirens and watching for vehicles. Audio was the better fit for this first version, with some limits:

  • Cost. At the time of the build, an ESP32-S3 dev board and INMP441 I2S microphone cost about £15–20. The camera option for classifying vehicle liveries started around £45.
  • What it can count. UK police, fire and ambulance sirens use essentially the same tone patterns. Audio can indicate that an emergency vehicle with its siren on passed, but cannot identify the service. It also misses silent, lights-only runs.
  • Privacy. Audio avoids the camera's visual recording of the street, though recording sound still raises privacy questions.

An audio-only count suited the question because the siren is what disturbs me. A camera remained a possible later extension rather than a requirement for the counter.

Stage 0: proving the board is what I paid for

I ordered the N16R8 variant with 16 MB flash and 8 MB octal PSRAM. The listing also offered a cheaper N8R2 with 2 MB PSRAM, so I checked which configuration had arrived before writing firmware.

esptool --chip esp32s3 flash-id reported 16 MB flash and an embedded 8 MB PSRAM feature line. Flash size turned out to be the trustworthy reading — PSRAM reporting is version-dependent and can come back blank on a perfectly good chip, so an absent PSRAM line isn't yet grounds to dispute a purchase. Flash size lying, on the other hand, is.

Both readings matched the ordered configuration. The check took five minutes and let me confirm the memory before the return window closed.

Wiring the mic, and the pins that are already spoken for

Several ESP32-S3 GPIOs were already reserved: 26–32 for SPI flash, 33–37 for octal PSRAM, and others for strapping and USB-JTAG. I used GPIO 4, 5 and 6 for the INMP441's clock, word-select and data-in, connected with short jumper leads. The microphone's L/R pin was tied to ground to select the left channel; it must not be left floating.

The datasheet also sets a clock floor that isn't obvious until you go looking for it: the mic's bit clock has to run at least 0.5 MHz or the part won't produce clean data. At 16 kHz sample rate with 32-bit slots, the clock lands at 1.024 MHz — comfortably clear. The tempting memory-saving move — dropping to 16-bit slots to save buffer space later — halves that to 0.512 MHz, right on the edge of spec. I kept 32-bit slots. The memory saving wasn't worth operating at the limit of what the datasheet promises.

First capture, and the bug that would have poisoned everything after it

With the board checked and the microphone wired, I recorded audio, listened back, and compared it with the sound in the room.

The amplitude looked healthy: a quiet baseline, a 37–40× jump on a finger snap, then a return to baseline. That check alone would not have revealed the fault.

The recording sounded harsh and buzzy. It was recognisable audio, so the fault could easily have been mistaken for poor microphone quality.

I checked several possible causes. The skew was consistent with correct bit alignment, and deliberately changing it made the result worse. There were no anomalous sample-to-sample jumps across 80,000 samples to suggest dropped DMA blocks, and no Nyquist energy spike indicating alternating-sample corruption. Only 5–6% of the energy was at 50/60 Hz, so mains hum did not explain it either.

The actual cause was a gain bug: converting the INMP441's 24-bit samples down to 16 bits used raw >> 14 — a 4× amplification, not the unity conversion I intended. Speech survived it without visibly clipping. A 1 kHz test tone did not: 40,407 of 80,000 samples pinned at full scale, 41.5% total harmonic distortion.

A clean rounded waveform next to an identical waveform with its peaks flattened off by clipping
Speech survives a 4× gain bug and looks fine. A loud siren wouldn't have.

The gain error was particularly relevant to this project: room noise and speech could pass the checks while a loud siren clipped. I changed the conversion to raw >> 16 for unity gain. A quiet recording can be amplified later; clipping discards information that amplification cannot recover.

Repeating the 1 kHz reference-tone test gave 0% clipped samples, with distortion harmonics decaying steeply rather than sitting flat. The measured noise floor was −67.4 dBFS broadband and −74.9 dBFS in the 500–1500 Hz band used for the siren frontend.

The frontend that both paths will share

I then added signal conditioning: a 150 Hz high-pass to remove desk rumble and handling noise, followed by a 500–1500 Hz bandpass targeting the siren's energy, both at 24 dB/octave. Validation against a host-side Python reference gave 0.0001 dB agreement, with both band corners at exactly −3.0 dB and the passband flat within 0.4 dB.

The same filtered, correctly scaled audio feeds the hand-written threshold detector in Part 2 and later the trained models in Parts 4 and 5. Checking this shared stage first gave the detector comparisons a consistent input path.

A few days later, the device captured its first confirmed siren pass at the window while running unattended.

Real waveform of the device's first confirmed siren pass, showing a quiet pre-roll followed by a sustained loud envelope
The actual recording — 2026-08-01, 20:18 local. Quiet pre-roll, then the siren swells into the sustained excursion the trigger was built to catch. (Not the earlier 16:17 clip — that one turned out to be the soundbar during bring-up, retracted two days later.)

What's next

With the capture path and filters checked, I could test detection. Part 2 starts with a threshold on the filtered signal to see how far a simple approach could get before considering a model.