pub struct LdpcCode {
pub decoder: LdpcDecoder,
/* private fields */
}Expand description
An LDPC code with its systematic encoder and its decoder settings.
Fields§
§decoder: LdpcDecoderThe decoder settings.
Implementations§
Source§impl LdpcCode
impl LdpcCode
Sourcepub fn from_rows(n: usize, rows: Vec<Vec<usize>>) -> Result<LdpcCode>
pub fn from_rows(n: usize, rows: Vec<Vec<usize>>) -> Result<LdpcCode>
The code of the parity-check matrix whose rows list the variable nodes of every check; $k = n - \operatorname{rank} H$.
§Errors
Error::Config for a variable index out of range or a code without
information bits.
Sourcepub fn without_encoder(
n: usize,
rows: Vec<Vec<usize>>,
info: Vec<usize>,
) -> Result<LdpcCode>
pub fn without_encoder( n: usize, rows: Vec<Vec<usize>>, info: Vec<usize>, ) -> Result<LdpcCode>
The code of the parity-check matrix rows whose information bits are at the
positions info, without an encoder of its own: its decoder only
(LdpcCode::decode_llr, BlockCode::decode_block), for a code whose
standard gives the encoder (the LDPC codes of crate::ccsds, whose systematic
generators LdpcCode::from_rows would store densely). BlockCode::encode_block
returns an error.
§Errors
Error::Config for a variable index out of range, or information positions
out of range, repeated or absent.
Sourcepub fn accumulate(n: usize, rows: Vec<Vec<usize>>) -> Result<LdpcCode>
pub fn accumulate(n: usize, rows: Vec<Vec<usize>>) -> Result<LdpcCode>
An irregular repeat-accumulate code: check $r$ of rows holds information bits
(positions below $k = n - m$, $m$ the number of checks) and the parity bits
$k + r$ and, for $r > 0$, $k + r - 1$ only (the dual-diagonal structure of the
DVB-S2, DVB-T2 and IEEE 802.11n codes). The encoder accumulates the checks, in
$O(n)$, without the elimination of LdpcCode::from_rows.
§Errors
Error::Config if the checks do not have this structure.
Sourcepub fn from_core_rows(
n: usize,
rows: Vec<Vec<usize>>,
k: usize,
core: usize,
) -> Result<LdpcCode>
pub fn from_core_rows( n: usize, rows: Vec<Vec<usize>>, k: usize, core: usize, ) -> Result<LdpcCode>
A code whose $m$ checks have a core and an extension, the structure of the LDPC
codes of 5G NR (TS 38.212, Sec. 5.3.2): the information bits are the first $k$;
the first core checks involve the bits below $k + \mathrm{core}$ only, with an
invertible square block on the core parity bits $k, \dots, k + \mathrm{core} - 1$;
every other check $r$ contains the parity bit $k + r$ and no bit above it. The
encoder inverts the core block once, by Gauss–Jordan elimination over GF(2), then
computes the extension parity bits one after the other, without the elimination of
the whole matrix of LdpcCode::from_rows.
§Errors
Error::Config if the checks do not have this structure or the core block is
singular.
Sourcepub fn peg(n: usize, k: usize, var_degree: usize, seed: u64) -> Result<LdpcCode>
pub fn peg(n: usize, k: usize, var_degree: usize, seed: u64) -> Result<LdpcCode>
A code of length n with n - k checks built by progressive edge growth, every
variable node of degree var_degree (seeded tie breaks).
§Errors
Error::Config for $k \ge n$ or a degree larger than the number of checks.
Sourcepub fn from_alist(text: &str) -> Result<LdpcCode>
pub fn from_alist(text: &str) -> Result<LdpcCode>
The code of a parity-check matrix written in MacKay’s alist format (the format
of MacKay’s Encyclopedia of Sparse Graph Codes and of the matrices shipped with
AFF3CT), with the systematic encoder of LdpcCode::from_rows. The rows of $H$
keep the order of the file, which is the order of a layered schedule.
The format is a list of integers: $n$ and $m$ (columns and rows of $H$), the
largest column and row degrees, the $n$ column degrees, the $m$ row degrees, then
for every column the (1-based) rows of its ones, and for every row the columns of
its ones. The lists may be padded with zeros up to the largest degree or not;
the text after a # is a comment. The two descriptions of the matrix must agree.
§Errors
Error::Config for a malformed file: a missing or extra number, a degree or an
index out of range, a repeated one, or column and row lists that disagree; or
for a matrix that LdpcCode::from_rows rejects.
§Examples
use comnum_fec::block::BlockCode;
use comnum_fec::ldpc::LdpcCode;
// the (7, 4) Hamming code: n = 7 columns, m = 3 rows
let alist = "7 3\n3 4\n3 2 2 2 1 1 1\n4 4 4\n\
1 2 3\n1 2 0\n1 3 0\n2 3 0\n1 0 0\n2 0 0\n3 0 0\n\
1 2 3 5\n1 2 4 6\n1 3 4 7\n";
let code = LdpcCode::from_alist(alist)?;
assert_eq!((code.n(), code.k()), (7, 4));
assert_eq!(code.rows()[1], [0, 1, 3, 5]);
assert_eq!(LdpcCode::from_alist(&code.to_alist())?, code);§References
- D. J. C. MacKay, Encyclopedia of Sparse Graph Codes, “alist” format, http://www.inference.org.uk/mackay/codes/alist.html.
Sourcepub fn from_alist_file(path: impl AsRef<Path>) -> Result<LdpcCode>
pub fn from_alist_file(path: impl AsRef<Path>) -> Result<LdpcCode>
LdpcCode::from_alist on the content of the file path.
§Errors
Error::Io if the file cannot be read, otherwise those of
LdpcCode::from_alist.
Sourcepub fn to_alist(&self) -> String
pub fn to_alist(&self) -> String
The parity-check matrix in the alist format of LdpcCode::from_alist, with
the lists padded with zeros (the format MacKay’s files use).
Sourcepub fn info_positions(&self) -> &[usize]
pub fn info_positions(&self) -> &[usize]
The positions of the information bits in the codeword, in the order of the
information bits of BlockCode::encode_block (the code is systematic).
Sourcepub fn is_codeword(&self, c: &[u8]) -> bool
pub fn is_codeword(&self, c: &[u8]) -> bool
Whether $H c = 0$.
Sourcepub fn girth(&self) -> usize
pub fn girth(&self) -> usize
The length of the shortest cycle through every variable node of the Tanner graph, minimised over the graph (the girth; 0 without cycle).
Sourcepub fn decode_llr(&self, llr: &[f64]) -> Result<(Vec<f64>, usize)>
pub fn decode_llr(&self, llr: &[f64]) -> Result<(Vec<f64>, usize)>
Decode a block of $n$ channel LLRs: the a posteriori LLRs of the coded bits and the number of iterations used.
§Errors
Error::Shape if llr does not have $n$ values.
Trait Implementations§
Source§impl BlockCode for LdpcCode
impl BlockCode for LdpcCode
Source§fn encode_block(&self, info: &[u8]) -> Result<Vec<u8>>
fn encode_block(&self, info: &[u8]) -> Result<Vec<u8>>
§Errors
Error::Shape unless info has $k$ bits; Error::Config for a code built
by LdpcCode::without_encoder.
Source§fn decode_block(&self, llr: &[f64]) -> Result<Vec<u8>>
fn decode_block(&self, llr: &[f64]) -> Result<Vec<u8>>
Source§fn encode_block_into(&self, info: &[u8], out: &mut [u8]) -> Result<()>
fn encode_block_into(&self, info: &[u8], out: &mut [u8]) -> Result<()>
out (ADR 0011: the default
copies BlockCode::encode_block; a code overrides it when a profile shows the
copy). Read moreSource§fn decode_block_into(&self, llr: &[f64], out: &mut [u8]) -> Result<()>
fn decode_block_into(&self, llr: &[f64], out: &mut [u8]) -> Result<()>
out (as
BlockCode::encode_block_into). Read more