| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Communications Blockset |
| Contents | Index |
| Learn more about Communications Blockset |
| On this page… |
|---|
Source coding, also known as quantization or signal formatting, is a way of processing data to reduce redundancy or prepare it for later processing. Analog-to-digital conversion and data compression are two categories of source coding.
Source coding divides into two basic procedures: source encoding and source decoding. Source encoding converts a source signal into a digital signal using a quantization method. The symbols in the resulting signal are nonnegative integers in some finite range. Source decoding recovers the original information from the source-coded signal.
For background material on the subject of source coding, see the works listed in Selected Bibliography for Source Coding.
This blockset supports scalar quantization, companders, and differential coding. It does not support vector quantization. You can open the Source Coding library by double-clicking its icon in the main Communications Blockset library.
Supporting functionality in Communications Toolbox also allows you to optimize source-coding parameters for a set of training data. See Optimizing Quantization Parameters in the Communications Toolbox User's Guide for more information about such capabilities.
Scalar quantization is a process that maps all inputs within a specified range to a common value. It maps inputs in a different range of values to a different common value. In effect, scalar quantization digitizes an analog signal. Two parameters determine a quantization: a partition and a codebook. This section describes how blocks represent these parameters.
A quantization partition defines several contiguous, nonoverlapping ranges of values within the set of real numbers. To specify a partition as a parameter, list the distinct endpoints of the different ranges in a vector.
For example, if the partition separates the real number line into the sets

then you can represent the partition as the three-element vector
[0,1,3]
The length of the partition vector is one less than the number of partition intervals.
A codebook tells the quantizer which common value to assign to inputs that fall into each range of the partition. Represent a codebook as a vector whose length is the same as the number of partition intervals. For example, the vector
[-1,0.5,2,3]
is one possible codebook for the partition [0,1,3].
This section shows how the Quantizing Encoder and Quantizing Decoder blocks use the partition and codebook parameters. The examples here are analogous to Scalar Quantization Example 1 and Scalar Quantization Example 2 in the Communications Toolbox documentation.
The figure below shows how the Quantizing Encoder block uses the partition and codebook as defined above to map a real vector to a new vector whose entries are either -1, 0.5, 2, or 3. In the Scope window, the bottom signal is the quantization of the (original) top signal.


To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
Signal From Workspace, in the Signal Processing Sources library
Set Signal to [-2.4,-1,-.2,0,.2,1,1.2,1.9,2,2.9,3,3.5]'.
Set Quantization partition to [0, 1, 3].
Set Quantization codebook to [-1, 0.5, 2, 3].
Terminator, in the Simulink Sinks library
Scope, in the Simulink Sinks library
After double-clicking the block to open it, click the Parameters icon and set Number of axes to 2.
Connect the blocks as shown in the figure. From the model window's Simulation menu, select Configuration parameters. In the Configuration Parameters dialog box, set Stop time to 12. Running the model produces a scope image similar to the one above. (To make the axis ranges and title exactly match those in the figure, right-click each plot area in the scope and select Axes properties.)
This example, shown in the figure below, illustrates the nature of scalar quantization more clearly. It samples and quantizes a sine wave and then plots the original (top) and quantized (bottom) signals. The plot contrasts the smooth sine curve with the polygonal curve of the quantized signal. The vertical coordinate of each flat part of the polygonal curve is a value in the Quantization codebook vector.


To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
Sine Wave, in the Simulink Sources library (not the Sine Wave block in the Signal Processing Sources library)
Zero-Order Hold, in the Simulink Discrete library
Set Sample time to 0.1.
Set Quantization partition to [-1:.2:1].
Set Quantization codebook to [-1.1:.2:1.1].
Terminator, in the Simulink Sinks library
Scope, in the Simulink Sinks library
After double-clicking the block to open it, click the Parameters icon and set Number of axes to 2.
Connect the blocks as shown in the figure. From the model window's Simulation menu, select Configuration parameters. In the Configuration Parameters dialog box, set Stop time to 2*pi. Running the model produces the scope image as shown above. (To make the axis ranges and title exactly match those in the figure, right-click each plot area in the scope and select Axes properties.)
The Quantizing Encoder block also returns a signal, at the first output port, that tells which interval each input is in. For example, the model below shows that the input entries lie within the intervals labeled 0, 6, and 5, respectively. Here, the 0th interval consists of real numbers less than or equal to 3; the 6th interval consists of real numbers greater than 8 but less than or equal to 9; and the 5th interval consists of real numbers greater than 7 but less than or equal to 8.

