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
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
14 % h: [7 5 1 7 5 1 7 5 1]
\r
15 % shift: [0 0 1 0 0 1 0 0 1]
\r
17 % Represents code with the following parity check matrix
\r
23 % Tomas Filler (tomas.filler@binghamton.edu)
\r
24 % http://dde.binghamton.edu/filler
\r
26 %% check input parameters
\r
27 if ~isa(H_hat, 'double')
\r
28 error('Matrix H_hat must be of type double.');
\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
36 % matrix should be ful of non-negative number representing columns in
\r
37 % binary notation, maximum is 32 bits
\r
39 error('Maximal height of H_hat is 32.');
\r
43 error('Maximal height of H_hat is 32.');
\r
46 %% calculate the code
\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
51 H_hat_uint32 = zeros(1, m, 'uint32');
\r
53 H_hat_uint32(i) = uint32(binvec2dec( H_hat(:,i)' ));
\r
56 H_hat_uint32 = H_hat;
\r
57 H_hat = zeros(32,m);
\r
59 H_hat(:,i) = dec2binvec(H_hat_uint32(i), 32)';
\r
63 % length of the code
\r
64 code.n = m*num_of_sub_blocks;
\r
66 % constraint length = index of the last nonzero row
\r
67 code.l = find( sum(H_hat,2)>0, 1, 'last');
\r
69 % sparse matrix represented by vector of uint32s
\r
70 code.h = repmat(double(H_hat_uint32), 1, num_of_sub_blocks);
\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
75 alpha = calc_relative_payload(code);
\r