comm.QPSKDemodulator
Demodulate using QPSK method
Description
The comm.QPSKDemodulator
object demodulates a signal that was modulated using the
quadrature phase shift keying (QPSK) method. The input is a baseband representation of the
modulated signal.
To demodulate a signal that was modulated using the QPSK method:
Create the
comm.QPSKDemodulator
object and set its properties.Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?
Creation
Syntax
Description
qpskdemod = comm.QPSKDemodulator
creates a System object™ to demodulate input QPSK signals.
qpskdemod = comm.QPSKDemodulator(
sets properties using one or more namevalue arguments. For example,
Name
=Value
)DecisionMethod="Hard decision"
specifies demodulation using the
harddecision method.
qpskdemod = comm.QPSKDemodulator(
sets the phase
=Name
,Value
)PhaseOffset
property to
phase
, and optional namevalue arguments. Specify
phase
in radians.
Properties
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release
function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
PhaseOffset
— Phase of zeroth point in constellation
pi/4
(default)  scalar
Phase of the zeroth point in the constellation in radians, specified as a scalar.
Example: PhaseOffset=0
aligns the QPSK signal constellation points
on the axes {(1,0), (0,j), (1,0), (0,j)}.
Data Types: double
BitOutput
— Option to output data as bits
0
or false
(default)  1
or true
Option to output data as bits, specified as a logical 0
(false
) or 1
(true
).
Set this property to
false
to output symbols as integer values in the range [0
,3
] with length equal to the input data vector length.Set this property to
true
to output a column vector of bit values with length equal to twice the input data vector length.
Data Types: logical
SymbolMapping
— Symbol encoding
'Gray'
(default)  'Binary'
Symbol encoding mapping of constellation bits, specified as
'Gray'
or 'Binary'
.
Setting  Constellation Mapping for Integers  Constellation Mapping for Bits  Comment 



 Map symbols using Graycoded ordering. 


 Map symbols using natural binarycoded ordering. The signal
constellation maps to the complex value 
DecisionMethod
— Demodulation decision method
'Hard decision'
(default)  'Loglikelihood ratio'
 'Approximate loglikelihood ratio'
VarianceSource
— Source of noise variance
'Property'
(default)  'Input port'
Source of noise variance, specified as 'Property'
or
'Input port'
.
Dependencies
To enable this property, set the BitOutput
property to
true
and the DecisionMethod
property to
'Loglikelihood ratio'
or 'Approximate loglikelihood
ratio'
.
Variance
— Noise variance
1
(default)  positive scalar
Noise variance, specified as a positive scalar.
Tunable: Yes
Tips
The exact LLR algorithm computes exponentials using finite precision arithmetic. For computations involving very large positive or negative magnitudes, the exact LLR algorithm yields:
Inf
orInf
if the noise variance is a very large valueNaN
if the noise variance and signal power are both very small values
The approximate LLR algorithm does not compute exponentials. You can avoid
Inf
, Inf
, and NaN
results by using
the approximate LLR algorithm.
Dependencies
To enable this property, set the BitOutput
property to
true
, the DecisionMethod
property to
'Loglikelihood ratio'
or 'Approximate loglikelihood
ratio'
, and the VarianceSource
property to
'Property'
.
Data Types: double
OutputDataType
— Data type of output
'Full precision'
(default)  'Smallest unsigned integer'
 'double'
 ...
