Chapter 3

MATLAB® for Communications System Design

In this chapter, we introduce some of the capabilities in MATLAB related to the analysis, design, modeling, simulation, implementation, and verification of communications systems. We attempt to answer the following question: How can MATLAB, a high-level programming language and a design and simulation environment with an extensive library of software toolboxes, help academics and practitioners in the development of mobile and wireless systems?

3.1 System Development Workflow

To answer this question, we review multiple stages of development: from early research and algorithm design to integration of individual algorithms into a prototype system model, to verification using simulations that the system works as intended, to checking whether the system is realizable, to assessing its resource consumption, memory, complexity, and so on, to coding the design as a software or hardware implementation. The step before implementation – that is, system-level resource assessment – requires some form of software coding for system-level simulation. It also involves integrating real constraints such as data types and memory with complexity trade-offs. This system-level code can be used as the basis for hardware implementation, with the aim being to integrate sufficient detail that the task of the implementer becomes the creation of a bit-accurate model of the software simulation as either assembly code for implementation on Digital Signal Processors (DSPs) or as Hardware Description Language (HDL) code for implementation on a Field-Programmable Gate Array (FPGA) or an Application-Specific Integrated Circuit (ASIC). Throughout this process we must continuously monitor new details as they are added to the model in order to ensure that the elaborated design still meets the requirements set out at the research and development level.

3.2 Challenges and Capabilities

We face a number of challenges when we start from a typical standards specification until we implement the design. These challenges include:

  • Translation from a specification based on text-based explanations to a software model that can act as a blueprint for implementation
  • Introduction of innovative proprietary algorithms specially for the receiver operations where standards provide flexibility
  • Execution of the software model in order to perform a dynamic system-level performance evaluation
  • Acceleration of simulation for the handling of large data sets
  • Resolving gaps in the implementation workflow.

MATLAB and its toolboxes can help address some of these challenges.

  • Digital signal processing and advanced linear algebra, as foundations of the LTE (Long Term Evolution) standard, form the core competency of the MATLAB language. The make-up of the standard can gradually and intuitively be synthesized with a series of MATLAB programs
  • The Communications System Toolbox provides ready-to-use MATLAB tools for the building of communications-system models. With over 100 algorithms for modulation, channel modeling, error correction, MIMO (Multiple Input Multiple Output) techniques, equalizers, and more, the Toolbox allows us to focus on communications system design rather than software engineering. It also includes many standards-based examples in order to allow a quick start
  • MATLAB and Simulink are ideal environments for dynamic and large-scale simulations.
  • MATLAB enables simulation to be accelerated.
  • MATLAB allows implementation workflow gaps to be addressed, using:
    • Automatic MATLAB to C/C++ and HDL (Hardware Description Language) code generation
    • Hardware-in-the-loop verification.

We can divide these capabilities into four categories: algorithm development, modeling and simulation, simulation acceleration, and path to implementation. In this chapter, following a quick introduction to MATLAB and Simulink as core products, we will introduce three categories of capability:

  • Tools for modeling and simulation
  • Tools for acceleration of the simulation speed
  • Tools that enable a path to implementation.

The modeling and simulation capabilities, including various toolboxes, enable users to create simulation models of communications standards, including wireless and mobile standards. Running these simulation models enables the designer to gauge the performance of the entire system and of individual algorithms and to determine the effects of channel degradations and other real-time conditions.

3.3 Focus

The focus of this book is on LTE PHY (Physical Layer) modeling as MATLAB programs. For example, we discuss modeling and simulation of the LTE standard only in the FDD (Frequency Division Duplex) mode. Without any loss of generality and with some modification of MATLAB code, the reader can then adopt our MATLAB program for TDD (Time Division Duplex) mode. We will not cover topics related to control-plane processing, roaming or random access, or multimedia broadcast frames, nor will we cover detailed MATLAB programs related to multicast mode or multi-user MIMO. We will focus instead on a general scenario in which a mobile unit is assigned to a cell and we fully detail user-plane data processing.

3.4 Approach

Starting from the simplest component of the LTE (i.e., the modulators), we will create a series of MATLAB programs that progressively add other components such as scrambling and channel coding to the signal processing chains. At each stage, we will compute performance measures such as Bit Error Rate (BER) to ensure that the combinations of components are properly modeled in MATLAB. We will continue this process and develop MATLAB programs to model OFDM and MIMO operations specified in the standard. In so doing, we will also generate multiple subfunctions that help match the model to the LTE standard. At the end of this process, we will have MATLAB programs and Simulink models that represent important signal processing operations of various downlink modes of the LTE standard.

3.5 PHY Models in MATLAB

In this book we will iteratively and systematically build up the necessary components of the LTE PHY in MATLAB for downlink transmission. However, in order to make the discussion fit a book of this size, we have to be selective in the details we highlight. The pedagogic value of iterative and gradual design can be more beneficial than adherence to all parameters and details specified in the standard. As the title of the book attests, we are aiming for a creating understanding of LTE by augmentation of technical discussions with software programs that can be executed in MATLAB. The ability to run and execute the software and simulate the system adds another dimension to the level of understanding.

Next, we will highlight various products that helps users model, simulate, prototype, and implement wireless systems in MATLAB.

3.6 MATLAB

