D12 · Lesson 14 · Capstone
Putting every stage together into a modem that sends text as sound, framing with a CRC, FSK modulation, a receiver that finds the frame at an unknown time and sampling phase through echoes and noise, and estimating how far apart a speaker and a microphone can be
Everything so far adds up to a complete link: text to bits, bits to a frame with a sync word and a CRC, the frame to FSK tones, tones through a room with an unknown delay, echoes and noise, and back. In this capstone you build the transmitter and the receiver end to end and send messages through a simulated room. The receiver has to find the message on its own, at an unknown moment and sampling phase, and it accepts only frames whose CRC checks, so a damaged message is rejected rather than printed wrong.
- How often a message gets through, against the distance from speaker to microphone. The speaker produces L dB SPL at 1 m, the room's noise in the modem's 4 kHz band is N dB SPL, and the message is n characters long.
- Sound falls 6 dB per doubling of distance. is the SNR times 4000/1200, and each bit is wrong with probability for orthogonal noncoherent FSK (this modem's tones leak at −14 dB, so it does a little worse).
- A frame needs all its 8n + 40 checked bits right, so success collapses quickly once the SNR runs out. Longer messages fail sooner.
Predict
A phone that decodes reliably 1 m from the speaker is moved to 4 m. How much SNR does it lose?
Sound pressure from a small source falls as 1/d, so the level drops by = 12 dB, 6 dB for each doubling. Echoes in a real room add some energy back, but the direct path is what the receiver locks onto.
Name it
The transmitter
- The text's ASCII bytes, then their CRC-16 (lesson 12), make the payload.
- The frame is 32 preamble bits, the sync word 0xD391, a length byte counting the payload's bytes, the payload, and 8 tail bits so the last real bit isn't cut short (lesson 2). That's 8n + 80 bits for n characters.
- Continuous-phase FSK at 1200 baud, 1200 and 2200 Hz, 9600 samples per second (lesson 3).
The receiver
- The frame can start at any sample, so the receiver tries each of the 8 sampling offsets (lesson 5).
- For each, it demodulates with tone correlators (lesson 4) and searches for the sync word, allowing one wrong bit.
- It reads the length and the payload, and accepts the frame only if the CRC over the payload, CRC included, comes out 0.
Wrong offsets either miss the sync word or produce a payload that fails the CRC, so the first frame that passes is the right one with a false-acceptance chance of per attempt.
Link budget
With the speaker's level L at 1 m and noise N in the band, the SNR at distance d is dB, and is that plus = 5.2 dB. A frame of checked bits survives with probability .
Through real air
Pyodide in the browser can't use the microphone, so this lab sends its audio through a simulated room. The same functions work on a laptop: play transmit()'s samples at 9600 samples per second on one device, record on another, and pass the recording to receive(). Real sound cards add a sample-rate mismatch of tens of parts per million, which a 200-bit frame tolerates easily (lesson 5).
Worked example
A speaker plays at 70 dB SPL at 1 m in a 45 dB room. How far away can a 20-character message get through 90% of the time?
Show the solution
- Count the checked bits.
- Bit error rate for 90% success.
- Required . Solve for : or 11.37 dB.
- Required SNR. is the SNR plus dB:
- Solve for the distance.
Answer about 8.8 m.
Worked example
How long does that 20-character frame take to send?
Show the solution
- Frame length.
- Airtime at 1200 baud.
- Going faster. A higher bit rate would need tones farther apart or a more efficient modulation such as QPSK or OFDM, along with the carrier recovery and equalization of lessons 8, 11 and 13.
Answer 0.2 s.
Worked example
How much SNR does halving the distance from the speaker gain?
Show the solution
- How the level falls. Sound pressure falls as 1/r in the open, so halving the distance raises the level by while the room's noise stays the same.
- In a real room. In a reverberant room the gain is smaller, because reflections keep the level up far from the speaker.
Answer 6.0 dB in the open, and less in a reverberant room.
Check
Build the whole modem: a framed, CRC-checked FSK transmitter, and a receiver that finds the message in a noisy, echoing room.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
How long does this modem take to send a 20-character message, frame included?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A receiver measures 10 dB of SNR in a 4000 Hz band and receives 1200 bits per second. What's its Eb/N0?
Check
Bits are wrong with probability 0.003. What's the chance that a 10-character frame's 8n + 40 checked bits all arrive right?
Check
A message of 20 characters carries 8 bits each plus 40 bits of checked framing, and must arrive whole with probability 0.99.
(a)
What bit error rate can be tolerated?
(b)
How long does it take at 1200 baud?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A speaker plays at 70 dB SPL at 1 m in a room whose noise is 35 dB SPL.
(a)
What SNR is there at 4 m, in the open?
(b)
And at half that distance?
Explain why
Why does the receiver check the CRC before trusting a frame, even when it found the sync word?
Finding the sync word only means some stretch of bits looked like it, which can happen by chance in noise or at a wrong sampling offset, and even a genuine frame can have bits flipped by noise or echoes in its payload. Without a check, the receiver would print garbage or a subtly wrong message as if it were real. The CRC is computed by the transmitter over the exact payload, so if any bit changed, the receiver's remainder comes out nonzero and the frame is rejected; only about one corrupted frame in 65,536 slips through. That lets the receiver try every sampling offset and accept the first frame that passes, knowing it's almost certainly the message that was sent.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.