Data type of the output, specified as 'Full precision'
,
'Smallest unsigned integer'
, 'double'
,
'single'
, 'int8'
, 'uint8'
,
'int16'
, 'uint16'
, 'int32'
,
or 'uint32'
,'logical'
.
When the input data type is single or double precision and you set the
BitOutput
property totrue
, theDecisionMethod
property to'Hard decision'
, and theOutputDataType
property to'Full precision'
, the output has the same data type as that of the input.When the input data is of a fixedpoint type, the output data type behaves as if you had set the
OutputDataType
property to'Smallest unsigned integer'
.When you set
BitOutput
totrue
and theDecisionMethod
property to'Hard Decision'
, then'logical'
data type is a valid option.When you set the
BitOutput
property totrue
and theDecisionMethod
property to'Loglikelihood ratio'
or'Approximate loglikelihood ratio'
, the output data type is the same as that of the input and the input data type must be single or double precision.
Dependencies
To enable this property, set the BitOutput
property to
false
or set the BitOutput
property to
true
and the DecisionMethod
property to
'Hard decision'
.
DerotateFactorDataType
— Data type of derotate factor
'Same word length as input'
(default)  'Custom'
Data type of the derotate factor, specified as 'Same word length as
input'
or 'Custom'
. The object uses the derotate factor
in the computations only when the input signal is a fixedpoint type and the PhaseOffset
property has a
value that is not an even multiple of π/4.
Dependencies
To enable this property, set the BitOutput
property to
false
or set the BitOutput
property to true
and the DecisionMethod
property to
'Hard decision'
.
CustomDerotateFactorDataType
— Fixedpoint data type of derotate factor
numerictype([],16)
(default)  unscaled numerictype
object
Fixedpoint data type of the derotate factor, specified as an unscaled numerictype
(FixedPoint Designer) object with a Signedness
of
Auto
.
Dependencies
To enable this property, set the DerotateFactorDataType
property to 'Custom'
.
Data Types: numerictype object
Usage
Description
uses soft decision demodulation and noise variance y
= qpskdemod(x
,var
)var
. This syntax
applies when you set the BitOutput
property to
true
, the DecisionMethod
property to
'Approximate loglikelihood ratio'
or 'Loglikelihood
ratio'
, and the VarianceSource
property to
'Input port'
.
Input Arguments
x
— QPSKmodulated signal
scalar  column vector
QPSKmodulated signal, specified as a scalar or column vector.
Dependencies
The object accepts inputs with a signed integer data type or signed fixed point
(sfi
(FixedPoint Designer)) objects when you set the
BitOutput
property to
false
or you set the DecisionMethod
property
to 'Hard decision'
and the BitOutput
property to true
.
Data Types: double
 single
 int
 fi
var
— Noise variance
scalar
Noise variance, specified as a scalar.
Dependencies
To enable this argument, set the VarianceSource
property
to 'Input port'
, the BitOutput
property to
true
, and the DecisionMethod
property
to 'Approximate loglikelihood ratio'
or 'Loglikelihood
ratio'
.
Data Types: single
 double
