Main Content

comm.TurboEncoder

Encode input signal using parallel concatenated encoding scheme

Description

The comm.TurboEncoder System object™ applies a parallel concatenated encoding scheme to a binary input message. This coding scheme uses two identical convolutional encoders and appends the termination bits at the end of the encoded data bit stream. For more information, see Parallel Concatenated Convolutional Encoding Scheme.

To encode a binary input message using a parallel concatenated encoding scheme:

  1. Create the comm.TurboEncoder object and set its properties.

  2. 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

Description

example

turboenc = comm.TurboEncoder creates a turbo encoder System object. This object performs turbo encoding using the default object configuration.

example

turboenc = comm.TurboEncoder(Name,Value) sets properties using one or more name-value pairs. For example, comm.TurboEncoder('InterleaverIndicesSource','Input port') configures a turbo encoder System object with the interleaver indices to be supplied as an input argument to the System object when it is called. Enclose each property name in quotes.

example

turboenc = comm.TurboEncoder(trellis,interlvrindices) creates a turbo encoder System object with the TrellisStructure and InterleaverIndices properties set to trellis and interlvrindices, respectively. The trellis input must be specified as described by the TrellisStructure property. The interlvrindices input must be specified as described by the InterleaverIndices property.

Properties

expand all

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.

Trellis description of the constituent convolutional code, specified as a structure that contains the trellis description for a rate K/N code. K is the number of input bit streams, and N is the number of output bit streams.

Note

K must be 1 for the turbo coder. For more information, see Coding Rate.

You can either use the poly2trellis function to create the trellis structure or create it manually. For more about this structure, see Trellis Description of a Convolutional Code and the istrellis function.

The trellis structure contains these fields.

Number of symbols input to the encoder, specified as an integer equal to 2K, where K is the number of input bit streams.

Data Types: double

Number of symbols output from the encoder, specified as an integer equal to 2N, where N is the number of output bit streams.

Data Types: double

Number of states in the encoder, specified as a power of 2.

Data Types: double

Next states for all combinations of current states and current inputs, specified as a matrix of integers. The matrix size must be numStates-by-2K.

Data Types: double

Outputs for all combinations of current states and current inputs, specified as a matrix of octal numbers. The matrix size must be numStates-by-2K.

Data Types: double

Data Types: struct

Source of interleaver indices, specified as 'Property' or 'Input port'.

  • When you set this property to 'Input port', the object executes using the input interleaver indices, set when you call the object. The vector length and values for the interleaver indices and binary input message can change with each call to the object.

  • When you set this property to 'Property', the object uses the interleaver indices that you specify for the InterleaverIndices property.

Data Types: char | string

Interleaver indices, specified as a column vector of integers. The vector must be of length L, where L is the length of the binary input message. Each element of the vector must be an integer in the range [1, L] and must be unique. The interleaver indices define the mapping used to permute the input bits at the encoder.

Tunable: Yes

Dependencies

To enable this property, set the InterleaverIndicesSource property to 'Property'.

Data Types: double

Usage

Description

example

codeword = turboenc(message) encodes the input message using the parallel concatenated convolutional encoding scheme specified by the trellis structure and interleaver indices. turboenc returns the binary encoded codeword. message and codeword are column vectors of numeric, logical, or unsigned fixed-point values with word length 1 (fi (Fixed-Point Designer) object). For more information, see Parallel Concatenated Convolutional Encoding Scheme.

example

codeword = turboenc(message,interlvrindices) additionally specifies the interleaver indices. interlvrindices must be a column vector containing integers in the range [1, L] with no repeated values. L is the length of the binary input message, message. This syntax applies when the InterleaverIndicesSource property is set to 'Input port'. The interleaver indices define the mapping used to permute the input bits at the encoder.

Input Arguments

expand all

Input message, specified as a binary column vector of length L, where L is the length of the uncoded input message.

Data Types: double | int8 | fi(data,0,1)

Output Arguments

expand all

Parallel concatenated codeword, returned as a binary column vector of length M, where M is the number of bits in the parallel concatenated codeword. This output inherits its data type from the message input.

Data Types: double | int8 | fi(data,0,1)

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)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Encode an input message by using a rate 1/3 turbo encoder configuration with the default trellis structure, poly2trellis(4,[13 15],13), as represented in this figure.

