TPC Encoder
Turbo product code (TPC) encoder
Libraries:
Communications Toolbox /
Error Detection and Correction /
Block
Description
The TPC Encoder block performs 2D turbo product code (TPC) encoding of an input message. The product code is a 2D concatenation of linear block codes. The linear block codes can be a parity check code, a Hamming code, or a BCH code capable of correcting two errors. Extended and shortened codes can be applied independently on each dimension. For a description of 2D TPC encoding, see Turbo Product Code Construction.
For information about valid code pairs and the errorcorrecting capability for each valid code pair, see Component Code Pairs.
Examples
Turbo Product Code Error Rate Calculation
Perform error rate calculations for a transmission signal that has been TPC encoded and decoded.
A random signal is TPC encoded, QPSK modulated, filtered through an AWGN channel, and QPSK demodulated. The bipolar mapping is converted from negative to positive mapping and then the signal is TPC decoded. An error rate calculation compares the original message to the recovered message.
Open Example Model and Explore Its Contents
Several settings must be aligned with each other to synchronize encoding and decoding of the message. Start by deciding on a code rate, and aligning the TPC Encoder
and TPC Decoder
2D [N,K] pairs. For this example the default settings are used, [Nr,Kr] = [15,11] and [Nc,Kc] = [32,26].
The number of samples per frame and the sample time used by the Bernoulli Binary Generator
block are determined based on the message length parameters, Number of rows in message, Kr
and Number of columns in message, Kc
.
Number of samples per frame = (Kr*Kc) = 286
Sample time = 1/(Kr*Kc) = 0.0035.
The white Gaussian noise the SNR setting is calculated based on the coding rate, modulation order, and Eb/N0.
Modulation order, M = 2
Eb/N0 = 11
rate = (Kr*Kc)/((NrKr)*(NcKc)) = 14.3
snr = 10*log10(M*rate*10^(ebn0/10)) = 3.5637
The noise variance used in the QPSK Demodulator Baseband
block is calculated based on the SNR.
Noise variance = 1/10^(snr/10) = 1/10^(3.5637/10) = 0.4402
Run the model and observe the error rate calculation. Results will vary from run to run due to the use of random input data.
Bit error rate: 0.00042
Further Exploration
To run the model yourself, open the example using the button provided or by entering open slex_tpc_err_rate_calc
at the MATLAB® command prompt. Consider modifying the model to change the signal to noise ratio. When adjusting TPC Encoder
settings be sure to align settings in the TPC Decoder
, Bernoulli Binary Generator
, AWGN Channel
, and QPSK Demodulator Baseband
.
Ports
Input
In — Message to encode
column vector
Input message bits to encode, specified as a column vector.
For fulllength input messages, the length of the column vector must be the product of Number of rows in message, Kr and Number of columns in message, Kc.
For shortened input messages, the length of the column vector must be the product of Number of rows in shortened message, Sr and Number of columns in shortened message, Sc.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 Boolean
Output
Out — TPCencoded message
column vector
TPCencoded message, returned as a column vector with the same data type as the input signal.
For fulllength input messages, the length of the column vector is the product of Number of rows in code, Nr and Number of columns in code, Nc.
For shortened input messages, the length of the column vector is the product of (N_{R}–K_{R}+S_{R}) and (N_{C}–K_{C}+S_{C}), where:
N_{R} is the value of Number of rows in code, Nr.
K_{R} is the value of Number of rows in message, Kr.
S_{R} is the value of Number of rows in shortened message, Sr.
N_{C} is the value of Number of columns in code, Nc.
K_{C} is the value of Number of columns in message, Kc.
S_{C} is the value of Number of columns in shortened message, Sc.
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink^{®} Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Row TPC parametersExtended codes — Extended codes indicator for TPC row parameters
on
(default)  off
When Extended codes is selected, the lists for Number of rows in code, Nr and Number of rows in message, Kr contain the valid values for extended individual code pairs (N_{R},K_{R}).
When Extended codes is cleared, the lists for Number of rows in code, Nr and Number of rows in message, Kr contain the valid values for nonextended individual code pairs (N_{R},K_{R}).
Number of rows in code, Nr — Number of rows in product code matrix
16
(default)  integer
Number of rows in the product code matrix, N_{R}. The list of integer values varies depending on the setting for Extended codes.
Number of rows in message, Kr — Number of rows in message matrix
11
(default)  integer
Number of rows in the message matrix, K_{R}. The list of integer values varies depending on the setting for Extended codes and Number of rows in code, Nr.
Specify shortened message length — Specify shortened message length for rows
off
(default)  on
Select Specify shortened message length to specify a value for Number of rows in shortened message, Sr.
Number of rows in shortened message, Sr — Number of rows in shortened message matrix
9
(default)  integer
Number of rows in the shortened message matrix, S_{R}, specified as an integer less than or equal to K_{R}. When you specify this parameter, provide fulllength N_{R} and K_{R} values to specify the (N_{R},K_{R}) code pair. This code pair is then shortened to the (N_{R}–K_{R}+S_{R},S_{R}) code pair, where:
N_{R} is the value of Number of rows in code, Nr.
K_{R} is the value of Number of rows in message, Kr.
S_{R} is the value of Number of rows in shortened message, Sr.
Dependencies
To enable this parameter, select Specify shortened message length.
Extended codes — Extended codes indicator for TPC column parameters
on
(default)  off
When Extended codes is selected, the lists for Number of columns in code, Nc and Number of columns in message, Kc contain the valid values for extended individual code pairs (N_{C},K_{C}).
When Extended codes is cleared, the lists for Number of columns in code, Nc and Number of columns in message, Kc contain the valid values for nonextended individual code pairs (N_{C},K_{C}).
Number of columns in code, Nc — Number of columns in product code matrix
32
(default)  integer
Number of columns in the product code matrix, N_{C}. The list of integer values varies depending on the setting for Extended codes.
Number of columns in message, Kc — Number of columns in message matrix
26
(default)  integer
Number of columns in the message matrix, K_{C}. The list of integer values varies depending on the setting for Extended codes and Number of columns in code, Nc.
Specify shortened message length — Specify shortened message length for columns
off
(default)  on
Select Specify shortened message length to specify a value for Number of columns in shortened message, Sc.
Number of columns in shortened message, Sc — Number of columns in shortened message matrix
22
(default)  integer
Number of columns in the shortened message matrix, S_{C}, specified as an integer. When you specify this parameter, provide fulllength N_{C} and K_{C} values to specify the (N_{C},K_{C}) code pair. This code pair is then shortened to the (N_{C}–K_{C}+S_{C}, S_{C}) code pair, where:
N_{C} is the value of Number of columns in code, Nc.
K_{C} is the value of Number of columns in message, Kc.
S_{C} is the value of Number of columns in shortened message, Sc.
Dependencies
To enable this parameter, select Specify shortened message length.
Simulate using — Type of simulation to run
Code generation
(default)  Interpreted execution
Type of simulation to run, specified as Code generation
or
Interpreted execution
.
Code generation
— Simulate the model by using generated C code. The first time you run a simulation, Simulink generates C code for the block. The model reuses the C code for subsequent simulations unless the model changes. This option requires additional startup time, but the speed of the subsequent simulations is faster than with theInterpreted execution
option.Interpreted execution
— Simulate the model by using the MATLAB^{®} interpreter. This option shortens startup time, but the speed of subsequent simulations is slower than with theCode generation
option. In this mode, you can debug the source code of the block.
For more information, see Interpreted Execution vs. Code Generation (Simulink).
Block Characteristics
Data Types 

