主要内容

ldpcEncode

对二进制 LDPC 码进行编码

自 R2021b 起

说明

Y = ldpcEncode(informationbits,encodercfg) 使用 LDPC 编码器配置对象 encodercfg 指定的 LDPC 矩阵对输入消息 informationbits 进行编码。输出 LDPC 码字包含信息位后跟奇偶校验位。LDPC 码是具有稀疏奇偶校验矩阵和长块长度的线性差错控制码,其性能可接近香农极限。

示例

Y = ldpcEncode(informationbits,encodercfg,OutputFormat=fmt) 指定码字的输出格式。

示例

全部折叠

初始化原型矩阵和块大小的参数,以配置在 IEEE® 802.11 中指定的码率 3/4 LDPC 码。使用 ldpcQuasiCyclicMatrix 函数创建奇偶校验矩阵。

P = [16 17 22 24  9  3 14 -1  4  2  7 -1 26 -1  2 -1 21 -1  1  0 -1 -1 -1 -1
     25 12 12  3  3 26  6 21 -1 15 22 -1 15 -1  4 -1 -1 16 -1  0  0 -1 -1 -1
     25 18 26 16 22 23  9 -1  0 -1  4 -1  4 -1  8 23 11 -1 -1 -1  0  0 -1 -1
      9  7  0  1 17 -1 -1  7  3 -1  3 23 -1 16 -1 -1 21 -1  0 -1 -1  0  0 -1
     24  5 26  7  1 -1 -1 15 24 15 -1  8 -1 13 -1 13 -1 11 -1 -1 -1 -1  0  0
      2  2 19 14 24  1 15 19 -1 21 -1  2 -1 24 -1  3 -1  2  1 -1 -1 -1 -1  0
    ];
blockSize = 27;
pcmatrix = ldpcQuasiCyclicMatrix(blockSize,P);

创建一个 LDPC 编码器配置对象,显示其属性。使用配置对象的 NumInformationBits 属性生成随机信息位,以指定 LDPC 码字中的信息位数。使用 LDPC 编码器配置对象指定的 LDPC 码对信息位进行编码。

cfgLDPCEnc = ldpcEncoderConfig(pcmatrix)
cfgLDPCEnc = 
  ldpcEncoderConfig with properties:

     ParityCheckMatrix: [162×648 logical]

   Read-only properties:
           BlockLength: 648
    NumInformationBits: 486
    NumParityCheckBits: 162
              CodeRate: 0.7500

infoBits = rand(cfgLDPCEnc.NumInformationBits,1) < 0.5;
codeword = ldpcEncode(infoBits, cfgLDPCEnc);

初始化原型矩阵和块大小的参数,以配置在 IEEE® 802.11 中指定的码率 3/4 LDPC 码。使用 ldpcQuasiCyclicMatrix 函数创建奇偶校验矩阵。

P = [
    16 17 22 24  9  3 14 -1  4  2  7 -1 26 -1  2 -1 21 -1  1  0 -1 -1 -1 -1
    25 12 12  3  3 26  6 21 -1 15 22 -1 15 -1  4 -1 -1 16 -1  0  0 -1 -1 -1
    25 18 26 16 22 23  9 -1  0 -1  4 -1  4 -1  8 23 11 -1 -1 -1  0  0 -1 -1
     9  7  0  1 17 -1 -1  7  3 -1  3 23 -1 16 -1 -1 21 -1  0 -1 -1  0  0 -1
    24  5 26  7  1 -1 -1 15 24 15 -1  8 -1 13 -1 13 -1 11 -1 -1 -1 -1  0  0
     2  2 19 14 24  1 15 19 -1 21 -1  2 -1 24 -1  3 -1  2  1 -1 -1 -1 -1  0
    ];
blockSize = 27;
pcmatrix = ldpcQuasiCyclicMatrix(blockSize,P);

创建 LDPC 编码器和解码器配置对象,显示其属性。

cfgLDPCEnc = ldpcEncoderConfig(pcmatrix)
cfgLDPCEnc = 
  ldpcEncoderConfig with properties:

     ParityCheckMatrix: [162×648 logical]

   Read-only properties:
           BlockLength: 648
    NumInformationBits: 486
    NumParityCheckBits: 162
              CodeRate: 0.7500

cfgLDPCDec = ldpcDecoderConfig(pcmatrix)
cfgLDPCDec = 
  ldpcDecoderConfig with properties:

     ParityCheckMatrix: [162×648 logical]
             Algorithm: 'bp'

   Read-only properties:
           BlockLength: 648
    NumInformationBits: 486
    NumParityCheckBits: 162
              CodeRate: 0.7500

