# Adaptive MIMO System with OSTBC

This model shows an adaptive orthogonal space-time block code (OSTBC) transceiver system over a multiple-input multiple-output (MIMO) channel. The system uses a variable number of transmit and receive antennas. In any frame, the system operates with either one, two, three or four transmit or receive antennas. The number of the transmit and receive antennas are adaptive and change either manually or according to an adaptation algorithm, based on the difference between target and actual frame-error rates of the overall system.

This example showcases features such as generating variable-size signals in Simulink® and the use of the MATLAB® Function block with System objects as part of a Simulink model. You can build and generate C code from this model.

## Contents

- Introduction
- Structure of the Example
- Random Data Generation
- QPSK Modulation
- Orthogonal Space-Time Block Codes (OSTBC) Encoder
- Adaptive MIMO Channel
- Receiver Noise
- Orthogonal Space-Time Block Codes (OSTBC) Combiner
- QPSK Demodulation
- Frame Error Rate (FER) Calculation
- Adaptation Algorithm
- Visualization and Displays
- Further Exploration
- Selected Bibliography

## Introduction

OSTBCs [ 1 ], [ 2 ] are attractive techniques for MIMO wireless communications. They exploit full spatial diversity order and employ symbol-wise maximum likelihood (ML) decoding. The OSTBC Combiner block at the receiver side provides soft information of the symbols that the system transmits, which can be utilized for decoding or demodulation of an outer code.

## Structure of the Example

This figure shows the example model commadaptivemimo.slx.

The model performs the following tasks:

## Random Data Generation

The Bernoulli Binary Generator block produces the information source for this simulation. The block generates a frame of random bits. The `Frame length` parameter determines the length of the output frame.

## QPSK Modulation

The QPSK Modulator block modulates the message data from the Bernoulli Binary Generator to a quaternary PSK constellation. The output is a baseband representation of the modulated signal with an output size equal to half of the Bernoulli Binary Generator block output size, as every two input bits produce one modulated symbol.

## Orthogonal Space-Time Block Codes (OSTBC) Encoder

The OSTBC Encoder block encodes the information symbols from the QPSK Modulator by using either the Alamouti code [ 1 ] for two transmit antennas or other generalized complex orthogonal codes [ 2 ] for three or four transmit antennas. The number of transmit antennas is given to this block as an input. The output of this block is an (Ns x Nt) variable-size matrix, where the number of columns (Nt) corresponds to the number of transmit antennas and the number of rows (Ns) corresponds to the number of orthogonal code samples transmitted over each transmit antenna in a frame. This block is a MATLAB Function block that uses the `comm.OSTBCEncoder` System object to implement the encoding algorithm for selected transmit antennas.

## Adaptive MIMO Channel

The MIMO Fading Channel block simulates the frequency-flat Rayleigh fading MIMO channel from the Nt transmit antennas to the Nr receive antennas. The block is configured as a spatially independent 4x4 MIMO channel with transmit and receive antenna selection. The `Sample rate (Hz)` parameter is set to `2e6/3` that is calculated based on the frame length, code rates and model sample time. The `Maximum Doppler shift (Hz)` parameter is set to `100`. The block uses this value so the MIMO channel behaves like a quasi-static fading channel, i.e., it keeps relatively constant during one code block transmission and varies along multiple blocks.

The first input to this block is an (Ns x Nt) variable-size matrix, where the number of columns (Nt) corresponds to the number of selected transmit antennas and the number of rows (Ns) corresponds to the number of orthogonal code samples that the system transmits over each transmit antenna in a frame. The second and third inputs to this block are (1 x 4) fixed-size binary row vectors to indicate that the first Nt transmit and Nr receive antennas are being selected for the current frame transmission, respectively. The first output of this block is an (Ns x Nr) variable-size channel output matrix. The second output of this block is an (Ns x 1 x 4 x 4) variable-size channel gain array with NaN values for those unselected transmit-receive antenna pairs.

## Receiver Noise

The AWGN Channel block adds white Gaussian noise at the receiver side. It uses the `comm.AWGNChannel` System object that supports variable-size signals. The first input of this block is the first output of the MIMO Channel block. The second input of this block is the noise variance calculated from the number of transmit antennas (Nt) and the `Signal to noise ratio (SNR)` value, where the MIMO channel normalization has been taken into account.

## Orthogonal Space-Time Block Codes (OSTBC) Combiner

