---
title: On-device keyword spotting on a microcontroller NPU
url: https://gurkanozkan.ai/learn/design/mle-on-device-keyword-spotting-on-a-microcontroller-npu-13/
markdown: https://gurkanozkan.ai/learn/design/mle-on-device-keyword-spotting-on-a-microcontroller-npu-13.md
kind: design
role: ML engineering
json: https://gurkanozkan.ai/api/learn/design/mle-on-device-keyword-spotting-on-a-microcontroller-npu-13.json
---

# On-device keyword spotting on a microcontroller NPU

Ship a wake-word detector that runs always-on on a battery device with an Arm Cortex-M CPU plus an Ethos-U microNPU.

## Constraints

- under 500 KB model size
- under 1 mW average power
- 20 ms frame hop
- false-accept target under 1 per 24 h, false-reject under 5%

## What to cover

- **Requirements**: Ship a wake-word detector that runs always-on on a battery device with an Arm Cortex-M CPU plus an Ethos-U microNPU.
- **Estimates**: under 500 KB model size; under 1 mW average power; 20 ms frame hop; false-accept target under 1 per 24 h, false-reject under 5%.
- **API**
- **Data model**
- **Architecture**: MFCC/log-mel front-end; small depthwise-separable CNN or tiny conformer.; Int8 PTQ or QAT; compiler (Vela) and operator-coverage checks; streaming inference with a ring buffer.; Two-stage cascade (tiny always-on model → larger verifier); on-device threshold calibration.; Data with noise augmentation and far-field simulation.
- **Deep dives**
- **Trade-offs**: accuracy vs memory and power; PTQ (fast) vs QAT (accuracy); NPU operator support vs model choice; cascade complexity.
- **Evaluation**: False accepts/hour on long negative audio; false-reject rate across accents and noise levels.; Latency and energy measured on the target board; int8 vs fp32 accuracy gap.

## Reference design

### Requirements

**Functional**: detect one wake word (assume a two-word phrase like "Hey Nova") continuously from a microphone on a battery device with a Cortex-M CPU and an Ethos-U microNPU; wake the application processor on detection; support sensitivity settings and over-the-air model updates; no audio leaves the device by default.

**Targets (as given)**: model ≤ 500 KB; average power ≤ 1 mW for the always-on path; 20 ms frame hop; false accepts < 1 per 24 h of real household audio; false rejects < 5% across speakers, accents, distances and noise.

**Assumptions to confirm**
- Ethos-U55-class NPU with ~1 MB SRAM shared and ~2 MB flash; a low-power MEMS microphone (PDM); detection latency ≤ 300 ms after the phrase ends.
- Far-field use (0.5–5 m), rooms with TV and music, kitchen noise; children and elderly speakers; UK English accents first, other languages later.
- Privacy: on-device only, telemetry limited to counters; any audio collection is opt-in.
- Power is measured at the board level, so the microphone and memory count, not just the NPU.


### Estimates

- **Front end**: 16 kHz audio, 30 ms window (480 samples), 20 ms hop → **50 frames/s**; 512-point FFT ≈ 256 × 9 butterflies × ~10 ops ≈ 23k ops plus 40 mel filters ≈ 30k ops per frame → ~1.5M ops/s, a few per cent of a 100 MHz Cortex-M with CMSIS-DSP.
- **Stage-1 model**: depthwise-separable CNN, ~50k int8 parameters ≈ **50 KB**; ~5M MACs for a full 1 s window, but run in streaming mode (cached intermediate activations) it needs ~0.3M MACs per hop → 50 × 0.3M ≈ **15M MAC/s**.
- **Stage-2 verifier**: ~300k int8 parameters ≈ **300 KB**, ~20M MACs per run, run only when stage 1 fires (a few times per hour) → negligible average energy.
- **Memory**: 50 KB + 300 KB ≈ 350 KB of weights (< 500 KB with room for front-end tables); SRAM tensor arena ~64–100 KB; feature ring buffer 1.5 s × 50 frames × 40 bins × 1 byte ≈ 3 KB.
- **Power budget**: microphone in low-power mode ~150–250 µW; Cortex-M front end and housekeeping (duty-cycled) ~150 µW; NPU at ~2 pJ/MAC × 15M MAC/s ≈ 30 µW; SRAM retention ~100 µW → **~0.5 mW**, leaving margin; an acoustic activity detector that idles the NPU in silence lowers it further.
- **Why a cascade**: 50 decisions/s = 4.32M per day; meeting < 1 false accept/day at a single stage needs a per-decision false-accept probability around 2 × 10⁻⁷ before smoothing, which a 50 KB model cannot reach alone.


### API

Firmware interface (C), plus offline tooling:
```c
kws_status_t kws_init(const kws_model_t *stage1, const kws_model_t *stage2,
                      const kws_config_t *cfg);   // thresholds, smoothing, refractory period
kws_status_t kws_process_frame(const int16_t *pcm_320_samples, kws_event_t *out);
// out->detected, out->keyword_id, out->score, out->timestamp_ms
void         kws_set_sensitivity(kws_sensitivity_t level);   // maps to calibrated thresholds
void         kws_get_counters(kws_counters_t *c);   // stage-1 triggers, stage-2 accepts, uptime
```
- Detection raises an interrupt to the host with the timestamp; the host may request the last 1.5 s of features for its own verification.
- Model updates arrive as signed blobs (model + thresholds + front-end version) and are swapped atomically with rollback on boot failure.
- Offline: `train → quantise → vela compile → benchmark on board` pipeline producing a versioned blob and a report (accuracy, latency, energy, operator placement).


