Main Content

istrellis

True for valid trellis structure

Description

[isok,status] = istrellis(s) checks if the input s is a valid trellis structure. If the input is a valid trellis structure, isok is 1 and status is an empty character vector. Otherwise, isok is 0 and status indicates why s is not a valid trellis structure.

example

Examples

collapse all

This example demonstrates creation of a nonstandard trellis structure for a convolutional encoder with uncoded bits and feedback. The encoder cannot be created using poly2trellis because the peculiar specifications for the encoder do not match the input requirements of poly2trellis.

You can manually create the trellis structure, and then use it as the input trellis structure for an encoder and decoder. The Convolutional Encoder and Viterbi Decoder blocks used in the Convolutional Encoder with Uncoded Bits and Feedback model load the trellis structure created here using a PreLoadFcn callback.

Convolutional Encoder

Create a rate 3/4 convolutional encoder with feedback connection whose MSB bit remains uncoded.

Declare variables according to the specifications.

K = 3;
N = 4;
constraintLength = 4;

Create trellis structure

A trellis structure has the following fields:

  • numInputSymbols – Number of input symbols

  • numOutputSymbols – Number of output symbols

  • numStates – Number of states

  • nextStates – Next state matrix

  • outputs – Output matrix

For more information about these structure fields, see istrellis.

Reset any previous occurrence of myTrellis structure.

clear myTrellis;

Define the trellis structure fields.

myTrellis.numInputSymbols = 2^K;
myTrellis.numOutputSymbols = 2^N;
myTrellis.numStates  = 2^(constraintLength-1);

Create nextStates Matrix

The nextStates matrix is a [numStates x numInputSymbols] matrix. The (i,j) element of the next state matrix is the resulting final state index that corresponds to a transition from the initial state i for an input equal to j.

myTrellis.nextStates = [0  1  2  3  0  1  2  3; ...
                        6  7  4  5  6  7  4  5; ...
                        1  0  3  2  1  0  3  2; ...
                        7  6  5  4  7  6  5  4; ...
                        2  3  0  1  2  3  0  1; ...
                        4  5  6  7  4  5  6  7; ...
                        3  2  1  0  3  2  1  0; ...
                        5  4  7  6  5  4  7  6]    
myTrellis = struct with fields:
     numInputSymbols: 8
    numOutputSymbols: 16
           numStates: 8
          nextStates: [8x8 double]

Plot nextStates Matrix

Use the commcnv_plotnextstates helper function to plot the nextStates matrix to illustrate the branch transitions between different states for a given input.

commcnv_plotnextstates(myTrellis.nextStates);

MATLAB figure

Create outputs Matrix

The outputs matrix is a [numStates x numInputSymbols] matrix. The (i,j) element of the output matrix is the output symbol in octal format given a current state i for an input equal to j.

outputs =  [0  2  4  6  10  12  14  16; ...
            1  3  5  7  11  13  15  17; ...
            0  2  4  6  10  12  14  16; ...
            1  3  5  7  11  13  15  17; ...
            0  2  4  6  10  12  14  16; ...
            1  3  5  7  11  13  15  17; ...
            0  2  4  6  10  12  14  16; ...
            1  3  5  7  11  13  15  17]
outputs = 8×8

     0     2     4     6    10    12    14    16
     1     3     5     7    11    13    15    17
     0     2     4     6    10    12    14    16
     1     3     5     7    11    13    15    17
     0     2     4     6    10    12    14    16
     1     3     5     7    11    13    15    17
     0     2     4     6    10    12    14    16
     1     3     5     7    11    13    15    17

Use oct2dec to display these values in decimal format.

outputs_dec = oct2dec(outputs)
outputs_dec = 8×8

     0     2     4     6     8    10    12    14
     1     3     5     7     9    11    13    15
     0     2     4     6     8    10    12    14
     1     3     5     7     9    11    13    15
     0     2     4     6     8    10    12    14
     1     3     5     7     9    11    13    15
     0     2     4     6     8    10    12    14
     1     3     5     7     9    11    13    15

Copy outputs matrix into the myTrellis structure.

myTrellis.outputs = outputs
myTrellis = struct with fields:
     numInputSymbols: 8
    numOutputSymbols: 16
           numStates: 8
          nextStates: [8x8 double]
             outputs: [8x8 double]

Plot outputs Matrix

Use the commcnv_plotoutputs helper function to plot the outputs matrix to illustrate the possible output symbols for a given state depending on the input symbol.

commcnv_plotoutputs(myTrellis.outputs, myTrellis.numOutputSymbols);

MATLAB figure

Check Resulting Trellis Structure

istrellis(myTrellis)
ans = logical
   1

A return value of 1 confirms the trellis structure is valid.

Input Arguments

collapse all

MATLAB structure to check, specified as a structure with the fields described in the table:

Field in Trellis StructureDimensionsMeaning
numInputSymbolsscalar Number of input symbols to the encoder: 2k
numOutputSymbolsscalar Number of output symbols from the encoder: 2n
numStatesscalar Number of states in the encoder
nextStatesnumStates-by-2k matrix Next states for all combinations of current state and current input
outputsnumStates-by-2k matrix Outputs (in octal) for all combinations of current state and current input

Data Types: struct

Output Arguments

collapse all

True or false result, returned as logical 1 (true) or 0 (false) indicating if the input is a valid trellis structure or not.

Data Types: logical

Reason for a false isok result, specified as a character vector. If isok is true, status is an empty character vector.

Data Types: char

More About

collapse all

Fields of a Valid Trellis Structure

A valid trellis MATLAB trellis structure for a rate k/n code has these fields:

Field in Trellis StructureDimensionsMeaning
numInputSymbolsscalar Number of input symbols to the encoder: 2k
numOutputSymbolsscalar Number of output symbols from the encoder: 2n
numStatesscalar Number of states in the encoder
nextStatesnumStates-by-2k matrix Next states for all combinations of current state and current input
outputsnumStates-by-2k matrix Outputs (in octal) for all combinations of current state and current input

In the nextStates matrix, each entry is an integer in the range [0, (numStates-1)]. The element in the sth row and uth column denotes the next state when the starting state is s-1 and the input bits have decimal representation u-1. To convert the input bits to a decimal value, use the first input bit as the most significant bit (MSB). For example, the second column of the nextStates matrix stores the next states when the current set of input values is {0,...,0,1}.

To convert the state to a decimal value, use this rule: If k exceeds 1, the shift register that receives the first input stream in the encoder provides the least significant bits in the state number, and the shift register that receives the last input stream in the encoder provides the most significant bits in the state number.

In the outputs matrix, the element in the sth row and uth column denotes the encoder's output when the starting state is s-1 and the input bits have decimal representation u-1. To convert to decimal value, use the first output bit as the MSB.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a