MATLAB is a widely-used programming language for algorithm development, data analysis, visualization, and numerical computation. If the volume of technical papers and publications mentioning it is any indication, MATLAB has a long history in communications system design and is used by both academics and practitioners. It lets designers focus on algorithms rather than low-level programming. Many of its features and capabilities are perfect for modeling wireless systems: (i) it has an interactive program and environment that matches the exploratory nature of science; (ii) it provides seamless access to data and algorithms; and (iii) it has tools for visualization, algorithm development, and data analysis.

Matrix as fundamental data type: The fundamental data type in MATLAB is the matrix. Since most algorithms used in communications systems are based on block-based or frame-based processing of data, expressing these algorithms is natural in MATLAB. This means the mathematical formula expressed in the matrix format is immediately expressed in MATLAB. For example, in MIMO systems the relationship between the received and the transmitted data is expressed by a system of linear equations of the form c03-math-0001. These kinds of relationship can be expressed easily by a single line of MATLAB code. Compare that to a typical C code representing the same algorithms, which will look like a double for loop.
Linear algebra and Fourier analysis: MATLAB contains mathematical, statistical, and engineering functions that support all common engineering and science operations. These functions, developed by experts in mathematics, are the foundation of the MATLAB language. The core math functions use the LAPACK and BLAS linear algebra subroutine libraries and the FFTW Discrete Fourier Transform library. Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, and numerical integration are implemented as fast and accurate functions in MATLAB.
Visualization for design validation: Most graphical features required to visualize engineering and scientific data are available in MATLAB. These include 2D and 3D plotting functions, 3D volume-visualization functions, tools for the interactive creation of plots, and the exporting of results to all popular graphics formats. Plots can be customized by a variety of methods.
Complex numbers and a range of data types: Simulation of communications systems relies on the extensive use of complex data and random number generators. MATLAB enables you to perform arithmetic operations on a wide range of data types, including doubles, singles, and integers. MATLAB also has optimized functions for random number generators. Functions such as randn (which models random numbers with normal distributions), rand (for uniform distribution), and randi (for discrete integer random distributions) have favorable properties in terms of periodicity and efficiency 1.

3.7 MATLAB Toolboxes

MATLAB's add-on software tools are called toolboxes. These provide specialized mathematical functionalities in areas including signal processing and communications. They complement the core MATLAB library and provide application-specific functions and objects that accelerate the process of modeling and building algorithms and systems. These algorithmic building blocks enable the user to focus on their area of expertise instead of having to reinvent and implement the basics.

Four system toolboxes – DSP System Toolbox 2, Communications System Toolbox 3, Phased Array System Toolbox 4, and Computer Vision System Toolbox 5 – are particularly suitable for system modeling in different application areas. Not only do they provide algorithms for the design, simulation, and verification of various application areas, but they provide components that facilitate the creation of simulation test benches for the modeling of dynamic systems. In later sections we will review some of these system toolboxes in further detail.

3.8 Simulink

Simulink requires MATLAB and provides an environment for multidomain simulation and model-based design for dynamic and embedded systems 6. It provides an interactive graphical environment and a customizable set of block libraries. With an easy-to-use graphical design environment, Simulink allows us to design, simulate, implement, and test a variety of time-varying systems, including communications, control, signal processing, and video processing.

With Simulink, we can create, model, and maintain a detailed block diagram of our system using a comprehensive set of predefined blocks. Simulink provides tools for hierarchical modeling, data management, and subsystem customization. Additional blocksets or system toolboxes extend Simulink with specific functionality for aerospace, communications, radio frequency, signal processing, video, image processing, and other applications; these features are particularly useful for the modeling and simulation of communications systems.

Integration with MATLAB: MATLAB functions can be called within Simulink models in order to implement algorithms that can analyze data and verify a design. Use of the MATLAB function block in Simulink allows MATLAB code to be integrated into Simulink. Simulink will first use its code-generation capabilities to translate the MATLAB code to C code, then compile the C code as a MEX (MATLAB Executables) function and call the resulting MEX function when executing the Simulink model.
Signal attributes and data-type support: Like MATLAB, Simulink defines the following signal and parameter attributes: data types – single, double, signed, or unsigned 8, 16, or 32 bit integers; Boolean and fixed-point; dimension – scalar, vector, matrix, or N-D arrays; values – real or complex. This enables us, for example, to monitor the effects of finite word lengths on the accuracy of the computation in an algorithm.
Simulation capabilities: After building a model in Simulink, we can simulate its dynamic behavior and view the results. Simulink provides several features and tools that ensure the speed and accuracy of a simulation, including fixed-step and variable-step solvers, a graphical debugger, and a model profiler.
Using solvers: Solvers are numerical-integration algorithms that compute the system dynamics over time using information contained in the model. Simulink provides solvers to support the simulation of continuous-time (analog), discrete-time (digital), hybrid (mixed-signal), and multirate systems.
Executing a simulation: Once we have set the simulation options for a model, we can run the simulation interactively, using the Simulink GUI (Graphical User Interface), or systematically, by running it in batch mode from the MATLAB command line. The following simulation modes can be used:
  • Normal (default), which interpretively simulates the model
  • Accelerator, which speeds model execution by creating compiled target code, while still allowing the model parameters to be changed
  • Rapid accelerator, which can simulate models faster than the accelerator mode but with less interactivity, by creating an executable separate from Simulink that can run on a second processing core.

