Y·B← All projects
Acoustics · signal processing

Laptop sonar

Bats and submarines find things by listening to echoes. Your laptop can too. It plays a 4-millisecond chirp twelve times a second, near the top of human hearing, and records it with the mic. A matched filter then turns each echo's delay into a distance. Move your hand slowly toward and away from the screen to see it.

Volume. It starts quiet, at 15%. The chirps sit near the top of human hearing: some people (and most pets) can hear them, and they get unpleasant at high volume. Turn it up slowly.

Use the laptop speakers, not headphones. Sonar needs the sound to leave the speaker and bounce back, and near-ultrasonic chirps straight into your ears aren't pleasant.

Needs microphone access and your laptop speakers.
Best in a quiet room, sitting about an arm's length away.
--cm · moving object
Off
sample rate–
band in use–
own chirp heard–
strongest static echo–
speaker → mic responsenot calibrated
echo profile now0 → 150 cm
signal
volume15%
01CalibrateShort tones from 15 to 21 kHz show which frequencies your speaker and mic actually pass, and the sonar uses the strongest stretch.
02Chirp + stackA smooth frequency sweep repeats on one audio clock, so each echo lands at the same spot. Four pings are averaged to cut the noise.
03Matched filterCorrelating the recording with the exact chirp (and its 90° twin) turns each echo into a sharp peak. Every frame is aligned on the direct speaker-to-mic peak.
04Delay → distanceAt 343 m/s, every extra millisecond means about 17 cm out and back. A running background removes static echoes, so a moving hand stands out.

The waterfall is a range-time plot: time scrolls left, distance goes up, and brightness is echo strength.

Tested so far: on a 13-inch MacBook Pro (M1) in Chrome, the built-in microphone runs at 48 kHz with echo cancellation, noise suppression and auto-gain all off. In simulation, a hand from 20 to 140 cm comes back within 2 cm. Real-hand range on hardware hasn't been measured yet.