-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathm_fTransMat.m
53 lines (45 loc) · 1.58 KB
/
m_fTransMat.m
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
function m_fTransition = m_fTransMat(s_nConst, s_nMemSize, v_fXtrain)
% Generate state transition matrix
%
% Syntax
% -------------------------------------------------------
% m_fTransition = m_fTransMat(s_nConst, s_nMemSize)
%
% INPUT:
% -------------------------------------------------------
% s_nConst - constellation size (positive integer)
% s_nMemSize - channel memory length
%
%
% OUTPUT:
% -------------------------------------------------------
% m_fTransition - transition probaiblity matrix
% row = current state
% column = previous state
s_nStates = s_nConst^s_nMemSize;
% Generate transition matrix
m_fTransition = zeros(s_nStates,s_nStates);
% Uniform transitions
if isempty(v_fXtrain)
for ii=1:s_nStates
Idx = mod(ii -1, s_nConst^(s_nMemSize-1));
for ll=1:s_nStates
if (floor((ll-1)/s_nConst) == Idx)
m_fTransition(ii,ll) = m_fTransition(ii,ll) + 1/s_nConst;
end
end
end
% Learn transition from training
else
% Reshape input symbols into a matrix representation
m_fXtrain = m_fMyReshape(v_fXtrain, s_nMemSize);
% Combine each set of inputs as a single unique category
v_fCombineVec = s_nConst.^(0:s_nMemSize-1);%
% Convert to states ordered sequentially
v_fS = 1+(v_fCombineVec*(m_fXtrain-1))';
for ii=1:(length(v_fS)-1)
m_fTransition(v_fS(ii+1),v_fS(ii)) = m_fTransition(v_fS(ii+1),v_fS(ii)) +1;
end
% Normalize columns to unit
m_fTransition = m_fTransition./sum(m_fTransition);
end