Data Communication · Lecture 5

Analog-to-Digital Conversion

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

Turning analog signals into bits: today's goals

  • Describe the three steps of PCM: sampling, quantising, encoding
  • Apply the Nyquist theorem and explain aliasing
  • Quantise samples, assign codes and calculate the error
  • Calculate SQNR, bit rate and required bandwidth
  • Explain delta modulation and serial transmission modes

The conversion roadmap

LectureConversionExample
5 · todayAnalog → digitalVoice → bits (PCM)
6Digital → digitalBits on Ethernet
7Digital → analogBits on Wi-Fi
8Analog → analogVoice 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

Why and how we digitise: PCM

  • Analog data must be digitised before it can travel as bits
  • Pulse code modulation (PCM): the standard method, used in phones, CDs and recording
  • Three steps: sample, quantise, encode
  • The device that does it is a codec (coder-decoder)

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…
Noiserepeaters regenerate clean bits; amplifiers cannot
Processingcompress, encrypt and error-check with software
One networkvoice, video and data all become bits

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

3 / 38

Step 1: sampling

  • Measure the signal's amplitude at equal intervals Ts
  • Ideal sampling uses instant impulses: a mathematical model
  • Natural sampling switches the signal on briefly
  • Flat-top (sample and hold) reads a value and holds it while it is converted

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

How fast must we sample? The Nyquist theorem

  • To rebuild a signal exactly, sample at at least twice its highest frequency
  • Intuition: each cycle needs at least two samples, one up and one down
  • Before sampling, a low-pass anti-aliasing filter removes frequencies above fs/2
  • Sampling at the Nyquist rate or above loses no information

fs ≥ 2 × fmax

fmax = the highest frequency in the signal. 2 × fmax is the Nyquist rate.

SignalHighest frequencySampling rate used
Telephone voiceabout 4 kHz (filtered)8,000 samples/s
CD audioabout 20 kHz (hearing limit)44,100 samples/s
Studio audioabout 20 kHz48,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

Sampling too slowly: aliasing

  • Below the Nyquist rate, the samples also fit a slower, false wave
  • The receiver rebuilds that wrong wave: an alias
  • Example: a 5 Hz wave sampled 6 times per second looks like 1 Hz
  • Everyday sign: wagon wheels or fan blades that seem to spin backwards on video

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

6 / 38

Try it: break the Nyquist rule

Interactive

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

7 / 38

Worked examples: choosing the sampling rate

  • (a) Telephone voice filtered below 4 kHz
  • (b) A low-pass signal occupying 0 to 200 kHz
  • (c) What does an undersampled 5 Hz wave look like?
  • Always find the highest frequency first, then double it

