Documente Academic
Documente Profesional
Documente Cultură
Quantization
22
Quantization
x1
x2 x3
y1
y2
y3
xN 2 xN 1
yN 1
yN
(a)
x1
y1
x3 xN 2 xN 1
x2
y2
y3
yN 1 yN
(b)
Figure 2.1. Illustration of a scalar quantizer by partitioning the real line.
y9
y8
x1
x9
x1
x8
y1
(a)
y1
(b)
Figure 2.2. Linear staircase quantizers: (a) midrise staircase quantizer, (b) midtread staircase quantizer
quantizer, we have to find out the dynamic range of the input, determine the desired resolution of the output (in terms of the number of quantization levels), and
select the proper type of quantizers (e.g., midtread or midrise).
From Figure 2.2, we have the following observation. The midrise quantizer
does not have the zero output level and any input signal will be quantized into an
even number of output steps. In contrast, the midtread quantizer is able to yield
the zero output and has an odd number of output steps. If the output is represented by R bits, the midrise quantizer and the midtread quantizer will have 2R
and 2R 1 dierent codes, respectively. Although the midtread quantizers output
a smaller number of codewords, they generally generate a better quantization result for a given distribution of audio signal amplitudes by accommodating the zero
output value.
It is dicult to handle an input of a very wide dynamic range. If the majority
of input signal values are bounded by a range, say, from Xmax to Xmax , we may
want to clip values outside this range into this range. That is, any value smaller than
Xmax is mapped to Xmax while any value larger than Xmax is mapped to Xmax .
The quantization error caused by clipping is often larger than the quantization
error occurring in the regular cell, which may result in some noticeable artifact in
Scalar quantization
23
1
11
10
1 3/4
1/4
00
01
1/4
3/4
high fidelity audio signal representation. Thus, there is a tradeo between signal
quality and the bit rate required for signal representation.
Once the bounded value Xmax and the number of bits per codeword, R, are
determined, the resolution of the output can be computed accordingly: =
2 Xmax /2R and = 2 Xmax /(2R 1) for the midrise quantizer and the midtread
quantizer, respectively.
In the following two examples, we explain the quantization procedure of the
midrise and the midtread quantizers when they are applied to input signals of
amplitude between 1 and 1.
Example (midrise quantizer). Let us consider a two-bit uniform midrise
quantizer as illustrated in Figure 2.3. The amplitude of the input signal is shown
at the left-hand side, which ranges from 1 to 1. For the two-bit quantizer, we can
split the input range into 4 equal intervals with assigned codewords 01, 00, 10, and
11 as shown in Figure 2.3. Note that the first bit of the codeword is the same for input numbers with the same sign. In other words, the first bit is used to denote the
sign while the remaining bits are used for the magnitude. At the decoder side, we
should convert the 2-bit codes back to the signal sign and magnitude. This process
is called dequantization. The dequantization process is often implemented by a
simple table lookup. In this two-bit example, codes 01, 00, 10, and 11 are mapped
to values of 0.75, 0.25, 0.25, and 0.75, respectively. Following the same principle, we can design midrise quantizers with more than two bits easily. A general
procedure to map input signals onto R-bit uniform midrise quantizer codes and
dequantize these codes back to signal amplitudes is shown in Algorithm 2.1.
Example (midtread quantizer). A two-bit midtread uniform quantizer is illustrated in Figure 2.4, where the input range is divided into three parts. They are
quantized in values of 01, 00 (or 10), and 11, respectively. At the decoder end,
the dequantizer reconstructs codes 01, 00 (or 10), and 11 to 2/3, 0, and 2/3, respectively. The quantization and dequantization procedure for an R-bit uniform
midtread quantizer is shown in Algorithm 2.2.
Quantization errors can be classified into two types: the round-o error and
the clipping (or the overload) error. The round-o error occurs when the input signal with amplitudes within an interval is mapped into a single codeword.
The wider this interval, the larger is the corresponding round-o error. We can
estimate the round-o error if the probability distribution of the input signal is
24
Quantization
Quantize:
(s, m) = quantize (n, R)
Inverse-quantize:
n = inverse-quantize (s, m)
Input:
s: sign bit (1 bit)
m: magnitude bits (R 1 bits)
Output:
n: output number
Input:
n: a number to be quantized
R: number of bits to be output
Output:
s: sign bit (1 bit)
m: magnitude bits (R 1 bits)
0,
s=
1,
1,
n 0,
n < 0.
1,
2R1 1,
m=
2R1
if s = 0,
if s = 1.
sign =
when |n| 1,
|n| , elsewhere.
|n| = (m + 0.5)/(2R1 )
n = sign |n|
11
2/3
00/10
01
2/3
available. The overload error is caused by input signals with an amplitude that is
either too big or too small for the quantizer. The magnitude of this kind of input
signals has to be clipped to the highest quantizer step. The overload error is associated with input signals with an amplitude greater than the quantizers maximum
amplitude Xmax . Thus, if we can find the probability distribution of the input signal
amplitude, we can characterize the amount of overload error for a given quantizer.
Comparing the two-bit midrise quantizer and midtread quantizer examples
given above, we see that the subinterval size of the midtread quantizer is larger
than that of the midrise quantizer. Thus, if the input signal is uniformly distributed, the average quantization error of the midtread quantizer is larger than
that of the midrise quantizer. However, when audio signals are being quantized,
we often have quiet portions. Thus, the uniform distribution does not hold. It is
observed in audio coding system design that a quantizer that can represent signals
with zero amplitude perform better than the one that cannot. Due to this reason,
the midtread quantizer is preferred.
Scalar quantization
Quantize:
(s, m) = quantize (n, R)
Input:
n: a number to be quantized
R: number of bits to be output
Output:
s: sign bit (1 bit)
m: magnitude bits (R 1 bits)
0,
s=
1,
n 0,
n < 0.
m=
when|n| 1,
2R1 1,
R
((2
1)
|
n
|
+1)
, elsewhere.
2
25
Inverse-quantize:
n = inverse-quantize (s, m)
Input:
s: sign bit (1 bit)
m: magnitude bits (R 1 bits)
Output:
n: output number
1,
sign =
1,
if s = 0,
if s = 1.
2m
(2R 1)
n = sign |n|
| n| =
26
Quantization
Uniform
quantizer
y
G1
A|x|
sgn(x)
1 + ln A
GA (x) =
V 1 + ln A|x|/V
sgn(x)
1 + ln A
for 0 |x|
V
A
(2.1)
V
for |x| V ,
A
ln 1 + |x|/V
G (x) = V
sgn(x);
ln(1 + )
|x| V.
(2.2)
In the above compressor functions, A and are parameters that control the degree
of compression by determining the ratio of the smallest to the largest step sizes.
The widely adopted values of A and in practice are 87.6 and 255, respectively.
Example (piecewise uniform quantization). Although the logarithmic compandors can be easily mathematically manipulated, they are dicult to implement
due to their nonlinearities. Instead, uniform quantizers can be more accurately implemented using todays technology. Thus, we can design a piecewise linear compressor to approximate the smooth curves of the logarithmic or other compressors. A piecewise uniform quantizer is defined over several segments, each of which
is a uniform quantizer. The quantization step size of dierent segments may be
dierent. Similarly, the number of output levels can be dierent for dierent segments.
2.2. Vector quantization
Vector quantization (VQ) quantizes a vector of k dimension. Scalar quantization
is a special and the simplest case of vector quantization, and only quantizes signals of one dimension. Unlike scalar quantization, VQ is usually only applied to
signals that have already been digitized. In VQ, an input vector is compared to a
set of predefined representative vectors. The index of the representative vector that
minimizes a certain criterion will be used to represent the input vector. Since the
amount of data needed for indices is much smaller than that of input vectors, a
high compression rate can be achieved by VQ.
Mathematically, a vector quantizer Q that has size N and dimension k maps
a vector in k-dimensional Euclidean space, Rk , into a finite set C containing N
Vector quantization
27
Cell
Cell wall
Centroid
representative points, which are called code vectors or codewords. In other words,
Q : Rk C,
(2.3)
Ri = x Rk : Q(x) = yi ,
(2.4)
is called the inverse image or preimage of yi based on mapping Q, and can also be
denoted by Ri = Q1 (yi ). Since Ri is a partition of space Rk , we have
Ri = Rk ,
Ri
R j = for i = j.
(2.5)
An unbounded cell is called an overload cell, while a bounded cell, that is, one
having a finite k-dimensional volume, is called a granular cell. An example of how
a 2D vector space is partitioned into cells is illustrated in Figure 2.6. The centroids
of each region are depicted as black dots in the figure, and they may be used as
codewords for input vectors that fall into the region.
A complete vector quantization/dequantization pair consists of two basic operations: the encoder and the decoder. The encoder E maps a vector in space Rk
to an index in the set of I while the decoder D maps an index in the set I to a
28
Quantization
VQ encoder
x = Q(x)
VQ decoder
I
Vector quantizer
Figure 2.7. A vector quantizer as the cascade of an encoder and a decoder.
D : I Rk .
(2.6)
It is important to point out that it is the partition of the space that determines how
the encoder should match an index to a given input vector. On the other hand, it is
the given codebook that determines how the decoder should reconstruct the output vector from a given index. Therefore, the encoders task is to identify which of
the N regions of the k-dimensional space the input vector falls in and the decoders
task is simply doing a table lookup to find out which codeword corresponds to the
index. The codebook of most practical vector quantizers contains sucient information to characterize the partition so that the codebook is the only necessary
data set in performing encoding and decoding since the encoder can implicitly
determine the partition via the codebook.
The overall operation of VQ is a cascade of the encoding and the decoding
operations as illustrated in Figure 2.7, that is,
(2.7)
In some cases, it is convenient to let the encoder generate both the index, i, and the
corresponding codeword, Q(x).
2.2.1. Nearest-neighbor quantizers
The nearest-neighbor vector quantizer, which is also called the Voronoi quantizer,
is an important special class of vector quantizers that is of particular interest. Its
special feature is that the partition is completely determined by the codebook and
a distortion measure. The nearest-neighbor vector encoder is optimal in the sense
of minimizing the average distortion for a given codebook. Such an encoder has
an attractive advantage that no explicit storage of the geometrical description of
cells is needed in the encoding process.
Let d(x, y) be a distortion measure on the input and output vector space. The
simplest and most commonly used measure is the squared error distortion measure,
d(x, y) = x y 2 =
k
2
xi y i ,
i=1
(2.8)
Vector quantization
29
which is the squared Euclidean distance between vectors x and y. The nearestneighbor (NN) or Voronoi-vector quantizer is defined as one whose partition cells
are given by
Ri = x : d x, yi d x, y j all j J .
(2.9)
30
Quantization
1
(a)
1
(b)
1
(c)
1
(d)
Figure 2.8. Comparison of several 2D quantization schemes: (a) 2D pdf, (b) scalar quantization, (c)
VQ, (d) alternative VQ.
16 cells is shown in Figure 2.8(b) based on the fact that each component of the random variable X is uniformly distributed. On the other hand, using vector quantization, we can partition the space into 16 cells as shown in Figure 2.8(c). The
worst-case
quantization error between
X and Q(X) measured by Euclidean dis
tance is 2/8 0.18 in case (b) and is 5/16 0.13 in case (c). In fact, the partition given by Figure 2.8(c) is superior to Figure 2.8(b) by any reasonable choice
of performance measure. Therefore, in this example, vector quantizers can achieve
smaller distortion than scale quantizers if the same numbers of bits are assigned
for the index. Figure 2.8(d) shows an alternative partition by vector quantizers.
It is clear that the average quantization error for case (d) is the same as for case
(b). However, only 8 dierent codewords are assigned in case (d). This indicates
that vector quantizers can achieve the same quantization error as scalar quantizers
using a codebook of a smaller size.
Even for random variables that have components statistically independent of
each other, vector quantization can still achieves better results than scalar quantization. Suppose that a 2D vector X is uniformly distributed on the square domain shown in Figure 2.9(a). A rectangular partition corresponding to the scalar
quantization of each component is shown in Figure 2.9(b). Figure 2.9(c) shows a
hexagonal partition by a vector quantizer. It is easy to verify that the worst-case
error calculated by the Euclidean distance for the hexagonal partition is smaller
Vector quantization
(a)
31
(b)
(c)
than for the square partition with the same number of partition cells. Since scale
quantizers are restricted special cases of vector quantizers, vector quantization can
always achieve better performance than or at least the same performance as scalar
quantization.
2.2.3. Vector quantizer design
A VQ codebook is iteratively designed by choosing an initial codebook and then
updating the partition based on the nearest-neighbor condition. The partition is
continuously modified until an optimal codebook is obtained. This iteration process uses a set of training vectors which are representative of the actual vectors that
the vector quantizer will work on.
The first important component in vector quantizer design is to select an initial codebook. If the initial codebook is properly chosen, the number of iterations
for codebook refinement can be greatly reduced. A variety of techniques that generate initial codebook have been developed. One such technique is the splitting
algorithm. It grows a large codebook from a small one and can produce increasingly larger codebooks of a fixed dimension. The splitting algorithm is given below. First, let us use only one vector to represent the whole training sequence. The
centroid of the entire sequence would be the globally optimal solution. Thus, the
optimal codebook of size 1 should have the only codeword equal to this centroid,
denoted by y0 . The codebook of size 2 can be obtained from the codebook of size
1 by splitting y0 into two codewords, y0 and y0 + , where is a vector of a small
Euclidean norm. One choice of is to make it proportional to the eigenvector corresponding to the largest eigenvalue of the covariance matrix of training vectors.
Alternatively, we can choose to be proportional to the vector whose ith component is the standard deviation of the ith component of the training vectors. This
codebook of size 2 can be refined iteratively to lead to two codewords that represent
the entire training set with a good resolution. Suppose we have a good resolution
codebook of size M. By splitting each of the M codewords into two codewords, we
have 2M vectors. Starting from these 2M initial vectors, we can do some codebook
refinement to produce a good resolution codebook of size 2M.
32
Quantization
The second important component in VQ codebook design is the codebook iterative refinement process. This is usually achieved by the generalized Lloyd algorithm, which is also known as the k-means algorithm in the field of pattern recognition or the LBG algorithm in the data compression literature1. Procedures of the
generalized Lloyd algorithm and Lloyd iteration for codebook improvement are
summarized below.
The generalized Lloyd algorithm.
(1) Start with an initial codebook C1 . Set m = 1 and set a threshold to be a
small value.
(2) Use the codebook Cm and perform the Lloyd iteration to generate the
improved codebook Cm+1 .
(3) Compute the average distortion between Cm and Cm+1 . If the distortion
is smaller than the threshold, stop. Otherwise set m + 1 m and go to
Step 2.
The Lloyd iteration for codebook improvement.
(a) Given a codebook Cm = { yi : i = 1, . . . , N }, find the optimal partition
of quantization cells using the nearest-neighbor condition, that is, find
the nearest-neighbor cells
Ri = x : d x, yi < d x, y j ; all j = i .
(2.10)
If x yields a tie for distortion, for example, if d(x, yi ) = d(x, y j ) for one
or more j
= i, then assign x to set R j for which j is the smallest.
(b) Compute the centroid for each cell. The optimal codewords for these
cells form the new codebook Cm+1 , that is,
Cm+1 = cent Ri ; i = 1, . . . , N .
(2.11)
Lloyd algorithm.
Bit allocation
33
D = D(b) =
k
W i bi .
(2.12)
i=1
Then, the bit allocation problem is to determine a set of optimal values for b1 , b2 ,
. . . , bk subject to the condition that the sum of bi is no larger than a fixed quota, B,
of available bits. It is stated below.
The bit allocation problem. Find bi for i = 1, 2, . . . , k to minimize D(b) =
k
i=1 Wi (bi ) subject to the constrain that
i=1 bi B.
Two basic approaches are available to find an optimal or near-optimal bit allocation. The first one is to find an algorithm that minimizes equation (2.12) over
all possible choices of b. However, this method is seldom used since it is computationally exhausted and the optimal distortion functions Wi (bi ) are usually unknown. The second approach to minimize equation (2.12) is realized by invoking
the high resolution quantization approximations2. Then, we can minimize D(b)
and generate the desired result, b1 , b2 , . . . , bk , using the Lagrangian technique.
k
2High resolution refers to the case of quantization when the average distortion is much less than
34
Quantization
(2.13)
B
b =
k
(2.14)
where
is the average number of bits per component, k is the number of components, and
2 =
k
1/k
i2
(2.15)
i=1