通过 AWGN 信道发射 LDPC 编码、M-QAM 调制的位流。解调信号,解码接收的码字,然后对误码进行计数。使用 for 循环处理多个 SNR 设置,分别对发射数据进行使用和不使用 LDPC 前向纠错 (FEC) 编码。

M = 64;
maxnumiter = 10;
snr = [0.5 1 1.5 2];
numframes = 20000;

for ii = 1:length(snr)
    data = randi([0 1],cfgLDPCEnc.NumInformationBits,numframes,'int8');

    % Transmit and receive with LDPC coding
    encodedData = ldpcEncode(data,cfgLDPCEnc);
    modSignal = qammod(encodedData,M,InputType='bit');
    [rxsig, noisevar] = awgn(modSignal,snr(ii));
    llrOut = qamdemod(rxsig,M, ...
        OutputType='approxllr', ... % Or use 'llr' for exact but slower LLR calculation
        NoiseVariance=noisevar);
    rxbits = ldpcDecode(llrOut,cfgLDPCDec,maxnumiter);
    fprintf(['SNR = %2.1f\n   Coded: Error rate = %1.6f, ' ...
        'Number of errors = %d\n'], ...
        snr(ii),nnz(data~=rxbits)/numel(data),nnz(data~=rxbits));

    % Transmit and receive with no LDPC coding
    noCoding = qammod(data,M,InputType='bit');
    rxNoCoding = awgn(noCoding,snr(ii));
    rxBitsNoCoding = qamdemod(rxNoCoding,M,OutputType='bit');

    fprintf(['Noncoded: Error rate = %1.6f, ' ...
        'Number of errors = %d\n\n'], ...
        nnz(data~=rxBitsNoCoding)/numel(data),nnz(data~=rxBitsNoCoding))
end
SNR = 0.5
   Coded: Error rate = 0.000441, Number of errors = 4282
Noncoded: Error rate = 0.039045, Number of errors = 379515
SNR = 1.0
   Coded: Error rate = 0.000062, Number of errors = 604
Noncoded: Error rate = 0.032813, Number of errors = 318941
SNR = 1.5
   Coded: Error rate = 0.000003, Number of errors = 27
Noncoded: Error rate = 0.027001, Number of errors = 262450
SNR = 2.0
   Coded: Error rate = 0.000000, Number of errors = 0
Noncoded: Error rate = 0.021778, Number of errors = 211686

输入参数

全部折叠

信息位,指定为矩阵。informationbits 中的行数必须等于输入 encodercfgNumInformationBits 属性的值。

数据类型: single | double | int8 | logical

LDPC 编码器配置,指定为 ldpcEncoderConfig 对象。

输出格式,指定为以下值之一:

  • 'whole' - 输出整个 LDPC 码字,包括信息位和奇偶校验位。函数输出的行数等于输入 encodercfgBlockLength 属性的值。

  • 'parity' - 仅输出奇偶校验位。函数输出的行数等于输入 encodercfgNumParityCheckBits 属性的值。

输出参量

全部折叠

经过编码的码字,以矩阵形式返回。对于编码操作,函数独立地对输入 informationbits 的每列进行编码。函数将 informationbits 中的非零值视为 1。编码会计算系统化码字矩阵,该矩阵在 [1:K,:] 子矩阵中用原始信息位填充,在 ((1:K + 1):end,:) 子矩阵中由奇偶校验位填充。K 等于输入 encodercfgNumInformationBits 属性。

  • 当输出格式为 'whole' 时,输出包含整个 LDPC 码字,包括信息位和奇偶校验位。函数输出的行数等于输入 encodercfgBlockLength 属性的值。

  • 当输出格式为 'parity' 时,输出仅包含奇偶校验位。函数输出的行数等于输入 encodercfgNumParityCheckBits 属性的值。

有关设置输出格式的信息,请参阅 OutputFormat 参量。输出与输入 informationbits 具有相同的数据类型。

参考

[1] IEEE® Std 802.11™-2020 (Revision of IEEE Std 802.11-2016). "Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications." IEEE Standard for Information technology — Telecommunications and information exchange between systems. Local and metropolitan area networks — Specific requirements.

[2] Gallager, Robert G. Low-Density Parity-Check Codes. Cambridge, MA: MIT Press, 1963.

扩展功能

全部展开

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

版本历史记录

在 R2021b 中推出

全部展开