Sensing & deployment · E53 · Implementation prototype

Keep the audio callback small; estimate the motion elsewhere

An acoustic prototype combines a high-frequency carrier, queued microphone blocks and a three-sample sinusoidal identity. It is not a validated breathing monitor.

sounddeviceQueueNumPy / filtering code
The carrier and slower motion variation suggest different time scales; the waveform is explanatory, not a recorded breathing measurement.
Figure 1. Estimate motion from a recurrence. The carrier and slower motion variation suggest different time scales; the waveform is explanatory, not a recorded breathing measurement. Illustrative acoustic waveform. Original vector illustration.

Follow the information

From input to outcome

The microphone records the physical path, while the callback only transfers samples into a queue. Windowed estimation and filtering happen downstream, outside the timing-critical callback.

The microphone records the physical path, while the callback only transfers samples into a queue. Windowed estimation and filtering happen downstream, outside the timing-critical callback.
Figure 2. Information flow. Solid arrows carry observations, tensors or artifacts; other routes are explicitly labelled. Signal shapes, matrices and network icons are schematic, not measured samples or literal neuron counts. Open full-size SVG ↗ On narrow screens, scroll the diagram horizontally.

Read this alongside Figure 1: The carrier and slower motion variation suggest different time scales; the waveform is explanatory, not a recorded breathing measurement. The module map and layer-level figures below expand the operations in this route.

Keep the audio callback small; estimate the motion elsewhere: architectureSpeaker carrier: 20 kHz at 48 kHz sampling → Acoustic path: Microphone observation → Audio callback: Copy block into queue → Windowed estimator: 50 ms context · 10 ms hop → Tracking / filtering: Derived motion proxy. A high-level module map; comparison branches and training details are explained in the article.SENSING & DEPLOYMENT / E53 / MODULE MAP01 INPUTSpeaker carrier20 kHz at 48 kHz sampling02 MODULEAcoustic pathMicrophone observation03 MODULEAudio callbackCopy block into queue04 MODULEWindowed estimator50 ms context · 10 ms hop05 OUTPUTTracking / filteringDerived motion proxy
Source-grounded module map. Boxes summarize operations, not individual neurons; comparison arms and training paths are detailed below. On a small screen, scroll the diagram horizontally.
Speaker carrier — 20 kHz at 48 kHz sampling

The architecture in context

The system we are building

The prototype emits a carrier and processes microphone input to estimate frequency changes. A sounddevice callback supplies output samples and copies input blocks into a queue; the main loop performs estimation and tracking. Separating these paths keeps plotting and heavier processing out of the immediate audio callback.

Who does what in the stack

sounddevice
Handles audio input/output callbacks.
Queue
Decouples capture from processing.
NumPy / filtering code
Estimates frequency and constructs a motion proxy.

The custom estimator uses the sinusoid recurrence x[n−1]+x[n+1]=2 cos(ωT)x[n]. It aggregates products across a window to estimate cos(ωT), clips the estimate to the arccos domain and converts the angle to a frequency. NumPy supplies the arithmetic; the physical interpretation depends on the measurement setup.

Framework responsibility map. Each row maps a library or custom component to its job; rows are not a sequential inference graph.
Framework responsibility map. Each row maps a library or custom component to its job; rows are not a sequential inference graph. Open full-size SVG ↗

Open up the implementation

A frequency estimator inside an audio callback system

A concrete operation-level view of this implementation; no unobserved neural architecture is implied.
A concrete operation-level view of this implementation; no unobserved neural architecture is implied. Open full-size SVG ↗

A sinusoid satisfies a second-order recurrence. The estimator fits its cosine coefficient using local products, then converts it to frequency. At 48 kHz, a 50 ms window contains 2,400 samples; a 10 ms hop supplies a 100 Hz update schedule with overlapping information. That is not 100 independent measurements per second.

The mathematical contract

ω^=arccos⁡∑n(xn−1+xn+1)xn2∑nxn2,f^=Fsω^/(2π)\widehat\omega=\arccos\frac{\sum_n(x_{n-1}+x_{n+1})x_n}{2\sum_n x_n^2},\qquad \widehat f=F_s\widehat\omega/(2\pi)

The ratio needs nonzero signal energy and a valid arccos domain. Clipping prevents numerical NaNs but can hide model mismatch. Multiple reflectors, multiple tones and weak signals need quality diagnostics. The active modality is acoustic emission and reception, not Wi-Fi, and a frequency trace is not yet a validated breathing-rate measurement.

Implementation and resource card

Capacity / budget
Carrier 20 kHz, sample rate 48 kHz, window 50 ms, hop 10 ms. No neural weights or training epochs; this is a model-based signal estimator.
Execution evidence
This revision inspects and explains the archived implementation. It does not rerun the original workload. No unrecorded convergence time, throughput or accelerator result is supplied.
Current reproduction context
Current workstation, supplied by the author: Apple M4, 128 GB unified RAM, 40 GPU cores and 16 CPU cores. This is context for prospective reproduction, not attribution of every archived run. Python and framework versions are not fully locked for these historical sources; declarations, when available, are identified separately.

From explanation to a reproducible check

Check a noiseless 20 kHz sinusoid, then add a nearby tone and lower the signal amplitude. Report estimation error and invalid-window rate. A zero-energy fallback to the carrier is an implementation choice, not evidence of a stable physiological signal.

Preserve input identities, configuration and failure records with the result. A successful numerical check only establishes the operation it exercises: it does not certify an entire dataset, model or deployed system. Reproduce the interface on a small deterministic input before optimizing throughput or increasing workload size.

A closer look at the implementation

The code that carries the idea

The denominator is twice the window’s interior signal energy. A zero denominator returns the nominal carrier rather than a reliable new observation. Clipping prevents NaNs, but can hide a poor model fit if it is not accompanied by a quality indicator.

Python · file · lines 58–73
    x_n = x[1:-1]
    x_prev = x[:-2]
    x_next = x[2:]
    
    num = np.sum((x_prev + x_next) * x_n)
    den = 2.0 * np.sum(x_n**2)
    
    if den == 0:
        return F_CARRIER
    
    cos_wT = num / den
    cos_wT = np.clip(cos_wT, -1.0, 1.0)
    
    wT = np.arccos(cos_wT)
    f_inst = wT / (2 * np.pi * T)
    return f_inst

Verbatim archive excerpt from ghost_v2.py. Context-dependent historical code, not a standalone runnable program. Comments retain their original wording; the article distinguishes implemented behavior from stale or overbroad comments.

The boundary that matters

This is an acoustic experiment, not Wi-Fi sensing. Multiple reflections, carrier leakage, noise and phase discontinuities can violate the single-tone model. A 10 ms hop does not mean a 10 ms independent measurement or validated physiological latency.

Keep building

Other posts of interest