3.9 Modeling and Simulation

Most algorithm development for various systems and components starts in MATLAB. With a library of digital signal-processing, linear algebra, and mathematical operators, designs can be expressed easily in MATLAB as algorithms composed of a pertinent sequence of operations. As individual algorithms are developed and connected to each other, this forms the basis of a system model. System modeling can best be done in either MATLAB or Simulink. As we saw earlier, Simulink allows MATLAB algorithms and functions to be integrated seamlessly as system components. By using various add-on toolboxes, we can expand the scope of the system and simulate it to verify that it behaves according to specifications. In this section we will introduce some of the MATLAB and Simulink add-on toolboxes that help with this process.

3.9.1 DSP System Toolbox

The DSP System Toolbox provides algorithms and tools for foundational signal processing operations. It comes with a slew of specialized filter design capabilities, FFTs (Fast Fourier Transforms), and multirate processing abilities and features algorithms captured as System objects that make the task of processing streaming data and creating real-time prototypes easier. The DSP System Toolbox has specialized tools for connecting to audio files and devices, performing spectral analysis, and using other interactive visualization techniques that enable the analysis of system behavior and performance. All of these components support automatic C/C++ code generation, most support fixed-point data, and a few generate HDL code.

3.9.2 Communications System Toolbox

The Communications System Toolbox provides algorithms and tools for the design, simulation, and analysis of communications systems. This toolbox is specially designed to model the PHY of communications systems. It contains a library of components including ones for source coding, channel coding, interleaving, modulation, equalization, synchronization, MIMO, and channel modeling. These components are provided as MATLAB functions, MATLAB System objects, and Simulink blocks, so they can be used as part of MATLAB or Simulink system models. All support C/C++ code generation, most support fixed-point data arithmetic, and a few generate HDL code for FPGA or ASIC hardware implementation.

3.9.3 Parallel Computing Toolbox

The Parallel Computing Toolbox 7 can help accelerate computationally and data-intensive problems using multicore processors, GPUs (Graphics Progressing Units), and computer clusters. Features such as parallelized for loops, special array types, and parallelized numerical algorithms allow the parallelization of MATLAB applications. The toolbox can be used with Simulink to run multiple simulations of a model in parallel. Two main approaches to simulation acceleration can be identified:

Multicore or cluster processing: Some applications can be sped up by organizing them into independent tasks and executing several at the same time on different processing units. This class of task-parallel application includes simulations for design optimization, BER testing, and Monte Carlo simulations. As one of its easy-to-use and intuitive capabilities, the toolbox offers parfor, a parallel for-loop construct that can automatically distribute independent tasks to multiple MATLAB workers. A MATLAB worker is a MATLAB computational engine that runs independently of the desktop MATLAB session. MATLAB can automatically detect the presence of workers and will revert to serial behavior if only the desktop session is present. Task execution can also be set up using other methods, such as manipulation of task objects in the toolbox.
GPU processing: The Parallel Computing Toolbox provides a special array type that allows computations to be performed on CUDA-enabled NVIDIA GPUs direct from MATLAB. Supported functions include FFT, element-wise operations, and several linear algebra operations. The toolbox also provides a mechanism that allows existing CUDA-based GPU kernels to be used directly from MATLAB. The Communication System Toolbox has many specialized algorithms that support GPU processing. The Parallel Computing Toolbox can be used to execute many communications algorithms directly on the GPU.

3.9.4 Fixed-Point Designer

Fixed-Point Designer 8, previously Fixed-Point Toolbox, provides fixed-point data types, operations, and algorithms in MATLAB. Using Fixed-Point Designer, the effects of finite word lengths can be modeled for variables in various algorithms. The toolbox allows fixed-point algorithms to be designed using MATLAB syntax and the results to be compared with the floating-point implementation of the same algorithm. These algorithms can be reused in Simulink and can pass fixed-point data to and from Simulink models. The toolbox provides a suite of tools that make it easier to convert an algorithm from a floating-point to a fixed-point implementation.

3.10 Prototyping and Implementation

Various MathWorks products can help elaborate a design from concept to embeddable code while staying within the MATLAB environment. The MATLAB algorithm must first be refined based on design constraints such as finite word lengths, limitations on memory and complexity, and so on. It can then be integrated and simulated as part of a larger system model, and bit-true test sequences can be generated to verify that software and hardware implementations match the golden reference results in MATLAB. Finally, C and HDL code can be generated for hardware implementation. With this step, the errors introduced by manual coding can be avoided by maintaining a single design source in MATLAB. Some of these products are presented in this section.

3.10.1 MATLAB Coder

MATLAB Coder 9 generates standalone C and C++ code from MATLAB code. The generated source code is portable and readable. MATLAB Coder supports code generation for a large subset of MATLAB language, including program control constructs, functions, and matrix operations. It also supports code generation for the functions and System objects of various toolboxes and System toolboxes. With MATLAB Coder we can generate:

  • MEX functions that let us accelerate computationally intensive portions of MATLAB code and verify the behavior of the generated code
  • Readable and portable C/C++ code for integration with existing C/C++ source codes and environments
  • Dynamic and static libraries for integration with C-based tools and environments
  • C/C++ executable for prototyping of algorithms and provision of proofs-of-concept.