For an input message with 64 bits, the codeword output from the encoder is 204 bits. The first 192 bits output correspond to the three 64 bit streams, interlaced as Xk, Zk, and Zk. The systematic bit stream, Xk, and parity bit stream, Zk, are from the first encoder and the parity bit stream, Zk, is from the second encoder. When the switches are in the lower position, signals follow the dashed lines and the last 12 bits correspond to the tail bits from the two encoders. The first group of six bits (three systematic bits and three parity bits) are the output tail bits from the first constituent encoder. The second group of six bits (three systematic bits and three parity bits) are the output tail bits from the second constituent encoder.

Create a turbo encoder using the default settings. Generate a frame of binary message data, and then encode the message data.

rng default
turboenc = comm.TurboEncoder;
frameLen = 64; % Frame length
data = randi([0 1],frameLen,1);
encData = turboenc(data);
codewordLen = length(encData);

Compute the coding rate. Due to the tail bits, the encoder output code rate is slightly less than 1/3.

codingrate = frameLen/codewordLen
codingrate = 0.3137

Simulate the transmission and reception of BPSK data over an AWGN channel by using turbo encoding and decoding.

Specify simulation parameters, and then compute the effective coding rate and noise variance. For BPSK modulation, ES/N0 equals Eb/N0 because the number of bits per symbol (bps) is 1. To ease reuse of this code for other modulation schemes, calculations in this example include the bps terms. Define the packet length, trellis structure, and number of iterations. Calculate the noise variance using ES/N0 and the code rate. Set the random number generator to its default state to ensure that the results are repeatable.

modOrd = 2; % Modulation order
bps = log2(modOrd); % Bits per symbol
EbNo = 1; % Energy per bit to noise power spectral density ratio in dB
EsNo = EbNo + 10*log10(bps); % Energy per symbol to noise power spectral density ratio in dB

L = 256; % Input packet length in bits
trellis = poly2trellis(4,[13 15 17],13);
numiter = 4;
n = log2(trellis.numOutputSymbols);
numTails = log2(trellis.numStates)*n;
M = L*(2*n - 1) + 2*numTails; % Output codeword packet length
rate = L/M; % Coding rate

snrdB = EsNo + 10*log10(rate); % Signal to noise ratio in dB
noiseVar = 1./(10.^(snrdB/10)); % Noise variance

rng default

Generate random interleaver indices.

intrlvrIndices = randperm(L);

Create a turbo encoder and decoder pair. Use the defined trellis structure and random interleaver indices. Configure the decoder to run a maximum of four iterations.

turboenc = comm.TurboEncoder(trellis,intrlvrIndices);
turbodec = comm.TurboDecoder(trellis,intrlvrIndices,numiter);

Create a BPSK modulator and demodulator pair, where the demodulator outputs soft bits determined using an LLR method.

bpskmod = comm.BPSKModulator;
bpskdemod = comm.BPSKDemodulator('DecisionMethod','Log-likelihood ratio', ...
    'Variance',noiseVar);

Create an AWGN channel object and an error rate object.

awgnchan = comm.AWGNChannel('NoiseMethod','Variance','Variance',noiseVar);
errrate = comm.ErrorRate;

The main processing loop performs these steps.

  1. Generate binary data.

  2. Turbo encode the data.

  3. Modulate the encoded data.

  4. Pass the modulated signal through an AWGN channel.

  5. Demodulate the noisy signal by using LLR to output soft bits.

  6. Turbo decode the demodulated data. Because the bit mapping from the demodulator is opposite of the mapping expected by the turbo decoder, the decoder input must use the inverse of the demodulated signal.

  7. Calculate the error statistics.

for frmIdx = 1:100
    data = randi([0 1],L,1);
    encodedData = turboenc(data);
    modSignal = bpskmod(encodedData);
    receivedSignal = awgnchan(modSignal);
    demodSignal = bpskdemod(receivedSignal);
    receivedBits = turbodec(-demodSignal);
    errorStats = errrate(data,receivedBits);
end

Display the error data.

fprintf('Bit error rate = %5.2e\nNumber of errors = %d\nTotal bits = %d\n', errorStats)
Bit error rate = 2.34e-04
Number of errors = 6
Total bits = 25600

Simulate an end-to-end communication link by using a 16-QAM signal and turbo codes in an AWGN channel. Inside a frame processing loop, packet sizes are randomly selected to be 500, 1000, or 1500 bits. Because the packet size varies, the interleaver indices are provided to the turbo encoder and decoder as an input argument of their associated System object.

