# qammod

Quadrature amplitude modulation (QAM)

## Description

specifies options using name-value arguments in addition to any of the input
argument combinations from previous syntaxes. For example,
`Y`

= qammod(___,`Name=Value`

)`InputType=bit`

sets the type of input signal to
bits.

## Examples

### Modulate Data Using QAM

Modulate data using QAM and display the result in a scatter plot.

Set the modulation order to 16 and create a data vector containing each of the possible symbols.

M = 16; x = (0:M-1)';

Modulate the data using the `qammod`

function.

y = qammod(x,M);

Display the modulated signal constellation using the `scatterplot`

function.

scatterplot(y)

Set the modulation order to 256, and display the scatter plot of the modulated signal.

M = 256; x = (0:M-1)'; y = qammod(x,M); scatterplot(y)

### Normalize QAM Signal by Average Power

Modulate random data symbols using QAM. Normalize the modulator output so that it has an average signal power of 1 W.

Set the modulation order and generate random data.

M = 64; x = randi([0 M-1],1000,1);

Modulate the data. Use the `'UnitAveragePower'`

name-value argument to set the output signal to have an average power of 1 W.

y = qammod(x,M,UnitAveragePower=true);

Confirm that the signal has unit average power.

avgPower = mean(abs(y).^2)

avgPower = 1.0070

Plot the resulting constellation.

```
scatterplot(y)
title('64-QAM, Average Power = 1 W')
```

### QAM Symbol Ordering

Plot QAM constellations for Gray, binary, and custom symbol mappings.

Set the modulation order, and create a data sequence that includes a complete set of symbols for the modulation scheme.

M = 16; d = 0:M-1;

Modulate the data, and plot its constellation. The default symbol mapping uses Gray-coded ordering. The ordering of the points is not sequential.

y = qammod(d,M,PlotConstellation=true);

Repeat the modulation process with binary symbol mapping. The symbol mapping follows a binary-coded order and is sequential.

`z = qammod(d,M,'bin',PlotConstellation=true);`

Create a custom symbol mapping.

smap = randperm(M)-1;

Modulate and plot the constellation.

w = qammod(d,M,smap,PlotConstellation=true);

### Quadrature Amplitude Modulation with Bit Inputs

Modulate a sequence of bits using 64-QAM. Pass the signal through a noisy channel. Display the resultant constellation diagram.

Set the modulation order, and determine the number of bits per symbol.

M = 64; k = log2(M);

Create a binary data sequence. When using binary inputs, the number of rows in the input must be an integer multiple of the number of bits per symbol.

data = randi([0 1],1000*k,1);

Modulate the signal using bit inputs, and set it to have unit average power.

txSig = qammod(data,M, ... InputType='bit', ... UnitAveragePower=true);

Pass the signal through a noisy channel.

rxSig = awgn(txSig,25);

Plot the constellation diagram.

cd = comm.ConstellationDiagram(ShowReferenceConstellation=false); cd(rxSig)

### Demodulate QAM Fixed-Point Signal

Demodulate a fixed-point QAM signal and verify that the data is recovered correctly.

Set the modulation order as `64`

, and determine the number of bits per symbol.

M = 64; bitsPerSym = log2(M);

Generate random bits. When operating in bit mode, the length of the input data must be an integer multiple of the number of bits per symbol.

x = randi([0 1],10*bitsPerSym,1);

Modulate the input data using a binary symbol mapping. Set the modulator to output fixed-point data. The numeric data type is signed with a 16-bit word length and a 10-bit fraction length.

y = qammod(x,M,'bin', ... InputType='bit', ... OutputDataType=numerictype(1,16,10));

Demodulate the 64-QAM signal. Verify that the demodulated data matches the input data.

z = qamdemod(y,M,'bin',OutputType='bit'); s = isequal(x,double(z))

`s = `*logical*
1

### Average Power Normalization for QAM