3.10.2 Hardware Implementation

A design for a communication system can be realized as either embedded software or embedded hardware. An embedded software implementation targets DSP and general-purpose processors. The path from a MATLAB model to an embedded software implementation involves two steps: (i) C/C++ code generation from MATLAB and (ii) compiling or hand-coding of the C code as assembly code on the target. MATLAB Coder can be used for the first step and the compilers of various software simulators for hardware targets can be used for the second.

An embedded hardware implementation targets the design on FPGAs and ASICs. The process of realizing a design from a MATLAB model to the final FPGA or ASIC prototype involves two steps: (i) VHDL or Verilog code generation of MATLAB functions or Simulink models with the HDL Coder and (ii) post-processing by the integrated simulation environments to convert the RTL (Register Transfer Level) Verilog and VHDL code into a fully synthesized FPGA or ASIC design. HDL Coder 10 generates portable, synthesizable VHDL and Verilog code from MATLAB functions and Simulink models. It can be used to perform the first step of the implementation. Another MathWorks HDL tool, HDL Verifier, automates Verilog and VHDL design verification using HDL simulators and FPGA hardware-in-the-loop. HDL Verifier 11 can be used to bring an RTL design into MATLAB and to verify it by comparing the outputs of the VHDL and Verilog code with detailed implementations of the same algorithm in MATLAB and Simulink. Since in this book we focus on modeling, simulation, and software prototyping of the LTE standard, discussions regarding hardware implementations and realization of a design as HDL code are outside our scope.

3.11 Introduction to System Objects

In this book we highlight many features of the Communications System Toolbox, particularly we will introduce the new System objects used in the product. With a very intuitive user interface, System objects make the task of expressing communications systems easier and make the resulting MATLAB code more readable and sharable. System objects can be used as part of both MATLAB programs and Simulink models. They are MATLAB objects that represent time-based and executable algorithms and they are organized as objects to make them easy to use and virtually self-documenting. Since in the rest of this book we rely on System objects to express LTE-system models in MATLAB, a short tutorial on how to use these algorithmic components is presented in this section.

3.11.1 System Objects of the Communications System Toolbox

System objects of the Communications System Toolbox belong to the communications (comm) package and their names start with the common prefix “comm.” In order to access all of the System objects of the Communications System Toolbox, type “comm.” followed by a Tab key at the MATLAB command prompt:

>> comm.<Tab>

This will produce an alphabetical list of all the System objects available in the toolbox. As of the latest release of MATLAB, the Communications System Toolbox contains a total of 123 algorithms provided as System objects.

Let us choose one of these System objects, for example comm.QPSKModulator, and create one instance of this type of modulator. Let us call this instance “Modulator”:

>> Modulator=comm.QPSKModulator

A QPSK (Quadratue Phase Shift Keying) modulator will be created and a description of this object will appear in the MATLAB workspace (Figure 3.1).

Figure 3.1 Creating a System object from the Communications System Toolbox

c03f001

Every System object contains properties and methods. Its default properties appear when they are created; this self-documentation is a useful feature of System objects. From looking at the property list of a given System object, we know what parameters it can take and what values are typically assigned to them. For example, the phase-offset property of the QPSK modulator is by default set to π/4. Let us change this parameter to π/2. There are two ways to modify properties:

  • Create an object with default values and then change a property using dot notation. For example:
    >> Modulator = comm.QPSKModulator;
    >> Modulator.PhaseOffset = pi/2
  • Set different properties as they are created using property–values pairs. For example:
    >>Modulator = comm.QPSKModulator ('PhaseOffset',pi/2);

If properties are expressed as a string of characters, a convenient list of possible values appears when we want to set a particular property. For example, when we type “Modulator.SymbolMapping=” followed by a Tab, a list of mapping choices appears to facilitate setting of the property to any of the several options, in this case “Binary” and “Gray.”

The step method is the main method of execution of a System object. After an object is created and configured, it can be passed an input (or multiple inputs) and its step method can be called to produce its output (or multiple outputs). There are two syntaxes available by which to execute the step method of a System object. We can:

  • Use dot notation to call the System object: y = Modulator.step (u)
  • Use the step method as a function and make the System object the first function argument: y = step (Modulator, u).

In Figure 3.2, a 10 × 1 column vector of bits (variable u) is created using the MATLAB randi function and then passed as input to the Modulator System object. By calling its step method, a 5 × 1 output vector (y) of modulated symbols representing the modulated bits using the QPSK algorithms based on specified properties is created.

Figure 3.2 Executing a System object by calling its step method

c03f002

Now that we have seen how to access, create, set the properties of, configure, and call a System object to perform computations, let us create a simple script that uses a few System objects to express a simple communications system.

3.11.2 Test Benches with System Objects

Following is a MATLAB script, otherwise known as a testbench, that uses System objects to perform BER analysis of a simple transceiver system. The transceiver is composed of a QPSK modulator, an Additive White Gaussian Noise (AWGN) channel, and a QPSK demodulator. Note that this code employs four System objects from the Communications System Toolbox: comm.QPSKModulator, comm.AWGNChannel, comm.QPSKDemodulator, and comm.ErrorRate.


