id: rb-analysis feature: 4-analysis branch: feat/4-analysis status: draft created: 2026-09-10 depends_on: [3-waveform-crop]

PRD — Analysis

Goal

Turn the cropped window into one RPM number, and produce the combustion positions that phase 5 will draw on the waveform.

Why

This is the feature. Everything before it exists to hand the analysis a clean window; everything after it presents the answer. The method is already settled and validated offline against seven recordings (audio/combustion-counts.md), so this phase is a port with a test suite, not a research project.

The port is the risky part: an IIR filter, an envelope and an autocorrelation written by hand in TypeScript can be subtly wrong and still return a plausible-looking number. The fixtures are what stop that, which is why they were built in phase 1 rather than here.

User stories

  1. As a user, I press Calculate and see one RPM number for the window I chose.
  2. As a user who knows roughly what the engine idles at, I type a range and the app stops telling me half or double the real figure.
  3. As a user whose recording was too noisy to read, I get told so, rather than a confident wrong number.

Scope

In

Out

Acceptance criteria

  1. A Node test runs the DSP module over all seven fixtures in test/fixtures/ and every one lands inside its toleranceRpm in expected.json.
  2. The two estimators agree within 3 % on all seven fixtures, as they do in the reference table.
  3. Unit tests cover each stage as a pure function: filter response, envelope, autocorrelation lag pick, peak positions, and the pulses-to-RPM conversion.
  4. In the browser, loading a fixture, cropping and pressing Calculate shows a number matching the test suite for that window, within one second on the phone.
  5. An expected range of 1300-1700 applied to a clip that reads 800 yields ~1600; with no range, the same clip still reads 800.
  6. A clip with no engine in it produces the failure message, not a number.
  7. The DSP module imports nothing from src/ui/, src/state/ or the DOM.
  8. npm test, npm run lint and npm run build pass.

Non-goals and constraints

Open questions