www.gusucode.com > LTE_TX_PDSCH > LTE_TX_turbo_coding_rate_matching.m
%% Turbo coding and Rate matching function output = LTE_TX_turbo_coding_rate_matching(LTE_params, crc_encoded_data, N_coded_bits) code_block_size = length(crc_encoded_data); vector_index = 0:code_block_size-1; interleaver_mapping = mod(15*vector_index + 32*(vector_index.^2),code_block_size); %0-indexed!! input_to_e1 = crc_encoded_data; input_to_e2 = crc_encoded_data(interleaver_mapping+1); hh = poly2trellis(4,[15 13],13); [encoded_1,FinalState1] = convenc(input_to_e1,hh); [encoded_2,FinalState2] = convenc(input_to_e2,hh); encoded_bits = [encoded_1(2:2:end) % Systematic bits encoded_1(1:2:end) % Parity from encoder 1 encoded_2(1:2:end)];% Parity from encoder 2 tail_bits = [zeros(3,4)]; % tail bits (flushing bits) not yet configured... coded_bits = [encoded_bits tail_bits]; %% LTE_TX data Turbo rate matching D = length(coded_bits); % Number of bits C = 32; % Number of columns of the permutation matrix R = ceil(D/32); % Number of rows of the permutation matrix Nd = R*C-D; % Number of padding bits input = coded_bits(1,:);% Put the data row by row into the permutation matrix data_to_interleave = [false(1,Nd) input]; tmp = reshape(data_to_interleave,C,R)'; tmp = tmp(:,LTE_params.sub_block_interleaver_permutation_pattern+1); vk(1,:) = reshape(tmp,1,R*C); input = coded_bits(2,:); % Put the data row by row into the permutation matrix data_to_interleave = [false(1,Nd) input]; tmp = reshape(data_to_interleave,C,R)'; tmp = tmp(:,LTE_params.sub_block_interleaver_permutation_pattern+1); vk(2,:) = reshape(tmp,1,R*C); input = coded_bits(3,:); % Put the data column by column into the permutation matrix. data_to_interleave = [false(1,Nd) input]; tmp = reshape(data_to_interleave,C,R)'; tmp = tmp(:,LTE_params.sub_block_interleaver_permutation_pattern+1); vk(3,:) = reshape(tmp,1,R*C); K_pi = length(vk); input = [vk(1,:) vk(2,:) vk(3,:)]; circ_buff_mapping = [[0:K_pi-1] reshape([[0:K_pi-1]+K_pi;[0:K_pi-1]+2*K_pi],1,2*K_pi)]; wk = input(circ_buff_mapping+1); wklen = length(wk); K_0 = 10; %bits selection and pruning mapping offset tmp = (0:N_coded_bits-1)+K_0; bit_selection_and_pruning_mapping = mod(tmp,wklen); ek = wk(bit_selection_and_pruning_mapping+1); % code block segmentation (only one block) output = ek;