Algorithm
MATLAB script
%% Constants
FRM=2048;
MaxNumErrs=200;MaxNumBits=1e7;
EbNo_vector=0:10;BER_vector=zeros(size(EbNo_vector));
%% Initializations
Modulator      = comm.QPSKModulator('BitInput',true);
AWGN             = comm.AWGNChannel;
DeModulator =  comm.QPSKDemodulator('BitOutput',true);
BitError           = comm.ErrorRate;
%% Outer Loop computing Bit-error rate as a function of EbNo
for EbNo = EbNo_vector
    snr = EbNo + 10*log10(2);
    AWGN.EbNo=snr;
    numErrs = 0; numBits = 0;results=zeros(3,1);
    %% Inner loop modeling transmitter, channel model and receiver for each EbNo
    while ((numErrs < MaxNumErrs) && (numBits < MaxNumBits))
        % Transmitter
        u             = randi([0 1], FRM,1);                  % Generate random bits
        mod_sig = step(Modulator,   u);               % QPSK Modulator
        % Channel
        rx_sig  = step(AWGN,        mod_sig);        % AWGN channel
        % Receiver
        y =       step(DeModulator, rx_sig);           % QPSK Demodulator
        results = step(BitError,    u, y);                   % Update BER
        numErrs = results(2);
        numBits = results(3);
    end
    % Compute BER
    ber = results(1); bits= results(3);
    %% Clean up & collect results
    reset(BitError);
    BER_vector(EbNo+1)=ber;
end
%% Visualize results
EbNoLin = 10.^(EbNo_vector/10);
theoretical_results = 0.5*erfc(sqrt(EbNoLin));
semilogy(EbNo_vector, BER_vector)
grid;title('BER vs. EbNo - QPSK modulation');
xlabel('Eb/No (dB)');ylabel('BER');hold;
semilogy(EbNo_vector,theoretical_results,'dr');hold;
legend('Simulation','Theoretical');

The script is organized in four sections. In the initialization section, the System objects are created and some parameters are set. The second section contains the processing testbench that iterates through Eb/N0 values and computes the corresponding BER measures. The third section is the transceiver processing loop, where the step methods of the System objects are called in order to modulate the input signal, add channel noise to the modulated signal, and demodulate to produce the received signal and compute BER. Finally, in the fourth section, the simulation is cleaned up and terminated and the BER performance results are visualized.

Figure 3.3 verifies that the simulated results match the analytical results.

Figure 3.3 BER curves for QPSK modulation under an AWGN channel; simulated and theoretical results match

c03f003

By running this script we obtain the BER curves of a QPSK modulation system using an AWGN channel. Theoretical results for a QPSK modulation scheme processed by an AWGN channel are expressed in the following equation:

3.1 c03-math-0002

The use of System objects results in a modular and easy-to-understand MATLAB code and fosters a structure that can be expanded for more complex systems. We will follow this four-step process of initialization, processing loop, termination, and visualization throughout this book. One way of improving MATLAB programs and making them more readable is to separate testbench and visualization operations from the algorithms and system description. Next we will show how to achieve this by capturing our transceiver as a MATLAB function and separating our algorithmic component from the testbench script.

3.11.3 Functions with System Objects

The MATLAB function chap3_ex02_qpsk performs the algorithmic portion of our simple QPSK transceiver system. This function has three input variables:

  • The first input is a scalar number that corresponds to Eb/N0
  • The second input is one of the stopping criteria, based on the maximum number of errors that can be observed before the simulation is stopped
  • The third input is the other stop criterion, based on the maximum number of bits that can be processed before the simulation is stopped.

For each Eb/N0 value, the code runs in a while loop until either the specified maximum number of errors is observed or the maximum number of bits is processed. The code executes each System object by calling the step method. It computes two outputs:

  • BER, defined as the ratio of the observed number of errors to the number bits processed
  • The number of bits processed, based on the stopping criterion defined by the second and third input variables.

Algorithm
MATLAB function
function [ber, bits]=chap3_ex02_qpsk(EbNo, maxNumErrs, maxNumBits)
%% Initializations
persistent Modulator AWGN DeModulator BitError
if isempty(Modulator)
    Modulator      = comm.QPSKModulator('BitInput',true);
    AWGN             = comm.AWGNChannel;
    DeModulator =  comm.QPSKDemodulator('BitOutput',true);
    BitError           = comm.ErrorRate;
end
%% Constants
FRM=2048;
M=4; k=log2(M);
snr = EbNo + 10*log10(k);
AWGN.EbNo=snr;
%% Processsing loop modeling transmitter, channel model and receiver
numErrs = 0; numBits = 0;results=zeros(3,1);
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
    % Transmitter
    u                   = randi([0 1], FRM,1);                   % Random bits generator
    mod_sig     = Modulator.step(u);                    % QPSK Modulator
    % Channel
    rx_sig          =  AWGN.step(mod_sig);             % AWGN channel
    % Receiver
    demod        =  DeModulator.step(rx_sig);      % QPSK Demodulator
    y                   = demod(1:FRM);                         % Compute output bits
    results        = BitError.step(u, y);                       % Update BER
    numErrs     = results(2);
    numBits      = results(3);