(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

Check your understanding

Q1

Music contains frequencies up to 15 kHz. What is the minimum sampling rate?

Q2

A 7 Hz signal is sampled at 10 samples per second. Is there aliasing? What frequency appears?

Q3

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

Step 2: quantisation

  • Divide the range Vmin to Vmax into L equal zones of height Δ
  • Each sample is replaced by the middle value of its zone
  • The difference is the quantisation error, never more than Δ/2
  • More levels → smaller Δ → smaller error, but more bits per sample

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

How good is it? Signal-to-quantisation-noise ratio

  • Quantisation error acts like noise added to the signal
  • SQNR compares signal power with quantisation-noise power
  • Each extra bit halves Δ, so it quarters the noise power: +6 dB
  • Use it to choose n for a required quality

SQNR(dB) = 6.02 n + 1.76

n = bits per sample; for a full-range sine-wave signal

Bits per sample nLevels LSQNRTypical use
3819.8 dBClassroom examples
825649.9 dBTelephone voice
1665,53698.1 dBCD audio
2416.7 million146 dBStudio 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

Non-uniform quantisation: companding

  • Speech is mostly quiet; uniform levels waste resolution on rare loud peaks
  • Companding = compress before quantising, expand after decoding
  • Small amplitudes get finer steps; large amplitudes coarser steps
  • Telephone networks use 8-bit μ-law or A-law (ITU-T G.711)

μ-law curve (μ = 255) vs straight line: quiet sounds get more of the levels

Two standards

μ-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

Try it: companding, small sounds get more levels

Interactive

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

13 / 38

Step 3: encoding, and the resulting bit rate

  • Each zone index is written as an n-bit binary code, with L = 2ⁿ
  • Codes for successive samples are sent one after another: the PCM bit stream
  • Bit rate = samples per second × bits per sample
  • Minimum bandwidth of the digital signal ≈ n × the analog bandwidth

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 i01234567
Code (n = 3)000001010011100101110111

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

14 / 38

Worked examples: PCM bit rate and bandwidth

  • Telephone: voice filtered to 4 kHz, 8 bits per sample
  • fs = 2 × 4 kHz = 8,000/s; bit rate = 8,000 × 8 = 64 kbps
  • Minimum bandwidth: 8 × 4 kHz = 32 kHz, eight times the analog voice
  • CD stereo: 44,100 × 16 × 2 = 1,411,200 bps

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

Try it: sample, quantise and encode

Interactive

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

16 / 38

Checkpoint 2 · 3 minutes

Check your understanding

Q1

Range −2 V to +2 V, 3 bits. What is Δ, and which code does a sample of 0.9 V get?

Q2

How many bits per sample give an SQNR of at least 60 dB?

Q3

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

Textbook example (Forouzan, Fig. 4.26): set up the quantiser

  • Amplitudes lie between −20 V and +20 V; nine samples (ideal sampling)
  • Choose the bits first: n = 3 gives L = 2³ = 8 levels
  • Δ = (Vmax − Vmin)/L = 40/8 = 5 V
  • Work in units of Δ: normalised value = amplitude / Δ, so the range is −4Δ to +4Δ
  • Zone midpoints: ±0.5, ±1.5, ±2.5, ±3.5 (in units of Δ)

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

Fig. 4.26 solved: the five rows of the chart

Sample123456789
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 code257762122
Encoded word010101111111110010001010010

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

Choosing the bits: the same samples with n = 4

Sample123456789
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 code5111415125345
Encoded word010110111110111111000101001101000101
n = 3 (book)n = 4
Levels L = 2ⁿ816
Δ = 40 / L5 V2.5 V
Largest possible error Δ/22.5 V1.25 V
SQNR = 6.02n + 1.7619.82 dB25.84 dB
Bits for 9 samples2736

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

Fig. 4.26, final step: the encoded words become a signal

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

Solved example A: PCM of a sine wave

  • Signal: s(t) = sin t, so period T = 2π s and f = 1/(2π) ≈ 0.159 Hz
  • Samples every Ts = 2π/7 ≈ 0.898 s: 7 samples per cycle
  • Check Nyquist: fs = 7/(2π) ≈ 1.11 Hz ≥ 2f ≈ 0.32 Hz ✓
  • Quantise with n = 3 bits over −1 to +1: L = 8, Δ = 2/8 = 0.25

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

Example A solved: zones, codes and errors

ktSampleZone i = ⌊(x − Vmin)/Δ⌋Quantised valueCodeError
00.000+0.004+0.125100+0.125
10.898+0.787+0.875111+0.095
21.795+0.977+0.875111-0.095
32.693+0.435+0.375101-0.055
43.590-0.432-0.375010+0.055
54.488-0.970-0.875000+0.095
65.386-0.780-0.875000-0.095
76.283+0.004+0.125100+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

Solved example B: a custom waveform

  • Samples at t = 0, 1, …, 7 (Ts = 1): 0, 2.2, 1.0, 0.5, −1.4, −0.8, 0.2, 1.5
  • Choose the range from the signal, not just the samples: it reaches about −1.5 and +2.25
  • Pick Vmin = −1.6, Vmax = +2.4 (a 4-unit span with a little margin)
  • n = 3 bits: L = 8, Δ = 4/8 = 0.5

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

Example B solved: zones, codes and errors

ktSampleZone i = ⌊(x − Vmin)/Δ⌋Quantised valueCodeError
00+0.003+0.150011+0.150
11+2.207+2.150111-0.050
22+1.005+1.150101+0.150
33+0.504+0.650100+0.150
44-1.400-1.350000+0.050
55-0.801-0.850001-0.050
66+0.203+0.150011-0.050
77+1.506+1.650110+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

Solved example C: a non-symmetric signal, start to finish

  • A sensor voltage between about 0.4 V and 7 V: all positive, not centred on zero
  • Fastest component: period 4.3 s, so fmax ≈ 0.23 Hz; sampling at fs = 1 sample/s (Ts = 1 s) beats 2 fmax ≈ 0.47 ✓
  • Step 1–2: the PAM values are the sample heights (table below)
  • Step 3: quantise over 0 to 8 V with n = 3: L = 8, Δ = 8/8 = 1 V

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

Example C solved: from PAM values to codes

ktSampleZone i = ⌊(x − Vmin)/Δ⌋Quantised valueCodeError
00+4.154+4.500100+0.350
11+6.236+6.500110+0.270
22+6.916+6.500110-0.410
33+5.505+5.500101+0.000
44+4.074+4.500100+0.430
55+3.873+3.500011-0.370
66+3.453+3.500011+0.050
77+1.741+1.500001-0.240
88+0.420+0.500000+0.080
99+1.311+1.500001+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

Example C, final step: the bits become a digital signal

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

At the receiver: the PCM decoder

  • Read n bits at a time and convert each code back to its level value
  • Hold each value until the next sample: a staircase
  • A low-pass filter smooths the staircase into an analog signal
  • The result equals the original plus quantisation noise

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

A simpler alternative: delta modulation

  • PCM sends the value of each sample; DM sends only the change
  • One bit per sample: is the signal above or below the staircase?
  • Very simple hardware, but needs a much higher sampling rate than PCM
  • Adaptive DM enlarges δ on steep slopes and shrinks it on flat parts

Each sample sends 1 bit: 1 = step up by δ, 0 = step down

ProblemCauseFix
Slope overloadsignal rises faster than δ per samplelarger δ or higher fs
Granular noisesteps jitter on flat partssmaller δ

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

30 / 38

Try it: delta modulation, step by step

Interactive

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

31 / 38

Sending the bits: parallel and serial transmission

  • Parallel: n bits at once over n wires; fast but costly and short-range
  • Serial: one bit at a time over one channel; used for almost all links
  • Asynchronous serial frames each byte with start and stop bits
  • Synchronous serial sends a continuous stream; isochronous guarantees a steady rate

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 modeTimingExample
Asynchronousstart/stop bits per byte; gaps allowedUART, old modems
Synchronouscontinuous stream; frames carry timingEthernet, SONET/SDH
Isochronousguaranteed fixed delivery ratereal-time audio and video

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

32 / 38

Worked example: the cost of asynchronous framing

  • Each 8-bit character gets 1 start bit and 1 stop bit
  • So 10 bits travel for every 8 useful bits: 80% efficiency
  • At 9,600 bps: 9,600 ÷ 10 = 960 characters per second
  • Synchronous transmission avoids per-byte overhead, so it suits high speeds

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

Try it yourself: PCM Lab

  • 1 · Sampling: find where aliasing begins for a 5 Hz signal
  • 2 · Quantise and encode: reproduce Fig. 4.26 and Examples A, B and C; change n and the range
  • 3 · Delta modulation: provoke slope overload and granular noise
  • 4 · Bit rate and 5 · Full pipeline: signal → PAM → codes → digital signal
QR code linking to the lab

Scan to open the lab on your phone

Open the lab ↗

Md Mahbub E Noor

Lecture 5: Analog-to-Digital Conversion

University of Barishal

34 / 38

See it in action: from voice to bits

  • Watch a smooth signal being sampled at equal intervals
  • See undersampling produce a false, slower wave
  • Watch samples snap to levels and become a bit stream (Example A)
  • When a “Pause & predict” card appears, answer before the video moves on

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

Check your understanding

Q1

Range 0 to 8 V, 4 bits. Quantise a sample of 5.3 V: zone, code, quantised value and error.

Q2

A voice signal is limited to 3.4 kHz and coded with 8 bits at the Nyquist rate. Bit rate?

Q3

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

Key takeaways

  • PCM = sample, quantise, encode; a codec does it
  • Sample at fs ≥ 2 fmax, or aliasing creates false frequencies
  • Δ = (Vmax − Vmin)/L; error ≤ Δ/2; SQNR ≈ 6.02n + 1.76 dB
  • Bit rate = fs × n; voice = 64 kbps; companding improves quiet sounds
  • Delta modulation sends 1 bit per sample; serial links are async, sync or isochronous

Next lecture

Lecture 6 · Digital-to-Digital Conversion

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