### Data model

**On device**
- PCM double buffer (DMA), feature ring buffer (int8 log-mel), streaming state buffers per layer, stage-1 posterior history for smoothing.
- Model blobs in flash (stage 1, stage 2), config (thresholds per sensitivity level, smoothing window, refractory period), counters.

**Offline**
- **Utterance**: audio, speaker id, accent, age band, gender, distance, device, room, SNR, transcript, label (wake word / near-miss / other speech).
- **NegativeCorpus**: long recordings (TV, radio, podcasts, conversation, household noise, music) with durations and categories — the denominator for false accepts per hour.
- **AugmentationRecipe**: noise sources, room impulse responses, gain, speed and pitch perturbation, codec effects.
- **ModelArtefact**: float checkpoint, quantised model, Vela report (operators on NPU vs CPU, SRAM use, cycle estimate), board measurements.
- **EvalResult**: model version × firmware version × test set → false-reject rate by slice, false accepts per hour by category, latency, energy.


### Architecture

```
MEMS mic (PDM) ─DMA─► PDM→PCM 16 kHz ─► acoustic activity detector (very low power)
   │ silence → NPU stays idle
   ▼
Cortex-M: framing (30 ms window, 20 ms hop) ─► FFT ─► 40 log-mel (int16→int8)
   ─► feature ring buffer (1.5 s)
   ─► Ethos-U: stage-1 streaming DS-CNN (int8, ~50 KB), one hop at a time
   ─► posterior smoothing (~10 frames) + threshold + refractory period
   ─► on trigger: stage-2 verifier (~300 KB, larger CNN or tiny conformer)
        on the buffered 1.5 s ─► accept ─► interrupt host / wake application
Offline pipeline:
   data (recorded + synthetic TTS positives, hard negatives)
   ─► augmentation (noise, room impulse responses, far-field simulation)
   ─► train float ─► int8 PTQ (calibration set) ─► if gap > 1 point → QAT
   ─► Vela compile + operator-coverage check ─► on-board benchmark
   ─► threshold calibration on long negative audio ─► signed blob ─► OTA
```


### Deep dives

**Operator coverage drives model choice.** Any layer the NPU cannot run falls back to the Cortex-M, which runs it much more slowly and at higher energy. Choose architectures built from well-supported operators (conv, depthwise conv, fully connected, pooling, ReLU), check the Vela report on every change, and treat a CPU fallback as a failing test. This is why a depthwise-separable CNN is the default and a tiny conformer is the verifier only if its attention and normalisation layers compile.

**Quantisation.** Post-training int8 quantisation with a representative calibration set is fast; if the int8 model loses more than ~1 point of false-reject rate at the target false-accept rate versus float, switch to quantisation-aware training. Quantise the front end consistently too — the model must see the same int8 features in training as on device.

**Threshold calibration.** Thresholds are set on long negative audio to hit the false-accept target with margin, then mapped to sensitivity levels. On device, a slowly adapting noise-floor estimate can shift the stage-1 threshold, while stage 2 keeps a fixed, conservative threshold so false accepts stay bounded.


### Trade-offs

- **Accuracy vs memory and power**: bigger models detect better but cost flash, SRAM and energy per hop; the cascade spends capacity only when needed.
- **PTQ (fast) vs QAT (accuracy)**: PTQ takes minutes and is usually enough for CNNs; QAT recovers accuracy for small or attention-based models at the cost of a longer training loop.
- **NPU operator support vs model choice**: the best architecture on paper may not compile; design within the supported operator set rather than accept CPU fallbacks.
- **Cascade complexity**: two models, two thresholds and buffering add engineering and test burden, but they are the practical way to reach < 1 false accept per day within 1 mW.
- **Real vs synthetic data**: TTS-generated positives broaden speaker coverage cheaply but can miss real far-field acoustics; use them to supplement, not replace, recorded data.


### Evaluation

- **False accepts per hour on long negative audio**: ≥ 200 hours across TV, music, conversation and household noise; with zero false accepts in T hours, the 95% upper bound on the rate is 3/T (rule of three), so ≥ 72 h is the bare minimum to claim < 1 per 24 h; report Poisson CIs per category.
- **False-reject rate across accents and noise levels**: ≥ 2,000 positive utterances (95% CI about ±1 point at 5%), sliced by accent, age, distance (0.5–5 m) and SNR (0–20 dB); no slice may exceed ~8%.
- **Latency and energy measured on the target board**: average power with a power analyser over hours of mixed audio, per-hop cycle counts, detection latency after the phrase ends.
- **Int8 vs fp32 accuracy gap**: reported for every model release; QAT triggered if > 1 point.
- **Field monitoring**: opt-in counters (stage-1 triggers per hour, stage-2 accepts, user "I didn't say that" cancellations) by firmware version to catch regressions after OTA updates.


## What a strong design shows

- Budgets memory and power for the whole always-on path (microphone, front end, NPU, SRAM), not just the model.
- Uses a streaming front end and model plus a two-stage cascade to reach the false-accept target.
- Chooses architectures by NPU operator coverage and treats CPU fallback as a failure; knows when PTQ suffices and when QAT is needed.
- Builds data for far-field, noisy, accented use with augmentation and hard negatives.
- Evaluates false accepts per hour on long negative audio with statistical bounds, and measures latency and energy on the real board.

---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
