ldpcQuasiCyclicMatrix
Description
Examples
Create Parity-Check Matrix of a Quasicyclic LDPC Code
Create a parity-check matrix of a quasicyclic LDPC code. Set the block size to 3
and the prototype matrix to [0 -1 1 2; 2 1 -1 0]
.
blockSize = 3; p = [0 -1 1 2; 2 1 -1 0]; pcmatrix = ldpcQuasiCyclicMatrix(blockSize,p)
pcmatrix = 6x12 sparse logical array (18 nonzeros)
(1,1) 1
(5,1) 1
(2,2) 1
(6,2) 1
(3,3) 1
(4,3) 1
(6,4) 1
(4,5) 1
(5,6) 1
(3,7) 1
(1,8) 1
(2,9) 1
(2,10) 1
(4,10) 1
(3,11) 1
(5,11) 1
(1,12) 1
(6,12) 1
Confirm that the resulting parity-check matrix is a sparse and logical matrix.
issparse(pcmatrix) & islogical(pcmatrix)
ans = logical
1
Parity-check matrices can be large, and displaying them as a full matrix is generally not advisable. Because the parity-check matrix in this example is only 6-by-12, display it as a full matrix.
full(pcmatrix)
ans = 6x12 logical array
1 0 0 0 0 0 0 1 0 0 0 1
0 1 0 0 0 0 0 0 1 1 0 0
0 0 1 0 0 0 1 0 0 0 1 0
0 0 1 0 1 0 0 0 0 1 0 0
1 0 0 0 0 1 0 0 0 0 1 0
0 1 0 1 0 0 0 0 0 0 0 1
Encode Information Bits Using Rate 3/4 LDPC Code
Initialize parameters for the prototype matrix and block size to configure a rate 3/4 LDPC code specified in IEEE® 802.11. Create the parity-check matrix by using the ldpcQuasiCyclicMatrix
function.
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);
Create an LDPC encoder configuration object, displaying its properties. Generate random information bits by using the NumInformationBits
property of the configuration object to specify the number of information bits in an LPDC codeword. Encode the information bits by the LDPC code specified by the LDPC encoder configuration object.
cfgLDPCEnc = ldpcEncoderConfig(pcmatrix)
cfgLDPCEnc = ldpcEncoderConfig with properties: ParityCheckMatrix: [162x648 logical] Read-only properties: BlockLength: 648 NumInformationBits: 486 NumParityCheckBits: 162 CodeRate: 0.7500
infoBits = rand(cfgLDPCEnc.NumInformationBits,1) < 0.5; codeword = ldpcEncode(infoBits, cfgLDPCEnc);
Decode Rate 3/4 LDPC Codewords
Initialize parameters for the prototype matrix and block size to configure a rate 3/4 LDPC code specified in IEEE® 802.11. Create the parity-check matrix by using the ldpcQuasiCyclicMatrix
function.
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);
Create LDPC encoder and decoder configuration objects, displaying their properties.
cfgLDPCEnc = ldpcEncoderConfig(pcmatrix)
cfgLDPCEnc = ldpcEncoderConfig with properties: ParityCheckMatrix: [162x648 logical] Read-only properties: BlockLength: 648 NumInformationBits: 486 NumParityCheckBits: 162 CodeRate: 0.7500
cfgLDPCDec = ldpcDecoderConfig(pcmatrix)
cfgLDPCDec = ldpcDecoderConfig with properties: ParityCheckMatrix: [162x648 logical] Algorithm: 'bp' Read-only properties: BlockLength: 648 NumInformationBits: 486 NumParityCheckBits: 162 CodeRate: 0.7500
Transmit an LDPC-encoded, QPSK-modulated bit stream through an AWGN channel. Demodulate the signal, decode the received codewords, and then count bit errors. Use nested for
loops to process multiple SNR settings and frames with and without LDPC forward error correction (FEC) coding of the transmitted data.
M = 4; maxnumiter = 10; snr = [3 6 20]; numframes = 10; ber = comm.ErrorRate; ber2 = comm.ErrorRate; for ii = 1:length(snr) for counter = 1:numframes data = randi([0 1],cfgLDPCEnc.NumInformationBits,1,'int8'); % Transmit and receive with LDPC coding encodedData = ldpcEncode(data,cfgLDPCEnc); modSignal = pskmod(encodedData,M,InputType='bit'); [rxsig, noisevar] = awgn(modSignal,snr(ii)); demodSignal = pskdemod(rxsig,M, ... OutputType='approxllr', ... NoiseVariance=noisevar); rxbits = ldpcDecode(demodSignal,cfgLDPCDec,maxnumiter); errStats = ber(data,rxbits); % Transmit and receive with no LDPC coding noCoding = pskmod(data,M,InputType='bit'); rxNoCoding = awgn(noCoding,snr(ii)); rxBitsNoCoding = pskdemod(rxNoCoding,M,OutputType='bit'); errStatsNoCoding = ber2(data,int8(rxBitsNoCoding)); end fprintf(['SNR = %2d\n Coded: Error rate = %1.2f, ' ... 'Number of errors = %d\n'], ... snr(ii),errStats(1),errStats(2)) fprintf(['Noncoded: Error rate = %1.2f, ' ... 'Number of errors = %d\n'], ... errStatsNoCoding(1),errStatsNoCoding(2)) reset(ber); reset(ber2); end
SNR = 3 Coded: Error rate = 0.07, Number of errors = 355
Noncoded: Error rate = 0.08, Number of errors = 384
SNR = 6 Coded: Error rate = 0.00, Number of errors = 0
Noncoded: Error rate = 0.02, Number of errors = 98
SNR = 20 Coded: Error rate = 0.00, Number of errors = 0
Noncoded: Error rate = 0.00, Number of errors = 0
Input Arguments
blocksize
— Block size
positive scalar
Block size of the quasi-cyclic LDPC code, specified as a positive scalar.
Data Types: double
P
— Prototype matrix
matrix
Prototype matrix, specified as a matrix. The number of columns in
P
must be greater than the number of rows in
P
. All values in P
must be
-1
, 0
, or positive integers less than the input
blocksize
. A value of -1
produces a
zero-valued blocksize
-by-blocksize
submatrix.
Other values indicate that the number of columns a
blocksize
-by-blocksize
diagonal matrix must
be cyclically shifted to the right. Each submatrix is either a zero matrix or a
cyclically shifted version of a diagonal matrix.
Data Types: double
Output Arguments
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2021b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)