end
%% Clean up & collect results
ber = results(1); bits= results(3);
reset(BitError);

To avoid the overhead involved in creating and releasing System objects every time we call a function, the System objects in a function are denoted by persistent variables. Using a persistent variable allows us to perform such operations as creating System objects only the first time a function is called. This adds to the efficiency of function calls and improves the simulation speed as we call the function in a loop.

3.11.4 Bit Error Rate Simulation

The Communication System Toolbox provides BERTool as an integrated testbench for the performance of BER simulations. BERTool is a graphical application that computes a series of simulated bit error rates and compares the results with known analytical results.

For example, to visualize the simulated BERs for the function chap3_ex02_qpsk.m, as depicted in Figure 3.4, go to the Monte Carlo tab, specify the file as the simulation MATLAB file, and specify the Eb/N0 values and stopping criteria. BERTool will compute the BER for the range of Eb/N0 values provided and will automatically display the results. These simulated results can be compared with theoretical results by going to the Theoretical tab and specifying the modulation and coding schemes used. Figure 3.5 shows an example of the comparison plots generated by the BERTool testbench.

Figure 3.4 BERTool: a testbench application for BER-result visualization

c03f004

Figure 3.5 Comparison of simulated and analytical BER values: QPSK and AWGN channel

c03f005

3.12 MATLAB Channel Coding Examples

In this section, using a pedagogic approach and a series of MATLAB programs, we will examine what the Toolbox offers in terms of channel coding. First we will model a system that uses convolutional encoding and Viterbi decoding based on hard-decision decoding. Then we will update the algorithm to use soft-decision decoding. Finally, we will replace convolutional coding with a turbo-coding algorithm and compare the performance at each stage. With these simple exercises, not only will we learn how easy it is to use MATLAB and the Communications System Toolbox to add more complexity to our mobile communication model but we will clearly see that the substantial improvement in BER performance explains the predominant role turbo coding plays in the channel coding of the LTE standard.

3.12.1 Error Correction and Detection

Channel coding comprises error detection and error correction. With error detection using the CRC (Cyclic Redundancy Check) detector, the receiver can request the repeat of a transmission, in what is known as an automatic repeat request. Forward-error-correction coding allows errors to be corrected based on the redundancy bits that are included with the transmitted signal. A hybrid of error detection and forward error correction known as HARQ (Hybrid Automatic Repeat Request) forms an integral part of most 3G standards and is also used in the LTE standards. Error-correcting codes are usually classified into block codes and convolutional codes. Convolutional codes are widely used in 2G and 3G mobile communications standards, primarily because of their low complexity.

In this section, we will elaborate our growing MATLAB model, which already includes modulation, to include channel coding. As a perfect vehicle for explaining the value and motivation of the use of turbo coding in the LTE standard, we will compare the performances of convolutional and turbo coding. Furthermore, to explain the tradeoff involved in the use of receiver designs, we will compare the performance of modulation-coding combinations with and without soft-decision decoding.

3.12.2 Convolutional Coding

Convolutional codes are generated by the convolution of the input sequence with the impulse response of the encoder. The encoder accepts blocks of k-bit input samples and, by operating on the current block of data and the m previous input blocks, produces an n-bit block of output samples. The coding rate of the encoder is given by the ratio Rc = k/n and the convolutional encoder is specified by these three parameters (n,k,m). Figure 3.6 illustrates a convolutional encoder.

Figure 3.6 Structure of an (n,k,m) convolutional encoder

c03f006

3.12.3 Hard-Decision Viterbi Decoding

In the first iteration of this exercise, we modify the MATLAB function in the last section to add a channel-coding scheme to the modulation. When a channel-coding scheme is used, the transmitter sends redundancy bits along with message bits through the wireless channel. The receiver accepts the transmitted signal and uses the redundancy bits to detect and correct some of the errors introduced by the channel. Let us start by adding a convolutional encoder and a Viterbi decoder to the communications system. This communications system uses hard-decision Viterbi decoding, where the demodulator maps the received signal to bits and then passes the bits to the Viterbi decoder for error correction. The following MATLAB function (chap3_ex03_qpsk_viterbi) uses QPSK modulation and hard-decision Viterbi decoding with an AWGN channel.


Algorithm
MATLAB function
function [ber, bits]=chap3_ex03_qpsk_viterbi(EbNo, maxNumErrs, maxNumBits)
%% Initializations
persistent Modulator AWGN DeModulator BitError ConvEncoder Viterbi
if isempty(Modulator)
    Modulator      = comm.QPSKModulator('BitInput',true);
    AWGN             = comm.AWGNChannel;
    DeModulator =  comm.QPSKDemodulator('BitOutput',true);
    BitError           = comm.ErrorRate;
    ConvEncoder=comm.ConvolutionalEncoder(
        'TerminationMethod','Terminated');
    Viterbi=comm.ViterbiDecoder('InputFormat','Hard',
        'TerminationMethod','Terminated');
