www.gusucode.com > wlan工具箱matlab源码程序 > wlan/wlan/+wlan/+internal/ldpcEncodeCore.m
function parityCheckBits = ldpcEncodeCore(infoBits, rate) %LDPCENCODECORE LDPC encoder core % % parityCheckBits = ldpcEncodeCore(infoBits, rate) calculates the % parity check bits for the binary input data (infoBits) using a WLAN % LDPC code at the specified rate (rate). % % rate must be equal to '1/2', '2/3', '3/4', or '5/6'. % Each column of infoBits specifies the information bits of a codeword. % rate and the number of rows in infoBits should correspond to one of the % three valid block lengths: 648, 1296, and 1944. % % To obtain the codewords, concatenate infoBits and parityCheckBits % vertically, i.e. [infoBits; parityCheckBits]. % % See also ldpcDecodeCore, ldpcMatrix. % Copyright 2015-2016 The MathWorks, Inc. %#codegen % Persistent variables for pre-computed data structures for LDPC codes persistent PT_1_2_648 % coding rate = 1/2, block length = 648 persistent PT_1_2_1296 % coding rate = 1/2, block length = 1296 persistent PT_1_2_1944 % coding rate = 1/2, block length = 1944 persistent PT_2_3_648 % coding rate = 2/3, block length = 648 persistent PT_2_3_1296 % coding rate = 2/3, block length = 1296 persistent PT_2_3_1944 % coding rate = 2/3, block length = 1944 persistent PT_3_4_648 % coding rate = 3/4, block length = 648 persistent PT_3_4_1296 % coding rate = 3/4, block length = 1296 persistent PT_3_4_1944 % coding rate = 3/4, block length = 1944 persistent PT_5_6_648 % coding rate = 5/6, block length = 648 persistent PT_5_6_1296 % coding rate = 5/6, block length = 1296 persistent PT_5_6_1944 % coding rate = 5/6, block length = 1944 infoLen = size(infoBits,1); % When an LDPC code is used for the first time, % load the corresponding pre-computed data structure and save it in a % persistent variable. % Compute parity check bits by direct modulo-2 matrix product if strcmp(rate, '1/2') || isequal(rate, 1/2) blockLength = infoLen/(1/2); switch blockLength case 648 if isempty(PT_1_2_648) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_1_2_648'); PT_1_2_648 = double(reshape(de2bi(G.PT_1_2_648,16),324,324)); end parityCheckBits = int8(mod(PT_1_2_648*double(infoBits),2)); case 1296 if isempty(PT_1_2_1296) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_1_2_1296'); PT_1_2_1296 = double(reshape(de2bi(G.PT_1_2_1296,16),648,648)); end parityCheckBits = int8(mod(PT_1_2_1296*double(infoBits),2)); otherwise % case 1944 if isempty(PT_1_2_1944) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_1_2_1944'); PT_1_2_1944 = double(reshape(de2bi(G.PT_1_2_1944,16),972, 972)); end parityCheckBits = int8(mod(PT_1_2_1944*double(infoBits),2)); end elseif strcmp(rate, '2/3') || isequal(rate, 2/3) blockLength = infoLen/(2/3); switch blockLength case 648 if isempty(PT_2_3_648) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_2_3_648'); PT_2_3_648 = double(reshape(de2bi(G.PT_2_3_648,16),216,432)); end parityCheckBits = int8(mod(PT_2_3_648*double(infoBits),2)); case 1296 if isempty(PT_2_3_1296) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_2_3_1296'); PT_2_3_1296 = double(reshape(de2bi(G.PT_2_3_1296,16),432,864)); end parityCheckBits = int8(mod(PT_2_3_1296*double(infoBits),2)); otherwise % case 1944 if isempty(PT_2_3_1944) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_2_3_1944'); PT_2_3_1944 = double(reshape(de2bi(G.PT_2_3_1944,16),648,1296)); end parityCheckBits = int8(mod(PT_2_3_1944*double(infoBits),2)); end elseif (strcmp(rate, '3/4') || isequal(rate, 3/4)) blockLength = infoLen/(3/4); switch blockLength case 648 if isempty(PT_3_4_648) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_3_4_648'); PT_3_4_648 = double(reshape(de2bi(G.PT_3_4_648,12),162,486)); end parityCheckBits = int8(mod(PT_3_4_648*double(infoBits),2)); case 1296 if isempty(PT_3_4_1296) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_3_4_1296'); PT_3_4_1296 = double(reshape(de2bi(G.PT_3_4_1296,16),324,972)); end parityCheckBits = int8(mod(PT_3_4_1296*double(infoBits),2)); otherwise % case 1944 if isempty(PT_3_4_1944) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_3_4_1944'); PT_3_4_1944 = double(reshape(de2bi(G.PT_3_4_1944,12),486,1458)); end parityCheckBits = int8(mod(PT_3_4_1944*double(infoBits),2)); end else % case '5/6' blockLength = infoLen/(5/6); switch blockLength case 648 if isempty(PT_5_6_648) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_5_6_648'); PT_5_6_648 = double(reshape(de2bi(G.PT_5_6_648,16),108,540)); end parityCheckBits = int8(mod(PT_5_6_648*double(infoBits),2)); case 1296 if isempty(PT_5_6_1296) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_5_6_1296'); PT_5_6_1296 = double(reshape(de2bi(G.PT_5_6_1296,16),216,1080)); end parityCheckBits = int8(mod(PT_5_6_1296*double(infoBits),2)); otherwise % case 1944 if isempty(PT_5_6_1944) G = coder.load('wlan/internal/ldpcMatrices.mat','PT_5_6_1944'); PT_5_6_1944 = double(reshape(de2bi(G.PT_5_6_1944,16),324,1620)); end parityCheckBits = int8(mod(PT_5_6_1944*double(infoBits),2)); end end