Output Arguments
y
— Output signal
scalar  column vector
Output signal, returned as a scalar or column vector. To specify whether the
object outputs values as integers or bits, use the BitOutput
property. To specify
the output data type, use the OutputDataType
property.
Object Functions
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
Specific to comm.QPSKDemodulator
constellation  Calculate or plot ideal signal constellation 
Examples
Plot QPSK Reference Constellation
Create a QPSK modulator.
mod = comm.QPSKModulator;
Determine the reference constellation points.
refC = constellation(mod)
refC = 4×1 complex
0.7071 + 0.7071i
0.7071 + 0.7071i
0.7071  0.7071i
0.7071  0.7071i
Plot the constellation.
constellation(mod)
Create a QPSK demodulator having phase offset set to 0
.
demod = comm.QPSKDemodulator(0);
Plot the reference constellation. The constellation
method works for both modulator and demodulator objects.
constellation(demod)
BER Estimate of QPSK Signal
Create a QPSK modulator and demodulator pair that operate on bits.
qpskModulator = comm.QPSKModulator('BitInput',true); qpskDemodulator = comm.QPSKDemodulator('BitOutput',true);
Create an AWGN channel object and an error rate counter.
channel = comm.AWGNChannel('EbNo',4,'BitsPerSymbol',2); errorRate = comm.ErrorRate;
Generate random binary data and apply QPSK modulation.
data = randi([0 1],1000,1); txSig = qpskModulator(data);
Pass the signal through the AWGN channel and demodulate it.
rxSig = channel(txSig); rxData = qpskDemodulator(rxSig);
Calculate the error statistics. Display the BER.
errorStats = errorRate(data,rxData); errorStats(1)
ans = 0.0100
LogLikelihood Ratio (LLR) Demodulation
This example shows the BER performance improvement for QPSK modulation when using loglikelihood ratio (LLR) instead of harddecision demodulation in a convolutionally coded communication link. With LLR demodulation, one can use the Viterbi decoder either in the unquantized decoding mode or the softdecision decoding mode. Unquantized decoding, where the decoder inputs are real values, though better in terms of BER, is not practically viable. In the more practical softdecision decoding, the demodulator output is quantized before being fed to the decoder. It is generally observed that this does not incur a significant cost in BER while significantly reducing the decoder complexity. We validate this experimentally through this example.
For a Simulink™ version of this example, see LLR vs. Hard Decision Demodulation in Simulink.
Initialization
Initialize simulation parameters.
M = 4; % Modulation order k = log2(M); % Bits per symbol bitsPerIter = 1.2e4; % Number of bits to simulate EbNo = 3; % Information bit Eb/No in dB
Initialize coding properties for a rate 1/2, constraint length 7 code.
codeRate = 1/2; % Code rate of convolutional encoder constLen = 7; % Constraint length of encoder codeGenPoly = [171 133]; % Code generator polynomial of encoder tblen = 32; % Traceback depth of Viterbi decoder trellis = poly2trellis(constLen,codeGenPoly);
Create a comm.ConvolutionalEncoder
System object™ by using trellis
as an input.
enc = comm.ConvolutionalEncoder(trellis);
Modulator and Channel
Create a comm.QPSKModulator
and two comm.QPSKDemodulator
System objects. Configure the first demodulator to output harddecision bits. Configure the second to output LLR values.
qpskMod = comm.QPSKModulator('BitInput',true); demodHard = comm.QPSKDemodulator('BitOutput',true,... 'DecisionMethod','Hard decision'); demodLLR = comm.QPSKDemodulator('BitOutput',true,... 'DecisionMethod','Loglikelihood ratio');
The signal going into the AWGN channel is the modulated encoded signal. To achieve the required noise level, adjust the Eb/No for coded bits and multibit symbols. Calculate the $$SNR$$ value based on the $${E}_{b}/{N}_{o}$$ value you want to simulate.
SNR = convertSNR(EbNo,"ebno","BitsPerSymbol",log2(M),"CodingRate",codeRate);
Viterbi Decoding
Create comm.ViterbiDecoder
objects to act as the harddecision, unquantized, and softdecision decoders. For all three decoders, set the traceback depth to tblen
.
decHard = comm.ViterbiDecoder(trellis,'InputFormat','Hard', ... 'TracebackDepth',tblen); decUnquant = comm.ViterbiDecoder(trellis,'InputFormat','Unquantized', ... 'TracebackDepth',tblen); decSoft = comm.ViterbiDecoder(trellis,'InputFormat','Soft', ... 'SoftInputWordLength',3,'TracebackDepth',tblen);
Calculating the Error Rate
Create comm.ErrorRate
objects to compare the decoded bits to the original transmitted bits. The Viterbi decoder creates a delay in the decoded bit stream output equal to the traceback length. To account for this delay, set the ReceiveDelay
property of the comm.ErrorRate
objects to tblen
.
errHard = comm.ErrorRate('ReceiveDelay',tblen); errUnquant = comm.ErrorRate('ReceiveDelay',tblen); errSoft = comm.ErrorRate('ReceiveDelay',tblen);
System Simulation
Generate bitsPerIter
message bits. Then convolutionally encode and modulate the data.
txData = randi([0 1],bitsPerIter,1); encData = enc(txData); modData = qpskMod(encData);
Pass the modulated signal through an AWGN channel.
[rxSig,noiseVariance] = awgn(modData,SNR);
Before using a comm.ViterbiDecoder
object in the softdecision mode, the output of the demodulator needs to be quantized. This example uses a comm.ViterbiDecoder
object with a SoftInputWordLength
of 3. This value is a good compromise between short word lengths and a small BER penalty. Define partition points for 3bit quantization.
demodLLR.Variance = noiseVariance; partitionPoints = (1.5:0.5:1.5)/noiseVariance;
Demodulate the received signal and output harddecision bits.
hardData = demodHard(rxSig);
Demodulate the received signal and output LLR values.
LLRData = demodLLR(rxSig);
Harddecision decoding
Pass the demodulated data through the Viterbi decoder. Compute the error statistics.
rxDataHard = decHard(hardData); berHard = errHard(txData,rxDataHard);
Unquantized decoding
Pass the demodulated data through the Viterbi decoder. Compute the error statistics.
rxDataUnquant = decUnquant(LLRData); berUnquant = errUnquant(txData,rxDataUnquant);
Softdecision decoding
Pass the demodulated data to the quantiz
function. This data must be multiplied by 1
before being passed to the quantizer, because, in softdecision mode, the Viterbi decoder assumes that positive numbers correspond to 1s and negative numbers to 0s. Pass the quantizer output to the Viterbi decoder. Compute the error statistics.
quantizedValue = quantiz(LLRData,partitionPoints); rxDataSoft = decSoft(double(quantizedValue)); berSoft = errSoft(txData,rxDataSoft);
Running Simulation Example
Simulate the previously described communications system over a range of Eb/No values by executing the simulation file simLLRvsHD
. It plots BER results as they are generated. BER results for harddecision demodulation and LLR demodulation with unquantized and softdecision decoding are plotted in red, blue, and black, respectively. A comparison of simulation results with theoretical results is also shown. Observe that the BER is only slightly degraded by using softdecision decoding instead of unquantized decoding. The gap between the BER curves for softdecision decoding and the theoretical bound can be narrowed by increasing the number of quantizer levels.
This example may take some time to compute BER results. If you have the Parallel Computing Toolbox™ (PCT) installed, you can set usePCT
to true
to run the simulation in parallel. In this case, the file LLRvsHDwithPCT
is run.
To obtain results over a larger range of Eb/No values, modify the appropriate supporting files. Note that you can obtain more statistically reliable results by collecting more errors.
usePCT = false; if usePCT && license('checkout','Distrib_Computing_Toolbox') ... && ~isempty(ver('parallel')) LLRvsHDwithPCT(1.5:0.5:5.5,5); else simLLRvsHD(1.5:0.5:5.5,5); end
Appendix
The following functions are used in this example:
simLLRvsHD.m — Simulates system without PCT.
LLRvsHDwithPCT.m — Simulates system with PCT.
simLLRvsHDPCT.m — Helper function called by LLRvsHDwithPCT.
More About
HardDecision QPSK Demodulation
The signal preprocessing required for QPSK demodulation depends on the configuration.
This figure shows the harddecision QPSK demodulation signal diagram for the trivial phase offset (odd multiple of π/4) configuration.
This figure shows the harddecision QPSK demodulation floating point signal diagram for the nontrivial phase offset configuration.
This figure shows the harddecision QPSK demodulation fixedpoint signal diagram for the nontrivial phase offset configuration.
SoftDecision QPSK Demodulation
For soft demodulation, two softdecision loglikelihood ratio (LLR) algorithms are available: exact LLR and approximate LLR. The exact LLR algorithm is more accurate but has slower execution speed than the approximate LLR algorithm. For further description of these algorithms, see the SoftDecision Demodulation topic.
Note
The exact LLR algorithm computes exponentials using finite precision arithmetic. For computations involving very large positive or negative magnitudes, the exact LLR algorithm yields:
Inf
orInf
if the noise variance is a very large valueNaN
if the noise variance and signal power are both very small values
The approximate LLR algorithm does not compute exponentials. You can avoid
Inf
, Inf
, and NaN
results by using
the approximate LLR algorithm.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.
double
and single
data
types are supported for simulation, but not for HDL code generation.
To generate HDL code from predefined System objects, see HDL Code Generation from Viterbi Decoder System Object (HDL Coder).
Version History
See Also
Functions
Objects
comm.QPSKModulator
comm.PSKDemodulator
comm.PSKModulator
comm.DPSKDemodulator
comm.OQPSKDemodulator
Blocks
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)