-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCodMatrix.m
70 lines (55 loc) · 2.23 KB
/
getCodMatrix.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [codMtrx, controlBitIdx] = getCodMatrix(mcsTable, sym)
puncRate = 1 -2/6;
codRate = 1/2;
uncodLen = int64(mcsTable.NCBPS / puncRate * codRate);
codLen = int64(mcsTable.NCBPS / puncRate);
% Create a convolutional matrix for 1/2 coding rate.
g0 = [1, 0, 1, 1, 0, 1, 1];
g0 = flip(g0);
g0 = [g0, zeros(1, uncodLen - 1)];
g0 = repmat(g0, [codLen / 2, 1]);
g1 = [1, 1, 1, 1, 0, 0, 1];
g1 = flip(g1);
g1 = [g1, zeros(1, uncodLen - 1)];
g1 = repmat(g1, [codLen / 2, 1]);
codMtr = zeros(codLen, uncodLen + 6);
codMtr(1:2:end, :) = g0;
codMtr(2:2:end, :) = g1;
codMtr = circshift(codMtr, -6, 2);
for ith = 3:2:size(codMtr, 1)
codMtr(ith, :) = circshift(codMtr(ith, :), (ith - 1) / 2);
end
for ith = 4:2:size(codMtr, 1)
codMtr(ith, :) = circshift(codMtr(ith, :), ith / 2 - 1);
end
codMtr = codMtr(:, 1:1:uncodLen);
% Create a convolutional matrix for 3/4 coding rate by puncturing the
% convolutional matrix for 1/2 coding rate.
% uncodeLen = NCPBS * 3 / 4;
puncMtr = zeros(4, codLen);
for ith = 1:1:4
puncMtr(ith, ith) = 1;
end
puncMtr(4, :) = circshift(puncMtr(4, :), 2);
puncMtr = repmat(puncMtr, [int64(codLen .* puncRate) / 4, 1]);
kth = 1;
for ith = 5:4:mcsTable.NCBPS
for jth = 0:1:3
puncMtr(ith + jth, :) = circshift(puncMtr(ith + jth, :), 6 * kth);
end
kth = kth + 1;
end
codMtrx = puncMtr * codMtr;
% Sub-coding matrix related to bits for emualation.
% Get indices of bits should be controled.
nonZeroSymIdx = find(sym(:, 1) ~= 0);
half = ceil(size(nonZeroSymIdx, 1)/2);
setZeroSymIdxCH1 = nonZeroSymIdx(1:1:half);
setZeroSymIdxCH2 = nonZeroSymIdx(half+1:1:end);
controlBitIdxCH1 = ((min(setZeroSymIdxCH1) - 1) * mcsTable.NBPSCS + 1): 1: (max(setZeroSymIdxCH1) * mcsTable.NBPSCS);
controlBitIdxCH2 = ((min(setZeroSymIdxCH2) - 1) * mcsTable.NBPSCS + 1): 1: (max(setZeroSymIdxCH2) * mcsTable.NBPSCS);
interleaverMapRe = getInterleaveMap(mcsTable);
controlBitIdx = [interleaverMapRe(1, controlBitIdxCH1), interleaverMapRe(1, controlBitIdxCH2)];
% Obtain the sub-coding matrix.
codMtrx = codMtrx(controlBitIdx, :);
end