NIS2337 Information Theory Notes (4): Source Coding
“Information has three great desires: compression rate, efficiency, and accuracy. Among these three desires, compression rate satisfies the need for compression survival, so the pursuit of compression rate takes the highest priority. If effective compression can be achieved during transmission, it also makes channel transmission extremely efficient. In real life, there exist codes that persistently pursue such efficiency. We usually refer to this type of code as an optimal code, and the encoder is specifically tailored for those channels weary of transmission distortion, providing source coding that matches their channel capacity.”
The role of source coding can be summarized as follows: - Symbol Transformation: To match the output symbols of the source with the input symbols of the channel; - Information Matching: To match the information output by the source with the transmission capability of the channel; - Redundancy Compression: To reduce redundant information in the source output, thereby improving transmission efficiency.
NIS2337 Foundations of Information Theory course notes — other chapters: 1. Source and Information Entropy 2. Channel and Channel Capacity 3. Rate-Distortion Function 4. Source Coding (this article) 5. Channel Coding
Supplementary information can be found in Beyond 2337.
Coding
Block Codes. The source messages are divided into
groups (or symbol sequences)
Block codes are memoryless; therefore, only block codes have a corresponding code table, whereas non-block codes do not.
Fixed-Length Codes. A fixed-length code is one in
which every codeword has the same length, i.e.,
Singular Codes. If there exist two distinct messages
Uniquely Decodable Codes. If any two different message sequences are encoded into different codeword sequences, the code is said to be uniquely decodable. Singular codes are not uniquely decodable; non-singular codes are not necessarily uniquely decodable, since there may exist multiple ways to parse the sequence.
Uniquely decodable codes can be divided into Instantaneous Codes and Non-instantaneous Codes. In an instantaneous code, as soon as a symbol is received, the codeword is known to be complete and can be decoded immediately. A uniquely decodable code is said to be instantaneous if no codeword is a prefix of any other codeword. Otherwise, the code is said to be non-instantaneous.
Instantaneous codes are also called Undelayed Codes or Prefix Codes — no codeword is a prefix of any other codeword.
A tree diagram can be used to represent instantaneous codes. In the tree diagram, terminal nodes represent codewords, and the labels on the edges represent the symbols of the codewords.
Kraft’s Inequality. For a set of codewords
Kraft’s inequality is a necessary and sufficient condition for the existence of a uniquely decodable code. If the inequality is satisfied, then a uniquely decodable code with these codeword lengths must exist; however, this does not imply that every code satisfying the inequality is uniquely decodable. Therefore, this inequality is a necessary and sufficient condition for the existence of a uniquely decodable code, but not a necessary and sufficient condition for determining whether a particular code is uniquely decodable.
Follower Sets are used to determine the unique
decodability of a code. - Examine all codewords in code
Noiseless Source Coding Theorem
Suppose the input message sequence of the source is
We seek an ideal coding scheme that minimizes both the distortion and
the information rate required to transmit
Fixed-Length Coding
In fixed-length coding, the output codewords have a
total of
The information transmission efficiency of fixed-length coding is extremely low.
Fixed-Length Coding Theorem. Under the condition of
noiseless coding (or arbitrarily small error probability), the minimum
required codeword length
This can also be expressed as:
For fixed-length coding to achieve nearly noiseless coding, the
source length
where
Coding Efficiency. Define the coding efficiency as
The efficiency of noiseless coding is always less than 1. When
Variable-Length Coding
In variable-length coding, the codeword length
Single-Symbol Variable-Length Coding Theorem. For a
discrete memoryless source with entropy
For a discrete stationary memoryless sequence, we have:
where
A lower bound on the efficiency of variable-length coding:
Define the redundancy of a code:
For a given source and a given code alphabet, if there exists a uniquely decodable code whose average length is less than that of all other uniquely decodable codes, then this code is called an optimal code or a compact code.
Shannon Coding. Shannon’s first theorem states that
each codeword length
- Arrange the source symbols in descending order of their probabilities of occurrence;
- Determine the integer codeword lengths
; - Compute the cumulative probability for the
-th message; - Convert the cumulative probability into an
-ary fraction, and take its first digits as the codeword for the -th message (progressively pruning the tree diagram).
Source Coding with a Fidelity Criterion
Noiseless source coding is entropy-preserving:
during the encoding process, the input and output codeword sets are in
one-to-one correspondence, so the information transmission rate
Mathematically, noiselessness is well understood; however, in practical applications, it is a very stringent requirement or necessity. In many applications, entropy preservation is neither required nor always possible, and lowering the information rate also facilitates information processing and transmission. Therefore, we can relax the requirement of noiselessness and allow a certain degree of distortion in exchange for a lower information rate.
Source Coding with a Fidelity Criterion Theorem.
Encoding methods exist that can make the information rate arbitrarily
close to
The source coding with a fidelity criterion theorem only demonstrates
the existence of optimal codes, but provides no insight into the
specific construction of encoding methods. In fact, to date, no suitable
implementable encoding method can approach the bound
Common Source Coding Methods
See data structures and discrete mathematics. Omitted.
Fano Coding
- Arrange the source symbols in descending order of their probabilities of occurrence;
- Partition the sequentially arranged source symbols into two groups based on their probability values, such that the sums of the probabilities of the two groups are as close as possible, and assign a binary code symbol 0 and 1 to each group;
- Further divide each large group of source symbols into two subgroups, again making the sums of the probabilities of the two subgroups as close as possible, and assign a binary code symbol 0 and 1 to each subgroup.
- Repeat this process until each group contains only one source symbol.
- The codewords corresponding to the source symbols constitute the Fano code.
Fano coding is well-suited for sources where the probabilities of each partition are very close, especially when encoding a source where the probabilities of each partition are exactly equal, achieving ideal coding efficiency.
This coding method is still a way of constructing a code tree, so it is an instantaneous code. Since the probabilities of each partition are approximately equal, the average codeword length of Fano coding is relatively short, and the coding efficiency is relatively high. However, the Fano coding method does not necessarily make full use of short codewords.
Arithmetic Coding
For block codes, the probability characteristics of the source must be accurately measured. If these characteristics change slightly, the code table must be replaced. Moreover, for binary sources, it is often necessary to combine multiple symbols jointly to improve coding efficiency, which requires constructing a huge code table, increasing coding complexity. Therefore, it is necessary to study a non-block coding method, namely arithmetic coding.
Consider a source alphabet
Define the cumulative probability of the
Thus, for a message sequence
Therefore, the arithmetic coding process is as follows: - Set up two
registers
The decoding process recursively determines the interval containing
the value, removes the cumulative probability, and scales the interval,
gradually recovering the message sequence
LZ Coding
For stationary sources with precisely known statistical characteristics, reliable algorithms (such as Huffman coding or arithmetic coding) already exist that can make the average codeword length approach the average entropy per symbol of the source, with relatively low implementation complexity.
However, in practical applications (such as file compression), the statistical characteristics of the source are often unknown, or they are so complex that accurate measurement is difficult. In such cases, we need a model-free coding method that does not rely on the statistical characteristics of the source to construct the code. This section uses the LZ78 algorithm as an example.
Suppose the source alphabet is
For decoding, the dictionary is built on the fly while decoding.
Run-Length Encoding
In practical signal transmission (e.g., fax, telephone), there are often repeated symbols such as pauses and blanks occurring consecutively. For such cases, run-length encoding (RLE) is a very effective coding method.
For a binary channel, the basic idea of run-length encoding is to
represent consecutive repeated symbols as a symbol and a count. For
example, for the input sequence
The most commonly used run-length encoding scheme is Modified Huffman (MH) Coding, which combines the advantages of run-length encoding and Huffman coding and is suitable for binary channels. MH coding divides consecutive symbols into two categories: short runs (length not exceeding 64) and long runs (length exceeding 64). For short runs, Huffman coding is used directly; for long runs, the run is decomposed into an integer multiple of 64 short runs plus a remaining short run, and each is encoded separately.
At the same time, it is stipulated that each line starts with a white run; if the first run of the current line is a black run, a white run of length 0 is added at the beginning of the line. Each line ends with an end-of-line code.