This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Quadrature amplitude demodulation


  • z = qamdemod(y,M,iniPhase)



z = qamdemod(y,M) returns a demodulated signal, z, given quadrature amplitude modulated (QAM) signal y of modulation order M.


z = qamdemod(y,M,symOrder) returns a demodulated signal and specifies the symbol order.


z = qamdemod(___,Name,Value) specifies demodulation behavior using Name,Value pairs and any of the previous syntaxes.

z = qamdemod(y,M,iniPhase) specifies the initial phase of the QAM constellation. qamdemod will not accept iniPhase in a future release. Use z = qamdemod(y,M) instead.

Input Arguments

collapse all

Input signal resulting from quadrature amplitude modulation, specified as a complex vector, matrix, or 3-D array. Each column is treated as an independent channel.

Data Types: double | single | fi
Complex Number Support: Yes

Modulation order, specified as a power-of-two scalar integer. The modulation order specifies the number of points in the signal constellation.

Example: 16

Data Types: double

Symbol order, specified as 'gray', 'bin', or a vector.

  • 'gray' — Use Gray Code ordering

  • 'bin' — Use natural binary-coded ordering

  • Vector — Use custom symbol ordering

Vectors must use unique elements whose values range from 0 to 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: char | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

collapse all

Unit average power flag, specified as the comma-separated pair consisting of UnitAveragePower and a logical scalar. When this flag is true, the QAM constellation is scaled to an average power of 1 W. When this flag is false, the QAM constellation points are separated by a minimum distance of 2.

Data Types: logical

Output type, specified as the comma-separated pair consisting of OutputType and one of the following: 'integer', 'bit', 'llr', or 'approxllr'.

Data Types: char

Option to plot constellation, specified as the comma-separated pair consisting of 'PlotConstellation' and a logical scalar. To plot the QAM constellation, set PlotConstellation to true.

Data Types: logical

Output Arguments

collapse all

Demodulated output signal, returned as a vector, matrix, or 3-D array. The data type is the same as that of the input signal, y. The dimensions of the output vary depending on the specified OutputType value.

'OutputType'Return Value of qamdemodDimensions of Output
'integer'Demodulated integer values from 0 to M – 1z has the same dimensions as input y.
'bit'Demodulated bitsThe number of rows in z is log2(M) times the number of rows in y. Each demodulated symbol is mapped to a group of log2(M) bits, where the first bit represents the MSB.
'llr'Log-likelihood ratio value for each bit
'approxllr'Approximate log-likelihood ratio value for each bit


collapse all

Demodulate an 8-QAM signal and plot the points corresponding to symbols 0 and 3.

Generate random 8-ary data symbols.

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

Apply 8-QAM.

txSig = qammod(data,8);

Pass the modulated signal through an AWGN channel.

rxSig = awgn(txSig,18,'measured');

Demodulate the received signal using an initial phase of $\pi$/8.

rxData = qamdemod(rxSig,8,pi/8);

Generate the reference constellation points.

refpts = qammod((0:7)',8,pi/8);

Plot the received signal points corresponding to symbols 0 and 3 and overlay the reference constellation. Only the received data corresponding to those symbols is displayed.

hold on
legend('Points corresponding to 0','Points corresponding to 3', ...
    'Reference constellation','location','nw');

Modulate and demodulate random data by using 16-QAM with WLAN symbol mapping. Verify that the input data symbols match the demodulated symbols.

Generate a 3-D array of random symbols.

x = randi([0,15],20,4,2);

Create a custom symbol mapping for the 16-QAM constellation based on WLAN standards.

wlanSymMap = [2 3 1 0 6 7 5 4 14 15 13 12 10 11 9 8];

Modulate the data, and set the constellation to have unit average signal power. Plot the constellation.

y = qammod(x,16,wlanSymMap,'UnitAveragePower', true,'PlotConstellation',true);

Demodulate the received signal.

z = qamdemod(y,16,wlanSymMap,'UnitAveragePower',true);

Verify that the demodulated signal is equal to the original data.

ans =



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

Set the modulation order, 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', ...

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 =



Estimate bit error rate (BER) performance for hard-decision and soft-decision Viterbi decoders in AWGN. Compare the performance to that of an uncoded 64-QAM link.

Set the simulation parameters.

clear; close all
rng default
M = 64;                 % Modulation order
k = log2(M);            % Bits per symbol
EbNoVec = (4:10)';       % Eb/No values (dB)
numSymPerFrame = 1000;   % Number of QAM symbols per frame

Initialize the BER results vectors.

berEstSoft = zeros(size(EbNoVec));
berEstHard = zeros(size(EbNoVec));

Set the trellis structure and traceback length for a rate 1/2, constraint length 7, convolutional code.

trellis = poly2trellis(7,[171 133]);
tbl = 32;
rate = 1/2;

The main processing loops performs these steps:

  • Generate binary data.

  • Convolutinally encode the data.

  • Apply QAM modulation to the data symbols.

  • Pass the modulated signal through an AWGN channel.

  • Demodulate the received signal using hard decision and approximate LLR methods.

  • Viterbi decode the signals using hard and unquantized methods.

  • Calculate the number of bit errors.

The while loop continues to process data until either 100 errors are encountered or 1e7 bits are transmitted.

for n = 1:length(EbNoVec)
    % Convert Eb/No to SNR
    snrdB = EbNoVec(n) + 10*log10(k*rate);
    % Reset the error and bit counters
    [numErrsSoft,numErrsHard,numBits] = deal(0);

    while numErrsSoft < 100 && numBits < 1e7
        % Generate binary data and convert to symbols
        dataIn = randi([0 1],numSymPerFrame*k,1);

        % Convolutionally encode the data
        dataEnc = convenc(dataIn,trellis);

        % QAM modulate
        txSig = qammod(dataEnc,M,'InputType','bit');

        % Pass through AWGN channel
        rxSig = awgn(txSig,snrdB,'measured');

        % Demodulate the noisy signal using hard decision (bit) and
        % approximate LLR approaches
        rxDataHard = qamdemod(rxSig,M,'OutputType','bit');
        rxDataSoft = qamdemod(rxSig,M,'OutputType','approxllr', ...

        % Viterbi decode the demodulated data
        dataHard = vitdec(rxDataHard,trellis,tbl,'cont','hard');
        dataSoft = vitdec(rxDataSoft,trellis,tbl,'cont','unquant');

        % Calculate the number of bit errors in the frame. Adjust for the
        % decoding delay, which is equal to the traceback depth.
        numErrsInFrameHard = biterr(dataIn(1:end-tbl),dataHard(tbl+1:end));
        numErrsInFrameSoft = biterr(dataIn(1:end-tbl),dataSoft(tbl+1:end));

        % Increment the error and bit counters
        numErrsHard = numErrsHard + numErrsInFrameHard;
        numErrsSoft = numErrsSoft + numErrsInFrameSoft;
        numBits = numBits + numSymPerFrame*k;


    % Estimate the BER for both methods
    berEstSoft(n) = numErrsSoft/numBits;
    berEstHard(n) = numErrsHard/numBits;

Plot the estimated hard and soft BER data. Plot the theoretical performance for an uncoded 64-QAM channel.

semilogy(EbNoVec,[berEstSoft berEstHard],'-*')
hold on
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')

As expected, the soft decision decoding produces the best results.

More About

collapse all

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.

Introduced before R2006a

Was this topic helpful?