end
%% Constants
FRM=2048;
M=4; k=log2(M); codeRate=1/2;
snr = EbNo + 10*log10(k) + 10*log10(codeRate);
AWGN.EbNo=snr;
%% Processsing loop modeling transmitter, channel model and receiver
numErrs = 0; numBits = 0;results=zeros(3,1);
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
    % Transmitter
    u                   = randi([0 1], FRM,1);                   % Random bits generator
    encoded     = ConvEncoder.step(u);               % Convolutional encoder
    mod_sig     = Modulator.step(encoded);       % QPSK Modulator
    % Channel
    rx_sig          =  AWGN.step(mod_sig);             % AWGN channel
    % Receiver
    demod        =  DeModulator.step(rx_sig);      % QPSK Demodulator
    decoded     = Viterbi.step(demod);                  % Viterbi decoder
    y                   = decoded(1:FRM);                         % Compute output bits
    results        = BitError.step(u, y);                       % Update BER
    numErrs     = results(2);
    numBits      = results(3);
end
%% Clean up & collect results
ber = results(1); bits= results(3);
reset(BitError);

By running this function within BERTool, we can gauge the performance of hard-decision Viterbi decoding and compare it with the upper-bound theoretical results. Examining the results in Figure 3.7, we can see that the simulated BER curve falls below the theoretical upper-bound values, which is consistent with our expectations. These results indicate that in order to arrive at a better performance we need to improve our decoding algorithm.

Figure 3.7 Performance with hard-decision Viterbi decoding: QPSK modulation with AWGN channel

c03f007

3.12.4 Soft-Decision Viterbi Decoding

In this iteration, we improve BER performance results by using a soft-decision decoding algorithm. In soft-decision decoding, the demodulator maps the received signal to log-likelihood ratios. These probability measures are based on the logarithm of the likelihood that the correct data are received instead of corrupted data. When log-likelihood ratios are provided as the input to the Viterbi decoder, the BER performance of the decoder is improved. An algorithm can be made to perform soft-decision Viterbi decoding by changing a few demodulator and Viterbi-decoder System-object parameters. The following MATLAB function (chap3_ex04_qpsk_viterbi_soft) has been updated to use soft-decision Viterbi decoding.


Algorithm
MATLAB function
function [ber, bits]=chap3_ex04_qpsk_viterbi_soft(EbNo, maxNumErrs, maxNumBits)
%% Initializations
persistent Modulator AWGN DeModulator BitError ConvEncoder Viterbi Quantizer
if isempty(Modulator)
    Modulator      = comm.QPSKModulator('BitInput',true);
    AWGN             = comm.AWGNChannel;
    DeModulator =  comm.QPSKDemodulator('BitOutput',true,
        'DecisionMethod','Log-likelihood ratio',
        'VarianceSource', 'Input port');
    BitError           = comm.ErrorRate;
    ConvEncoder=comm.ConvolutionalEncoder(
        'TerminationMethod','Terminated');
    Viterbi=comm.ViterbiDecoder(
        'InputFormat','Soft',
        'SoftInputWordLength', 4,
        'OutputDataType', 'double',
        'TerminationMethod','Terminated');
    Quantizer=dsp.ScalarQuantizerEncoder(
        'Partitioning',  'Unbounded',
        'BoundaryPoints', -7:7,
        'OutputIndexDataType','uint8');
end
%% Constants
FRM=2048;
M=4; k=log2(M); codeRate=1/2;
snr = EbNo + 10*log10(k) + 10*log10(codeRate);
noise_var = 10.^(-snr/10);
AWGN.EbNo=snr;
%% Processsing loop modeling transmitter, channel model and receiver
numErrs = 0; numBits = 0;results=zeros(3,1);
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
    % Transmitter
    u                   = randi([0 1], FRM,1);                                         % Random bits generator
    encoded     = ConvEncoder.step(u);                                     % Convolutional encoder
    mod_sig     = Modulator.step(encoded);                             % QPSK Modulator
    % Channel
    rx_sig          =  AWGN.step(mod_sig);                                    % AWGN channel
    % Receiver
    demod        =  DeModulator.step(rx_sig, noise_var);       % Soft-decision QPSK Demodulator
    llr                 = Quantizer.step(-demod);                                 % Quantize Log-Likelihood Ratios
    decoded     = Viterbi.step(llr);                                                  % Viterbi decoder with LLRs
    y                   = decoded(1:FRM);                                               % Compute output bits
    results        = BitError.step(u, y);                                             % Update BER
    numErrs     = results(2);
    numBits      = results(3);
end
%% Clean up & collect results
ber = results(1); bits= results(3);
reset(BitError);

Theoretically, we expect a 2 dB improvement in the results, and that is exactly what is shown by the simulated curves in Figure 3.8. Next we examine turbo coding to see whether it can offer any improvements to BER results.

Figure 3.8 Performance with soft-decision Viterbi decoding: QPSK modulation with AWGN channel

c03f008

3.12.5 Turbo Coding

Turbo codes substantially improve BER performance over soft-decision Viterbi decoding. Turbo coding uses two convolutional encoders in parallel at the transmitter and two A Posteriori Probability (APP) decoders in series at the receiver. This example uses a rate 1/3 turbo coder. For each input bit, the output has one systematic bit and two parity bits, for a total of three bits.

The following MATLAB function has been updated to use turbo encoders and decoders. Note that turbo decoding is an iterative iteration, where performance improves as more iterations are gone through. In this example, we have chosen six as the number of iterations the decoder performs.


