Skip to main content

comnum_spec/blocks/coding/
mod.rs

1//! Coding blocks: channel codes, mapping of the coded bits and soft demapping
2//! (bit-interleaved coded modulation).
3//!
4//! | Block | Does |
5//! |---|---|
6//! | `fec_encode` | draws the information bits of `blocks` codewords and encodes them, optionally through a random bit interleaver |
7//! | `map` | maps the coded bits on a constellation (the last symbol padded with random bits) |
8//! | `demap` | the bit LLRs of the received symbols with their noise variances (exact or max-log) |
9//! | `fec_decode` | deinterleaves and decodes the LLRs |
10//!
11//! A code is a mapping with a `type`:
12//!
13//! | `type` | Parameters | Code |
14//! |---|---|---|
15//! | `conv` | `k`, `hard`, `puncture` | the $(133, 171)_{8}$ code of constraint length 7, terminated, Viterbi decoding; `puncture` names a pattern of `comnum_fec::puncture::Puncturer::from_name` (`ieee80211_2_3`, `ieee80211_3_4`, `ieee80211_5_6`, `dvbs_2_3`, `dvbs_3_4`, `dvbs_5_6`, `dvbs_7_8`) |
16//! | `rs` | `m`, `t`, `n`, `first_root`, `root_step`, `poly` | a Reed–Solomon code over $\mathrm{GF}(2^{m})$ correcting $t$ symbols, shortened to $n$ symbols, hard decisions (`n = 2^m - 1`, $b = 1$, $c = 1$ and the conventional field by default; the CCSDS code in the conventional basis: `m: 8, t: 16, first_root: 112, root_step: 11, poly: 391`; its dual basis and interleaving are `comnum_fec::ccsds::CcsdsRs`) |
17//! | `turbo` | `k`, `iterations`, `max_log` | the turbo code of LTE (log-MAP or max-log-MAP) |
18//! | `ldpc` | `n`, `k`, `var_degree`, `seed`, `rule`, `alpha`, `layered`, `iterations` | a regular LDPC code built by progressive edge growth; the defaults are those of `comnum_fec::ldpc` (degree 3, seed 1, layered sum-product, 50 iterations, $\alpha = 0.8$) |
19//! | `polar` | `n`, `k`, `design_ebn0_db`, `crc`, `list` | a polar code of the Gaussian approximation, SC or CRC-aided SCL decoding |
20//!
21//! The parameters of every code are declared as those of the blocks: `comnum blocks
22//! fec_encode` lists them with their defaults, units and accepted values, and the JSON
23//! Schema of `comnum schema` describes them.
24//!
25//! The encoder and the decoder are built from the same mapping (the decoder settings
26//! are ignored by the encoder), so that a specification writes the code once with a
27//! YAML anchor:
28//!
29//! ```yaml
30//! link:
31//!   - {type: fec_encode, code: &code {type: ldpc, n: 1024, k: 512}, blocks: 4, interleave: true}
32//!   - {type: map, constellation: 16-QAM}
33//!   - {type: rayleigh, coherence_samples: 1}
34//!   - {type: awgn_ebn0, ebn0_db: $ebn0_db}
35//!   - mimo_rx
36//!   - demap
37//!   - {type: fec_decode, code: *code, interleave: true}
38//! metrics: {report: [ber, coded_ber, bler]}
39//! ```
40//!
41//! `awgn_ebn0` after `fec_encode` counts the energy per information bit: $E_{s}/N_{0} =
42//! R \log_{2} M \cdot E_{b}/N_{0}$ with the code rate $R$.
43//!
44//! # References
45//!
46//! 1. G. Caire, G. Taricco and E. Biglieri, "Bit-interleaved coded modulation," *IEEE
47//!    Trans. Inf. Theory*, 44(3), 927–946, 1998.
48
49use super::Extension;
50
51mod codes;
52mod fec;
53mod map;
54mod pas;
55
56pub use codes::build_code;
57use fec::{Decode, DecodeSpec, Encode, EncodeSpec};
58use map::{Demap, Map, MapSpec};
59use pas::{PasDecode, PasEncode, PasLink, PasSpec};
60
61/// The blocks of this module: their documentation and their builders.
62pub(super) fn blocks() -> Vec<Extension> {
63    vec![
64        builtin!(
65            start "pas_encode",
66            "Probabilistic amplitude shaping: CCDM-shaped amplitudes, an LDPC code whose parity bits are the signs, square QAM (the first block of a link).",
67            PasSpec,
68            needs [],
69            gives [Bits, Symbols, Constellation, Samples, Payload],
70            |q, _, _| Ok(Box::new(PasEncode(PasLink::new(&q)?))),
71        ),
72        builtin!(
73            "pas_decode",
74            "PAS receiver: bit LLRs with the amplitude priors, LDPC decoding, dematching (the parameters of pas_encode).",
75            PasSpec,
76            needs [Samples, Symbols, Noise],
77            gives [Decoded],
78            |q, _, _| Ok(Box::new(PasDecode(PasLink::new(&q)?))),
79        ),
80        builtin!(
81            start "fec_encode",
82            "Draw the information bits of the coded blocks and encode them (the first block of a coded link).",
83            EncodeSpec,
84            needs [],
85            gives [Bits, Payload],
86            |q, _, _| Ok(Box::new(Encode::new(&q)?)),
87        ),
88        builtin!(
89            "map",
90            "Map the coded bits on a constellation (Gray labels, the last symbol padded with random bits).",
91            MapSpec,
92            needs [Bits],
93            gives [Symbols, Constellation, Samples],
94            |q, _, _| Ok(Box::new(Map::new(&q)?)),
95        ),
96        builtin!(
97            "demap",
98            "Bit LLRs of the received symbols, with the noise variance of every symbol (from the receiver, or the noise block).",
99            Demap,
100            needs [Samples, Symbols, Constellation, Noise],
101            gives [Llr],
102            |q, _, _| Ok(Box::new(q)),
103        ),
104        builtin!(
105            "fec_decode",
106            "Deinterleave and decode the LLRs into the information bits.",
107            DecodeSpec,
108            needs[Llr],
109            gives[Decoded],
110            |q, _, _| Ok(Box::new(Decode::new(&q)?)),
111        ),
112    ]
113}
114
115#[cfg(test)]
116mod tests;