D1214 of 14
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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. Eb/N0 is the SNR times 4000/1200, and each bit is wrong with probability 12e−Eb/2N0 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?

Name it

The transmitter

  1. The text's ASCII bytes, then their CRC-16 (lesson 12), make the payload.
  2. 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.
  3. Continuous-phase FSK at 1200 baud, 1200 and 2200 Hz, 9600 samples per second (lesson 3).

The receiver

  1. The frame can start at any sample, so the receiver tries each of the 8 sampling offsets (lesson 5).
  2. For each, it demodulates with tone correlators (lesson 4) and searches for the sync word, allowing one wrong bit.
  3. 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 2−16 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 L−20log10⁡d−N dB, and Eb/N0 is that plus 10log10⁡(4000/1200) = 5.2 dB. A frame of Nb checked bits survives with probability (1−p)Nb.

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
  1. Count the checked bits. Nb=8×20+40=200
  2. Bit error rate for 90% success. (1−p)200=0.9p=5.27×10−4
  3. Required Eb/N0. Solve 12e−x/2=p for x=Eb/N0: x=−2ln⁡(2p)=13.7 or 11.37 dB.
  4. Required SNR. Eb/N0 is the SNR plus 10log10⁡(4000/1200)=5.23 dB: SNR=11.37−5.23=6.1dB
  5. Solve for the distance. 70−20log10⁡d−45=6.1d=8.8m

Answer about 8.8 m.

Worked example

How long does that 20-character frame take to send?

Show the solution
  1. Frame length. 8×20+80=240bits
  2. Airtime at 1200 baud. t=2401200s=0.2s
  3. 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
  1. How the level falls. Sound pressure falls as 1/r in the open, so halving the distance raises the level by 20log10⁡2=6.0dB while the room's noise stays the same.
  2. 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?

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.