Chapter 4 - Introduction To Source Coding
Chapter 4 - Introduction To Source Coding
P.1
ELEC1010 Electronic & Information Technology
Source Coding
Communication
Channel Coding Channel e.g. Channel Decoding
20MB/s (160Mb/s)
Channel Coding
P.3
Coding for Digital Communications
• In Chapter 3, we discussed digitization, where the analog signal
x(t) is sampled and quantized to become a digital signal
P.4
Source Coding – Compression & Decompression
In source coding, data is compressed into a smaller number
of bits for storage or transmission. Decompression is the act
of reconstructing the original signal, exactly (lossless) or
approximately (lossy), from the compressed version.
P.5
Lossless Compression
• It is a class of compression techniques for which nothing about
the original set of numbers or symbols is lost in the compression
process.
• Lossless compression is reversible and by the reverse
decompression process, the exact set of the original numbers
can be recovered.
• Lossless compression is important for signals and information
that we count on for accuracy; e.g. text documents, computer
programs, financial and medical records, scientific data
P.6
Lossy Compression
• It is a class of compression techniques that selectively throw
away information about the sets of numbers or symbols being
compressed. The idea is to lose those features that would not
be noticed or that are not considered important in the
application.
• Lossy compression is not reversible – you cannot get back the
exact original set of numbers from the compressed version.
• Lossy compression are most often used for signals and
information that we perceive, such as sounds and images: MP3
music, DVD movies, etc. The quality of what we see and hear
is closely tied to the limitations of our eyes and ears. By
exploiting these limits and throwing away “unnecessary” bits,
we can achieve a higher compression ratio
P.7
Lossless Compression Example – Text File
P.8
Lossy Compression Example: JPEG Images
P.10
• Compressed JPEG image (.jpg file), file size = 28 KB
P.11
• Compressed JPEG image (.jpg file), file size = 13.4 KB
P.12
Essence of Source Coding: Symbol-to-bit assignment
• We can think of the information that we want to encode as a
sequence of symbols. The set of possible symbols is a set
{x} such as:
– The 26 alphabets in a book {a, b, c, d,….z} (*ignoring
capital letters)
– Boy or Girl for a group of ELEC1010 students {B, G}
– The black dot and the white dot in a fax page {B, W}
• The essence of source coding is to assign different
sequences of bits (called codewords) to represent different
source symbols.
• We have some liberty to define the set of symbols to make
our coding more efficient. For example, we may consider
students in pairs, resulting in {BB, BG, GB, GG}.
P.13
Fixed-Length Code
• A simplest type of code is fixed-length code – where every
codeword has the same code length (number of bits).
Examples:
# of Symbols Symbol Set Possible Codewords
2: {B, W} 0, 1
4: {a, e, q, z} 00, 01, 10, 11
P.14
Variable-Length Code
• A fixed-length code has the advantage that it is simple.
The number of bits is the same for all symbols.
• But, a fixed-length code can be inefficient because we do
not take into consideration of frequency of occurrence of
the symbols
P.15
Uniquely Decodable Code – Prefix Code
• What characteristics must a variable code have so that we
can always unambiguously decode?
P.16
Prefix Code – A Code Tree
• A way to think of a prefix code is to think of a tree. Each branch of
the tree corresponds to a “0” bit or a “1” bit. For a prefix code all
codewords must be at the leaves. To decode, we start from the top
of the tree and follow the branches according to the bits received
until we hit a leaf. Then we start over from the top of the tree. (But if
we have one error, everything following will be messed up! )
0 1
0 1
1 0 1
e a c
0 1
0 1 0 1
0 1 0 1
00 01 11
000 001 010 011 e b d
a b c d Non-Prefix Code ->
Prefix Code -> Not Uniquely Decodable
Uniquely Decodable
P.17
How efficient is Variable-Length Code?
• Four symbols with frequency of occurrence:
• a: 0.2 e: 0.5 q: 0.15 z: 0.15
1 e
1
1
01 a
0
001 q 1 0
000 z 0
P.19
ELEC1010 Electronic & Information Technology
P.20
Frequency Matters
• In the last lecture, we explained that we may use a variable-length
code because symbols may be of different frequencies
• Relative Frequency of a symbol is defined as the number of
occurrence of this symbol divided by the total number of symbols,
in a specific symbol sequence (e.g. winzip), or over many typical
symbol sequences that we need to encode. It means the same as
probability and is the p(x) in Shannon’s entropy formula!
• For simplicity, we assume that neighboring symbols are
independent, meaning that the probabilities of a symbol do not
change because of its neighbors. In reality this may not be always
true. For example, in English, the letter “q” is almost always
followed by a “u”. On a fax page, a white dot is very likely to be
followed by another white dot. (Dependency among symbols will only give
more opportunity to compress; it will not make things worse. As shown in later
example, MPEG takes advantage of dependency across pixels in video)
P.21
Prefix Code – A Code Tree
• We see that there are many ways to set up the prefix code
tree
Our 5 Symbol Example An Alternative Prefix Code Tree
0 1 0 1
1
e
0 1 1 0 1
0
01 10 11
0 1 0 1 0 1 c d e
0 A
0.4 0
1
10 B
0.3 0
0.6 1
110 C
0.2 0 0.3 1
111 D 1
0.1
P.24
A Slightly More Complicated Huffman Example
a (0.2), b (0.1), c(0.3), d (0.15), e(0.25)
(4) Done
(1) smallest: b(0.1), d(0.15) 1
-> b+d = 0.25 0 (3) e+c (0.55)
P.27
Finding the Huffman Code for the Grade Example
P.29
Encoding Groups of Three Students
P.31
Further Notes on Huffman
• Solution is not necessarily unique but gives the same average
bits/symbol
– 0 on left or 0 on right; larger probability on left or right
– Two symbols may have the same relative freq. and we have
to pick one arbitrarily: FP and PF (0.16), and b+d (0.25) and
e (0.25) in earlier example
• Huffman coding is uniquely decodable and completely reversible
(assuming no bit errors over transmission). It is lossless.
• But even a single bit error can be disastrous. There must be a
way to limit the propagation of error. Fax encoding, for example,
has a special end-of-line codeword that enables the decoder to
get back in sync
• Huffman’s idea is used in most source coding schemes, lossless
and lossy. It is used in Fax as well as JPEG.
P.32
Lossy Compression – MP3
• Recall from Chapter 2 that digital CD audio signals consist
of 16-bit samples recorded at a sampling rate of 44.1 kHz.
• For stereo music, there are two channel. Without
compression, a 3 minute CD quality stereo audio signals
require 254,016,000 bits, or about 30 MB of storage! To
stream the signal and play it in real time would take 1.35
Mbit per second (Mbps).
• MP3 (Audio Layer 3 of the MPEG-1 Multimedia Coding
Standard), a popular audio compression standard, greatly
reduces the data required to store and transmit audio files
by the use of lossy compression
P.33
MP3 Audio Compression
MP3 encoded audio at 192 kbps is similar to CD-quality
audio at 1.35 Mbps (according to international listening
tests).
P.34
MP3 Audio Compression
Perceptual noise shaping is built around the way human
hear sound.
For example,
(1) there are certain sounds that we cannot hear.
(2) there are certain sounds that we hear better than other
sounds.
(3) If there are two sounds at adjacent frequencies playing
simultaneously, we hear the louder one but cannot hear the
softer one.
So if you eliminate all the parts of the song that one does
not hear very well anyway, you can reduce the file size quite
a bit without changing the sound noticeably!
P.35
We can just remove
all other frequency
data in this particular
time.
Quantization and
Huffman Coding
MP3 music
P.37
MPEG – A Family of Audio-Visual Coding Standard
• MPEG (pronounced M-peg) stands for Moving Picture
Experts Group. It is the name of the family of standards
used for coding audio-visual information (e.g., movies,
video, music) in a digital compressed format.
• The major advantage of MPEG compared to other video
and audio formats is that MPEG files are much smaller
for the same quality. This is because MPEG uses very
sophisticated compression techniques.
• MP3 is part of the MPEG standard.
P.38
MPEG-2 for Cable TV and DVD
• MPEG-2 is the first popular MPEG standard. It is typically used to
encode audio and video for broadcast signals, including direct
broadcast satellite and Cable TV. With some modifications, it is
also the coding format used by standard commercial DVD movies
and HDTV (High Definition Television).
• Key techniques used include inter-frame prediction and coding in
the frequency domain (Discrete Cosine Transform coding/DCT).
• In predictive coding, the coder and decoder use an algorithm to
predict what many intermediate frames should be based on some
anchor frames. The coder encodes only the difference between the
actual frame and the predicted. If this difference is small most of
the time, there is not much information to encode.
• DCT takes advantage of the fact that most signal energy is at low
frequencies and that there are often many consecutive zero values
in the amplitudes of adjacent frequency components
P.39
MPEG-4
• MPEG-4 is a more advanced standard for video and audio
compression introduced in late 1998. (HKUST played a key role
here!)
• The MPEG-4 standard is now used in web (streaming media) and
CD distribution, conversation (videophone), video-conference and
broadcast television.
• MPEG-4 absorbs many of the features of MPEG-2, and adds
advanced techniques such as motion estimation – predicting
how blocks of pixels will move across the picture in successive
frames.
• Most features included in MPEG-4 are optional and left to
individual developers to decide whether to implement them.
P.40
Summary – Lecture 14
• Introduced the Huffman code as an algorithm for symbol-to-
codeword assignment. The Huffman code minimizes the average
number of bits needed to encode symbols by assigning long
codewords to less likely symbols.
P.41
ELEC1010 Electronic & Information Technology
P.42
Errors in Digital Transmission
• In the transmission and storage of digital information, errors
invariably occur. Signals suffer from attenuation, distortion and
noise in the process of transmission, and there can be scratches
or defective elements in CD and electronic memories.
• Bit error means that a “0” bit is corrupted into a “1” and vice
versa. A single bit error can lead to a large absolute error
P.44
Error Detection
• Detecting error allows a receiver to identify transmission errors and take
actions such as:
ignore the received signal and reconstruct from other signals (e.g. in
GSM-based 2G mobile communications)
request re-transmission (e.g. in web protocol)
e.g. original 7-bit sequence coded 8-bit word with even parity bit
1110001 11100010
1011110 10111101
P.45
Error Detection Code
• The set of allowable encoded sequences, called
codewords, are only a subset of possible sequences, e.g.
P.47
Parity Check Detects All Errors with Odd Number of
Bit Errors
• Suppose we use even parity, and an “e” (= 110 0101) is keyed in.
The “e” is then encoded as “0110 0101” to be sent out.
• Now, if the code is received as “0110 1101”, which consists of 5
“1”s, we immediately know that it is an invalid code. The sender
will be requested to resend the data.
• Clearly, if two errors occur, for example, the intended “e” is
received as “0100 1101”, then we may incorrectly decode it as an
“M”. Engineers who design the data transmission system should
ensure that it is very unlikely to have two errors in the same
transmission.
• Parity check achieves error detection of all odd number of errors.
P.48
Error Detection: HKID and Credit Card Number Examples
• When people provide their ID or credit card numbers over the
phone, there may be common errors such as flipping two
adjacent numbers
• We can use algorithms similar to parity check with special
focus on the common error types
P.49
A Common Error Detection Method
• Basic Principle
– This kind of detection can help make sure the ID card or credit
card number provided by the user is a valid number.
P.50
Hong Kong ID Number (I)
1. First write down the first seven digits of your ID Card Number (including the
first English letter) e.g. C668668
2. Convert the first English letter into a number according to the following table
1 2 3 4 5 6 7 8 9 10 11
A B C D E F G H I J K e.g. C=3
L M N O P Q R S T U V
W X Y Z
P.51
Hong Kong ID Number (II)
3. Multiply the first SEVEN numbers by 8,7,6,5,4,3 and 2, respectively.
3x8 = 24
6x7 = 42
6x6 = 36
8x5 = 40
6x4 = 24
6x3 = 18
8x2 = 16
6. Subtract the remainder from 11 (i.e. 11-2 = 9): the result is the check digit
-- If the result = 11 (remainder = 0) check digit = 0
-- If the result = 10 (remainder = 1) check digit = A
encoder
encoded stream (even parity)
0011 0101 1001 1010 0101
Transmission
• Introduced the concept of even and odd parity check codes and
the ASCII standard as an example
P.54
ELEC1010 Electronic & Information Technology
P.55
Error Correcting Codes
• Suppose we receive 1011 in the even parity code example,
we know
1. there is an error because the parity is NOT even
2. If the transmission introduces one error, possible correct
codewords includes 0011, 1001, 1010, 1111. We cannot
tell which one is more likely!
P.56
Simple Approach: Repetition Code
• It is possible to correct a limited number of errors using error
correcting codes. For example, the “repetition code” for 1
bit (repeating the input bit for at least three times)
1 0 1 1 1 1 0 1 1 1
0 1 0 1 1 0 1 1 1 1
Bit Error! Violation
1 0 1 0 0
1 0 1 0 0 0 1 0 0 1
0 1 0 0 1 0 0 0 0
Violation
0 0 1 0
Violation
P.58
Efficiency of Error Correcting Codes
• Efficiency, or the code rate is defined as
No. of Data Bits
Code Rate (R) =
No. of Data Bits + No. of Parity Bits
• For 2-dimension parity code, transmit N x N data bits and
2N parity bits. Code Rate is N2 / (N2 + 2N) = N/(N+2)
• For N = 2, we refer to the code as a (8, 4) code. Transmit 8
bits for every 4 data bits. efficiency, or code rate, is 4/8.
• The 2-dimension parity code can correct all 1-bit error
patterns in a data block of N x N bits
• For the same block size, we want to find codes with code
rates (or efficiency) closer to 1
P.59
Structured Error Correcting Codes
• Even a code randomly designed is a GOOD code!!
• However, no structure means difficult to decode, i.e. finding
the bits difference between the received sequence and all
the possible 2k (e.g. for k=number of bits=100, 2100)
codewords has high computational complexity
• Solution: Having structure using mathematics (e.g. discrete
mathematics) to enable efficient decoding algorithms
• Example:
• Reed Solomon or BCH Code: used in CD, VCD, DVD
• Convolutional Code: used in Wireless communication
P.60
Summary – Lecture 16
P.61
ELEC1010 Electronic & Information Technology
P.62
What is a Communication Channel?
• Examples of a Communication Channel:
• A wire/cable connecting two points that take a signal from
point A to point B, e.g. a copper wire, an fiber optic cable
• The space where a Electromagnetic (EM) wave transmits
from the transmit antenna to the receive antenna
• Even a storage media where bits are stored and then
retrieve later, e.g. Hard disc drive, optical disc such as CDs,
VCDs, DVDs,
P.63
Models for Communication Channel?
• Model for a channel:
• Send a signal x(t) over a communication channel and
receive y(t) at the other end
• y(t) depends on x(t), e.g. y(t) = a x(t) where a is the
attenuation factor
• However, in general y(t) is a possible distorted and usually
corrupted by noise and possibly interference.
P.64
Simplest Binary Symmetry Channel Model
• Transmit a bit (i.e. ‘1’ or ‘0’) and receive a bit (i.e. ‘1’ or ‘0’)
• Most of the time (with probability 1- ε where ε is generally very
small), you get exactly what was transmitted. No error
• Occasionally, (with probability ε), the transmitted bit is flipped
(i.e. a bit error, or a ‘1’ becomes a ‘0’, and a ‘0’ becomes a ‘1’)
• The error could be caused by noise, interference, etc, but the
final effect is that a bit error occurs.
• Symbol rate gives the number of channel symbol per second
• Diagram for the BSC model:
1 1
0 0
P.65
Shannon Capacity
• “Channel Capacity” is another revolutionary concept from
Shannon who defined the “Capacity” of a channel as the
maximum information (or data) rate that can be
transmitted reliably over the channel.
• He proved that if the data rate is below the channel capacity,
given that we are willing to accept large blocks, large coding
delay, we can achieve arbitrarily low error probability
• For Example, if a BSC with symbol rate 1k symbol/second has
an error probability equal to 0.1
• Data rate is1kbps and bit error rate is 0.1
• With repetition code (3 times), Data rate is 1/3 kbps and
block error rate is 0.028 (0.028=0.13+3*0.12*0.9)
• Question: What is the maximum data rate for a given error
rate??
• Shannon: For arbitrarily small error rate, max data rate is
CAPACITY P.66
Capacity of a Binary Symmetric Channel
• Assume a Binary Symmetric channel with a bit error rate .
Shannon defines the capacity of the channel as follow:
•
Capacity = 1 + log2 + (1-) log2 (1-)
𝐶𝑎𝑝𝑎𝑐𝑖𝑡𝑦 = 1 − 𝐸𝑛𝑡𝑟𝑜𝑝𝑦
= 1 − 𝐻(𝜀)
= 1 − 𝜀𝑙𝑜𝑔 + 1 − 𝜀 𝑙𝑜𝑔
= 1 + 𝜀𝑙𝑜𝑔 𝜀 + 1 − 𝜀 𝑙𝑜𝑔 1 − 𝜀
1 1
0 0
P.67
Shannon’s Channel Capacity
Channel Capacity
1
The curve to the right 0.9
rate . 0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
P.68
Error-Free Communications
• Here is the surprising part of Shannon’s theory. Assume we
transmit b bits over the channel with a coding rate of r,
Shannon shows that if r < capacity, theoretically it is possible to
correct all error bits with certainty when b becomes large!
• This means that one can find a code, such that for every 0.278
data bit transmitted, there are at least 0.722 protection bits, we
can decode and correct all errors with almost certainty.
P.69
Approaching Shannon’s Limit
• To achieve Shannon’s limit, b must be large. That means large
delay and a large codebook (i.e., many symbols).
• Modern theories on error correcting codes are to find algorithms
to approach Shannon’s limit while keeping b small and the
encoding and decoding simple.
• Such theories make use of advanced mathematics (discrete
mathematics) and there have been many exciting inventions!
• Another very important class of error correcting codes which does
not operate on blocks of data bits is the convolutional code.
Galois (1811-1832)
His mathematical field theory provided the
foundation for discrete mathematics which The Rubik’s cube can be
allowed us to develop very efficient block codes. formulated as a discrete math
Unfortunately he was killed in a duel at age 20. problem
P.70
Error Correcting Codes in Daily Lives
• For example, all of our CD and DVD recordings use an error-
correcting block code known as the Reed-Solomon code. For
example, a (255, 223) Reed-Solomon code encode 223 bits of
data into 255 bits, adding 32 bits of redundancy. This makes our
music and video readable even when there are defects and
scratches on the disc.
• The wireless channel is very noisy and error-prone. The GSM 2G
mobile phone network, for example, uses different speech source
coding schemes together with a ½ rate of convolutional code (there
are as much redundancy as data bits!) to give us an acceptable level
of voice quality on the mobile phone.
• The modern world cannot function today without error correcting
codes!
P.71
Summary – Lecture 17
• Introduced the Binary Symmetric Channel
P.72