The OSTBC Combiner block combines the received signal rxSig with the channel state information (CSI) chEst to output the estimates of the modulated symbols. The input signal rxSig is an (Ns x Nr) variable-size matrix and the input signal chEst is an (Ns x 1x 4 x 4) variable-size array. In this example, the CSI is assumed perfectly known at the receiver side. This block is a MATLAB Function block that uses the `comm.OSTBCCombiner` System object to implement the combining algorithm for the selected transmit and receive antennas.

## QPSK Demodulation

The QPSK Demodulator block demodulates the output of the OSTBC Combiner that is the recovered modulated signal using the quaternary phase shift keying method. The input is a baseband representation of the modulated signal with an input size equal to half of that of the Bernoulli Binary Generator block, as every one input symbol produces two output bits.

## Frame Error Rate (FER) Calculation

The Frame Error Rate (FER) Calculation subsystem compares the decoded bits with the original source bits per frame to detect errors and dynamically updates the FER along the simulation. The output of this subsystem is a three-element vector containing the FER, the number of error frames observed, and the number of frames processed. This vector is from the Error Rate Calculation block and also saved as a MATLAB workspace variable `FER_Data` to ease the simulation for multiple SNR values.

The model checks the `Stop simulation` parameter to control the duration of the simulation. The simulation stops upon detecting a target number of error frames (specified by the `Maximum number of errors` parameter) or a maximum number of frames (specified by the `Maximum number of frames` parameter), whichever comes first.

## Adaptation Algorithm

By using the blocks in the bottom part of this model, denoted by Adaptation Control Panel, you can experiment with the effect that varying the number of transmit or receive antennas has on the overall performance of a MIMO system.

**First mode: Manual setting**

You can use two 'switch' blocks in the bottom of the model to manually set the number of transmit antennas (Nt) or the receive antennas (Nr) in the corresponding 'Constant' blocks. Note that (Nt) and (Nr) are scalar numbers in the range of 1-4.

**Second mode: Adaptation algorithm**

Alternatively, you can use the two 'switch' blocks to enable the Adaptation Algorithm block in the bottom of the model. This adaptation algorithm is a MATLAB Function block implementation that adapts the number of transmit antennas (Nt) or receive antennas (Nr) based on the difference between the `Target frame error rate` and the actual frame error rate of the overall system.

## Visualization and Displays

To view data graphically, open the display window by double-clicking the Signal Visualization icon. This subsystem generates a figure that helps visualize the effect of varying the number of transmit or receive antennas on the overall frame-error rate of the system.

The plots within the display window show:

- The frame error rate as a function of time

- The number of transmit and receive antennas in the current frame

- Scatter plots of the received signal before and after the OSTBC Combiner. The plot of the OSTBC Combiner output indicates the system is recovering a signal with a QPSK constellation.

**Color Legend** The model uses colors at the top level of the hierarchy to help you distinguish blocks that play different roles.

- Light Blue color code represents blocks, or subsystems composed of blocks, from the Communications System Toolbox™.

- Light Green color code denotes blocks involved in signal routing, measurements and displays.

- Blue color code represents blocks you can use to set different parameters of the model.

- Purple color code represents blocks that use MATLAB Function blocks with System objects. You can examine, edit or change the System object configurations that characterize the operations of these blocks.

## Further Exploration

When you load this model, you create a variable called 'adaptivemimo' in the MATLAB workspace. This variable is a MATLAB structure containing five fields. By modifying any of these fields (FrameLen, SNR,TargetFER, MaxNumErrs, MaxNumFrames), you can explore the effects of different parameter settings on the simulation duration and numerical results. These five fields correspond to parameters used in this model, i.e., (`Frame length`, `Signal to noise ratio (SNR)`, `Target frame error rate` `Maximum number of errors` and `Maximum number of frames`) respectively. You can set different values for these five parameters, by double-clicking the sub-system found in the top portion of the model, called Model Parameters, and typing your desired parameters values directly in the dialog boxes.

## Selected Bibliography

- S. M. Alamouti, "A simple transmit diversity technique for wireless communications,"
*IEEE Journal on Selected Areas in Communications*, vol. 16, no. 8, pp. 1451-1458, Oct. 1998. - V. Tarokh, H. Jafarkhami, and A. R. Calderbank, "Space-time block codes from orthogonal designs,"
*IEEE Transactions on Information Theory*, vol. 45, no. 5, pp. 1456-1467, Jul. 1999.