nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
blockcoding.hpp
Go to the documentation of this file.
1
3// toolboxes/comm/include/nk/comm/coding/blockcoding.hpp
4//
5// Block linear coding — Error Correction Codes section of the
6// Communications Toolbox. Generator / parity-check matrix construction
7// (hammgen, gen2par, cyclgen) and cyclic generator polynomials
8// (cyclpoly), plus the block encoder / decoder (encode / decode).
9//
10// Everything here is GF(2) (binary) arithmetic on plain double matrices —
11// no Galois-field object type is required. BCH / Reed-Solomon (which need
12// a GF(2^m) `gf` array type) are a documented gap.
13
14#pragma once
15
16#include <memory_resource>
17#include <string>
18#include <nk/value/value.hpp>
19
20namespace nk::comm {
21
24
25
43Value gen2par(const Value &mat, std::pmr::memory_resource *mr = nullptr);
44
50 long long n;
51 long long k;
52};
53
72HammgenResult hammgen(long long m, const Value &primPoly = Value::Empty,
73 std::pmr::memory_resource *mr = nullptr);
74
96Value cyclpoly(long long n, long long k, const std::string &opt = "",
97 std::pmr::memory_resource *mr = nullptr);
98
104 long long k;
105};
106
127CyclgenResult cyclgen(long long n, const Value &genpoly,
128 const std::string &opt = "system",
129 std::pmr::memory_resource *mr = nullptr);
130
135 long long added;
136};
137
163EncodeResult encode(const Value &msg, long long n, long long k,
164 const std::string &method = "hamming/binary",
165 const Value &opt = Value::Empty,
166 std::pmr::memory_resource *mr = nullptr);
167
174
196DecodeResult decode(const Value &code, long long n, long long k,
197 const std::string &method = "hamming/binary",
198 const Value &opt = Value::Empty,
199 std::pmr::memory_resource *mr = nullptr);
200
217Value syndtable(const Value &H, std::pmr::memory_resource *mr = nullptr);
218
219
221} // namespace nk::comm
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
static const Value Empty
MATLAB-style empty matrix sentinel — a 0×0 DOUBLE value.
Definition value.hpp:136
Value syndtable(const Value &H, std::pmr::memory_resource *mr=nullptr)
Syndrome decoding table (coset-leader lookup) from a parity-check matrix (t = syndtable(H)).
DecodeResult decode(const Value &code, long long n, long long k, const std::string &method="hamming/binary", const Value &opt=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Decode a linear block code ([msg, err] = decode(code, n, k, method, opt)).
CyclgenResult cyclgen(long long n, const Value &genpoly, const std::string &opt="system", std::pmr::memory_resource *mr=nullptr)
Parity-check and generator matrices for a cyclic code ([h, g, k] = cyclgen(n, genpoly) / cyclgen(n,...
Value cyclpoly(long long n, long long k, const std::string &opt="", std::pmr::memory_resource *mr=nullptr)
Generator polynomial(s) for an (n, k) cyclic code (p = cyclpoly(n, k) / cyclpoly(n,...
HammgenResult hammgen(long long m, const Value &primPoly=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Parity-check and generator matrices for a Hamming code ([h, g, n, k] = hammgen(m)).
EncodeResult encode(const Value &msg, long long n, long long k, const std::string &method="hamming/binary", const Value &opt=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Encode a message with a linear block code (code = encode(msg, n, k, method, opt)).
Value gen2par(const Value &mat, std::pmr::memory_resource *mr=nullptr)
Parity-check matrix from a generator matrix, or vice versa (h = gen2par(g)).
Result of cyclgen: parity-check / generator matrices and the message length.
Value h
Parity-check matrix, (n-k) × n.
long long k
Message length n - (deg genpoly).
Value g
Generator matrix, k × n.
Result of decode: the recovered message and error report.
Value msg
Decoded message words (same orientation as code).
Value err
Per-word number of errors corrected (-1 if a word could not be decoded), as a column/row to match msg...
Result of encode: the codeword stream and any zero-padding added.
Value code
Encoded codewords (same orientation as msg).
long long added
Number of zero message bits padded before coding.
Result of hammgen: parity-check / generator matrices and the code dimensions.
long long k
Message length n - m.
Value h
Parity-check matrix, m × n.
Value g
Generator matrix, k × n.
long long n
Codeword length 2^m - 1.