Apply average power normalization for hard decision output when using qammod and qamdemod functions by using the `helperAvgPow2MinD`

utility function. Scale the constellation to the normalized average power, and then plot the reference and scaled constellations.

Compute the minimum distance for symbols based on specified average power and modulation order.

M = 64; avgPwr = 2; minD = helperAvgPow2MinD(avgPwr,M);

Modulate a signal composed of random integers in the range [0, `M `

- 1], scale the modulated symbols.

x = randi([0,M-1],1000,1); y = qammod(x,M); yTx = (minD/2) .* y;

Verify signal average power approximately equals the specified average power, avg`Pow`

.

sigPwr = mean(abs(yTx).^2)

sigPwr = 2.0141

avgPwr

avgPwr = 2

Assign the transmitted signal to the receive signal without applying any RF or channel impairments. With no impairments to distort the received signal, the demodulated matches the original signal. Demodulate symbols using hard decisions, and confirm correct signal demodulation.

yRx = yTx; z = qamdemod(yRx*2/minD,M); checkDemodIsEqual = isequal(x,z)

`checkDemodIsEqual = `*logical*
1

refC = qammod([0:M-1]',M);

Show constellation

maxAx = ceil(max(abs(refC))); cd = comm.ConstellationDiagram(2, ... 'ShowReferenceConstellation',0, ... 'ShowLegend',true, ... 'XLimits',[-(maxAx) maxAx],'YLimits',[-(maxAx) maxAx], ... 'ChannelNames', ... {'y','yTx'}); cd(y,yTx)

### Peak Power Normalization for QAM

Apply peak power normalization for hard decision output when using qammod and qamdemod functions by using the `helperPeakPow2MinD`

utility function. Scale the constellation to the normalized peak power, and then plot the reference and scaled constellations.

Compute the minimum distance for symbols based on specified peak power and modulation order.

M = 16; pkPwr = 30; minD = helperPeakPow2MinD(pkPwr,M);

Modulate a signal composed of random integers in the range [0, `M `

- 1], scale the modulated symbols.

x = randi([0,M-1],1000,1); y = qammod(x,M); yTx = (minD/2) .* y;

Verify signal peak power approximately equals the specified peak power, `pkPow`

.

sigPwr = max(abs(yTx).^2)

sigPwr = 30

pkPwr

pkPwr = 30

Assign the transmitted signal to the receive signal without applying any RF or channel impairments. With no impairments to distort the received signal, the demodulated matches the original signal. Demodulate symbols using hard decisions, and confirm correct signal demodulation.

yRx = yTx; z = qamdemod(yRx*2/minD,M); checkDemodIsEqual = isequal(x,z)

`checkDemodIsEqual = `*logical*
1

refC = qammod([0:M-1]',M);

Show constellation

maxAx = ceil(max(abs(refC))); cd = comm.ConstellationDiagram(2, ... 'ShowReferenceConstellation',0, ... 'ShowLegend',true, ... 'XLimits',[-(maxAx) maxAx],'YLimits',[-(maxAx) maxAx], ... 'ChannelNames', ... {'y','yTx'}); cd(y,yTx)

## Input Arguments

`X`

— Input signal

scalar | vector | matrix | array

Input signal, specified as a scalar, vector, matrix, or array. The
elements of this input signal must be binary values or integers in the range [0, (`M`

– 1)], where `M`

is the modulation
order.

**Note**

To process input signal as binary elements, specify
`InputType='bit'`

. For binary inputs, the number of
rows must be an integer multiple of log_{2}(`M`

). Groups of log_{2}(`M`

) bits are mapped onto a symbol, with the first bit
representing the MSB and the last bit representing the LSB.

**Data Types: **`double`

| `single`

| `fi(S,WL,0)`

| `int8`

| `int16`

| `uint8`

| `uint16`

`M`

— Modulation order

positive integer power of two

Modulation order, specified as an positive integer power of two. The modulation order specifies the number of points in the signal constellation.

**Data Types: **`double`

| `single`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`symOrder`

— Symbol order

`'gray'`

(default) | `'bin'`

| vector

Symbol order, specified as `'gray'`

,
`'bin'`

, or a vector.

`'gray'`

— Use Gray-coded ordering. For more information, see Gray Code.`'bin'`

— Use binary-coded ordering.Vector — Use custom symbol ordering

Vectors must use unique elements in the range [0, (`M`

– 1)]. The first element corresponds to the upper-left point of
the constellation, with subsequent elements running down column-wise from
left to right.

**Example: **[0 3 1 2]

**Data Types: **`string`

| `char`

| `double`

| `single`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

### 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: **```
y =
qammod(x,M,symOrder,'InputType','bit')
```

`InputType`

— Input type

`'integer'`

(default) | `'bit'`

Input type, specified as `'integer'`

or
`'bit'`

.

If you specify

`'integer'`

, the input signal must consist of integers in the range [0, (`M`

– 1)].If you specify

`'bit'`

, the input signal must contain binary values, and the number of rows must be an integer multiple of log_{2}(`M`

).

`UnitAveragePower`

— Unit average power flag

`false`

or
`0`

(default) | `true`

or `1`

Unit average power flag, specified as a numeric or logical
`0`

(`false`

) or
`1`

(`true`

).

When this flag is

`1`

(`true`

), the function scales the constellation to the average power of one watt referenced to 1 ohm.When this flag is

`0`

(`false`

), the function scales the constellation so that the QAM constellation points are separated by a minimum distance of two.

`OutputDataType`

— Output data type

`'double'`

| `'single'`

| `numerictype`

object

Output data type, specified as `'double'`

,
`'single'`

, or a `numerictype`

object. For more information on constructing these objects, see
`numerictype`

(Fixed-Point Designer). This
argument determines the data type of the output modulated symbols and
the data type used for intermediate computations. Output the fixed-point
type as a signed, unscaled `numerictype`

object in
MATLAB^{®} simulation, and as a signed, scaled
`numerictype`

object during C code or MEX generation.

If you do not specify this argument and the input is data type

`double`

or a built-in integer, the output data type is`double`

.If the input is data type

`single`

, the output data type is`single`

.If the input is fixed-point, this argument must be specified.

`PlotConstellation`

— Option to plot constellation

`false`

or
`0`

(default) | `true`

or `1`

Option to plot constellation, specified as a numeric or logical
`0`

(`false`

) or
`1`

(`true`

). To plot the QAM
constellation, specify `PlotConstellation=true`

.

## Output Arguments

`Y`

— Modulated signal

scalar | vector | matrix | array

Modulated signal, returned as a complex scalar, vector, matrix, or array of numeric values.

For more information on the output data type, see `OutputDataType`

.

**Data Types: **`double`

| `single`

| `fi`

| `int8`

| `int16`

| `uint8`

| `uint16`

## More About

### Gray Code

A *Gray code*, also known as a reflected
binary code, is a system where the bit patterns in adjacent constellation points
differ by only one bit.

## 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™.

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

Usage notes and limitations:

Fixed-point output data types are not supported.

## Version History

**Introduced before R2006a**

### R2024a: Enhance output data type support

The `qammod`

function enhances output data type offering by
using the `OutputDataType`

argument. Previously, the output data type was inherited from input data type or set
to a fixed-point setting. This addition allows you to also specify the output data
type as `single`

or `double`

.

### R2023b: Add GPU array support

The `qammod`

function adds support for `gpuArray`

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

### R2018b: Initial Phase Input Removed

Starting in R2018b, you can no longer offset the initial phase for the QAM
constellation using the `qammod`

function.

To adjust the initial phase of the QAM-modulated data, instead use `genqammod`

to offset the initial
phase of the data being modulated, or you can multiply the
`qammod`

output by the desired initial
phase:

y = qammod(x,M) .* exp(1i*initPhase)

## 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)