← Echolocator RU

Experiment · sound

Echolocator

Your phone or laptop chirps, listens to the echo and sees the room with it: walls, furniture, a hand in front of the screen. Bats and dolphins find their way like this and submarine sonars work like this, but here it is all built from an ordinary speaker and microphone.

A virtual room: the same instrument, with a model of a room with a sofa, a cabinet and a hand instead of the microphone.

  • 🎧 Take your headphones off. The pulses are short but loud, not something to have in your ear. The volume rises step by step, only as far as it has to.
  • 🐈 Cats and dogs hear near-ultrasound better than we do. If a pet pricks up its ears, switch to the low band.
  • 🔒 The sound goes nowhere. The recording is processed right in the browser and is never stored.

Works best in a quiet room, with the device on a table or held at arm’s length.

How it works

An echo is a time

In room air, sound covers 343 metres a second. To a wall 1.7 metres away and back takes exactly 10 milliseconds, and every extra millisecond of delay is another 17 centimetres to the obstacle. At heart, an echolocator does one thing: it measures, very precisely, how long the sound took to come back.

A phone microphone records 48,000 samples a second, one sample for every 3.6 millimetres of distance. That is enough to tell apart objects a couple of centimetres from each other, provided there is something to time: a moment in the recording you can recognise as “there, it came back”.

Why a sweep and not a click

The obvious approach is to click and wait for the echo. A click is short, so its return is easy to pin down. The trouble is that a speaker has a loudness limit: the cone can only move so far. A short click at full volume carries very little energy, and the faint echo from a far wall drowns in noise.

The way out, which nature found before engineers did, is a sweep: a tone gliding from low to high over a few milliseconds. It is long, so it carries hundreds of times more energy. To get the precision back, the recording is compared with the sound that was sent: the template slides along the recording, and at every position you measure how well it matches. This is a matched filter. Wherever a copy of the sweep arrived, the match is sharp, and the long sound collapses into a narrow peak. How narrow depends not on the sweep’s length but on how many frequencies it spans: about two centimetres for 2–20 kHz.

Top: a 5 ms sweep. Middle: a recording with the direct sound, two faint echoes and noise. Bottom: what the matched filter leaves: three sharp peaks, one for each copy. An echo you can’t make out in the recording stands here as a needle of its own.

There is a subtlety. Even after compression the peak keeps “shoulders”, and the direct sound, thousands of times louder than any echo, smothers everything around it with them. So the band is weighted before compression, as radars do: the edges of the frequency range are turned down with a Blackman window. The peak becomes about twice as wide, but the shoulders drop below −58 dB, and an echo 40 dB quieter than the direct sound stays visible.

Sync without a shared clock

To measure an echo’s delay you have to know when the sound left the speaker. The browser can’t say exactly: tens of milliseconds pass between the “play” command and the sound, and as many again between the sound and the microphone handing over its recording. The figure differs from device to device and drifts a little, and an error of one millisecond shifts every distance by 17 centimetres.

The echolocator does without it. The first thing the microphone hears after every pulse is the pulse itself, arriving straight from the speaker a few centimetres away. The earliest strong peak is time zero for that pulse’s echoes, so the unknown delay cancels out on every pulse. The status line shows the delay found on your device and how steady it is: usually it varies by hundredths of a millisecond.

The very first pulse is a long sweep from 150 Hz to the top. Its direct sound shows which frequencies the speaker and microphone let through at all: that is the “What the microphone hears” chart below the instrument.

Frequencies: precision, loudness and materials

Range resolution is inversely proportional to bandwidth: the more frequencies a pulse spans, the narrower its peak. Hence three ready-made bands.

  • Wide, 2–20 kHz. The sharpest, about 2 cm, but clearly audible: a short “chirp” ten times a second.
  • Low, 0.5–4 kHz. Sounds softer, bends round obstacles better and carries further, but the peak is about 11 cm wide.
  • Near-ultrasound, 17–21 kHz. Most adults can barely hear it, but the band is narrow (about 10 cm), and not every speaker and microphone reaches that high.

Frequencies also tell you about materials. Hard, smooth things — a wall, a cabinet, glass — reflect everything alike. Soft, porous things — a sofa, curtains, a jumper — absorb the highs. In “By spectrum” mode each pulse is split into three sub-bands, each compared with its own direct sound so the device’s uneven response doesn’t get in the way, and the echo is coloured: dark means everything came back, warm means the highs were lost, blue means mostly highs came back.

Where does direction come from

One speaker and one microphone give only distance: an echo from 1.5 metres could have come from anywhere — ahead, the side, the ceiling. To get a map, direction has to be found separately.

Radar by turning. A phone hears in almost every direction, but not quite equally: behind it, your hands and body are in the way. Turn slowly on the spot and each pulse lands in its own direction; hundreds of blurry beams add up to a round map. An echo that comes from the same distance everywhere is you and the phone’s case, and it can be subtracted.

Two speakers. A laptop has its speakers at the sides. Pulses come from them in turn, and the delay of each echo draws an ellipse: all the points for which the path “speaker → object → microphone” has that length. Two speakers, two ellipses; the object is where they cross. The instrument doesn’t look for crossings explicitly: every point of the picture checks whether both recordings were loud at the delays it would produce. That is how synthetic-aperture sonars form images. A bonus: the difference between the direct sounds’ arrivals from left and right shows where between the speakers the microphone hides.

Each ellipse is every place the echo could have come from with the measured delay. The foci are a speaker and the microphone. The object sits where they cross.

Doppler: speed from pitch

If a reflector moves, the echo returns at a different frequency: higher when it approaches, lower when it recedes. The shift is Δf = 2·v·f₀/c. With an 18.5 kHz tone, a hand moving at 10 cm/s shifts the echo by about 11 Hz. In Doppler mode the device holds a steady tone, and every 40 ms the instrument takes the spectrum of the recording to within about 6 Hz and looks for energy on either side of the tone. Police radar guns work the same way, and so does Doppler ultrasound, which measures how fast blood flows in the vessels.

Who else does this

Bats call in sweeps from 100 down to 20 kHz a few milliseconds long and can detect wires a fraction of a millimetre thick. Closing in on prey they call faster and shorter, up to two hundred times a second. Horseshoe bats call a long tone instead and pick up the Doppler flutter of an insect’s wingbeats. Dolphins use broadband clicks up to 150 kHz and find fish buried in sand. Ship and submarine sonars work on the same principles, only in water sound is more than four times faster. And people can do it too: blind echolocators such as Daniel Kish click their tongues and tell poles, cars and bushes apart by the echo.

Honest limits

  • Blind zone. Almost nothing closer than 5–15 centimetres shows: the direct sound and the case are still ringing there.
  • Echoes of echoes. Sound can bounce twice, from a wall to a cabinet and back, and draw a “ghost” wall further than the real one.
  • The device interferes. Some phones filter the microphone even when asked not to. Bluetooth speakers and headphones break everything: the delay drifts and the sound comes from somewhere other than the microphone.
  • Direction is rough. A phone has no array of transducers like a sonar, so the radar gives blobs rather than a crisp outline.

But all of it is an ordinary browser, one speaker and one microphone, and every number on the screen is measured right now.