To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
Constant, in the Simulink Sources library
Set Constant value to [2, 9, 8].
Set Quantization partition to [3, 4, 5, 6, 7, 8, 9].
Set Quantization codebook to any vector whose length exceeds the length of Quantization Partition by one.
Terminator, in the Simulink Sinks library
Display, in the Simulink Sinks library
Drag the bottom edge of the icon to make the display big enough for three entries.
Connect the blocks as shown above. From the model window's Simulation menu, select Configuration parameters. In the Configuration Parameters dialog box, set Stop time to 10. Running the model produces the display numbers as shown in the figure.
You can continue this example by branching the first output of the Quantizing Encoder block, connecting one branch to the input port of the Quantizing Decoder block, and connecting the output of the Quantizing Decoder block to another Display block. If the two source coding blocks' Quantization codebook parameters match, the output of the Quantizing Decoder block is the same as the second output of the Quantizing Encoder block. Thus the Quantizing Decoder block partially duplicates the functionality of the Quantizing Encoder block, but requires different input data and fewer parameters.
In certain applications, such as speech processing, it is common to use a logarithm computation, called a compressor, before quantizing. The inverse operation of a compressor is called an expander. The combination of a compressor and expander is called a compander.
This blockset supports two kinds of companders: µ-law and A-law companders. The reference pages for the A-Law Compressor, A-Law Expander, Mu-Law Compressor, and Mu-Law Expander blocks list the relevant expander and compressor laws.
This example quantizes an exponential signal in two ways and compares the resulting mean-square distortions. To create the signal in the MATLAB workspace, execute these commands:
sig = -4:.1:4; sig = exp(sig'); % Exponential signal to quantize
The model in the following figure performs two computations. One computation uses the Quantizing Encoder block with a partition consisting of length-one intervals. The second computation uses the Mu-Law Compressor block to implement a µ-law compressor, the Quantizing Encoder block to quantize the compressed data and, finally, the Mu-Law Expander block to expand the quantized data.

To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
Signal From Workspace, in the Signal Processing Sources library
Set Signal to sig.
Set Peak signal magnitude to max(sig).
Mux, in the Simulink Signal Routing library
Quantizing Encoder, in the Source Coding library
Set Quantization partition to 0:floor(max(sig)).
Set Quantization codebook to 0:ceil(max(sig)).
Terminator, in the Simulink Sinks library
Demux, in the Simulink Signal Routing library
Set Peak signal magnitude to ceil(max(sig)).
Two copies of To Workspace, in the Simulink Sinks library
Set Variable name to nocompander and withcompander, respectively, in the two copies of this block.
Set Save format to Array in each of the two copies of this block.
Connect the blocks as shown above. From the model window's Simulation menu, select Configuration parameters. In the Configuration Parameters dialog box, set Stop time to 80. Run the model and execute these commands:
distor = sum((nocompander-sig).^2)/length(sig);
distor2 = sum((withcompander-sig).^2)/length(sig);
[distor distor2]
ans =
0.5348 0.0397
This output shows that the distortion is smaller for the second scheme. This is because equal-length intervals are well suited to the logarithm of the data but not as well suited to the data itself.
The following audio processing demos, located in the Signal Processing Blockset documentation, highlight different techniques for source coding.
[1] Couch, Leon W., II, Digital and Analog Communication Systems, 6th edition, Upper Saddle River, NJ, Prentice Hall, 2001.
[2] Kondoz, A.M., Digital Speech, Chichester, England, John Wiley & Sons, 1994.
[3] Sklar, Bernard. Digital Communications: Fundamentals and Applications, Englewood Cliffs, NJ, Prentice Hall, 1988.
![]() | Communications Sinks | Block Coding | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |