LearnSystem design

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.

ML engineering8 parts

Contents

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

Sketch your own design first. A complete answer has these parts; the notes say what each should settle.

  1. RequirementsShip a wake-word detector that runs always-on on a battery device with an Arm Cortex-M CPU plus an Ethos-U microNPU.
  2. Estimatesunder 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%.
  3. API
  4. Data model
  5. ArchitectureMFCC/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.
  6. Deep dives
  7. Trade-offsaccuracy vs memory and power; PTQ (fast) vs QAT (accuracy); NPU operator support vs model choice; cascade complexity.
  8. EvaluationFalse 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

One way to answer it, part by part. Open a part once you have your own version of it.

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

Stack · 4 layersMemory and power budget for the always-on path

  1. Stage-1 ~50 KB plus stage-2 ~300 KB ≈ 350 KB of weights, under the 500 KB limit with room for front-end tables.

  2. SRAM tensor arena ~64–100 KB and a 1.5 s feature ring buffer of about 3 KB.

  3. Microphone ~150–250 µW, Cortex-M front end ~150 µW, NPU ~30 µW and SRAM retention ~100 µW.

  4. ~0.5 mW average, leaving margin under the 1 mW target; an acoustic activity detector can idle the NPU in silence.

The always-on path fits under 500 KB of weights and roughly 0.5 mW average power, leaving margin against the 1 mW target.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
  • 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:

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

Flow · 3 stepsOn-device keyword spotting path

On-device keyword spotting pathA MEMS PDM microphone feeds PDM-to-PCM 16 kHz audio into an acoustic activity detector, then a Cortex-M front end frames 30 ms windows at a 20 ms hop, computes FFT and 40 log-mel features, and writes int8 features to a 1.5 s ring buffer. The Ethos-U runs the stage-1 depthwise-separable CNN one hop at a time; smoothing, threshold and refractory period decide whether stage 2 runs on the buffered 1.5 s, and an accept interrupts the host.MEMS mic (PDM)low-power PDMPDM→PCM 16 kHzDMAAcoustic activity detectorsilence idles NPUCortex-M front end30 ms window · 20 ms hopFeature ring buffer1.5 s · int8 log-melStage-1 DS-CNNEthos-U · int8 · ~50 KBSmoothing + threshold~10 frames · refractoryStage-2 verifier~300 KB · buffered 1.5 sHost interrupt / wake apptimestamp on detectionDMA16 kHzactiveint8 log-melone hopposteriortriggeraccept123InputFront endInferenceOutput
  1. Capture and frame PDM audio is converted to 16 kHz PCM, activity is checked, and the Cortex-M frames 30 ms windows at a 20 ms hop into int8 log-mel features.
  2. Stream stage 1 The ring buffer feeds the Ethos-U stage-1 depthwise-separable CNN one hop at a time; posteriors pass to smoothing, threshold and refractory period.
  3. Verify and wake On trigger, the stage-2 verifier runs on the buffered 1.5 s; an accept raises the host interrupt and wakes the application.

Audio enters through the PDM microphone, is framed and converted to int8 log-mel features, runs a streaming stage-1 model, and only a trigger reaches the stage-2 verifier and host wake-up.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Capture and framePDM audio is converted to 16 kHz PCM, activity is checked, and the Cortex-M frames 30 ms windows at a 20 ms hop into int8 log-mel features.
2Stream stage 1The ring buffer feeds the Ethos-U stage-1 depthwise-separable CNN one hop at a time; posteriors pass to smoothing, threshold and refractory period.
3Verify and wakeOn trigger, the stage-2 verifier runs on the buffered 1.5 s; an accept raises the host interrupt and wakes the application.

Source: This page's text

Boxes
BoxGroupDetail
MEMS mic (PDM)Inputlow-power PDM
PDM→PCM 16 kHzInputDMA
Acoustic activity detectorInputsilence idles NPU
Cortex-M front endFront end30 ms window · 20 ms hop
Feature ring bufferFront end1.5 s · int8 log-mel
Stage-1 DS-CNNInferenceEthos-U · int8 · ~50 KB
Smoothing + thresholdInference~10 frames · refractory
Stage-2 verifierInference~300 KB · buffered 1.5 s
Host interrupt / wake appOutputtimestamp on detection

Source: This page's text

Flow · 4 stepsOffline model path for the wake-word detector

Offline model path for the wake-word detectorA left-to-right flow of nine boxes grouped as Data, Train, Verify and Ship. Recorded and synthetic TTS positives with hard negatives are augmented, trained as a float model, quantised to int8 with PTQ (falling back to QAT if the gap exceeds 1 point), compiled with Vela and checked for operator coverage, benchmarked on the board, calibrated on long negative audio, then packed as a signed blob for OTA.Datarecorded + TTS positives, hardnegativesAugmentationnoise, room impulse responses,far-fieldTrain floatfloat checkpointInt8 PTQcalibration setQATif gap > 1 pointVela compileoperator-coverage checkOn-board benchmarkaccuracy, latency, energyThreshold calibrationlong negative audioSigned blobversioned, OTAgap within 1 pointgap > 1 point1234DataTrainVerifyShip
  1. Prepare data Recorded and synthetic TTS positives with hard negatives are augmented with noise, room impulse responses and far-field simulation.
  2. Train and quantise The float model is trained, then quantised to int8 with PTQ on a calibration set; if the gap exceeds 1 point, QAT is used instead.
  3. Compile and benchmark Vela compiles the model with an operator-coverage check, then the build is benchmarked on the board.
  4. Calibrate and ship Thresholds are calibrated on long negative audio, then the versioned signed blob is produced for OTA.

The offline pipeline turns recorded and synthetic data into a signed, calibrated blob that is shipped over the air.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Prepare dataRecorded and synthetic TTS positives with hard negatives are augmented with noise, room impulse responses and far-field simulation.
2Train and quantiseThe float model is trained, then quantised to int8 with PTQ on a calibration set; if the gap exceeds 1 point, QAT is used instead.
3Compile and benchmarkVela compiles the model with an operator-coverage check, then the build is benchmarked on the board.
4Calibrate and shipThresholds are calibrated on long negative audio, then the versioned signed blob is produced for OTA.

Source: This page's text

Boxes
BoxGroupDetail
DataDatarecorded + TTS positives, hard negatives
AugmentationDatanoise, room impulse responses, far-field
Train floatTrainfloat checkpoint
Int8 PTQTraincalibration set
QATTrainif gap > 1 point
Vela compileVerifyoperator-coverage check
On-board benchmarkVerifyaccuracy, latency, energy
Threshold calibrationVerifylong negative audio
Signed blobShipversioned, OTA

Source: This page's text

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.