1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
function [isOk, status] = istrellis(S)
// This function checks if the given input is of trellis structure
// Calling Sequence
// [ISOK, STATUS] = ISTRELLIS(S)
//
// Description
// [ISOK, STATUS] = ISTRELLIS(S) returns [T,''] if the given input is valid trellis structure. Otherwise ISOK is F and STATUS
// indicates the reason for invalidity
// Fields in trellis structure are
// numInputSymbols, (number of input symbols)
// numOutputSymbols, (number of output symbols)
// numStates, (number of states)
// nextStates, (next state matrix)
// outputs, (output matrix)
// Properties of the fields are as follows
// numInputSymbols and numOutputSymbols should be a power of 2 (as data is represented in bits).
// The 'nextStates' and 'outputs' fields are matrices of size 'numStates' x 'numInputSymbols' .
// Each element in the 'nextStates' matrix and 'output' matrix is an integer value between zero and (numStates-1).
// The (r,c) element of the 'nextStates' matrix and 'output' matrix,denotes the next state and output respectively when
// the starting state is (r-1) and the input bits have decimal representation (c-1).
// To convert to decimal value, use the first input bit as the most significant bit (MSB).
// Examples
// Valid trellis structure
// trellis.numInputSymbols = 4;
// trellis.numOutputSymbols = 4;
// trellis.numStates = 3;
// trellis.nextStates = [0 1 2 1;0 1 2 1; 0 1 2 1];
// trellis.outputs = [0 0 1 1;1 1 2 1; 1 0 1 1];
// [isok,status] = istrellis(trellis)
// Inavlid trellis structure
// trellis.numInputSymbols = 3;
// trellis.numOutputSymbols = 3;
// trellis.numStates = 3;
// trellis.nextStates = [0 1 2 ;0 1 2 ; 0 1 2 ];
// trellis.outputs = [0 0 1 ;1 1 2 ; 1 0 1 ];
// [isok,status] = istrellis(trellis)
// See also
// iscatastrophic
// Authors
// Pola Lakshmi Priyanka, IIT Bombay//
//*************************************************************************************************************************************//
// Check arguments
[out_a,inp_a]=argn(0)
if (inp_a~=1 | out_a>2) then
error('comm:istrellis:Invalid number of arguments')
end
status = '';
// Check if input is a structure
isOk = isstruct(S);
if ~isOk then
status = string(('comm:trellis:Input is not a structure'));
return;
end
// Check for valid field names
names = fieldnames(S);
numf = size(names, 1);
actual = {'numInputSymbols';'numOutputSymbols';'numStates';'nextStates';'outputs'}
isOk = (numf == 5) & isequal(gsort(names),gsort(actual));
if ~isOk then
status = string(('comm:trellis:Structure is not of trellis type'));
return;
end
// Check for number of Input Symbols.
numInputSymbols = S.numInputSymbols;
isOk = isequal(length(numInputSymbols), 1);
if ~isOk then
status = string(('comm:trellis:Number of input symbols is not scalar'));
return;
end
power = log2(numInputSymbols);
isOk = isequal(power, double(int32(power)));
if ~isOk then
status = string(('comm:trellis:Number of input symbols is not power of 2'));
return;
end
// Check for number of Output Symbols.
numOutputSymbols = S.numOutputSymbols;
isOk = isequal(length(numOutputSymbols), 1);
if ~isOk then
status = string(('comm:trellis:Number of output symbols is not scalar'));
return;
end
power = log2(numOutputSymbols);
isOk = isequal(power, double(int32(power)));
if ~isOk then
status = string(('comm:trellis:Number of input symbols is not power of 2'));
return;
end
//Check Number of states
isOk = isequal(length(S.numStates), 1) & ...
isequal(S.numStates, double(int32(S.numStates)));
if isOk then
isOk = S.numStates > 0;
end
if ~isOk then
status = string(('comm:trellis:Number of states is not scalar positive integer'));
return;
end
// Check nextStates
nextStates = S.nextStates;
numStates = S.numStates;
// Check size of nextStates
s = size(nextStates);
isOk = ((length(s) == 2) & (s(1) == numStates) & (s(2) == numInputSymbols) & isequal(double(uint32(nextStates)), nextStates));
if ~isOk then
status = string(('comm:trellis:Next states field matrix size is incorrect'));
return;
end
//Check values of nextState
isOk = isempty(find(nextStates >= numStates));
if ~isOk then
status = string(('comm:trellis: Elements in next state must be in between 0 to numStates - 1'));
return;
end
// Check outputs
outputs = S.outputs;
// check size of outputs
s = size(outputs);
isOk = ((length(s) == 2) & (s(1) == numStates) & (s(2)== numInputSymbols) );
if ~isOk then
status = string(('comm:trellis:Outputs field matrix size is incorrect'));
return;
end
//Check values of output
decOutputs = oct2dec(string(outputs));
isOk = isempty(find(decOutputs >= numOutputSymbols));
if ~isOk then
status = string(('comm:trellis: Elements in output must be in between 0 to numStates - 1 '));
return;
end
endfunction
|