www.gusucode.com > wlan工具箱matlab源码程序 > wlan/wlan/+wlan/+internal/wlanLDPCEncode.m

    function y = wlanLDPCEncode(x,cfg)
%wlanLDPCEncode Low-Density-Parity-Check (LDPC) encoder
%
%   Note: This is an internal undocumented function and its API and/or
%   functionality may change in subsequent releases.
%
%   Y = wlanLDPCEncode(X, CFG) encodes the binary input data X using LDPC
%   parameters as specified in CFG. The input data is LDPC encoded as
%   defined in [1][2], section 20.3.11.17.3 and section 22.3.10.5.4
%   respectively.
%
%   Input X must be a column vector of length equal to number of SERVICE,
%   PSDU and Padding bits.
%
%   CFG should be a structure including the fields:
%   VecPayloadBits  - Number of payload bits within a codeword
%   Rate            - Coding rate
%   NumCBPS         - Number of coded bits per OFDM symbol
%   NumCW           - Number of LDPC codewords
%   LengthLDPC      - LDPC codeword length
%   VecShortenBits  - Vector of shortening bits in each codeword
%   VecPunctureBits - Vector of puncture bits in each codeword
%   VecRepeatBits   - Number of coded bits to be repeated
%   NumSymbol       - Number of OFDM data symbols
%
%   %   References:
%   [1] IEEE Std 802.11(TM)-2012 IEEE Standard for Information technology -
%   Telecommunications and information exchange between systems - Local and
%   metropolitan area networks - Specific requirements - Part 11: Wireless
%   LAN Medium Access Control (MAC) and Physical Layer (PHY)
%   Specifications.
%   [2] IEEE Std 802.11ac(TM)-2013 IEEE Standard for Information technology
%   - Telecommunications and information exchange between systems - Local
%   and metropolitan area networks - Specific requirements - Part 11:
%   Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY)
%   Specifications - Amendment 4: Enhancements for Very High Throughput for
%   Operation in Bands below 6 GHz.
%
%   See also wlanLDPCDecode, getLDPCparameters. 

%   Copyright 2016 The MathWorks, Inc.

%#codegen

numCW            = cfg.NumCW;
lengthLDPC       = cfg.LengthLDPC;
vecShortenBits   = cfg.VecShortenBits; 
vecPunctureBits  = cfg.VecPunctureBits;
numPunctureBits  = sum(cfg.VecPunctureBits);
vecRepeatBits    = cfg.VecRepeatBits;
vecPayloadBits   = cfg.VecPayloadBits;
numOFDMSymbols   = cfg.NumSymbol;
rate             = cfg.Rate;
numCBPS          = cfg.NumCBPS;

startIdx = 0;
dataIdx  = 0;
y = coder.nullcopy(zeros(numOFDMSymbols*numCBPS,1,'int8'));
blkData = coder.nullcopy(zeros(vecPayloadBits(1)+vecShortenBits(1),numCW,'int8'));

for nCW = 1:numCW
    inpBits = x(startIdx+(1:vecPayloadBits(nCW)));
    blkData(:,nCW) = [inpBits;zeros(vecShortenBits(nCW), 1, 'int8')];
    startIdx = startIdx + vecPayloadBits(nCW); % Update index
end

parityBits = wlan.internal.ldpcEncodeCore(blkData, rate);
startIdx = 0;

for nCW = 1:numCW 
    inpBits = x(startIdx+(1:vecPayloadBits(nCW)));
    if(numPunctureBits > 0) % Puncturing
        outPunc = parityBits(1:end-(vecPunctureBits(nCW)),nCW);
        out = [inpBits;outPunc];
    else % Repetition
        % Compute the number of coded bits to be repeated
        infoParityBits = [inpBits;parityBits(:,nCW)];
        % Code word length after Shortening and Repeating
        cwLength = lengthLDPC - vecShortenBits(nCW) + vecRepeatBits(nCW);
        % Extend the length of the coded bits by appending repeating bits
        repeatFactor = ceil(cwLength/length(infoParityBits));
        repeatBlkData = kron(ones(1, repeatFactor,'int8'), infoParityBits.');
        out = repeatBlkData(1:cwLength).';
    end
    y(dataIdx+(1:length(out))) = out;         % Store output
    startIdx = startIdx + vecPayloadBits(nCW);% Update index
    dataIdx  = dataIdx+length(out);
end

% [EOF]