Algorithm
MATLAB function
function [ber, bits]=chap5_ex05_qpsk_turbo(EbNo, maxNumErrs, maxNumBits)
%% Constants
FRM=2048;
Trellis=poly2trellis(4, [13 15], 13);
Indices=randperm(FRM);
M=4;k=log2(M);
R= FRM/(3* FRM + 4*3);
snr = EbNo + 10*log10(k) + 10*log10(R);
noise_var = 10.^(-snr/10);
%% Initializations
persistent Modulator AWGN DeModulator BitError TurboEncoder TurboDecoder
if isempty(Modulator)
    Modulator      = comm.QPSKModulator('BitInput',true);
    AWGN             = comm.AWGNChannel;
    DeModulator =  comm.QPSKDemodulator('BitOutput',true,
        'DecisionMethod','Log-likelihood ratio',
        'VarianceSource', 'Input port');
    BitError           = comm.ErrorRate;
    TurboEncoder=comm.TurboEncoder(
        'TrellisStructure',Trellis,
        'InterleaverIndices',Indices);
    TurboDecoder=comm.TurboDecoder(
        'TrellisStructure',Trellis,
        'InterleaverIndices',Indices,
        'NumIterations',6);
end
%% Processsing loop modeling transmitter, channel model and receiver
AWGN.EbNo=snr;
numErrs = 0; numBits = 0;results=zeros(3,1);
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
    % Transmitter
    u                  = randi([0 1], FRM,1);                                         % Random bits generator
    encoded      = TurboEncoder.step(u);                                    % Turbo Encoder
    mod_sig      = Modulator.step(encoded);                             % QPSK Modulator
    % Channel
    rx_sig          =  AWGN.step(mod_sig);                                    % AWGN channel
    % Receiver
    demod         =  DeModulator.step(rx_sig, noise_var);       % Soft-decision QPSK Demodulator
    decoded      = TurboDecoder.step(-demod);                             % Turbo Decoder
    y                  = decoded(1:FRM);                                               % Compute output bits
    results         = BitError.step(u, y);                                             % Update BER
    numErrs       = results(2);
    numBits       = results(3);
end
%% Clean up & collect results
ber = results(1); bits= results(3);
reset(BitError);

Figure 3.9 illustrates the results for turbo coding in QPSK modulation under an AWGN channel. Note that at 1 dB we have a BER value that occurs at 5 dB for hard-decision and at 3 dB for soft-decision decoding. This clearly indicates the superiority of the turbo-coding algorithm. Bear in mind that this performance gain comes at the cost of an increase in computational complexity. Our turbo decoder went through iterative decoding six times to arrive at this performance. We will study this compromise between performance and complexity for turbo decoders in later chapters.

Figure 3.9 Performance with turbo coding: QPSK modulation with AWGN channel

c03f009

3.13 Chapter Summary

MATLAB, Simulink, and their toolboxes provide capabilities that can be used to model, simulate, assess the performance of, and eventually generate and implement code for communication systems. For modeling and simulation, we can use algorithmic building blocks from the Communications System Toolbox, either as System objects or as Simulink blocks. Many aspects of PHY processing of mobile standards can be modeled and simulated more efficiently in MATLAB because instead of focusing on creating building blocks, such as modulators and coders, we can focus on introducing more advanced functionality to a system model. Of special interest are the System objects of the Communications System Toolbox. System objects are modeling and simulation components that are designed to be self-documented, easy-to-use, and custom-designed for the modeling of block-based streaming systems.

When simulating complex systems, we need to access various acceleration techniques. These techniques help us process larger sets of test data and obtain statistically correct assessments in reasonable simulation times. MATLAB toolboxes such as the Parallel Processing Toolbox and MATLAB Coder can speed up simulations. Finally, in order to implement a design in software or hardware we can use code-generation products to gain access to the exact implementation detail via automatic C or HDL code generation.

References

[1] MathWorks Documentation Center, http://www.mathworks.com/help/MATLAB/random-number-generation.html (accessed 16 August 2013).

[2] MathWorks DSP System Toolbox, http://www.mathworks.com/products/dsp-system (accessed 16 August 2013).

[3] MathWorks Communications System Toolbox, http://www.mathworks.com/products/communications (accessed 16 August 2013).

[4] MathWorks Phased Array System Toolbox, http://www.mathworks.com/products/phased-array (accessed 16 August 2013).

[5] MathWorks Computer Vision System Toolbox, http://www.mathworks.com/products/computer-vision (accessed 16 August 2013).

[6] MathWorks Simulink, http://www.mathworks.com/products/simulink (accessed 16 August 2013).

[7] MathWorks Parallel Computing Toolbox, http://www.mathworks.com/products/parallel-computing (accessed 16 August 2013).

[8] MathWorks Fixed-Point Designer, http://www.mathworks.com/products/fixed-point-designer (accessed 16 August 2013).

[9] MathWorks MATLAB Coder, http://www.mathworks.com/help/coder/index.html (accessed 16 August 2013).

[10] MathWorks HDL Coder, http://www.mathworks.com/products/hdl-coder (accessed 16 August 2013).

[11] MathWorks HDL Verifier, http://www.mathworks.com/products/hdl-verifier (accessed 16 August 2013).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset