# ofdmEqualize

## Syntax

## Description

`[`

returns equalized symbols `eqsym`

,`csi`

]= ofdmEqualize(`rxsym`

,`heff`

,`nvar`

)`eqsym`

and soft channel state information
`csi`

after performing minimum mean squared error (MMSE) equalization
on input OFDM symbols `rxsym`

. `heff`

specifies the
effective estimated channel information. `nvar`

specifies the estimated
noise variance.

## Examples

### OFDM Equalization for MIMO Channel with Beamforming

Obtain the channel response for a beamformed OFDM signal with ${\mathit{N}}_{\mathrm{S}}$ parallel data streams filtered through an ${\mathit{N}}_{\mathrm{T}}$-by-${\mathit{N}}_{\mathrm{R}}$ MIMO channel. Use the channel response to apply OFDM equalization to the received OFDM-demodulated signal.

Define simulation variables.

rng(1); numStreams = 2; % Number of parallel data streams (Ns) numTx = 4; % Number of transmit antennas (Nt) numRx = 3; % Number of receive antennas (Nr) bps = 6; % Bits per QAM symbol (and OFDM data subcarrier) nfft = 256; % FFT length cpLen = 16; % Cyclic prefix length numOFDMSym = 10; % Number of OFDM symbols SNRdB = 40; % Signal-to-noise ratio

Check that the number of data streams is no greater than either the number of transmit antennas or the number of receive antennas.

if numStreams > min(numTx,numRx) error('numStreams must be equal to or less than numTx and numRx.'); end

Configure OFDM subcarriers.

ofdmNullIdx = ... % Guard bands and DC subcarrier [1:9 (nfft/2+1) (nfft-8+1:nfft)]'; numDataSC = ... % Number of data subcarriers nfft-length(ofdmNullIdx);

Generate an array of data symbols consisting of ${\mathit{N}}_{\mathrm{S}}$ parallel data streams, QAM-modulate the symbols, and then OFDM-modulate the QAM-modulated symbols.

dataBits = randi([0,1],[numDataSC*bps numOFDMSym numStreams]); M = 2^bps; % Modulation order qamTx = qammod(dataBits,M, ... InputType="bit", ... UnitAveragePower=true); ofdmOut = ofdmmod(qamTx,nfft,cpLen,ofdmNullIdx);

Beamforming expands the dimensionality of the transmit signal to improve link performance over multipath channels. The data streams are fed through a beamformer that focuses the transmit energy over an ${\mathit{N}}_{\mathrm{T}}$-by-1 transmit antenna array where the number of antennas ${\mathit{N}}_{\mathrm{T}}\ge {\mathit{N}}_{\mathrm{S}}$.

Form a beamformer matrix from steering vectors acting on each stream.

