]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/matlab/STC matlab implementation/create_code_from_submatrix.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
60d35232a18a0f01ec5b802e9a5e811cfe47e275
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / matlab / STC matlab implementation / create_code_from_submatrix.m
1 function [ code alpha ] = create_code_from_submatrix( H_hat, num_of_sub_blocks )\r
2 %CREATE_CODE_FROM_SUBMATRIX creates code from binary submatrix H_hat by\r
3 % replicating it by num_of_sub_blocks times. H_hat can be either binary\r
4 % matrix or row of integers, where integer represents the binary vector.\r
5 %\r
6 % Example (both gives the same code):\r
7 %   create_code_from_submatrix([1 1 1;1 0 0;1 1 0],3)\r
8 %   create_code_from_submatrix([7 5 1],3)\r
9 %\r
10 % Output:\r
11 % ans = \r
12 %         n: 9\r
13 %         l: 3\r
14 %         h: [7 5 1 7 5 1 7 5 1]\r
15 %     shift: [0 0 1 0 0 1 0 0 1]\r
16 %\r
17 % Represents code with the following parity check matrix\r
18 %\r
19 %    1 1 1 0 0 0 0 0 0\r
20 %    1 0 0 1 1 1 0 0 0\r
21 %    1 1 0 1 0 0 1 1 1\r
22 %\r
23 % Tomas Filler (tomas.filler@binghamton.edu)\r
24 % http://dde.binghamton.edu/filler\r
25 \r
26 %% check input parameters\r
27 if ~isa(H_hat, 'double')\r
28     error('Matrix H_hat must be of type double.');\r
29 end\r
30 if size(H_hat,1)>1\r
31     % binary matrix should be on input\r
32     if (sum(H_hat(:)==0) + sum(H_hat(:)==1))~=numel(H_hat)\r
33         error('Matrix H_hat must be binary.');\r
34     end\r
35 else\r
36     % matrix should be ful of non-negative number representing columns in\r
37     % binary notation, maximum is 32 bits\r
38     if any(H_hat>2^32)\r
39         error('Maximal height of H_hat is 32.');\r
40     end\r
41 end\r
42 if size(H_hat,1)>32\r
43     error('Maximal height of H_hat is 32.');\r
44 end\r
45 \r
46 %% calculate the code\r
47 m = size(H_hat,2);\r
48 % H_hat may be of different kind, either binary or single row, where binary\r
49 % vectors are written in binary notation as single integer.\r
50 if size(H_hat,1)>1\r
51     H_hat_uint32 = zeros(1, m, 'uint32');\r
52     for i = 1:m\r
53         H_hat_uint32(i) = uint32(binvec2dec( H_hat(:,i)' ));\r
54     end\r
55 else\r
56     H_hat_uint32 = H_hat;\r
57     H_hat = zeros(32,m);\r
58     for i = 1:m\r
59         H_hat(:,i) = dec2binvec(H_hat_uint32(i), 32)';\r
60     end\r
61 end\r
62 \r
63 % length of the code\r
64 code.n = m*num_of_sub_blocks;\r
65 \r
66 % constraint length = index of the last nonzero row\r
67 code.l = find( sum(H_hat,2)>0, 1, 'last');\r
68 \r
69 % sparse matrix represented by vector of uint32s\r
70 code.h = repmat(double(H_hat_uint32), 1, num_of_sub_blocks);\r
71 \r
72 % vector representing the shifts in parity check matrix of the code\r
73 code.shift = repmat([zeros(1,m-1) 1], 1, num_of_sub_blocks);\r
74 \r
75 alpha = calc_relative_payload(code);\r
76 end\r
77 \r