comm.RSDecoder
Decode data using Reed-Solomon decoder
Description
The comm.RSDecoder
System object™ recovers a message vector from a Reed-Solomon (RS) codeword vector. For proper
decoding, the property values for this object must match the property values in the
corresponding comm.RSEncoder
object. For more information, see
Algorithms.
To decode data using an RS-coding scheme:
Create the
comm.RSDecoder
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
creates an RS decoder
System object, dec
= comm.RSDecoderdec
, that applies RS decoding.
sets dec
= comm.RSDecoder(N
,K
)CodewordLength
to
N
and MessageLength
to
K
. For example, comm.RSDecoder(7,3)
creates a
(7,3) RS decoder object.
additionally sets dec
= comm.RSDecoder(N
,K
,GP
)GeneratorPolynomial
to
GP
and GeneratorPolynomialSource
to 'Property'
.
additionally sets dec
= comm.RSDecoder(N
,K
,GP
,S
)ShortMessageLength
to
S
and ShortMessageLengthSource
to 'Property'
.
specifies options using one or more name-value arguments in addition to the input
arguments in previous syntaxes. For example,
dec
= comm.RSDecoder(___,Name
,Value
)comm.RSDecoder(BitInput="true")
creates an RS decoder object
configured to decode an input column vector of bits.
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.
BitInput
— Option to input bits
false
or 0
(default) | true
or 1
Option to input bits, specified as a logical 0
(false
) or 1
(true
).
When you set this property to
false
, the inputX
must be a numeric, column vector of integers with a length equal to an integer multiple of (CodewordLength
– Npunctures). The decoded data output,Y
, is a column vector of integers whose length is an integer multiple ofMessageLength
. Each symbol that forms the input codewords and output message is an integer in the range [0, (2M – 1)]. These integers correspond to an element of the finite Galois fieldgf
(2M).When you set
ErasuresInputPort
totrue
andBitInput
tofalse
, the erasures input,erasures
, must be of length equal to the encoded data input vectorX
. Values of1
in theerasures
vector correspond to erased symbols in the same position as the input codewords, and values of0
correspond to non-erased symbols.
When you set this property to true, the input
X
must be a numeric, column vector of bits with a length equal to an integer multiple of (CodewordLength
– Npunctures)×M. The data type of inputX
can be numeric, logical, or unsigned fixed point of word length 1 (fi
(Fixed-Point Designer) object). The decoded output,Y
, is a column vector of bits with length equal to an integer multiple ofMessageLength
×M. A group of M bits represents an integer in the range [0, (2M – 1)]. These integers correspond to an element of the finite Galois fieldgf
(2M).When you set
ErasuresInputPort
totrue
andBitInput
totrue
, the erasures input,erasures
, must be of length 1/M times the length of the input encoded data vectorX
. Values of1
in theerasures
vector correspond to erased symbols and values of0
correspond to non-erased symbols. In this case a symbol corresponds to M bits.
Npunctures is the number of punctures. You
specify the number of punctures with the PuncturePatternSource
and PuncturePattern
properties.
M is the degree of the primitive polynomial that you specify with
the PrimitivePolynomialSource
and PrimitivePolynomial
properties.
Data Types: logical
CodewordLength
— Codeword length of RS code
7 (default) | positive integer
Codeword length of RS code
Codeword length of the RS code in symbols, specified as a positive integer.
If you set
PrimitivePolynomialSource
to"Auto"
,CodewordLength
must be in the range (3, 216 – 1].If you set
PrimitivePolynomialSource
to"Property"
,CodewordLength
must be in the range [3, 2M – 1], where M is the degree of the primitive polynomial that you specify withPrimitivePolynomialSource
andPrimitivePolynomial
. M must be in the range [3, 16]. The difference (CodewordLength
–MessageLength
) must be an even integer.
For a full-length RS code, CodewordLength
must be
(2M – 1). If
CodewordLength
is less than
(2M – 1), the object assumes a shortened
RS code.
MessageLength
— Message length
3 (default) | positive integer
Message length in symbols, specified as a positive integer.
ShortMessageLengthSource
— Source of short message length
"Auto"
(default) | "Property"
Source of the short message length, specified as "Auto"
or
"Property"
.
When you set this property to
"Auto"
, shortening is specified viaCodewordLength
andMessageLength
. The object defines the RS code based on theCodewordLength
,MessageLength
,GeneratorPolynomial
, andPrimitivePolynomial
properties.When you set this property to
"Property"
, the object usesShortMessageLength
.
ShortMessageLength
— Shortened message length
3
(default) | positive integer
Shortened message length in symbols, specified as a positive integer whose value
must be less than or equal to MessageLength
. When
ShortMessageLength
< MessageLength
, the object
shortens the RS code.
Dependencies
This property applies when you set ShortMessageLengthSource
to
"Property"
.
GeneratorPolynomialSource
— Source of generator polynomial
"Auto"
(default) | "Property"
Source of the generator polynomial, specified as Auto
or
"Property"
.
When you set this property to
"Auto"
, the object calculates the generator polynomial based on the value ofPrimitivePolynomialSource
andPrimitivePolynomial
.When you set
PrimitivePolynomialSource
to"Auto"
, the object computes the generator polynomial asrsgenpoly
(CodewordLength
+ SL,MessageLength
+ SL).When you set
PrimitivePolynomialSource
to"Property"
, the object computes generator polynomial asrsgenpoly
(CodewordLength
+ SL,MessageLength
+ SL,PrimitivePolynomial
).In both cases, SL = (2M – 1) –
CodewordLength
is the shortening length and M is the degree of the primitive polynomial you specify withPrimitivePolynomialSource
andPrimitivePolynomial
.
When you set this property to
"Property"
, the object usesGeneratorPolynomial
to define the generator polynomial.
GeneratorPolynomial
— Generator polynomial
[1 3 1 2 3]
(default) | integer row vector | gf
row vector
Generator polynomial, specified as a polynomial string, integer row vector, or
Galois field row vector. The length of the generator polynomial must be (CodewordLength
– MessageLength
+ 1).
Galois field row vector entries must be in the range [0,
2M – 1] and represent a generator
polynomial in descending order of powers. Each coefficient must be an element of the
Galois field gf
(2M), represented in
integer format.
The default is the result of
, which corresponds to
rsgenpoly
(7,3,[],[],'double')[1 3 1 2 3]
.
Dependencies
This property applies when you set GeneratorPolynomialSource
to Property
.
CheckGeneratorPolynomial
— Option to check generator polynomial
true
or 1
(default) | false
or 0
Option to check the generator polynomial, specified as a logical
1
(true
) or 0
(false
). Set this property to true
to confirm
that XN + 1 is divisible by the generator polynomial you specify in GeneratorPolynomial
.
N is CodewordLength
.
A valid generator polynomial is given by (X – αB)×(X –
α(B +
1))×...×(X –
α(B + N –
K – 1)). Where α is a root of the primitive polynomial, B is an integer, N is CodewordLength
, and
K is MessageLength
. If the value
of B is 1, then you can set this property to
false
. For more information about B, see the rsgenpoly
.
Tips
For codes with generator polynomials of high degree, disabling the check speeds up
processing. As a best practice, perform the check at least once before setting this
property to false
.
Dependencies
This property applies when you set GeneratorPolynomialSource
to "Property"
.
Data Types: logical
PrimitivePolynomialSource
— Source of primitive polynomial
"Auto"
(default) | "Property"
Source of the primitive polynomial, specified as "Auto"
or
"Property"
.
When you set this property to
"Auto"
, the object uses a primitive polynomial of degree M =ceil
(log2(CodewordLength
+ 1)).When you set this property to
"Property"
, the object usesPrimitivePolynomial
to define the primitive polynomial.
PrimitivePolynomial
— Primitive polynomial
[1 0 1 1]
(default) | binary row vector | character vector | string scalar
Primitive polynomial, specified as a binary row vector that defines the finite field
gf
(2M) in descending order
of powers corresponding to the integers that form messages and codewords.
Express the polynomial as one of these options:
Character vector or string scalar of a polynomial whose constant term is
1
. For more information, see Representation of Polynomials in Communications Toolbox.Binary-valued row vector that represents the coefficients of the polynomial in order of descending powers. The length of this vector must be M + 1, where M is the degree of the polynomial. The first and last entries must be
1
, indicating the leading term with degree M and a constant term of 1.Integer-valued row vector of elements that represent the exponents for the nonzero terms of the polynomial in order of descending powers. The last entry must be
0
, indicating a constant term of 1.
The default is the result of
, which is
int2bit
(primpoly
(3),4)'[1 0 1 1]
or the polynomial x3 + x +
1.
Dependencies
This property applies when you set PrimitivePolynomialSource
to Property
.
PuncturePatternSource
— Source of puncture pattern
"None"
(default) | "Property"
Source of the puncture pattern, specified as "None"
or
"Property"
.
When you set this property to
"None"
, the object does not apply puncturing to the code.When you set this property to
"Property"
, the object punctures the code using the puncture pattern vector defined byPuncturePattern
.
PuncturePattern
— Puncture pattern
[ones(2,1); zeros(2,1)]
(default) | binary column vector
Puncture pattern, specified as a binary column vector with a length of
(N – K), where N is CodewordLength
and
K is MessageLength
. Zeros in the
puncture pattern vector indicate the position of the parity symbols that are punctured
or excluded from each codeword.
Dependencies
This property applies when you set PuncturePatternSource
to "Property"
.
ErasuresInputPort
— Option to enable erasures input
false
or 0
(default) | true
or 1
Option to enable erasures input, specified as a logical 0
(false
) or 1
(true
).
When you set this property to true
, you must provide the
erasures
vector input when running the object. The length of the erasures vector is explained in
Input and Output Signal Lengths in BCH and RS System Objects.
When you set this property to false
, the object assumes no
erasures.
Data Types: logical
NumCorrectedErrorsOutputPort
— Option to output number of corrected errors
true
or 1
(default) | false
or 0
Option to output number of corrected errors, specified as logical
1
(true
) or 0
(false
).
Set this property to true
to obtain the number of corrected
errors as an output when running the object. A nonnegative value in the
ith element of the error output vector, denotes the number of
corrected errors in the ith input codeword. A value of
-1
in the ith element of the error output vector
indicates that a decoding error occurred for that codeword. A decoding error occurs when
an input codeword has more errors than the error correction capability of the RS
code.
Data Types: logical
OutputDataType
— Output data type
"Same as input"
(default) | "double"
| "logical"
Output data type, specified as "Same as input"
,
"double"
, or "logical"
.
Dependencies
This property applies when you set BitInput
to
true
.
Usage
Description
decodes the
encoded input data using a (Y
= dec(X
)CodewordLength
,MessageLength
) RS decoder. This
syntax applies when you set NumCorrectedErrorsOutputPort
to false
. For information
about the input and output lengths when you run the object, see Input and Output Signal Lengths in BCH and RS System Objects.
uses the Y
= dec(X
,erasures
)erasures
input vector to erase symbols of the input
codewords in X
. This syntax
applies when you set ErasuresInputPort
to
true
.
[
decodes using inputs from either of the previous syntaxes, and returns the RS-decoded
output vector Y
,err
] = dec(___)Y
and the
number of corrected symbols in output vector err
. A value of
-1
in the ith element of the error output vector
indicates that a decoding error occurred for that codeword. This syntax applies when you
set NumCorrectedErrorsOutputPort
to true
.
Input Arguments
X
— Input codeword
column vector
Input codeword, specified as a column vector. For information about the input and output lengths when you run the object, see Input and Output Signal Lengths in BCH and RS System Objects.
Data Types: double
| single
| logical
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi object
erasures
— Symbols to erase
binary column vector
Symbols to erase from the input codewords, specified as a binary column input
vector. Values of 1 in the erasures
vector correspond to erased
symbols, and values of 0 correspond to non-erased symbols.
Data Types: double
| logical
Output Arguments
Y
— RS-decoded data
column vector
RS-decoded data, returned as a column vector. The output vector length and data
type depends on BitInput
and OutputDataType
.
err
— Number of corrected symbols
integer
Number of corrected symbols when decoding the input codeword, returned as an integer.
A nonnegative value indicates the number of corrected errors in the current input codeword.
A value of
-1
indicates that a decoding error occurred for that codeword. A decoding error occurs when an input codeword has more errors than the error correction capability of the RS code.
Data Types: double
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)
Examples
Transmit RS-Encoded, 8-DPSK-Modulated Symbol Stream
Transmit an RS-encoded, 8-DPSK-modulated symbol stream through an AWGN channel. After channel filtering demodulate and decode the received signal, and then count errors.
M = 8; rsEnc = comm.RSEncoder; rsDec = comm.RSDecoder; errorRate = comm.ErrorRate(ComputationDelay=3); for counter = 1:20 data = randi([0 7], 30, 1); encodedData = rsEnc(data); modSignal = dpskmod(encodedData,M); receivedSignal = awgn(modSignal,10); demodSignal = dpskdemod(receivedSignal,M); receivedSymbols = rsDec(demodSignal); errorStats = errorRate(data,receivedSymbols); end fprintf('Error rate = %f\nNumber of errors = %d\n', ... errorStats(1), errorStats(2))
Error rate = 0.128978 Number of errors = 77
Estimate BER of QPSK in AWGN with Reed-Solomon Coding
Transmit Reed-Solomon encoded data using QPSK over an AWGN channel. Demodulate and decode the received signal and collect error statistics. Compute the theoretical bit error rate (BER) for coded and noncoded data. Plot the BER results to compare performance.
Define the example parameters.
rng(1993); % Seed random number generator for repeatable results M = 4; % Modulation order bps = log2(M); % Bits per symbol N = 7; % RS codeword length K = 5; % RS message length
Create AWGN channel and error rate objects.
awgnChannel = comm.AWGNChannel( ...
BitsPerSymbol=bps);
errorRate = comm.ErrorRate;
Create a (7,5) Reed-Solomon encoder and decoder pair that accepts bit inputs.
rsEncoder = comm.RSEncoder( ... BitInput=true, ... CodewordLength=N, ... MessageLength=K); rsDecoder = comm.RSDecoder( ... BitInput=true, ... CodewordLength=N, ... MessageLength=K);
Set the range of values and account for RS coding gain. Initialize the error statistics matrix.
ebnoVec = (3:0.5:8)'; ebnoVecCodingGain = ... ebnoVec + 10*log10(K/N); % Account for RS coding gain errorStats = zeros(length(ebnoVec),3);
Estimate the bit error rate for each value. The simulation runs until either 100 errors or bits is encountered. The simulation loop encodes and modulates random data, filters the signal through an AWGN channel, demodulate and decodes the signal, and then computes error statistics.
for i = 1:length(ebnoVec) awgnChannel.EbNo = ebnoVecCodingGain(i); reset(errorRate) while errorStats(i,2) < 100 && errorStats(i,3) < 1e7 data = randi([0 1],1500,1); encData = rsEncoder(data); modData = pskmod(encData,M,InputType='bit'); rxSig = awgnChannel(modData); rxData = pskdemod(rxSig,M,OutputType='bit'); decData = rsDecoder(rxData); errorStats(i,:) = errorRate(data,decData); end end
Fit a curve to the BER data using berfit
. Generate an estimate of QPSK performance with and without coding by using the bercoding
and berawgn
functions.
berCurveFit = berfit(ebnoVecCodingGain,errorStats(:,1)); berwCoding = bercoding(ebnoVec,'RS','hard',N,K,'psk',M,'nondiff'); berNoCoding = berawgn(ebnoVec,'psk',M,'nondiff');
Plot the RS-coded BER data, curve fit of the BER data, theoretical performance with RS coding, and theoretical performance without RS coding. The (7,5) RS code improves the required to achieve a bit error rate by approximately 1.2 dB.
semilogy(ebnoVecCodingGain,errorStats(:,1),'b*', ... ebnoVecCodingGain,berCurveFit,'c-', ... ebnoVecCodingGain,berwCoding,'r', ... ebnoVec,berNoCoding) ylabel('BER') xlabel('Eb/No (dB)') legend( ... 'RS-coded BER','Curve fit', ... 'Theory with coding','Theory no coding') grid
Transmit Shortened, RS-Encoded, 256-QAM-Modulated Symbol Stream
Transmit a shortened, RS-encoded, 256-QAM-modulated symbol stream through an AWGN channel. Then demodulate, decode, and count errors.
Set the parameters for the Reed-Solomon code, where N
is the codeword length, K
is the nominal message length, and S
is the shortened message length. Set the modulation order, M
, and the number of frames, L
.
N = 255; K = 239; S = 188; M = 256; L = 50; bps = log2(M);
Create an AWGN channel System object and an error rate System object.
awgnChan = comm.AWGNChannel( ... NoiseMethod='Signal to noise ratio (Eb/No)', ... EbNo=15, ... BitsPerSymbol=bps); errorRate = comm.ErrorRate(ComputationDelay=3);
Create the Reed-Solomon generator polynomial from the DVB-T standard.
gp = rsgenpoly(N,K,[],0);
Create a Reed-Solomon encoder and decoder pair using the shortened message length, S
, and the DVB-T generator polynomial, gp
.
enc = comm.RSEncoder(N,K,gp,S); dec = comm.RSDecoder(N,K,gp,S);
Generate random symbol frames whose length equals one message block. Encode, modulate, apply AWGN, demodulate, decode, and collect statistics.
for counter = 1:L data = randi([0 1],S*bps,1); encodedData = enc(bit2int(data,bps)); modSignal = qammod(encodedData,M,UnitAveragePower=true); rxSignal = awgnChan(modSignal); demodSignal = qamdemod(rxSignal,M,UnitAveragePower=true); rxBits = dec(demodSignal); dataOut = int2bit(rxBits,bps); errorStats = errorRate(data(:),dataOut(:)); end
Display the error rate and number of errors.
fprintf('Error rate = %5.2e\nNumber of errors = %d\n', ... errorStats(1), errorStats(2))
Error rate = 2.01e-02 Number of errors = 1514
Reed-Solomon Coding with Erasures
This example shows how to configure the comm.RSEncoder
and comm.RSDecoder
System objects to perform Reed-Solomon (RS) block coding with erasures when simulating a communications system. A codeword with erasures can have those erasures in either message symbols or parity symbols. A punctured codeword has only parity symbols removed, and a shortened codeword has only message symbols removed.
RS decoders can correct both errors and erasures. A receiver that identifies the most unreliable symbols in a given codeword can generate symbol erasures and replace those symbols with zeros. When sending a symbol to the decoder, the receiver passes a flag to the decoder to indicate if the symbol is an erasure rather than a valid code symbol. In a similar fashion, the encoder can apply a puncture pattern that always removes specific parity symbols from its output. Given the puncture pattern, the decoder inserts zeros in the puncture positions, and treats those symbols the same way it treats erasures. Punctured codes offer code rate flexibility, but at the expense of some error correction capability. For the same demodulator input energy per bit to noise power spectral density ratio (), shortened codes, however, achieve the same code rate flexibility without degrading the error correction performance.
In this example, you simulate a communications system that consists of a random source, an RS encoder, a 64-QAM modulator, an AWGN channel, a 64-QAM demodulator, and an RS decoder. You analyze the RS coding with erasures by comparing the channel bit error rate (BER) performance versus the coded BER performance. You obtain the channel BER by comparing inputs for the QAM modulator to outputs from the QAM demodulator and the coded BER by comparing inputs for the RS encoder to outputs from the RS decoder.
Initialization
The helperRSCodingConfig.m helper function initializes the simulation parameters and configures the comm.AWGNChannel
and comm.ErrorRate
System objects that simulate the communications system. The helper function also sets the uncoded ratio (EbNoUncoded
) to 15 dB and the simulation stop criteria for 500 errors or a maximum bits are transmitted.
helperRSCodingConfig;
Configure RS Encoder/Decoder
This example uses a (63,53) RS code operating with a 64-QAM modulation scheme. This code can correct (63 – 53)/2 = 5 errors, or it can alternatively correct (63 – 53) = 10 erasures. For each codeword at the output of the 64-QAM demodulator, the receiver determines the six least reliable symbols using the helperRSCodingGetErasures.m helper function. The indices that point to the location of these unreliable symbols are an input to the RS decoder. The RS decoder treats these symbols as erasures resulting in an error correction capability of (10 – 6)/2 = 2 errors per codeword.
Create a comm.RSEncoder
System object and set the BitInput
property to false
so that the encoder inputs and outputs are integer symbols.
N = 63; % Codeword length K = 53; % Message length rsEncoder = comm.RSEncoder(N,K,BitInput=false); numErasures = 6;
Create a comm.RSDecoder
System object that matches the configuration of the comm.RSEncoder
object.
rsDecoder = comm.RSDecoder(N,K,BitInput=false);
Set the ErasuresInputPort
property to true
to specify erasures as an input to the decoder object.
rsDecoder.ErasuresInputPort = true;
Set the NumCorrectedErrorsOutputPort
property to true
so that the decoder outputs the number of corrected errors. A nonnegative value in the error output denotes the number of corrected errors in the input codeword. A value of –1 in the error output indicates a decoding error. A decoding error occurs when the input codeword has more errors than the error correction capability of the RS code.
rsDecoder.NumCorrectedErrorsOutputPort = true;
Stream Processing Loop
Simulate the communications system for an uncoded ratio of 15 dB. The uncoded is the ratio that would be measured at the input of the channel if there were no coding in the system.
Since the signal going into the AWGN channel is the encoded signal, you must convert the uncoded values so that they correspond to the energy ratio at the encoder output. This ratio is the coded ratio. If you input K
symbols to the encoder and obtain N
output symbols, then the energy relation is given by the K/N
rate. Set the EbNo
property of the AWGN channel object to the computed coded value.
EbNoCoded = EbNoUncoded + 10*log10(K/N); channel.EbNo = EbNoCoded;
Loop the simulation until it reaches the target number of errors or the maximum number of transmissions.
chanErrorStats = zeros(3,1); codedErrorStats = zeros(3,1); correctedErrors = 0; while (codedErrorStats(2) < targetErrors) && ... (codedErrorStats(3) < maxNumTransmissions)
The data symbols transmit one message word at a time. Each message word has K
symbols in the range [0, N
].
data = randi([0 N],K,1);
Encode the message word. The encoded word, encData
, is (N
– numPunc
) symbols long.
encData = rsEncoder(data);
Modulate encoded data and add noise. Then demodulate channel output.
modData = qammod(encData,M); chanOutput = channel(modData); demodData = qamdemod(chanOutput,M);
Use the helperRSCodingGetErasures.m
helper function to find the six least reliable symbols and generate an erasures vector. The length of the erasures vector must be equal to the number of symbols in the demodulated codeword. A one in the ith element of the vector erases the ith symbol in the codeword. Zeros in the vector indicate no erasures.
erasuresVec = helperRSCodingGetErasures(chanOutput,numErasures);
Decode the data. Log the number of errors corrected by the RS decoder.
[estData,errs] = rsDecoder(demodData,erasuresVec); if (errs >= 0) correctedErrors = correctedErrors + errs; end
When computing the channel and coded BERs, convert integers to bits.
chanErrorStats(:,1) = ... chanBERCalc(int2bit(encData,log2(M)), ... int2bit(demodData,log2(M))); codedErrorStats(:,1) = ... codedBERCalc(int2bit(data,log2(M)), ... int2bit(estData,log2(M))); end
The error rate measurement objects, chanBERCalc
and codedBERCalc
, output 3-by-1 vectors containing BER measurement updates, the number of errors, and the total number of bit transmissions. Display the channel BER, the coded BER and the total number of errors corrected by the RS decoder.
chanBitErrorRate = chanErrorStats(1)
chanBitErrorRate = 0.0017
codedBitErrorRate = codedErrorStats(1)
codedBitErrorRate = 0
totalCorrectedErrors = correctedErrors
totalCorrectedErrors = 882
To run the simulation for a set of values, you can add a for
-loop around the processing loop above. For a simulation with uncoded values in the range 4:15 dB, a target number of errors equal to 5000, and maximum number of transmissions equal to , the results in the figure show that the channel BER is worse than the theoretical 64-QAM BER because is reduced by the code rate.
Helper Functions
Reed-Solomon Coding with Erasures and Punctures
This example shows how to configure the comm.RSEncoder
and comm.RSDecoder
System objects to perform Reed-Solomon (RS) block coding with erasures and puncture codes when simulating a communications system. An encoder can generate punctures to remove specific parity symbols from its output. Given the puncture pattern, the decoder inserts zeros in the puncture positions and treats those symbols as erasures. The decoder treats encoder-generated punctures and receiver-generated erasures in exactly the same way when it decodes. Puncturing provides code rate flexibility, but at the expense of some error correction capability.
In this example, you simulate a communications system that consists of a random source, an RS encoder, a 64-QAM modulator, an AWGN channel, a 64-QAM demodulator, and an RS decoder. You analyze the RS coding with erasures and puncturing by comparing the channel bit error rate (BER) performance versus the coded BER performance. You obtain the channel BER by comparing inputs for the QAM modulator to outputs from the QAM demodulator and the coded BER by comparing inputs for the RS encoder to outputs from the RS decoder.
Initialization
The helperRSCodingConfig.m helper function initializes the simulation parameters and configures the comm.AWGNChannel
and comm.ErrorRate
System objects that simulate the communications system. The helper function also sets the uncoded ratio (EbNoUncoded
) to 15 dB and the simulation stop criteria for 500 errors or a maximum bits are transmitted.
helperRSCodingConfig;
Configure RS Encoder/Decoder
This example uses the same (63,53) RS code operating with a 64-QAM modulation scheme that is configured for erasures and code puncturing. The RS algorithm decodes receiver-generated erasures and corrects encoder-generated punctures. For each codeword, the sum of the punctures and erasures cannot exceed twice the error-correcting capability of the code.
Create a comm.RSEncoder
System object and set the BitInput
property to false
so that the encoder inputs and outputs are integer symbols.
N = 63; % Codeword length K = 53; % Message length rsEncoder = comm.RSEncoder(N,K,BitInput=false); numErasures = 6;
Create a comm.RSDecoder
System object that matches the configuration of the comm.RSEncoder
object. Then set the ErasuresInputPort
property to true
to specify erasures as an input to the decoder object.
rsDecoder = comm.RSDecoder(N,K,BitInput=false); rsDecoder.ErasuresInputPort = true;
To enable code puncturing, set the PuncturePatternSource
property to 'Property'
and set the PuncturePattern
property to the desired puncture pattern vector. The same puncture vector must be specified in both the encoder and decoder. This example punctures two symbols from each codeword. Values of 1
in the puncture pattern vector indicate nonpunctured symbols, and values of 0
indicate punctured symbols.
numPuncs = 2; rsEnc.PuncturePatternSource = 'Property'; rsEnc.PuncturePattern = [ones(N-K-numPuncs,1); zeros(numPuncs,1)]; rsDec.PuncturePatternSource = 'Property'; rsDec.PuncturePattern = rsEnc.PuncturePattern;
Stream Processing Loop
Simulate the communications system for an uncoded ratio of 15 dB. The uncoded is the ratio that would be measured at the input of the channel if there were no coding in the system.
Since the signal going into the AWGN channel is the encoded signal, you must convert the uncoded values so that they correspond to the energy ratio at the encoder output. This ratio is the coded ratio. If you input K
symbols to the encoder and obtain N
output symbols, then the energy relation is given by the K/N
rate. Since the length of the codewords generated by the RS encoder is reduced by the number of punctures specified in the puncture pattern vector, the value of the coded ratio needs to be adjusted to account for these punctures. In this example, the number of output symbols is (N
– numPuncs
) and the uncoded ratio relates to the coded as shown below. Set the EbNo
property of the AWGN channel object to the computed coded value.
EbNoCoded = EbNoUncoded + 10*log10(K/(N - numPuncs)); channel.EbNo = EbNoCoded;
Loop the simulation until it reaches the target number of errors or the maximum number of transmissions.
chanErrorStats = zeros(3,1); codedErrorStats = zeros(3,1); correctedErrors = 0; while (codedErrorStats(2) < targetErrors) && ... (codedErrorStats(3) < maxNumTransmissions)
The data symbols transmit one message word at a time. Each message word has K
symbols in the range [0, N
].
data = randi([0 N],K,1);
Encode the message word. The encoded word, encData
, is (N
– numPunc
) symbols long.
encData = rsEncoder(data);
Modulate encoded data and add noise. Then demodulate channel output.
modData = qammod(encData,M); chanOutput = channel(modData); demodData = qamdemod(chanOutput,M);
Use the helperRSCodingGetErasures.m helper function to find the six least reliable symbols and generate an erasures vector. The length of the erasures vector must be equal to the number of symbols in the demodulated codeword. A one in the ith element of the vector erases the ith symbol in the codeword. Zeros in the vector indicate no erasures.
erasuresVec = helperRSCodingGetErasures(chanOutput,numErasures);
Decode the data. Log the number of errors corrected by the RS decoder.
[estData,errs] = rsDecoder(demodData,erasuresVec); if (errs >= 0) correctedErrors = correctedErrors+errs; end
When computing the channel and coded BERs, convert integers to bits.
chanErrorStats(:,1) = ... chanBERCalc(int2bit(encData,log2(M)), ... int2bit(demodData,log2(M))); codedErrorStats(:,1) = ... codedBERCalc(int2bit(data,log2(M)), ... int2bit(estData,log2(M))); end
The error rate measurement objects, chanBERCalc
and codedBERCalc
, output 3-by-1 vectors containing BER measurement updates, the number of errors, and the total number of bit transmissions. Display the channel BER, the coded BER and the total number of errors corrected by the RS decoder.
chanBitErrorRate = chanErrorStats(1)
chanBitErrorRate = 0.0015
codedBitErrorRate = codedErrorStats(1)
codedBitErrorRate = 0
totalCorrectedErrors = correctedErrors
totalCorrectedErrors = 632
To run the simulation for a set of values, you can add a for
-loop around the processing loop above. For a simulation with uncoded values in the range 4:15 dB, a target number of errors equal to 5000, and maximum number of transmissions equal to , the figure compares results for:
RS coding with only erasures
RS coding with erasures and puncturing
Theoretical BER for 64-QAM
The coded is slightly higher than the channel , so the channel BER is slightly better in the punctured case. On the other hand, the coded BER is worse in the punctured case because the two punctures reduce the error correcting capability of the code by one, leaving it able to correct only (10 – 6 – 2) / 2 = 1 error per codeword.
Help Functions
Reed-Solomon Coding with Erasures, Punctures, and Shortening
This example shows how to configure the comm.RSEncoder
and comm.RSDecoder
System objects to perform Reed-Solomon (RS) block coding that shortens a (63,53) code to a (28,18) code. You simulate a communications system that consists of a random source, an RS encoder, a 64-QAM modulator, an AWGN channel, a 64-QAM demodulator, and an RS decoder.
In this example, you analyze the effects of RS coding with erasures, puncturing, and shortening by comparing the channel bit error rate (BER) performance versus the coded BER performance. You obtain the channel BER by comparing inputs for the QAM modulator to outputs from the QAM demodulator and the coded BER by comparing inputs for the RS encoder to outputs from the RS decoder. Puncturing is the removal of parity symbols from a codeword, and shortening is the removal of message symbols from a codeword. Puncturing has the benefit of making the code rate more flexible, at the expense of some error correction capability. Shortened codes achieve the same code rate flexibility without degrading the error correction performance for the same demodulator input .
Initialization
The helperRSCodingConfig.m helper function initializes the simulation parameters and configures the comm.AWGNChannel
and comm.ErrorRate
System objects that simulate the communications system. The helper function also sets the uncoded ratio (EbNoUncoded
) to 15 dB and the simulation stop criteria for 500 errors or a maximum bits are transmitted.
helperRSCodingConfig;
Configure RS Encoder/Decoder
This example uses a (63,53) RS code operating with a 64-QAM modulation scheme. The RS coding operation includes erasures, puncturing, and code shortening. This example shows how to shorten the (63,53) code to a (28,18) code.
To shorten a (63,53) code by 10 symbols to a (53,43) code, you can simply enter 53 and 43 for the CodewordLength
and MessageLength
properties, respectively (since ). However, to shorten it by 35 symbols to a (28,18) code, you must explicitly specify that the symbols belong to the Galois field GF(26). Otherwise, the RS System objects assume that the code is shortened from a (31,21) code (since ).
Create a pair of comm.RSEncoder
and comm.RSDecoder
System objects so that they perform block coding with a (28,18) code shortened from a (63,53) code that is configured to input and output integer symbols. Configure the decoder to accept an erasure input and two punctures. For each codeword at the output of the 64-QAM demodulator, the receiver determines the six least reliable symbols by using the helperRSCodingGetErasures.m helper function. The indices that point to the location of these unreliable symbols are an input to the RS decoder.
N = 63; % Codeword length K = 53; % Message length S = 18; % Shortenened message length numErasures = 6; numPuncs = 2; rsEncoder = comm.RSEncoder(N,K, ... BitInput=false, ... PuncturePatternSource="Property", ... PuncturePattern = [ones(N-K-numPuncs,1); zeros(numPuncs,1)]); rsDecoder = comm.RSDecoder(N,K, ... BitInput=false, ... ErasuresInputPort=true, ... PuncturePatternSource="Property", ... PuncturePattern = rsEncoder.PuncturePattern);
Set the shortened codeword length and message length values.
rsEncoder.ShortMessageLength = S; rsDecoder.ShortMessageLength = S;
Specify the field of in the RS encoder/decoder System objects, by setting the PrimitivePolynomialSource
property to 'Property'
and the PrimitivePolynomial
property to a sixth degree primitive polynomial.
primPolyDegree = 6; rsEncoder.PrimitivePolynomialSource = 'Property'; rsEncoder.PrimitivePolynomial = ... int2bit(primpoly(primPolyDegree,'nodisplay'),7)'; rsDecoder.PrimitivePolynomialSource = 'Property'; rsDecoder.PrimitivePolynomial = ... int2bit(primpoly(primPolyDegree,'nodisplay'),7)';
Stream Processing Loop
Simulate the communications system for an uncoded ratio of 15 dB. The uncoded is the ratio that would be measured at the input of the channel if there were no coding in the system.
Since the signal going into the AWGN channel is the encoded signal, you must convert the uncoded values so that they correspond to the energy ratio at the encoder output. This ratio is the coded ratio. If you input K
symbols to the encoder and obtain N
output symbols, then the energy relation is given by the K/N
rate. Since the length of the codewords generated by the RS encoder is shortened and reduced by the number of punctures specified in the puncture pattern vector, the value of the coded ratio needs to be adjusted to account for the shortened code and the punctures. In this example, the number of output symbols is (N
– numPuncs
– S
) and the uncoded ratio relates to the coded as shown below. Set the EbNo
property of the AWGN channel object to the computed coded value.
EbNoCoded = EbNoUncoded + 10*log10(S/(N - numPuncs - K + S)); channel.EbNo = EbNoCoded;
Loop the simulation until it reaches the target number of errors or the maximum number of transmissions.
chanErrorStats = zeros(3,1); codedErrorStats = zeros(3,1); correctedErrors = 0; while (codedErrorStats(2) < targetErrors) && ... (codedErrorStats(3) < maxNumTransmissions)
The data symbols transmit one message word at a time. Each message word has (K
– S
) symbols in the range [0, (2^primPolyDegree
) – 1].
data = randi([0 2^primPolyDegree-1],S,1);
Encode the shortened message word. The encoded word encData
is (N
– numPuncs
– S
) symbols long.
encData = rsEncoder(data);
Modulate encoded data and add noise. Then demodulate channel output.
modData = qammod(encData,M); chanOutput = channel(modData); demodData = qamdemod(chanOutput,M);
Use the helperRSCodingGetErasures.m helper function to find the six least reliable symbols and generate an erasures vector. The length of the erasures vector must be equal to the number of symbols in the demodulated codeword. A one in the ith element of the vector erases the ith symbol in the codeword. Zeros in the vector indicate no erasures.
erasuresVec = helperRSCodingGetErasures(chanOutput,numErasures);
Decode the data. Log the number of errors corrected by the RS decoder.
[estData,errs] = rsDecoder(demodData,erasuresVec); if (errs >= 0) correctedErrors = correctedErrors + errs; end
When computing the channel and coded BERs, convert integers to bits.
chanErrorStats(:,1) = ... chanBERCalc(int2bit(encData,log2(M)), ... int2bit(demodData,log2(M))); codedErrorStats(:,1) = ... codedBERCalc(int2bit(data,log2(M)), ... int2bit(estData,log2(M))); end
The error rate measurement objects, chanBERCalc
and codedBERCalc
, output 3-by-1 vectors containing BER measurement updates, the number of errors, and the total number of bit transmissions. Display the channel BER, the coded BER, and the total number of errors corrected by the RS decoder.
chanBitErrorRate = chanErrorStats(1)
chanBitErrorRate = 0.0036
codedBitErrorRate = codedErrorStats(1)
codedBitErrorRate = 4.6399e-05
totalCorrectedErrors = correctedErrors
totalCorrectedErrors = 1416
To run the simulation for a set of values, you can add a for
-loop around the processing loop above. For a simulation with uncoded values in the range 4:15 dB, a target number of errors equal to 5000, and maximum number of transmissions equal to , the figure compares results for:
RS coding with only erasures
RS coding with erasures and puncturing
RS coding with erasures, puncturing, and shortening
Theoretical BER for 64-QAM
The BER out of the 64-QAM demodulator is worse with shortening than it is without shortening. The code rate of the shortened code is much lower than the code rate of the nonshortened code. Therefore, the coded into the demodulator is worse with shortening. A shortened code has the same error correcting capability as nonshortened code for the same , but the reduction in manifests in the form of a higher BER out of the RS decoder with shortening than without.
The coded is slightly higher than the channel , so the channel BER is slightly better than the coded BER in the shortened case. The degraded coded occurs because the code rate of the shortened code is lower than that of the nonshortened code. Shortening results in degraded coded BER, most noticeably at lower values.
Helper functions
Algorithms
This object implements Reed-Solomon (RS) coding as described in [3] and Algorithms for BCH and RS Errors-only Decoding.
Input and Output Signal Lengths in BCH and RS System Objects
The notation y = c * x
denotes that y
is an integer multiple of x
.
The number of punctures equals the number of zeros in the puncture vector.
M is the degree of the primitive polynomial. Each group of
M bits represents an integer in the range [0,
(2M–1)] that belongs to the finite
Galois field gf
(2M).
ShortMessageLengthSource | "Auto" | "Property" |
---|---|---|
and
| Input Length:
Output Length:
| Input Length:
Output Length:
|
and
| Input Length:
Output Length:
Erasures Length:
| Input Length:
Output Length:
Erasures Length:
|
| Input Length:
Output Length:
| Input Length:
Output Length:
|
| Input Length:
Output Length:
Erasures Length:
| Input Length:
Output Length:
Erasures Length:
|
References
[1] Blahut, Richard E. Algebraic Codes for Data Transmission. Cambridge University Press, 2003.
[2] Wicker, Stephen B., Error Control Systems for Digital Communication and Storage. Upper Saddle River, NJ, Prentice Hall, 1995.
[3] Clark, George C., and J. Bibb Cain. Error-Correction Coding for Digital Communications. Applications of Communications Theory. New York: Plenum Press, 1981.
[4] Berlekamp, Elwyn R., Algebraic Coding Theory, New York, McGraw-Hill, 1968.
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).
When you use this object to generate code, you must set the generator polynomial to a double-precision integer row vector.
Version History
Introduced in R2012a
See Also
Objects
Functions
Topics
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)