Multidimensional Signals 

VariableSize Signals 

More About
Component Code Pairs
This table lists the supported component code pairs for the row (N_{R},K_{R}) and column (N_{C},K_{C}) parameters.
N_{R} and K_{R} represent the number of rows in the product code matrix and message matrix, respectively.
N_{C} and K_{C} represent the number of columns in the product code matrix and message matrix, respectively.
Within each code type, any two component code pairs can form a 2D TPC code. The table also includes the errorcorrection capability for each code pair.
Code type  Component Code Pairs(N_{R},K_{R}) and (N_{C},K_{C})  ErrorCorrection Capability (T) 
Hamming code  (255,247)  1 
(127,120)  1  
(63,57)  1  
(31,26)  1  
(15,11)  1  
(7,4)  1  
Extended Hamming code  (256,247)  1 
(128,120)  1  
(64,57)  1  
(32,26)  1  
(16,11)  1  
(8,4)  1  
BCH code  (255,239)  2 
(127,113)  2  
(63,51)  2  
(31,21)  2  
(15,7)  2  
Extended BCH code  (256,239)  2 
(128,113)  2  
(64,51)  2  
(32,21)  2  
(16,7)  2  
Parity check code  (256,255)   
(128,127)    
(64,63)    
(32,31)    
(16,15)    
(8,7)    
(4,3)   
Turbo Product Code Construction
Turbo product codes (TPC) are a form of concatenated codes used as forward errorcorrecting (FEC) codes. Two or more component block codes, such as systematic linear block codes, are used to construct TPCs. This encoder implements 2D product code encoding, as described in [1], using two Linear Block Codes.
The TPC encoder accepts either fulllength or shortened messages.
Construction of FullLength Message Product Codes
Fulllength input messages are encoded using specified 2D TPC code pairs. Rowwise encoding uses the (N_{C},K_{C}) code pair and columnwise encoding uses the (N_{R},K_{R}) code pair. The input vector length must be K_{R} · K_{C}. The input message bits vector is arranged into a K_{R}byK_{C} matrix.
Rowwise encoding uses an (N_{C},K_{C}) systematic linear block encoder with K_{C} bits per row. The rowwise encoding results in a K_{R}byN_{C} matrix that includes parity bits added to each row.
Next, columnwise encoding uses an (N_{R},K_{R}) systematic linear block encoder on each of the N_{C} columns. Applying this 2D TPC encoding to the initial K_{R}byK_{C} matrix results in an N_{R}byN_{C} matrix that includes parity bits added to each row and column.
The 2D TPC fullcode matrix is reshaped into a column vector of length N_{R} · N_{C} and returned as the TPCencoded output.
Construction of Shortened Message Product Codes
Shortened input messages are encoded using specified 2D TPC code pairs. Rowwise encoding uses the (N_{C},K_{C}) code pair and columnwise encoding uses an (N_{R},K_{R}) code pair. The input vector length must be S_{R} · S_{C}. The input shortened message bits vector is arranged into an S_{R}byS_{C} matrix. The shortened message matrix prepends two dimensions by padding the beginning of the message matrix with zeros. The resulting matrix is a K_{R}byK_{C} matrix.
Rowwise encoding uses an (N_{C},K_{C}) systematic linear block encoder with K_{C} bits per row. The rowwise encoding results in a K_{R}byN_{C} matrix that includes parity bits added to each row.
Next, the columnwise encoding uses an (N_{R},K_{R}) systematic linear block encoder on each of the N_{C} columns.
Applying this 2D TPC encoding to the initial K_{R}byK_{C} matrix and excluding the zeropadded bits from the output results in an (N_{R}–K_{R}+S_{R})by(N_{C}–K_{C}+S_{C}) matrix. This matrix includes parity bits added to each row and column.
The 2D TPC shortenedcode matrix is reshaped into a column vector of length (N_{R}–K_{R}+S_{R}) · (N_{C}–K_{C}+S_{C}) and returned as the TPCencoded output.
References
[1] Pyndiah, R. M. "NearOptimum Decoding of Product Codes: Block Turbo Codes." IEEE Transactions on Communications. Vol. 46, Number 8, August 1998, pp. 1003–1010.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2018b
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)