Quadrature amplitude demodulation
specifies
demodulation behavior using z
= qamdemod(___,Name,Value
)Name,Value
pairs
and any of the previous syntaxes.
y
— Input signalInput signal resulting from quadrature amplitude modulation, specified as a complex scalar, vector, matrix, or 3-D array. Each column is treated as an independent channel.
Data Types: double
| single
| fi
Complex Number Support: Yes
M
— Modulation orderModulation 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
symOrder
— Symbol order'gray'
(default) | 'bin'
| vectorSymbol 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
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'UnitAveragePower'
— Unit average power flagfalse
(default) | true
Unit average power flag, specified as the comma-separated pair
consisting of UnitAveragePower
and a logical scalar.
When this flag is true
, the function scales the
constellation to an average power of 1 watt referenced to 1 ohm. When
this flag is false
, the function scales the
constellation so that the QAM constellation points are separated by a
minimum distance of 2.
Data Types: logical
'OutputType'
— Output type'integer'
(default) | 'bit'
| 'llr'
| 'approxllr'
Output type, specified as the comma-separated pair consisting of
OutputType
and one of the following:
'integer'
, 'bit'
,
'llr'
, or 'approxllr'
.
Data Types: char
'NoiseVariance'
— Noise variance1
(default) | positive scalar | vector of positive valuesNoise variance, specified as a positive scalar or vector of positive values.
When specified as a scalar, the same noise variance value is used on all input elements.
When specified as a vector, the vector length must be equal to the number of elements in the last dimension of the input signal. Each element of the vector specifies noise variance for all the elements of the input along the corresponding last dimension.
When OutputType
= ‘llr’
,
if the demodulation computation outputs Inf
or
-Inf
values, it is likely because the
specified noise variance values are significantly smaller than the
SNR. Since the LLR algorithm computes exponentials using finite
precision arithmetic, computation of exponentials with very large or
very small numbers can yield positive or negative infinity.
Try using OutputType
=
‘approxllr’
instead, because the approximate
LLR algorithm does not compute exponentials.
This input argument applies only when
'OutputType'
is set to
'llr'
or
'approxllr'
.
Data Types: double
'PlotConstellation'
— Option to plot constellationfalse
(default) | true
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
z
— Demodulated output signalDemodulated output signal, returned as a scalar, 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 qamdemod | Dimensions of Output |
---|---|---|
'integer' | Demodulated integer values from 0 to M –
1 | z has the same dimensions as input y . |
'bit' | Demodulated bits | The 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 and the last bit represents the LSB. |
'llr' | Log-likelihood ratio value for each bit | |
'approxllr' | Approximate log-likelihood ratio value for each bit |
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 /8.
rxData = qamdemod(rxSig.*exp(-1i*pi/8),8);
Generate the reference constellation points.
refpts = qammod((0:7)',8) .* exp(1i*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.
plot(rxSig(rxData==0),'g.'); hold on plot(rxSig(rxData==3),'c.'); plot(refpts,'r*') text(real(refpts)+0.1,imag(refpts),num2str((0:7)')) xlabel('In-Phase') ylabel('Quadrature') 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.
isequal(x,z)
ans = logical
1
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', ... 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
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.
Convolutionally encode the data.
Apply QAM modulation to the data symbols. Specify unit average power for the transmitted signal.
Pass the modulated signal through an AWGN channel.
Demodulate the received signal using hard decision and approximate LLR methods. Specify unit average power for the received signal.
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); % Noise variance calculation for unity average signal power. noiseVar = 10.^(-snrdB/10); % 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','UnitAveragePower',true); % Pass through AWGN channel rxSig = awgn(txSig,snrdB,'measured'); % Demodulate the noisy signal using hard decision (bit) and % soft decision (approximate LLR) approaches. rxDataHard = qamdemod(rxSig,M,'OutputType','bit','UnitAveragePower',true); rxDataSoft = qamdemod(rxSig,M,'OutputType','approxllr', ... 'UnitAveragePower',true,'NoiseVariance',noiseVar); % 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; end % Estimate the BER for both methods berEstSoft(n) = numErrsSoft/numBits; berEstHard(n) = numErrsHard/numBits; end
Plot the estimated hard and soft BER data. Plot the theoretical performance for an uncoded 64-QAM channel.
semilogy(EbNoVec,[berEstSoft berEstHard],'-*') hold on semilogy(EbNoVec,berawgn(EbNoVec,'qam',M)) legend('Soft','Hard','Uncoded','location','best') grid xlabel('Eb/No (dB)') ylabel('Bit Error Rate')
As expected, the soft decision decoding produces the best results.
Use the qamdemod
function to simulate soft decision output for OQPSK-modulated signals.
Create an OQPSK modulated signal and add noise to the signal.
sps = 4; msg = randi([0 1],1000,1); oqpskMod = comm.OQPSKModulator('SamplesPerSymbol',sps,'BitInput',true); oqpskSig = oqpskMod(msg); impairedSig = awgn(oqpskSig,15);
Perform Soft-Decision Demodulation
Create QPSK equivalent signal to align I and Q. Apply matched filtering to the received OQPSK signal.
impairedQPSK = complex(real(impairedSig(1+sps/2:end-sps/2)), imag(impairedSig(sps+1:end)));
halfSinePulse = sin(0:pi/sps:(sps)*pi/sps);
matchedFilter = dsp.FIRDecimator(sps,halfSinePulse,'DecimationOffset',sps/2);
filteredQPSK = matchedFilter(impairedQPSK);
To perform soft demodulation of the filtered OQPSK signal use the qamdemod
function. Align symbol mapping of qamdemod
with the symbol mapping used by the comm.OQPSKModulator
, then demodulate the signal.
oqpskModSymbolMapping = [1 3 0 2]; demodulated = qamdemod(filteredQPSK,4,oqpskModSymbolMapping,'OutputType','llr');
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.
Errors starting in R2018b
Starting in R2018b, you can no longer offset the initial phase for the QAM
constellation using the qamdemod
function.
Instead use genqamdemod
to offset the initial
phase of the QAM data being demodulated or you can multiply the modulated input to
qamdemod
by the desired initial
phase:
z = qamdemod(y .* exp(-1i*initPhase,M))
genqamdemod
| genqammod
| modnorm
| pamdemod
| qammod
A modified version of this example exists on your system. Do you want to open this version instead? (ko_KR)
아래 MATLAB 명령에 해당하는 링크를 클릭하셨습니다.
이 명령을 MATLAB 명령 창에 입력해 실행하십시오. 웹 브라우저에서는 MATLAB 명령을 지원하지 않습니다.
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: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.