## Thursday, May 26, 2011

### Pulse Code Modulation: Quantization

The discrete signal i.e. sampled values produced as a result of sampling (discussed in the previous post) has to be quantized, hence the process called Quantization. In simple words, this is the process in which a value from a given set of values is assigned to each sample of the discrete signal. The number of values in the set actually is the number of quantization levels to which samples of discrete signals are assigned to. Digital communication is based on bits and bytes, the number of bits used identify the number of quantization levels,  hence, in this case when the samples are binary encoded that means they are essentially being quantized in one of the fixed number of quantization levels.
In the figure below, the process has been explained where an input discrete signal s(t) has been quantized into a signal sq(t). The input signal s(t) moves between low peak amplitude AL to high peak amplitude AH . This range from AL to AH is divided into M intervals (an interval represent a quantization level, also referred as quantization interval) each of size L such that L =  (AH - AL)/M. In the figure, eight intervals have been shown i.e. M=8. Let As be the peak-to-peak amplitude of s(t)  i.e. total range between high and low peaks i.e. As = AH - AL hence L = As /M. The value of each quantization interval is taken as the center of the interval, in figure, shown as a0 , a1 , a2 , a3 , a4 , a5 , a6 , a7 . The range of values for each interval has been shown as l0, l1, l2 , l3 , l4 , l5 , l6 , l7 . Moreover, the midpoints between consecutive quantization intervals are shown by  A01 , A12 , A23 , A34 , A45 , A56 , A67 . Each of these midpoints is at a distance of L/2 from its corresponding intervals values e.g. A67 is the midpoint between two quantization intervals whose values are a6 and a7 and is located at a distance of L/2 from a6 and a7. The distance between two consecutive midpoints and also between two interval values is L. It is, in fact, these mid points which define when the value of the quantized signal sq(t) changes. It should also be noted that the peak values i.e. AH and AL are at a distance of L/2 from their corresponding quantization levels. This results in affecting the peak-to-peak amplitude of sq(t) shown as  Aq and has a value of (M-1)L.
As shown in the figure, when the signal being quantized i.e. s(t) is in the range of l7 , the quantized signal sq(t) maintains a constant value of a7 . As soon as s(t) gets in the range of l6 , sq(t) makes a jump to the value of a6 and maintains this value as long as s(t) assumes a value in the range of l6 . The sudden jump is made when s(t) crosses the midpoint  A67 . Similar changes occur to sq(t) through the rest of the process of quantization. Therefore, at any time, the quantized signal sq(t) holds a value from a0 , a1 , a2 , a3 , a4 , a5 , a6  and  a7 . That means, at any moment, sq(t) exits in one of the quantization intervals that is nearest to  s(t).
As the above description and the figure indicate that sq(t) is not same as s(t) rather it’s an approximation with a difference between the two. This difference is very important and is known as Quantization Error. Quantization Error’s magnitude is always less than or equal to L/2 (We’ll discuss Quantization Error later). The approximation can be improved by making the interval size smaller, hence increasing the number of intervals (quantization levels). In digital communication, high number of intervals requires high number of bits which itself, in turn, require high transmission bandwidth. On the other hand, if interval size is increased using lesser number of quantization levels, approximation is poor. Therefore, there has to be a tradeoff between approximation and bandwidth.

## Thursday, March 17, 2011

### Pulse Code Modulation: Filtering and Sampling

In Digital Telephony, analog signals have to be converted into digital signals before transmission because of several advantages they have over Analog signals, one of which is their strong immunity against noise. Pulse Code Modulation (PCM) is one of the techniques to achieve the objective. Generally, PCM is a four step process consisting of Filtering and Sampling, Quantization and Encoding. However, Quantization may be performed either of two ways: Linear Quantization or Non-Linear Quantization. For Non-Linear Quantization, sometimes an additional step of Companding is performed after Sampling and before Quantization to prepare the samples for non-linear Quantization.
Here, in this post, we’ll discuss Filtering and Sampling. Later, in the next posts, we’ll discuss Linear Quantization, Quantization Error, Non-Linear Quantization, Companding and Encoding. Our discussion is based on digital telephony.

Analog Low Pass Filtering:
Before an analog signal is converted into digital one, it is passed through an analog Low-Pass Filter (see here). Following figure shows the frequency responses of a Low Pass Filter.

This filtering comes handy later to avoid aliasing when the analog signal is sampled and then reconstructed from the digital signal (see here), hence also called Anti-Aliasing Filter. In simple words, this is performed to filter out the frequencies which are higher than a “certain frequency”. We are interested in the frequency band lower than the “certain frequency” and not the higher.

“Certain Frequency” is just a made up term for explanation and is not a technical term.

For Telephony Systems whose main objective is to transfer human voice, that “certain frequency” can be found from high school physics. We have read human voice consists of frequency range of 300Hz to 3000Hz. Due to some constraints in designing an ideal filter, we make this certain frequency 4000Hz instead of 3000Hz. So after filtering, for the next step of Sampling, we know that bandwidth of the signal is 4000Hz i.e. the greatest frequency analog signal consists of is 4000Hz.

Sampling
Sampling is the process of creation of a Discrete Signal by taking samples of an Analog Signal. These samples are taken at regular intervals; intervals may be time base (for time domain) or space based (for spatial domain) or any other independent variables. In our case, intervals are generally time based, these regular intervals define the sampling rate--the rate at which samples are taken, also called sampling frequency Fs.
Sampling is governed by Nyquist Sampling Theorem, according to which when a signal is sampled, the sampling rate (or sampling frequency) must be at least twice the highest frequency the signal contains, to avoid aliasing. In other words, sampling frequency must be at least twice the bandwidth of the signal. This means at least two samples are required per cycle of each frequency in the analog signal.
Therefore
Fs = 2 x 4000 = 8000 Samples/sec

Filtering and Sampling work in collaboration to overcome a possible artifact of aliasing which is a result of under sampling. Aliasing is an important concept to be understood and an important artifact to be overcome for correct transfer of voice data in telephony systems.
On the other hand, sampling rate, higher than minimum sampling rate of 8000 samples/sec, results in too much voice data to be transferred over the communication channel demanding a high bandwidth. Between the two extremes of under-sampling and over-sampling, above sampling frequency of 8K samples/sec is the threshold which is good enough for the reconstructed analog signal and is good enough for the usage of bandwidth.
A technique often used for sampling is Pulse Amplitude Modulation (PAM) in which a pulse is modulated with the filtered analog signal. This has been shown is the following figure created on Simulink Matlab, pink colored graph is the pulse, yellow colored graph is a sine wave to be sampled and aqua graph is the output of the PAM sampling.

Sampling creates discrete signals not the digitized signals; Quantization is the step to digitize the samples into binary encoded form.