Set the modulation order and Eb/N0. Compute the number of bits per symbol and the energy per symbol to noise ratio (ES/N0) based on the modulation order and Eb/N0. To get repeatable results, set the random number generator to its default state.

modOrder = 16;
bps = log2(modOrder); % Bits per symbol
EbNo = 2.8; % Energy per bit to noise power spectral density ratio in dB
EsNo = EbNo + 10*log10(bps); % Energy per symbol to noise power spectral density ratio in dB
rng default

Create a turbo encoder and decoder pair. Because the packet length varies for each frame, specify that the interleaver indices be supplied by an input argument of the System object when executed. Specify that the decoder perform four iterations.

turboEnc = comm.TurboEncoder('InterleaverIndicesSource','Input port');
turboDec = comm.TurboDecoder('InterleaverIndicesSource','Input port','NumIterations',4);
trellis = poly2trellis(4,[13 15 17],13);
n = log2(turboEnc.TrellisStructure.numOutputSymbols);
numTails = log2(turboEnc.TrellisStructure.numStates)*n;

Create an error rate object.

errRate = comm.ErrorRate;

The frame processing loop performs these steps.

  1. Select a random packet length, and generate random binary data.

  2. Compute the output codeword length and coding rate.

  3. Compute the signal to noise ratio (SNR) and noise variance.

  4. Generate interleaver indices.

  5. Turbo encode the data.

  6. Apply 16-QAM modulation, and normalize the average signal power.

  7. Pass the modulated signal through an AWGN channel.

  8. Demodulate the noisy signal by using an LLR method, output soft bits, and normalize the average signal power.

  9. Turbo decode the data. Because the bit mapping order from the demodulator is opposite the mapping order expected by the turbo decoder, the decoder input must use the inverse of the demodulated signal.

  10. Calculate the error statistics.

numFrames = 100;
for pktIdx = 1:numFrames
    L = 500*randi([1 3],1,1); % Packet length in bits
    data = randi([0 1],L,1);

    M = L*(2*n - 1) + 2*numTails; % Output codeword packet length
    rate = L/M; % Coding rate for current packet
    snrdB = EsNo + 10*log10(rate); % Signal to noise ratio in dB
    noiseVar = 1./(10.^(snrdB/10)); % Noise variance
    
    intrlvrIndices = randperm(L);
    encodedData = turboEnc(data,intrlvrIndices);
    modSignal = qammod(encodedData,modOrder,'InputType','bit','UnitAveragePower',true);
    receivedSignal = awgn(modSignal,snrdB);
    demodSignal = qamdemod(receivedSignal,modOrder,'OutputType','llr', ...
        'UnitAveragePower',true,'NoiseVariance',noiseVar);
    receivedBits = turboDec(-demodSignal,intrlvrIndices); % Demodulated signal is negated
    
    errorStats = errRate(data,receivedBits);
end

Display the error data.

fprintf('Bit error rate = %5.2e\nNumber of errors = %d\nTotal bits = %d\n',errorStats)
Bit error rate = 8.51e-04
Number of errors = 80
Total bits = 94000

More About

expand all

References

[1] Berrou, C., A. Glavieux, and P. Thitimajshima. “Near Shannon Limit Error-Correcting Coding and Decoding: Turbo-Codes.” Proceedings of ICC 93 - IEEE International Conference on Communications, Geneva, Switzerland, May 1993, 1064–70. https://doi.org/10.1109/icc.1993.397441.

[2] Benedetto, S., G. Montorsi, D. Divsalar, and F. Pollara. "A Soft-Input Soft-Output Maximum A Posterior (MAP) Module to Decode Parallel and Serial Concatenated Codes." Jet Propulsion Lab TDA Progress Report, 42–127, (November 1996).

[3] Schlegel, Christian, and Lance Perez. Trellis and Turbo Coding. IEEE Press Series on Digital & Mobile Communication. Piscataway, NJ ; Hoboken, NJ: IEEE Press ; Wiley-Interscience, 2004.

[4] 3GPP TS 36.212. "Multiplexing and channel coding." 3rd Generation Partnership Project; Technical Specification Group Radio Access Network; Evolved Universal Terrestrial Radio Access (E-UTRA). https://www.3gpp.org.

Extended Capabilities

Introduced in R2012a