istrellis
True for valid trellis structure
Description
Examples
Create User Defined Trellis Structure
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 symbolsnumOutputSymbols
– Number of output symbolsnumStates
– Number of statesnextStates
– Next state matrixoutputs
– 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);
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);
Check Resulting Trellis Structure
istrellis(myTrellis)
ans = logical
1
A return value of 1
confirms the trellis structure is valid.
Input Arguments
s
— MATLAB® structure
struct
MATLAB structure to check, specified as a structure with the fields described in the table:
Field in Trellis Structure | Dimensions | Meaning |
---|---|---|
numInputSymbols | scalar | Number of input symbols to the encoder: 2k |
numOutputSymbols | scalar | Number of output symbols from the encoder: 2n |
numStates | scalar | Number of states in the encoder |
nextStates | numStates -by-2k matrix | Next states for all combinations of current state and current input |
outputs | numStates -by-2k matrix | Outputs (in octal) for all combinations of current state and current input |
Data Types: struct
Output Arguments
isok
— True or false
0
| 1
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
status
— Reason for a false isok
result
character vector
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
Fields of a Valid Trellis Structure
A valid trellis MATLAB trellis structure for a rate k/n code has these fields:
Field in Trellis Structure | Dimensions | Meaning |
---|---|---|
numInputSymbols | scalar | Number of input symbols to the encoder: 2k |
numOutputSymbols | scalar | Number of output symbols from the encoder: 2n |
numStates | scalar | Number of states in the encoder |
nextStates | numStates -by-2k matrix | Next states for all combinations of current state and current input |
outputs | numStates -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
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)