% Beamform the transmitted signal fc = 1e9; lambda = physconst('LightSpeed')/fc; beamAngles = 15; antIdx = (0:numTx-1); antDelay = 2*pi*sin(2*pi*beamAngles*(0:numStreams-1).'/360)/lambda; B = exp(1i*antIdx.*antDelay); % Ns x Nt beamformer matrix txOut = ofdmOut * B;

Filter the OFDM-modulated signal through a MIMO channel to get the channel coefficients.

mimoChannel = comm.MIMOChannel( ... SampleRate=1e6, ... PathDelays=[0 3e-6 5e-6], ... AveragePathGains=[0 0.5 0.2], ... MaximumDopplerShift=0, ... SpatialCorrelationSpecification="None", ... NumTransmitAntennas=numTx, ... NumReceiveAntennas=numRx, ... PathGainsOutputPort=true); [channelOut,pathGains] = mimoChannel(txOut);

In a practical system, the channel must be sounded to estimate the channel response. Instead of sounding, the `ofdmChannelResponse`

function computes the exact channel response using the path gains and path filters that are available after you pass data through the MIMO channel System object. Use channel path gains returned by the MIMO channel object, and the path filters and timing offset returned by the `info`

object function, to obtain the OFDM channel response. If ${\mathit{N}}_{\mathrm{T}}<{\mathit{N}}_{\mathrm{R}}$, the channel forms an over-determined system (there are more receive antennas than necessary to adequately decode the transmitted signals). Call `ofdmChannelResponse`

with the `pathGains`

from the MIMO channel function to get the channel response.

mimoChannelInfo = info(mimoChannel); pathFilters = mimoChannelInfo.ChannelFilterCoefficients; toffset = mimoChannelInfo.ChannelFilterDelay; h = ofdmChannelResponse(pathGains,pathFilters,nfft,cpLen, ... setdiff(1:nfft,ofdmNullIdx),toffset); % Nsc x Nsym x Nt x Nr [rxIn,nVar] = awgn(channelOut,SNRdB,"measured");

Before demodulating the OFDM signal, account for the timing offset and symbol offset, remove the initial samples, and then pad with zeros to keep the signal length unchanged.

zeropadding = zeros(toffset,numRx); ofdmDemodIn = [rxIn(toffset+1:end,:); zeropadding]; symOffset = cpLen/2;

OFDM-demodulate and equalize the received signal.

rxSym = ofdmdemod(ofdmDemodIn,nfft,cpLen,symOffset,ofdmNullIdx);

The effects of beamforming and the MIMO channel affect the received data streams. The *effective channel* (${\mathit{H}}_{\mathrm{eff}}$) is an ${\mathit{N}}_{\mathrm{S}}$-by-${\mathit{N}}_{\mathrm{R}}$ matrix defined as the product of the transmit beamformer and the MIMO channel coefficients.

To use the OFDM channel response when equalizing the OFDM-demodulated signal, you must reshape the ${\mathit{N}}_{\mathit{SC}}$-by-${\mathit{N}}_{\mathrm{OFDMsym}}$-by-${\mathit{N}}_{\mathrm{T}}$-by-${\mathit{N}}_{\mathrm{R}}$ array to an ${\mathit{N}}_{\mathrm{QAMsym}}$-by-${\mathit{N}}_{\mathrm{T}}$-by-${\mathit{N}}_{\mathrm{R}}$ array. Form the effective channel using the beamformer matrix `B`

and the reshaped channel coefficients `h`

. Equalize the received OFDM signal using the calculated effective channel, the noise variance, and the MMSE algorithm.

hReshaped = reshape(h,[],numTx,numRx); hEff = zeros(numDataSC*numOFDMSym,numStreams,numRx); for k = 1:numOFDMSym*numDataSC hEff(k,:,:) = B * squeeze(hReshaped(k,:,:)); end eqSym = ofdmEqualize(rxSym,hEff,nVar);

Show the received OFDM-demodulated symbols (`rxSym`

) and the equalized OFDM-demodulated symbols (`eqSym`

). The constellation of the OFDM-demodulated symbols before equalization does not resemble the QAM constellation. After equalization, the constellation points lay near the reference constellation.

figure(1); scatterplot(rxSym(:));

figure(2); scatterplot(eqSym(:));

### Show Equivalence of 2-D and 3-D Data Format for OFDM Equalization

Initialize variables for simulation of a MIMO system and a 120-resource-element subset of the OFDM subcarrier-symbol grid.

Nre = 120; % Number of resource elements Ns = 4; % Number of data streams Nr = 8; % Number of receive antennas nvar = 0.1; % Noise variance

Create random signals for a 2-D symbol array and a channel estimate.

rxsym2d = complex(randn(Nre,Nr),randn(Nre,Nr)); Hest = complex(randn(Nre,Ns,Nr),randn(Nre,Ns,Nr));

Apply OFDM equalization to the 2-D signal contained in an 120-by-8 symbol array.

`[eqsym2d,csi2d] = ofdmEqualize(rxsym2d,Hest,nvar,DataFormat="2-D");`

Reshape the 2-D signal to a 30-by-4-by-8 symbol array. Apply OFDM equalization to the 3-D signal. Compare the results of OFDM equalization for the 30-by-4-by-8 symbol array with OFDM equalization for the 120-by-8 symbol array. As the `isequal`

function result shows, the equalized symbols and soft channel state information returned for the 30-by-4-by-8 and 120-by-8 symbol arrays are equal.

```
rxsym3d = reshape(rxsym2d,30,4,Nr);
[eqsym3d,csi3d] = ofdmEqualize(rxsym3d,Hest,nvar,DataFormat="3-D");
isequal(eqsym3d,reshape(eqsym2d,30,4,Ns))
```

`ans = `*logical*
1

isequal(csi3d,csi2d)

`ans = `*logical*
1

Reshape the 2-D signal to a 60-by-2-by-8 symbol array. Apply OFDM equalization to the 3-D signal. Compare the results of OFDM equalization for the 60-by-2-by-8 symbol array with OFDM equalization for the 120-by-8 symbol array. The `isequal`

function result confirms the equalized symbols and soft channel state information returned for the 60-by-2-by-8 and 120-by-8 symbol arrays are equal.

```
rxsym3d2 = reshape(rxsym2d,60,2,Nr);
[eqsym3d2,csi3d2] = ofdmEqualize(rxsym3d2,Hest,nvar,DataFormat="3-D");
isequal(eqsym3d2,reshape(eqsym2d,60,2,Ns))
```

`ans = `*logical*
1

isequal(csi3d2,csi2d)

`ans = `*logical*
1

## Input Arguments

`rxsym`

— Received symbols

numeric array | `dlarray`

object

Received symbols, specified as a numeric array or a `dlarray`

(Deep Learning Toolbox)
object. For more information, see Array Support.

If

`DataFormat`

is set to`"3-D"`

, the function expects`rxsym`

to be specified as an*N*_{SC}-by-*N*_{Symbols}-by-*N*_{R}array.*N*_{SC}represents the number of OFDM subcarriers,*N*_{Symbols}represents the number of OFDM symbols, and*N*_{R}represents the number of receive antennas.If

`DataFormat`

is set to`"2-D"`

, the function expects`rxsym`

to be specified as an*N*_{RE}-by-*N*_{R}array.*N*_{RE}represents the number of resource elements in an irregular subset of the OFDM subcarrier symbol grid. A resource element comprises one subcarrier in the frequency domain and one OFDM symbol in the time domain.

**Data Types: **`double`

| `single`

**Complex Number Support: **Yes

`heff`

— Effective channel estimate

numeric array | `dlarray`

object

Effective channel estimate, specified as a 3-D numeric array, or a `dlarray`

(Deep Learning Toolbox)
object. `heff`

can be a `dlarray`

object only when
the number of data streams *N*_{S} == 1. For more information, see Effective Channel and Array Support.

If

`DataFormat`

is set to`"3-D"`

, the function expects`heff`

to be an*N*_{SC}-by-*N*_{S}-by-*N*_{R}or an (*N*_{SC}×*N*_{Symbols})-by-*N*_{S}-by-*N*_{R}array.If

`heff`

is an*N*_{SC}-by-*N*_{S}-by-*N*_{R}array, all OFDM symbols in`rxsym`

are equalized by the same channel estimate.*N*_{SC}represents the number of OFDM subcarriers,*N*_{S}represents the number of data streams, and*N*_{R}represents the number of receive antennas.If

`heff`

is an (*N*_{SC}×*N*_{Symbols})-by-*N*_{S}-by-*N*_{R}array, each OFDM symbol in`rxsym`

is equalized by the corresponding entry in`heff`

.*N*_{Symbols}represents the number of OFDM symbols.

If

`DataFormat`

is set to`"2-D"`

, the function expects`heff`

to be an*N*_{RE}-by-*N*_{S}-by-*N*_{R}array. Each OFDM symbol in`rxsym`

is equalized by the corresponding entry in`heff`

.*N*_{RE}represents the number of resource elements in an irregular subset of the OFDM subcarrier symbol grid.

**Data Types: **`double`

| `single`

**Complex Number Support: **Yes

`nvar`

— Noise variance

0 (default) | nonnegative scalar

Noise variance estimate for MMSE equalization, specified as a nonnegative scalar.

#### Dependencies

The noise variance setting is used only when you set
`Algorithm`

to `"mmse"`

.

**Data Types: **`double`

| `single`

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **`ofdmEqualize(rxsym,heff,DataFormat="2-D")`

equalizes an
*N*_{RE}-by-*N*_{R}
input OFDM symbol array using the MMSE algorithm.

`Algorithm`

— Equalization algorithm

`"mmse"`

(default) | `"zf"`

Equalization algorithm, specified as `"mmse"`

or
`"zf"`

.

When this argument is set to

`"mmse"`

, the function equalizes using the MMSE algorithm.When this argument is set to

`"zf"`

, the function equalizes using the zero-forcing algorithm. When using the zero-forcing algorithm, the`nvar`

argument value is ignored.

`DataFormat`

— Format of signals

`"3-D"`

(default) | `"2-D"`

Format of the signals, specified as `"3-D"`

or
`"2-D"`

.

When this argument is set to `"3-D"`

, OFDM subcarriers and OFDM
symbols use two separate dimensions in the representation of
`rxsym`

and `eqsym`

.

The

`rxsym`

input must be an*N*_{SC}-by-*N*_{Symbols}-by-*N*_{R}array.The

`eqsym`

output is returned as an*N*_{SC}-by-*N*_{Symbols}-by-*N*_{S}array.

When this argument is set to `"2-D"`

, OFDM subcarriers and OFDM
symbols use one combined dimension in the representation of `rxsym`

and `eqsym`

.

The

`rxsym`

input must be an*N*_{RE}-by-*N*_{R}array.The

`eqsym`

output is returned as an*N*_{RE}-by-*N*_{S}array.

*N*_{SC} represents the number of OFDM
subcarriers. *N*_{Symbols} represents the number
of symbols. *N*_{RE} represents the number of
resource elements in an irregular subset of the OFDM subcarrier symbol grid.
*N*_{S} represents the number of data streams.
*N*_{R} represents the number of receive
antennas.

## Output Arguments

`eqsym`

— Equalized symbols

3-D array | 2-D array

Equalized symbols, returned as a 3-D or 2-D numeric array, or a `dlarray`

(Deep Learning Toolbox). For
more information, see Array Support.

If

`DataFormat`

is set to`"3-D"`

, the function returns an*N*_{SC}-by-*N*_{Symbols}-by-*N*_{S}array.*N*_{SC}represents the number of OFDM subcarriers,*N*_{Symbols}represents the number of OFDM symbols, and*N*_{S}represents the number of data streams.If

`DataFormat`

is set to`"2-D"`

, the function returns an*N*_{RE}-by-*N*_{S}array.*N*_{RE}represents the number of resource elements in an irregular subset of the OFDM subcarrier symbol grid.

`csi`

— Soft channel state information

matrix

Soft channel state information, returned as a matrix with ```
size(csi,1) =
size(heff,1)
```

and ```
size(csi,2) =
```

.
*N*_{S} = size(heff,2)*N*_{S} represents the number of data streams.
This output is a log-likelihood ratio (LLR) scaling factor that accounts for the SNR in
each resource element. A resource element comprises one subcarrier in the frequency
domain and one OFDM symbol in the time domain.

The returned matrix can be a numeric array, or a `dlarray`

(Deep Learning Toolbox). For
more information, see Array Support.

## More About

### Array Support

The `ofdmEqualize`

function supports input signals
represented in a numeric array, `dlarray`

(Deep Learning Toolbox), or
`gpuArray`

(Parallel Computing Toolbox). If inputs are specified as a
combination of `dlarray`

and `gpuArray`

, the returned
matrix is a `dlarray`

object on the GPU.

The number of batch observations (*N*_{B}) is an
optional dimension that can be added to these inputs for all supported data types.

`rxsym`

— The received symbols can be an:*N*_{SC}-by-*N*_{Symbols}-by-*N*_{R}-by-*N*_{B}array, if`DataFormat`

is specified as`"3-D"`

.*N*_{RE}-by-*N*_{R}-by-*N*_{B}array, if`DataFormat`

is specified as`"2-D"`

.

`heff`

— The channel estimate can be an:*N*_{SC}-by-*N*_{S}-by-*N*_{R}-by-*N*_{B}or (*N*_{SC}×*N*_{Symbols})-by-*N*_{S}-by-*N*_{R}-by-*N*_{B}array, if`DataFormat`

is specified as`"3-D"`

.*N*_{RE}-by-*N*_{S}-by-*N*_{R}-by-*N*_{B}array, if`DataFormat`

is specified as`"2-D"`

.

`nvar`

— The noise variance can be a real vector with number of elements equal to number of batch observations,*N*_{B}.

*N*_{SC} is the number of OFDM subcarriers,
*N*_{Symbols} is the number of symbols,
*N*_{RE} is the number of resource elements in an
irregular subset of the OFDM subcarrier symbol grid,
*N*_{S} is the number of data streams, and
*N*_{R} is the number of receive antennas.

For a list of Communications Toolbox™ features that support `dlarray`

objects, see AI for Wireless.

## Algorithms

Represent a MIMO, SISO, SIMO, or MISO communications system as *Y* =
*X**H*_{eff} +
*N*, where:

*X*is an*N*_{SC}-by-*N*_{S}transmitted signal.*H*_{eff}is an*N*_{S}-by-*N*_{R}MIMO channel matrix.*N*is an*N*_{R}-by-1 AWGN signal at receiver.*Y*is an*N*_{SC}-by-*N*_{R}received signal.*N*_{SC}is the number of OFDM subcarriers.*N*_{S}is the number of data streams.*N*_{R}is the number of receive antennas.

### OFDM Equalization

In an OFDM system, *Y* =
*X**H*_{eff} +
*N* applies to each frequency subcarrier. Equalization estimates the
transmitted OFDM signal *X* and the soft channel state information by using
a zero-forcing (ZF) equalizer or a minimum mean square estimate (MMSE) equalizer.

**ZF Equalizer**

With a ZF equalizer, the estimate of *X* is

$$\widehat{X}=Y{\widehat{H}}_{\text{eff}}^{\u2020},$$

where $${\widehat{H}}_{\text{eff}}^{\u2020}$$ is the pseudo inverse of
*Ĥ*_{eff}.

When *N*_{S} <
*N*_{R}, the soft channel state information is

$$CSI=\mathrm{diag}({\widehat{H}}_{\text{eff}}{\widehat{H}}_{\text{eff}}^{\text{'}})$$

and when *N*_{S} ≥
*N*_{R}

$$CSI=1/(\mathrm{diag}{({\widehat{H}}_{\text{eff}}{\widehat{H}}_{\text{eff}}^{\text{'}})}^{-1}).$$

**MMSE Equalizer**

With an MMSE equalizer, the estimate of *X* is

$$\widehat{X}=Y{\widehat{H}}_{\text{eff}}^{\text{'}}{({\widehat{H}}_{\text{eff}}{\widehat{H}}_{\text{eff}}^{\text{'}}+{N}_{0}I)}^{-1}.$$

The soft channel state information is

$$CSI=1/(\mathrm{diag}{({\widehat{H}}_{\text{eff}}{\widehat{H}}_{\text{eff}}^{\text{'}}+{N}_{0}I)}^{-1}).$$

### Effective Channel

The effective channel, *H*_{eff} =
*PBH*, measures the channel from the transmitted data streams to the receive
antennas and results in an
*N*_{S}-by-*N*_{R} matrix.

*P*is an*N*_{S}-by-*N*_{S}precoding matrix. When there is no precoding, the precoding matrix is an*N*_{S}-by-*N*_{S}identity matrix.*B*is an*N*_{S}-by-*N*_{T}beamforming matrix. When there is no beamforming,*N*_{S}=*N*_{T}, and the beamforming matrix is an*N*_{S}-by-*N*_{S}identity matrix.*H*is an*N*_{T}-by-*N*_{R}matrix containing the estimated channel information.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

### GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

Usage notes and limitations:

For the dimensions of input signals, if

*N*_{S}≤*N*_{R}, then*N*_{R}must not exceed 32.*N*_{S}represents the number of data streams.*N*_{R}represents the number of receive antennas.

This function supports GPU array inputs. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

## Version History

**Introduced in R2022b**

### R2023b: Add deep learning array support

The `ofdmEqualize`

function adds support for `dlarray`

(Deep Learning Toolbox) object
processing for deep learning applications.

### R2023b: Add GPU array support

The `ofdmEqualize`

function adds support for `gpuArray`

(Parallel Computing Toolbox) object processing to run code on a graphics processing unit
(GPU).

## See Also

### Functions

### Objects

### Blocks

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)