Week6 Channel Encoding
Week6 Channel Encoding
• Week 6
Agenda
• Recap +
• Source encoding
• Channel encoding
• Block codes
• Error correction
• Other Order of Business
Types of Coding
• Source Coding - Code data to more efficiently represent the
information
– Reduces “size” of data
– Analog - Encode analog source data into a binary format
– Digital - Reduce the “size” of digital source data
• Channel Coding - Code data for transmission over a noisy
communication channel
– Increases “size” of data
– Digital - add redundancy to identify and correct errors
– Analog - represent digital values by analog signals
Source Encoding (compression)
• The digital result of the A/D conversion can be encoded (represented) in
many ways.
• One purpose of the source encoder is to eliminate redundant binary digits
from the digitized signal
• Thermometer code
• N bits for N levels
• Binary code
• log2N bits for N
levels
Huffman codes
E e r i space
ysnarlk.
Building a Tree
Scan the original text
Eerie eyes seen near lake.
• What is the frequency of each character in the text?
E i y l k . r s n a sp e
1 1 1 1 1 1 2 2 2 2 4 8
E i y l k . r s n a sp e
1 1 1 1 1 1 2 2 2 2 4 8
Building a Tree
y l k . r s n a sp e
1 1 1 1 2 2 2 2 4 8
E i
1 1
Building a Tree
y l k . r s n a sp e
2
1 1 1 1 2 2 2 2 4 8
E i
1 1
Building a Tree
k . r s n a sp e
2
1 1 2 2 2 2 4 8
E i
1 1
y l
1 1
Building a Tree
2
k . r s n a 2 sp e
1 1 2 2 2 2 4 8
y l
1 1
E i
1 1
Building a Tree
r s n a 2 2 sp e
2 2 2 2 4 8
y l
E i 1 1
1 1
k .
1 1
Building a Tree
r s n a 2 2 sp e
2
2 2 2 2 4 8
E i y l k .
1 1 1 1 1 1
Building a Tree
n a 2 sp e
2 2
2 2 4 8
E i y l k .
1 1 1 1 1 1
r s
2 2
Building a Tree
n a 2 sp e
2 4
2
2 2 4 8
E i y l k . r s
1 1 1 1 1 1 2 2
Building a Tree
2 4 e
2 2 sp
8
4
y l k . r s
E i 1 1 1 1 2 2
1 1
n a
2 2
Building a Tree
2 4 4 e
2 2 sp
8
4
y l k . r s n a
E i 1 1 1 1 2 2 2 2
1 1
Building a Tree
4 4 e
2 sp
8
4
k . r s n a
1 1 2 2 2 2
2 2
E i y l
1 1 1 1
Building a Tree
4 4 4
2 sp e
4 2 2 8
k . r s n a
1 1 2 2 2 2
E i y l
1 1 1 1
Building a Tree
4 4 4
e
2 2 8
r s n a
2 2 2 2
E i y l
1 1 1 1
2 sp
4
k .
1 1
Building a Tree
4 4 4 6 e
2 sp 8
r s n a 2 2
4
2 2 2 2 k .
E i y l 1 1
1 1 1 1
4
6 e
2 2 2 8
sp
4
E i y l k .
1 1 1 1 1 1
8
4 4
r s n a
2 2 2 2
Building a Tree
4
6 e 8
2 2 2 8
sp
4 4 4
E i y l k .
1 1 1 1 1 1
r s n a
2 2 2 2
Building a Tree
8
e
8
4 4
10
r s n a
2 2 2 2 4
6
2 2 2 sp
4
E i y l k .
1 1 1 1 1 1
Building a Tree
8 10
e
8 4
4 4
6
2 2
r s n a 2 sp
2 2 2 2 4
E i y l k .
1 1 1 1 1 1
Building a Tree
10
16
4
6
2 2 e 8
2 sp 8
4
E i y l k . 4 4
1 1 1 1 1 1
r s n a
2 2 2 2
Building a Tree
10 16
4
6
e 8
2 2 8
2 sp
4 4 4
E i y l k .
1 1 1 1 1 1
r s n a
2 2 2 2
Building a Tree
26
16
10
4 e 8
6 8
2 2 2 sp 4 4
4
E i y l k .
1 1 1 1 1 1 r s n a
2 2 2 2
Building a Tree
After enqueueing this node
there is only one node left in
priority queue.
26
16
10
4 e 8
6 8
2 2 2 sp 4 4
4
E i y l k .
1 1 1 1 1 1 r s n a
2 2 2 2
Building a Tree
Dequeue the single node left in the
queue.
26
Char Code
E 0000
i 0001
y 0010
l 0011 26
k 0100 16
. 0101 10
space 011 4
e 10 e 8
6 8
r 1100 2 2 2
s 1101 sp 4 4
4
n 1110 E i y l k .
a 1111 1 1 1 1 1 1 r s n a
2 2 2 2
Encoding the File
• Rescan text and encode
file using new code words
Char Code
E 0000
Eerie eyes seen near lake. i 0001
y 0010
l 0011
000010110000011001110001010110110100
k 0100
. 0101
111110101111110001100111111010010010 space 011
1 e 10
r 1100
s 1101
n 1110
a 1111
Why is there no need for a
separator character?
Encoding the File
Results
“heads” “tails”
1
Hamming Distance
(Richard Hamming, 1950)
The Hamming distance between a valid binary code word and the
same code word with single-bit error is 1.
The problem with our simple encoding is that the two valid code words
(“0” and “1”) also have a Hamming distance of
1. So a single-bit error changes a valid code word into
“heads” 0 1 “tails”
Error Detection
What we need is an encoding where a single-bit
error doesn’t produce another valid code word.
single-bit error
01
If D is the minimum
Hamming distance
between code
“heads” 00 11 “tails” words, we can
detect up to
(D-1)-bit errors
10
• One can “count” by summing the bits in the word modulo 2 (which is
equivalent to XOR’ing the bits together).
Error Correction
101 111 “tails”
By increasing the Hamming distance between valid code words to 3, we guarantee that the sets of words produced by
single-bit errors don’t overlap. So if we detect an error, we can perform error correction since we can tell what the
valid code was before the error happened.
• Can we safely detect double-bit errors while correcting 1-bit errors?
• Do we always need to triple the number of bits?
Error Correcting Codes (ECC)
Basic idea:
– Use multiple parity bits, each covering a subset of the data bits.
– The subsets overlap, ie, each data bit belongs to multiple subsets
– No two data bits belong to exactly the same subsets, so a single-bit
error will generate a unique set of parity check errors
Suppose we check the parity and
discover that P2 and P3 indicate
an error?
n
• Split message into k-bit blocks
• Add (n-k) parity bits to each block, making each block n bits
long. How many parity bits do we need to correct single-
bit errors?
– Need enough combinations of parity bit values to identify which of the
n bits has the error (remember that parity bits can get errors too!), or
to indicate no error at all, so 2n-k ≥ n+1 or, equivalently, 2n-k > n
– Multiply both sides by 2k and divide by n: 2n/n > 2k
– Most efficient (i.e., we use all possible encodings of the parity bits)
when 2n-k – 1 = n
• (7,4), (15,11), (31, 26) Hamming codes
011 0 1 1 011
110 10 0 111
10 1 0 10
Parity for each row and Parity check fails for row Parity check only fails for
column is correct #2 and column #2 row #2
=> no errors => bit D4 is incorrect => bit P2 is incorrect
Well, can we think of a way to turn a B-bit error burst into B single-bit
errors?
Row-by-row Col-by-col
B transmission B transmission
order order