Data Communication · Lecture 5
Sampling, quantisation and encoding: how a voice becomes bits
Md Mahbub E Noor · Assistant Professor, Department of CSE, University of Barishal
Course: Data Communication · 2nd Year, 2nd Semester
The conversion roadmap
| Lecture | Conversion | Example |
|---|---|---|
| 5 · today | Analog → digital | Voice → bits (PCM) |
| 6 | Digital → digital | Bits on Ethernet |
| 7 | Digital → analog | Bits on Wi-Fi |
| 8 | Analog → analog | Voice on FM radio |
Reading: Forouzan, Sections 4.2 and 4.3
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
2 / 38
The PCM encoder
Sample
measure at fixed times
Quantise
round to a level
Encode
level → n bits
Then line coding (Lecture 6) turns the bits into a digital signal.
| Why digitise? | Because… |
|---|---|
| Noise | repeaters regenerate clean bits; amplifiers cannot |
| Processing | compress, encrypt and error-check with software |
| One network | voice, video and data all become bits |
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
3 / 38
Ideal: instant impulses
Natural: pulse tops follow
Flat-top: sample and hold
Sampling interval Ts (seconds) and sampling rate fs = 1 / Ts (samples per second). Flat-top, using a sample-and-hold circuit, is what real converters use.
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
4 / 38
fs ≥ 2 × fmax
fmax = the highest frequency in the signal. 2 × fmax is the Nyquist rate.
| Signal | Highest frequency | Sampling rate used |
|---|---|---|
| Telephone voice | about 4 kHz (filtered) | 8,000 samples/s |
| CD audio | about 20 kHz (hearing limit) | 44,100 samples/s |
| Studio audio | about 20 kHz | 48,000 or 96,000 samples/s |
Engineers sample a bit above 2 fmax because real filters are not perfectly sharp.
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
5 / 38
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
6 / 38
Interactive
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
7 / 38
(a) Voice, fmax = 4 kHz
fs ≥ 2 × 4,000
8,000 samples/s
(b) Low-pass signal, 0 to 200 kHz
fs ≥ 2 × 200 kHz
400,000 samples/s
(c) 5 Hz sampled at 6 samples/s
|5 − 6| = 1
alias at 1 Hz
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
8 / 38
Checkpoint 1 · 3 minutes
Music contains frequencies up to 15 kHz. What is the minimum sampling rate?
A 7 Hz signal is sampled at 10 samples per second. Is there aliasing? What frequency appears?
Why must the anti-aliasing filter come before the sampler, not after?
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
9 / 38
Signal vs quantised: 8 levels (dashed boundaries)
Δ = (Vmax − Vmin) / L
|error| ≤ Δ / 2
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
10 / 38
SQNR(dB) = 6.02 n + 1.76
n = bits per sample; for a full-range sine-wave signal
| Bits per sample n | Levels L | SQNR | Typical use |
|---|---|---|---|
| 3 | 8 | 19.8 dB | Classroom examples |
| 8 | 256 | 49.9 dB | Telephone voice |
| 16 | 65,536 | 98.1 dB | CD audio |
| 24 | 16.7 million | 146 dB | Studio recording |
Rule of thumb: each extra bit adds about 6 dB. A telephone line needing SQNR ≥ 40 dB needs n ≥ (40 − 1.76)/6.02 = 6.35, so 7 bits.
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
11 / 38
μ-law curve (μ = 255) vs straight line: quiet sounds get more of the levels
μ-law: North America and Japan
A-law: Europe and most other countries
Both: 8 bits per sample, about the same quality as 12-bit uniform quantisation for speech
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
12 / 38
Interactive
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
13 / 38
n = log₂ L bits per sample
bit rate = fs × n
Bmin ≈ n × Banalog
Last line: for a low-pass signal sampled at the Nyquist rate (B = fmax)
| Zone i | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Code (n = 3) | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
14 / 38
Telephone: 8,000 samples/s × 8 bits
fs × n
64 kbps
Bandwidth needed for that voice channel
n × B = 8 × 4 kHz
32 kHz (vs 4 kHz analog)
CD: 44,100 × 16 bits × 2 channels
fs × n × channels
1.411 Mbps
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
15 / 38
Interactive
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
16 / 38
Checkpoint 2 · 3 minutes
Range −2 V to +2 V, 3 bits. What is Δ, and which code does a sample of 0.9 V get?
How many bits per sample give an SQNR of at least 60 dB?
A 10 kHz signal is sampled at the Nyquist rate with 10 bits. What is the bit rate?
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
17 / 38
Samples (V): −6.1, 7.5, 16.2, 19.7, 11.0, −5.5, −11.3, −9.4, −6.0
7
6
5
4
3
2
1
0
+4Δ
+3Δ
+2Δ
+1Δ
+0Δ
-1Δ
-2Δ
-3Δ
-4Δ
Left: quantisation codes 0–7 and zone boundaries in units of Δ · red: samples · orange: quantised values
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
18 / 38
| Sample | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Amplitude (V) | -6.1 | +7.5 | +16.2 | +19.7 | +11.0 | -5.5 | -11.3 | -9.4 | -6.0 |
| Normalised PAM (x/Δ) | -1.22 | +1.50 | +3.24 | +3.94 | +2.20 | -1.10 | -2.26 | -1.88 | -1.20 |
| Normalised quantised | -1.50 | +1.50 | +3.50 | +3.50 | +2.50 | -1.50 | -2.50 | -1.50 | -1.50 |
| Normalised error | -0.28 | +0.00 | +0.26 | -0.44 | +0.30 | -0.40 | -0.24 | +0.38 | -0.30 |
| Quantisation code | 2 | 5 | 7 | 7 | 6 | 2 | 1 | 2 | 2 |
| Encoded word | 010 | 101 | 111 | 111 | 110 | 010 | 001 | 010 | 010 |
x/Δ → zone z = ⌊x/Δ⌋ → quantised = z + 0.5 → error = quantised − x/Δ
code = z + L/2 = z + 4 → encoded word = code in 3-bit binary
Textbook typo: sample 1's error is printed as −0.38; it is −1.50 − (−1.22) = −0.28.
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
19 / 38
| Sample | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Normalised PAM (x/Δ) | -2.44 | +3.00 | +6.48 | +7.88 | +4.40 | -2.20 | -4.52 | -3.76 | -2.40 |
| Normalised quantised | -2.50 | +3.50 | +6.50 | +7.50 | +4.50 | -2.50 | -4.50 | -3.50 | -2.50 |
| Normalised error | -0.06 | +0.50 | +0.02 | -0.38 | +0.10 | -0.30 | +0.02 | +0.26 | -0.10 |
| Quantisation code | 5 | 11 | 14 | 15 | 12 | 5 | 3 | 4 | 5 |
| Encoded word | 0101 | 1011 | 1110 | 1111 | 1100 | 0101 | 0011 | 0100 | 0101 |
| n = 3 (book) | n = 4 | |
|---|---|---|
| Levels L = 2ⁿ | 8 | 16 |
| Δ = 40 / L | 5 V | 2.5 V |
| Largest possible error Δ/2 | 2.5 V | 1.25 V |
| SQNR = 6.02n + 1.76 | 19.82 dB | 25.84 dB |
| Bits for 9 samples | 27 | 36 |
Now Δ = 2.5 V, so x/Δ doubles, zones run −8 to +8, and code = ⌊x/Δ⌋ + 8.
One more bit: half the error, +6 dB, but 33% more bits to send.
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
20 / 38
0: 010
1: 101
2: 111
3: 111
4: 110
5: 010
6: 001
7: 010
8: 010
Unipolar NRZ: 1 = +V, 0 = 0 V for the whole bit interval (27 bits)
0
1
0
1
0
1
1
1
1
1
1
1
1
1
0
0
1
0
0
0
1
0
1
0
0
1
0
Polar NRZ: 1 = +V, 0 = −V
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
21 / 38
Samples (k = 0…7): 0.00, 0.78, 0.97, 0.43, −0.43, −0.97, −0.78, 0.00
Dashed blue: signal · red: samples · orange: quantised values · dashed lines: the 8 zones
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
22 / 38
| k | t | Sample | Zone i = ⌊(x − Vmin)/Δ⌋ | Quantised value | Code | Error |
|---|---|---|---|---|---|---|
| 0 | 0.000 | +0.00 | 4 | +0.125 | 100 | +0.125 |
| 1 | 0.898 | +0.78 | 7 | +0.875 | 111 | +0.095 |
| 2 | 1.795 | +0.97 | 7 | +0.875 | 111 | -0.095 |
| 3 | 2.693 | +0.43 | 5 | +0.375 | 101 | -0.055 |
| 4 | 3.590 | -0.43 | 2 | -0.375 | 010 | +0.055 |
| 5 | 4.488 | -0.97 | 0 | -0.875 | 000 | +0.095 |
| 6 | 5.386 | -0.78 | 0 | -0.875 | 000 | -0.095 |
| 7 | 6.283 | +0.00 | 4 | +0.125 | 100 | +0.125 |
PCM bit stream (24 bits)
100 111 111 101 010 000 000 100
Largest error 0.125 = Δ/2 · theory SQNR = 6.02 × 3 + 1.76 = 19.8 dB
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
23 / 38
If we had used only the sample extremes (−1.4 to 2.2), the true peak of 2.25 would be clipped (overload).
The curve peaks near 2.25 and dips near −1.5, but the samples only reach 2.20 and −1.40
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
24 / 38
| k | t | Sample | Zone i = ⌊(x − Vmin)/Δ⌋ | Quantised value | Code | Error |
|---|---|---|---|---|---|---|
| 0 | 0 | +0.00 | 3 | +0.150 | 011 | +0.150 |
| 1 | 1 | +2.20 | 7 | +2.150 | 111 | -0.050 |
| 2 | 2 | +1.00 | 5 | +1.150 | 101 | +0.150 |
| 3 | 3 | +0.50 | 4 | +0.650 | 100 | +0.150 |
| 4 | 4 | -1.40 | 0 | -1.350 | 000 | +0.050 |
| 5 | 5 | -0.80 | 1 | -0.850 | 001 | -0.050 |
| 6 | 6 | +0.20 | 3 | +0.150 | 011 | -0.050 |
| 7 | 7 | +1.50 | 6 | +1.650 | 110 | +0.150 |
PCM bit stream (24 bits)
011 111 101 100 000 001 011 110
All errors within ±Δ/2 = ±0.25 · bit rate = 1 sample/s × 3 bits = 3 bps
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
25 / 38
PAM values (k = 0…9): 4.15, 6.23, 6.91, 5.50, 4.07, 3.87, 3.45, 1.74, 0.42, 1.31 V
Dashed blue: signal · orange: PAM pulses (flat-top samples) · dashed lines: 1 V levels from 0 to 8 V
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
26 / 38
| k | t | Sample | Zone i = ⌊(x − Vmin)/Δ⌋ | Quantised value | Code | Error |
|---|---|---|---|---|---|---|
| 0 | 0 | +4.15 | 4 | +4.500 | 100 | +0.350 |
| 1 | 1 | +6.23 | 6 | +6.500 | 110 | +0.270 |
| 2 | 2 | +6.91 | 6 | +6.500 | 110 | -0.410 |
| 3 | 3 | +5.50 | 5 | +5.500 | 101 | +0.000 |
| 4 | 4 | +4.07 | 4 | +4.500 | 100 | +0.430 |
| 5 | 5 | +3.87 | 3 | +3.500 | 011 | -0.370 |
| 6 | 6 | +3.45 | 3 | +3.500 | 011 | +0.050 |
| 7 | 7 | +1.74 | 1 | +1.500 | 001 | -0.240 |
| 8 | 8 | +0.42 | 0 | +0.500 | 000 | +0.080 |
| 9 | 9 | +1.31 | 1 | +1.500 | 001 | +0.190 |
PCM bit stream (10 samples × 3 bits = 30 bits)
100 110 110 101 100 011 011 001 000 001
With Δ = 1 V: zone = ⌊x⌋, value = ⌊x⌋ + 0.5 · bit rate = 1 × 3 = 3 bps
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
27 / 38
k=0: 100
k=1: 110
k=2: 110
k=3: 101
k=4: 100
k=5: 011
k=6: 011
k=7: 001
k=8: 000
k=9: 001
Unipolar NRZ (Lecture 2's two-level rule): 1 = +V, 0 = 0 V for the whole bit interval
1
0
0
1
1
0
1
1
0
1
0
1
1
0
0
0
1
1
0
1
1
0
0
1
0
0
0
0
0
1
Polar NRZ: 1 = +V, 0 = −V (no zero level, so the average is closer to 0 V)
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
28 / 38
Bits
011 111 101…
Levels
code → value
Hold
staircase
Filter
low-pass
Staircase from the hold circuit, smoothed by the low-pass filter
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
29 / 38
Each sample sends 1 bit: 1 = step up by δ, 0 = step down
| Problem | Cause | Fix |
|---|---|---|
| Slope overload | signal rises faster than δ per sample | larger δ or higher fs |
| Granular noise | steps jitter on flat parts | smaller δ |
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
30 / 38
Interactive
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
31 / 38
Parallel: 8 bits at once, 8 wires
Serial: 1 bit at a time, 1 wire
Asynchronous byte: start bit (0) + 8 data bits + stop bit (1)
| Serial mode | Timing | Example |
|---|---|---|
| Asynchronous | start/stop bits per byte; gaps allowed | UART, old modems |
| Synchronous | continuous stream; frames carry timing | Ethernet, SONET/SDH |
| Isochronous | guaranteed fixed delivery rate | real-time audio and video |
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
32 / 38
Bits sent per character
1 start + 8 data + 1 stop
10 bits
Efficiency
8 useful ÷ 10 sent
80%
Characters per second at 9,600 bps
9,600 ÷ 10
960 chars/s
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
33 / 38
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
34 / 38
Click the video to play or pause · Press → for full screen
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
35 / 38
Checkpoint 3 · 3 minutes
Range 0 to 8 V, 4 bits. Quantise a sample of 5.3 V: zone, code, quantised value and error.
A voice signal is limited to 3.4 kHz and coded with 8 bits at the Nyquist rate. Bit rate?
Asynchronous transmission at 19,200 bps with 1 start and 1 stop bit: how many characters per second?
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
37 / 38
Next lecture
Line coding: how bits become voltage levels on a wire (NRZ, Manchester, AMI and more), plus block coding and scrambling.
Reading: Forouzan, Section 4.1 · Revisit Examples A, B and C in PCM Lab
Md Mahbub E Noor
Lecture 5: Analog-to-Digital Conversion
University of Barishal
38 / 38