Digital modulation schemes (PSK, QAM, APSK, FSK, OFDM), channel models (AWGN, fading), error correction coding, and source coding. More...
Files | |
| file | channel.hpp |
| file | fading.hpp |
| file | blockcoding.hpp |
| file | convcoding.hpp |
| file | compand.hpp |
| file | errors.hpp |
| file | pulse.hpp |
| file | scrambler.hpp |
| file | analog.hpp |
| file | apsk.hpp |
| file | fsk_ofdm.hpp |
| file | generic_qam.hpp |
| file | mil188.hpp |
| file | psk.hpp |
| file | qam.hpp |
| file | arithcoding.hpp |
| file | base_conversions.hpp |
| file | dpcm.hpp |
| file | dpcmopt.hpp |
| file | huffman.hpp |
| file | lloyds.hpp |
| file | quantiz.hpp |
| file | random_source.hpp |
Classes | |
| struct | nk::comm::HammgenResult |
| Result of hammgen: parity-check / generator matrices and the code dimensions. More... | |
| struct | nk::comm::CyclgenResult |
| Result of cyclgen: parity-check / generator matrices and the message length. More... | |
| struct | nk::comm::EncodeResult |
| Result of encode: the codeword stream and any zero-padding added. More... | |
| struct | nk::comm::DecodeResult |
| Result of decode: the recovered message and error report. More... | |
| struct | nk::comm::DpcmOptResult |
| Result of dpcmopt. More... | |
| struct | nk::comm::QuantizResult |
| Result of the three-output form of quantiz. More... | |
Functions | |
| Value | nk::comm::awgn (::nk::ops::RngContext &rng, const Value &x, double snr_db, double sigpower_db, std::pmr::memory_resource *mr=nullptr) |
| Add white Gaussian noise so the resulting SNR is snr_db dB (y = awgn(x, snr_db, sigpower_db)). | |
| Value | nk::comm::wgn (::nk::ops::RngContext &rng, int m, int n, double p, const std::string &type, bool complex_out, std::pmr::memory_resource *mr=nullptr) |
| Generate an m×n matrix of white Gaussian noise samples (y = wgn(m, n, p, type, complex)). | |
| Value | nk::comm::bsc (::nk::ops::RngContext &rng, const Value &x, double p, std::pmr::memory_resource *mr=nullptr) |
| Binary symmetric channel — flip each bit with probability p (y = bsc(x, p)). | |
| Value | nk::comm::qfunc (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Gaussian Q-function: Q(x) = 0.5·erfc(x/√2). | |
| Value | nk::comm::qfuncinv (const Value &p, std::pmr::memory_resource *mr=nullptr) |
| Inverse Q-function: Q⁻¹(p) = √2·erfc⁻¹(2p). | |
| Value | nk::comm::marcumq (const Value &a, const Value &b, int m, std::pmr::memory_resource *mr=nullptr) |
| Generalised Marcum Q-function (q = marcumq(a, b, m)). | |
| Value | nk::comm::berawgn (const Value &EbNo_dB, const std::string &mod, int M, std::pmr::memory_resource *mr=nullptr) |
| Analytical bit-error rate over AWGN (ber = berawgn(EbNo_dB, mod, M)). | |
| Value | nk::comm::noisebw (const Value &num, const Value &den, int Nsamp, double fs, std::pmr::memory_resource *mr=nullptr) |
| Equivalent noise bandwidth of an LTI filter (bw = noisebw(num, den, Nsamp, fs)). | |
| std::tuple< Value, Value > | nk::comm::berconfint (double numErrs, double numBits, double level, std::pmr::memory_resource *mr=nullptr) |
| Clopper–Pearson exact binomial confidence interval for a measured BER ([ber, ci] = berconfint(numErrs, numBits, level)). | |
| Value | nk::comm::convertSNR (const Value &snr_in, const std::string &in_type, const std::string &out_type, int bits_per_symbol, std::pmr::memory_resource *mr=nullptr) |
| Convert between Eb/No, Es/No, and SNR (snr_out = convertSNR(snr_in, in_type, out_type, k)). | |
| Value | nk::comm::rayleighchan (::nk::ops::RngContext &rng, const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Apply iid frequency-flat Rayleigh fading (y = rayleighchan(x)). | |
| Value | nk::comm::ricianchan (::nk::ops::RngContext &rng, const Value &x, double K, std::pmr::memory_resource *mr=nullptr) |
| Apply iid frequency-flat Rician fading (y = ricianchan(x, K)). | |
| Value | nk::comm::gen2par (const Value &mat, std::pmr::memory_resource *mr=nullptr) |
| Parity-check matrix from a generator matrix, or vice versa (h = gen2par(g)). | |
| HammgenResult | nk::comm::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)). | |
| Value | nk::comm::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, k, opt)). | |
| CyclgenResult | nk::comm::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, genpoly, opt)). | |
| EncodeResult | nk::comm::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)). | |
| DecodeResult | nk::comm::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)). | |
| Value | nk::comm::syndtable (const Value &H, std::pmr::memory_resource *mr=nullptr) |
| Syndrome decoding table (coset-leader lookup) from a parity-check matrix (t = syndtable(H)). | |
| Value | nk::comm::poly2trellis (const Value &constraintLength, const Value &codeGenerator, std::pmr::memory_resource *mr=nullptr) |
| Convolutional-code trellis from polynomial generators (trellis = poly2trellis(ConstraintLength, CodeGenerator)). | |
| Value | nk::comm::convenc (const Value &msg, const Value &trellis, std::pmr::memory_resource *mr=nullptr) |
| Convolutionally encode a bit stream (code = convenc(msg, trellis)). | |
| Value | nk::comm::vitdec (const Value &code, const Value &trellis, long long tblen, const std::string &opmode="trunc", const std::string &dectype="hard", std::pmr::memory_resource *mr=nullptr) |
| Viterbi-decode a convolutional code (msg = vitdec(code, trellis, tblen, opmode, dectype)). | |
| Value | nk::comm::istrellis (const Value &S, std::pmr::memory_resource *mr=nullptr) |
| Validate a trellis structure (tf = istrellis(S)). | |
| Value | nk::comm::compand (const Value &x, double param, double V, const std::string &method, std::pmr::memory_resource *mr=nullptr) |
| μ-law / A-law signal compander (y = compand(x, param, V, method)). | |
| std::pair< Value, Value > | nk::comm::biterr (const Value &x, const Value &y, int k=0, std::pmr::memory_resource *mr=nullptr) |
| Bit-error count and rate ([number, ratio] = biterr(x, y, k)). | |
| std::pair< Value, Value > | nk::comm::symerr (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr) |
| Symbol-error count and rate ([number, ratio] = symerr(x, y)). | |
| Value | nk::comm::rcosdesign (double beta, int span, int sps, const std::string &shape="normal", std::pmr::memory_resource *mr=nullptr) |
| Design a raised-cosine or root-raised-cosine FIR filter (h = rcosdesign(beta, span, sps, shape)). | |
| Value | nk::comm::gaussdesign (double BT, int span, int sps, std::pmr::memory_resource *mr=nullptr) |
| Design a Gaussian FIR pulse-shaping filter (h = gaussdesign(BT, span, sps)). | |
| Value | nk::comm::rectpulse (const Value &x, int n, std::pmr::memory_resource *mr=nullptr) |
| Rectangular pulse shaping (y = rectpulse(x, n)). | |
| Value | nk::comm::intdump (const Value &x, int n, std::pmr::memory_resource *mr=nullptr) |
| Integrate-and-dump (y = intdump(x, n)). | |
| Value | nk::comm::scrambler (const Value &x, const Value &poly, const Value &initState, std::pmr::memory_resource *mr=nullptr) |
| Multiplicative bit scrambler (y = scrambler(x, poly, initState)). | |
| Value | nk::comm::descrambler (const Value &y, const Value &poly, const Value &initState, std::pmr::memory_resource *mr=nullptr) |
| Multiplicative bit descrambler — algebraic inverse of scrambler (x = descrambler(y, poly, initState)). | |
| Value | nk::comm::pmmod (const Value &x, double fc, double fs, double phasedev, double ini_phase, std::pmr::memory_resource *mr=nullptr) |
| Phase modulator (y = pmmod(x, fc, fs, phasedev, ini_phase)). | |
| Value | nk::comm::ammod (const Value &x, double fc, double fs, double ini_phase, double carr_amp, std::pmr::memory_resource *mr=nullptr) |
| Amplitude modulator (y = ammod(x, fc, fs, ini_phase, carr_amp)). | |
| Value | nk::comm::fmmod (const Value &x, double fc, double fs, double freqdev, double ini_phase, std::pmr::memory_resource *mr=nullptr) |
| Frequency modulator (y = fmmod(x, fc, fs, freqdev, ini_phase)). | |
| Value | nk::comm::pmdemod (const Value &y, double fc, double fs, double phasedev, double ini_phase, std::pmr::memory_resource *mr=nullptr) |
| Phase demodulator — inverse of pmmod (x = pmdemod(y, fc, fs, phasedev, ini_phase)). | |
| Value | nk::comm::fmdemod (const Value &y, double fc, double fs, double freqdev, double ini_phase, std::pmr::memory_resource *mr=nullptr) |
| Frequency demodulator — inverse of fmmod (x = fmdemod(y, fc, fs, freqdev, ini_phase)). | |
| Value | nk::comm::amdemod (const Value &y, double fc, double fs, double ini_phase, double carr_amp, std::pmr::memory_resource *mr=nullptr) |
| Amplitude demodulator — inverse of ammod (x = amdemod(y, fc, fs, ini_phase, carramp)). | |
| Value | nk::comm::ssbdemod (const Value &y, double fc, double fs, double ini_phase, std::pmr::memory_resource *mr=nullptr) |
| Single-sideband demodulator — inverse of ssbmod (x = ssbdemod(y, fc, fs, ini_phase)). | |
| Value | nk::comm::ssbmod (const Value &x, double fc, double fs, double ini_phase, bool upper, std::pmr::memory_resource *mr=nullptr) |
| Single-sideband modulator (y = ssbmod(x, fc, fs, ini_phase, upper)). | |
| Value | nk::comm::mskmod (const Value &x, int nSamp, double ini_phase, std::pmr::memory_resource *mr=nullptr) |
| Minimum-shift-keying modulator (differential variant) (y = mskmod(x, nSamp, ini_phase)). | |
| Value | nk::comm::mskdemod (const Value &y, int nSamp, double ini_phase, double *phase_out=nullptr, std::pmr::memory_resource *mr=nullptr) |
| Minimum-shift-keying demodulator (differential variant) (z = mskdemod(y, nSamp [, ini_phase])). | |
| Value | nk::comm::apskmod (const Value &x, Span< const size_t > M, Span< const double > radii, const Value &phaseoffset=Value::Empty, const Value &mapping=Value::Empty, std::pmr::memory_resource *mr=nullptr) |
| APSK modulator (y = apskmod(x, M, radii, phaseoffset, mapping)). | |
| Value | nk::comm::apskdemod (const Value &y, Span< const size_t > M, Span< const double > radii, const Value &phaseoffset=Value::Empty, const Value &mapping=Value::Empty, std::pmr::memory_resource *mr=nullptr) |
| APSK demodulator (z = apskdemod(y, M, radii, phaseoffset, mapping)). | |
| Value | nk::comm::fskmod (const Value &x, int M, double freq_sep, int nsamp, double fs, const std::string &phase_continuity, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| M-ary FSK modulator (y = fskmod(x, M, freq_sep, nsamp, fs, phase_continuity, symbol_order)). | |
| Value | nk::comm::fskdemod (const Value &y, int M, double freq_sep, int nsamp, double fs, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| M-ary FSK demodulator (x = fskdemod(y, M, freq_sep, nsamp, fs, symbol_order)). | |
| Value | nk::comm::ofdmmod (const Value &in, int nfft, int cplen, std::pmr::memory_resource *mr=nullptr) |
| Basic OFDM modulator (y = ofdmmod(in, nfft, cplen)). | |
| Value | nk::comm::ofdmdemod (const Value &in, int nfft, int cplen, int symoffset, std::pmr::memory_resource *mr=nullptr) |
| Basic OFDM demodulator (out = ofdmdemod(in, nfft, cplen, symoffset)). | |
| Value | nk::comm::genqammod (const Value &x, const Value &constellation, std::pmr::memory_resource *mr=nullptr) |
| Generic constellation modulator (y = genqammod(x, constellation)). | |
| Value | nk::comm::genqamdemod (const Value &y, const Value &constellation, std::pmr::memory_resource *mr=nullptr) |
| Generic constellation demodulator (x = genqamdemod(y, constellation)). | |
| Value | nk::comm::mil188qammod (const Value &x, int M, std::pmr::memory_resource *mr=nullptr) |
| MIL-STD-188-110 QAM modulator (y = mil188qammod(x, M)). | |
| Value | nk::comm::mil188qamdemod (const Value &y, int M, std::pmr::memory_resource *mr=nullptr) |
| MIL-STD-188-110 QAM demodulator (z = mil188qamdemod(y, M)). | |
| Value | nk::comm::pskmod (const Value &x, int M, double ini_phase, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| M-ary PSK modulator (y = pskmod(x, M, ini_phase, symbol_order)). | |
| Value | nk::comm::pskdemod (const Value &y, int M, double ini_phase, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| M-ary PSK demodulator — nearest-phase decision (x = pskdemod(y, M, ini_phase, symbol_order)). | |
| Value | nk::comm::dpskmod (const Value &x, int M, double phase_rot, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| Differential PSK modulator (y = dpskmod(x, M, phase_rot, symbol_order)). | |
| Value | nk::comm::dpskdemod (const Value &y, int M, double phase_rot, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| Differential PSK demodulator — phase-difference decoder (x = dpskdemod(y, M, phase_rot, symbol_order)). | |
| Value | nk::comm::pammod (const Value &x, int M, double ini_phase, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| M-ary PAM modulator (y = pammod(x, M, ini_phase, symbol_order)). | |
| Value | nk::comm::pamdemod (const Value &y, int M, double ini_phase, const std::string &symbol_order, std::pmr::memory_resource *mr=nullptr) |
| M-ary PAM demodulator — nearest-amplitude decision (x = pamdemod(y, M, ini_phase, symbol_order)). | |
| Value | nk::comm::qammod (const Value &x, int M, const std::string &symbol_order, bool unit_power, std::pmr::memory_resource *mr=nullptr) |
| Rectangular M-ary QAM modulator (y = qammod(x, M, symbol_order, unit_power)). | |
| Value | nk::comm::qamdemod (const Value &y, int M, const std::string &symbol_order, bool unit_power, std::pmr::memory_resource *mr=nullptr) |
| Rectangular M-ary QAM demodulator (x = qamdemod(y, M, symbol_order, unit_power)). | |
| Value | nk::comm::modnorm (const Value &ref, const std::string &type, double target, std::pmr::memory_resource *mr=nullptr) |
| Constellation normalisation factor (factor = modnorm(ref, type, target)). | |
| Value | nk::comm::arithenco (const Value &seq, const Value &counts, std::pmr::memory_resource *mr=nullptr) |
| Arithmetic-encode a symbol sequence (code = arithenco(seq, counts)). | |
| Value | nk::comm::arithdeco (const Value &code, const Value &counts, std::size_t len, std::pmr::memory_resource *mr=nullptr) |
| Invert arithenco (seq = arithdeco(code, counts, len)). | |
| Value | nk::comm::bit2int (const Value &b, int n, bool msbfirst=true, std::pmr::memory_resource *mr=nullptr) |
| Pack a bit vector into integers — y = bit2int(b, n). | |
| Value | nk::comm::int2bit (const Value &d, int n, bool msbfirst=true, std::pmr::memory_resource *mr=nullptr) |
| Unpack integers into a bit matrix — b = int2bit(d, n). | |
| Value | nk::comm::bi2de (const Value &b, int base=2, bool msbfirst=false, std::pmr::memory_resource *mr=nullptr) |
| Convert digit-rows to decimal — d = bi2de(b) (legacy). | |
| Value | nk::comm::de2bi (const Value &d, int n=-1, int base=2, bool msbfirst=false, std::pmr::memory_resource *mr=nullptr) |
| Convert integers to digit-rows — b = de2bi(d) (legacy). | |
| std::pair< Value, int > | nk::comm::vec2mat (const Value &v, int n, double padval=0.0, std::pmr::memory_resource *mr=nullptr) |
| Reshape a vector into an N-column matrix with padding — [m, pad] = vec2mat(v, n). | |
| std::pair< Value, Value > | nk::comm::dpcmenco (const Value &sig, const Value &codebook, const Value &partition, const Value &predictor, std::pmr::memory_resource *mr=nullptr) |
| DPCM encoder ([indx, quanterr] = dpcmenco(sig, codebook, partition, predictor)). | |
| std::pair< Value, Value > | nk::comm::dpcmdeco (const Value &indx, const Value &codebook, const Value &predictor, std::pmr::memory_resource *mr=nullptr) |
| DPCM decoder — invert dpcmenco ([sig, quanterr] = dpcmdeco(indx, codebook, predictor)). | |
| DpcmOptResult | nk::comm::dpcmopt (const Value &training_set, int ord, const Value &ini_codebook=Value::Empty, std::pmr::memory_resource *mr=nullptr) |
| Optimise DPCM predictor + (optional) quantizer ([predictor, codebook, partition] = dpcmopt(training, ord, ini_codebook)). | |
| std::pair< Value, double > | nk::comm::huffmandict (const Value &symbols, const Value &probs, std::pmr::memory_resource *mr=nullptr) |
| Build a canonical Huffman dictionary ([dict, avglen] = huffmandict(symbols, probs)). | |
| Value | nk::comm::huffmanenco (const Value &sig, const Value &dict, std::pmr::memory_resource *mr=nullptr) |
| Encode a symbol sequence using a Huffman dictionary (enc = huffmanenco(sig, dict)). | |
| Value | nk::comm::huffmandeco (const Value &bits, const Value &dict, std::pmr::memory_resource *mr=nullptr) |
| Decode a Huffman bit stream (dec = huffmandeco(bits, dict)). | |
| std::tuple< Value, Value, double, double > | nk::comm::lloyds (const Value &training_set, const Value &ini_codebook, double tol=1e-7, std::pmr::memory_resource *mr=nullptr) |
| Lloyd-Max scalar quantizer designer ([partition, codebook, distor, rel] = lloyds(training, ini_codebook, tol)). | |
| Value | nk::comm::quantiz_indx (const Value &sig, const Value &partition, std::pmr::memory_resource *mr=nullptr) |
| One-output form of quantiz — bin index per sample (indx = quantiz(sig, partition)). | |
| QuantizResult | nk::comm::quantiz (const Value &sig, const Value &partition, const Value &codebook, std::pmr::memory_resource *mr=nullptr) |
| Three-output form of quantiz ([indx, quantv, distor] = quantiz(sig, partition, codebook)). | |
| Value | nk::comm::randsrc (::nk::ops::RngContext &rng, size_t m, size_t n, const Value &alphabet, bool have_state, uint32_t state, std::pmr::memory_resource *mr=nullptr) |
| Generate an m×n random matrix from a finite alphabet (out = randsrc(m, n, alphabet, state)). | |
| Value | nk::comm::randerr (::nk::ops::RngContext &rng, size_t m, size_t n, const Value &errspec, bool have_state, uint32_t state, std::pmr::memory_resource *mr=nullptr) |
| Generate an m×n binary error pattern (out = randerr(m, n, errors, state)). | |
Digital modulation schemes (PSK, QAM, APSK, FSK, OFDM), channel models (AWGN, fading), error correction coding, and source coding.
| Value nk::comm::amdemod | ( | const Value & | y, |
| double | fc, | ||
| double | fs, | ||
| double | ini_phase, | ||
| double | carr_amp, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Amplitude demodulator — inverse of ammod (x = amdemod(y, fc, fs, ini_phase, carramp)).
Coherent (synchronous) detection: multiply by the carrier and zero-phase low-pass — x = 2·filtfilt(butter(5, fc·2/fs), y·cos(2π·fc·t + ini_phase)) − carramp. (carramp is the transmitted-carrier amplitude; the default 0 is double-sideband suppressed-carrier.)
| y | Modulated signal. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| ini_phase | Initial carrier phase in radians. |
| carr_amp | Transmitted-carrier amplitude (subtracted after detect). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::ammod | ( | const Value & | x, |
| double | fc, | ||
| double | fs, | ||
| double | ini_phase, | ||
| double | carr_amp, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Amplitude modulator (y = ammod(x, fc, fs, ini_phase, carr_amp)).
y = (x + carr_amp) · cos(2π·fc·t + ini_phase). carr_amp == 0 gives DSB-SC (suppressed carrier); carr_amp != 0 gives DSB-TC (transmitted carrier).
| x | Real input message. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| ini_phase | Initial carrier phase in radians. |
| carr_amp | Carrier amplitude (0 → DSB-SC). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::apskdemod | ( | const Value & | y, |
| Span< const size_t > | M, | ||
| Span< const double > | radii, | ||
| const Value & | phaseoffset = Value::Empty, | ||
| const Value & | mapping = Value::Empty, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
APSK demodulator (z = apskdemod(y, M, radii, phaseoffset, mapping)).
Inverts apskmod via nearest-constellation-point search.
| y | Received complex samples. |
| M | Per-ring symbol count. |
| radii | Per-ring radius. |
| phaseoffset | Optional per-ring phase offset; Value::Empty uses the default π / M_k. |
| mapping | Optional symbol-mapping permutation; Value::Empty uses identity. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::apskmod | ( | const Value & | x, |
| Span< const size_t > | M, | ||
| Span< const double > | radii, | ||
| const Value & | phaseoffset = Value::Empty, | ||
| const Value & | mapping = Value::Empty, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
APSK modulator (y = apskmod(x, M, radii, phaseoffset, mapping)).
Indexes integer symbols x into a multi-ring PSK constellation built from M symbols per ring at the corresponding radii. M and radii must have matching length.
Default phaseoffset is π / M_k per ring. Default mapping is the identity permutation 0..sum(M)-1; pass an explicit permutation to reorder. Per-ring Gray default is deferred.
| x | Integer symbol indices in 0..sum(M)-1. |
| M | Per-ring symbol count (length R). |
| radii | Per-ring radius (length R, same as M). |
| phaseoffset | Optional per-ring phase offset; Value::Empty uses the default π / M_k. |
| mapping | Optional symbol-mapping permutation; Value::Empty uses identity. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::arithdeco | ( | const Value & | code, |
| const Value & | counts, | ||
| std::size_t | len, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Invert arithenco (seq = arithdeco(code, counts, len)).
The contract requires the decoded length len explicitly; the encoder emits no stop sentinel.
| code | 0/1 bit vector produced by arithenco. |
| counts | Same count vector used during encoding. |
| len | Expected decoded length. |
| mr | Memory resource (nullptr → process default). |
| Error | On bad inputs or truncated bit stream. |
| Value nk::comm::arithenco | ( | const Value & | seq, |
| const Value & | counts, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Arithmetic-encode a symbol sequence (code = arithenco(seq, counts)).
Uses the cumulative-probability intervals derived from counts. Output is a 0/1 bit vector whose orientation matches seq.
| seq | Symbol sequence (positive integer values in 1..length(counts)). |
| counts | Positive integer count vector (length K). |
| mr | Memory resource (nullptr → process default). |
| Error | On bad seq symbols or non-positive counts. |
| Value nk::comm::awgn | ( | ::nk::ops::RngContext & | rng, |
| const Value & | x, | ||
| double | snr_db, | ||
| double | sigpower_db, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Add white Gaussian noise so the resulting SNR is snr_db dB (y = awgn(x, snr_db, sigpower_db)).
Noise is complex when x is complex, real otherwise. The signal power may be specified or estimated.
| x | Input signal. |
| snr_db | Target SNR in dB. |
| sigpower_db | Signal power in dBW, or -1 ⇒ "measured" (estimate from x). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::berawgn | ( | const Value & | EbNo_dB, |
| const std::string & | mod, | ||
| int | M, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Analytical bit-error rate over AWGN (ber = berawgn(EbNo_dB, mod, M)).
| EbNo_dB | Eb/No values in dB (array). |
| mod | "psk", "dpsk", "qam", "pam", or "fsk". |
| M | Modulation order. |
| mr | Memory resource (nullptr → process default). |
| Error | Unknown modulation string or invalid M. |
| std::tuple< Value, Value > nk::comm::berconfint | ( | double | numErrs, |
| double | numBits, | ||
| double | level, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Clopper–Pearson exact binomial confidence interval for a measured BER ([ber, ci] = berconfint(numErrs, numBits, level)).
| numErrs | Observed error count. |
| numBits | Total bit count. |
| level | Confidence level in (0, 1), e.g. 0.95. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::bi2de | ( | const Value & | b, |
| int | base = 2, | ||
| bool | msbfirst = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Convert digit-rows to decimal — d = bi2de(b) (legacy).
Each row of the 2-D matrix b is a group of base-base digits; returns a column vector with the decimal value of each row. Defaults to base 2, LSB-first ('right-msb'). MATLAB documents bi2de as a legacy synonym (superseded by bit2int) but it still ships in R2025b.
| b | 2-D matrix of digit rows. |
| base | Digit base, >= 2 (default 2). |
| msbfirst | false (default, 'right-msb') treats the first column as least significant; true ('left-msb') reverses. |
| mr | Memory resource (nullptr → process default). |
| Error | if b is not 2-D or base < 2. |
| Value nk::comm::bit2int | ( | const Value & | b, |
| int | n, | ||
| bool | msbfirst = true, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Pack a bit vector into integers — y = bit2int(b, n).
Groups the numel(b) bits of b (which must be divisible by n) into numel(b) / n integers, n bits each, MSB-first by default. Returns a column vector of the packed integer values.
| b | Bit values (numel divisible by n). |
| n | Bits per integer, in 1..64. |
| msbfirst | true (default) packs MSB-first; false LSB-first. |
| mr | Memory resource (nullptr → process default). |
| Error | if n ∉ 1..64 or numel(b) is not divisible by n. |
| std::pair< Value, Value > nk::comm::biterr | ( | const Value & | x, |
| const Value & | y, | ||
| int | k = 0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Bit-error count and rate ([number, ratio] = biterr(x, y, k)).
Counts the differing bits between the same-shape non-negative integer arrays x and y, treating each element as a k-bit symbol. k <= 0 (default) auto-selects the smallest bit width covering all values. Returns { number, ratio } where ratio = number / (numel * k). (MATLAB's 3rd individual output is a v1 gap.)
| x,y | Same-numel non-negative integer arrays. |
| k | Bits per symbol; <= 0 (default) → smallest covering width. |
| mr | Memory resource (nullptr → process default). |
| Error | on numel mismatch, or negative inputs on the auto-k path. |
| Value nk::comm::bsc | ( | ::nk::ops::RngContext & | rng, |
| const Value & | x, | ||
| double | p, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Binary symmetric channel — flip each bit with probability p (y = bsc(x, p)).
| x | Input bit array (logical or 0/1 numeric). |
| p | Bit-flip probability in [0, 1]. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::compand | ( | const Value & | x, |
| double | param, | ||
| double | V, | ||
| const std::string & | method, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
μ-law / A-law signal compander (y = compand(x, param, V, method)).
Formulas:
Output preserves input shape.
| x | Input signal (any shape). |
| param | μ for μ-law (typical 255) or A for A-law (typical 87.6). |
| V | Peak magnitude. |
| method | "mu/compressor", "mu/expander", "A/compressor", or "A/expander". |
| mr | Memory resource (nullptr → process default). |
| Error | Unknown method string. |
| Value nk::comm::convenc | ( | const Value & | msg, |
| const Value & | trellis, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Convolutionally encode a bit stream (code = convenc(msg, trellis)).
Runs the rate-1/n encoder described by trellis (from poly2trellis) over the input bits msg, starting from the all-zeros state. Each input bit emits n = log2(numOutputSymbols) output bits (the trellis output word, MSB first); the encoder then advances to nextStates(state, bit). The output has n * numel(msg) bits and takes msg's orientation (row → row, column → column). No tail-biting / termination flush (truncated mode) and no puncturing in v1.
| msg | Input bit vector (0/1). |
| trellis | Trellis struct from poly2trellis (k = 1 / rate 1/n). |
| mr | Memory resource (nullptr → process default). |
| Error | if trellis is not a valid 1×1 trellis struct. |
| Value nk::comm::convertSNR | ( | const Value & | snr_in, |
| const std::string & | in_type, | ||
| const std::string & | out_type, | ||
| int | bits_per_symbol, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Convert between Eb/No, Es/No, and SNR (snr_out = convertSNR(snr_in, in_type, out_type, k)).
Currently supports k-only conversion via Es/No = Eb/No + 10·log10(k). Sample-rate conversion requires extra arguments and is deferred.
| snr_in | Input SNR in dB (array). |
| in_type | "ebno", "esno", or "snr". |
| out_type | Destination type (same set). |
| bits_per_symbol | k, bits per symbol. |
| mr | Memory resource (nullptr → process default). |
| CyclgenResult nk::comm::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, genpoly, opt)).
Builds the (n, k) cyclic code defined by generator polynomial genpoly (a binary row in ascending powers; k = n - deg(genpoly)). genpoly must divide x^n - 1 over GF(2).
| n | Codeword length. |
| genpoly | Generator polynomial (ascending binary row). |
| opt | "system" (default) or "nonsystem". |
| mr | Memory resource (nullptr → process default). |
| Error | if genpoly does not divide x^n - 1, or opt is unknown. |
| Value nk::comm::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, k, opt)).
Searches degree-(n-k) binary polynomials of the form 1 + … + x^(n-k) (constant and leading terms set) for those that divide x^n - 1 over GF(2) — the defining property of a cyclic generator polynomial. The opt flag selects which result(s) to return:
| n | Codeword length (>= 1). |
| k | Message length (1 <= k <= n). |
| opt | Selection flag ("", "min", "max", "all"). |
| mr | Memory resource (nullptr → process default). |
| Error | on non-integer / out-of-range n or k, or an unknown opt. |
| Value nk::comm::de2bi | ( | const Value & | d, |
| int | n = -1, | ||
| int | base = 2, | ||
| bool | msbfirst = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Convert integers to digit-rows — b = de2bi(d) (legacy).
Inverse of bi2de: each input integer becomes one row of base-base digits. Width n is the minimum number of digits; when n <= 0 it is computed from the largest input. Defaults to base 2, LSB-first ('right-msb'). Legacy synonym of int2bit (still in R2025b).
| d | Integer values. |
| n | Digit width; <= 0 (default -1) auto-sizes from max(d). |
| base | Digit base, >= 2 (default 2). |
| msbfirst | false (default, 'right-msb') puts the least significant digit first; true ('left-msb') reverses. |
| mr | Memory resource (nullptr → process default). |
| Error | if base < 2. |
| DecodeResult nk::comm::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)).
Syndrome decoder: reshapes code into n-bit words, computes each syndrome against the parity-check matrix, looks up the minimum-weight coset leader, corrects, and extracts the k message bits. Methods and opt mirror encode ("hamming/binary" default, "linear/binary" with a generator matrix, "cyclic/binary" with a generator polynomial). The Hamming method corrects any single-bit error directly from the syndrome.
| code | Received codeword bits (or integers for decimal). |
| n | Codeword length. |
| k | Message length. |
| method | Coding method (default "hamming/binary"). |
| opt | Method option (as in encode), or empty. |
| mr | Memory resource (nullptr → process default). |
| Error | on a bad n/k, an unknown method, or a missing / malformed opt. |
| Value nk::comm::descrambler | ( | const Value & | y, |
| const Value & | poly, | ||
| const Value & | initState, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Multiplicative bit descrambler — algebraic inverse of scrambler (x = descrambler(y, poly, initState)).
Per-bit recursion:
Round-trip with scrambler using the same poly and initState recovers the original bit sequence exactly.
| y | Column of scrambled bits. |
| poly | Same coefficient vector as the scrambler. |
| initState | Same initial state as the scrambler. |
| mr | Memory resource (nullptr → process default). |
| Error | On bad poly or state size. |
| std::pair< Value, Value > nk::comm::dpcmdeco | ( | const Value & | indx, |
| const Value & | codebook, | ||
| const Value & | predictor, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
DPCM decoder — invert dpcmenco ([sig, quanterr] = dpcmdeco(indx, codebook, predictor)).
Recovers the signal from the index sequence using the same codebook and predictor as the encoder.
| indx | Index sequence from dpcmenco. |
| codebook | Quantization codebook (length K). |
| predictor | Same [0, p1, …, pM] used at encode time. |
| mr | Memory resource (nullptr → process default). |
| std::pair< Value, Value > nk::comm::dpcmenco | ( | const Value & | sig, |
| const Value & | codebook, | ||
| const Value & | partition, | ||
| const Value & | predictor, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
DPCM encoder ([indx, quanterr] = dpcmenco(sig, codebook, partition, predictor)).
The predictor's leading element is a sentinel 0; the remaining M elements are the FIR coefficients. length(codebook) == length(partition) + 1.
| sig | Real input vector. |
| codebook | Quantization codebook (length K). |
| partition | Strictly increasing partition (length K − 1). |
| predictor | [0, p1, …, pM]. |
| mr | Memory resource (nullptr → process default). |
| DpcmOptResult nk::comm::dpcmopt | ( | const Value & | training_set, |
| int | ord, | ||
| const Value & | ini_codebook = Value::Empty, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Optimise DPCM predictor + (optional) quantizer ([predictor, codebook, partition] = dpcmopt(training, ord, ini_codebook)).
| training_set | Training signal (real vector). |
| ord | Predictor order ≥ 0. |
| ini_codebook | Optional initial codebook (or codebook size). Pass Value::Empty to skip codebook design. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::dpskdemod | ( | const Value & | y, |
| int | M, | ||
| double | phase_rot, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Differential PSK demodulator — phase-difference decoder (x = dpskdemod(y, M, phase_rot, symbol_order)).
| y | Received complex samples. |
| M | Modulation order. |
| phase_rot | Same per-step rotation used at modulation. |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::dpskmod | ( | const Value & | x, |
| int | M, | ||
| double | phase_rot, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Differential PSK modulator (y = dpskmod(x, M, phase_rot, symbol_order)).
First symbol uses an initial reference phase (default phase_rot); each subsequent input adds a phase increment determined by the symbol.
| x | Integer symbols in 0..M-1. |
| M | Modulation order. |
| phase_rot | Per-step phase rotation in radians. |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| EncodeResult nk::comm::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)).
Reshapes the message into k-bit words and multiplies (mod 2) by the code's generator matrix. Supported method strings:
| msg | Message bits (or integers for the decimal format). |
| n | Codeword length. |
| k | Message length. |
| method | Coding method (see above; default "hamming/binary"). |
| opt | Method option (primitive poly / generator matrix / generator polynomial), or empty. |
| mr | Memory resource (nullptr → process default). |
| Error | on a bad n/k, an unknown method, or a missing / malformed opt where the method requires one. |
| Value nk::comm::fmdemod | ( | const Value & | y, |
| double | fc, | ||
| double | fs, | ||
| double | freqdev, | ||
| double | ini_phase, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Frequency demodulator — inverse of fmmod (x = fmdemod(y, fc, fs, freqdev, ini_phase)).
Differentiates the unwrapped instantaneous phase of the down-converted analytic signal: x = [0, diff(unwrap(φ))]·fs / (2π·freqdev) where φ = angle(hilbert(y)·exp(−j·(2π·fc·t + ini_phase))).
| y | Modulated signal. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| freqdev | Frequency-deviation factor (Hz per unit message). |
| ini_phase | Initial carrier phase in radians. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::fmmod | ( | const Value & | x, |
| double | fc, | ||
| double | fs, | ||
| double | freqdev, | ||
| double | ini_phase, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Frequency modulator (y = fmmod(x, fc, fs, freqdev, ini_phase)).
int_x = cumsum(x)/fs; y = cos(2π·fc·t + 2π·freqdev·int_x + ini_phase).
| x | Real input message. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| freqdev | Frequency-deviation factor (Hz per unit of x). |
| ini_phase | Initial carrier phase in radians. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::fskdemod | ( | const Value & | y, |
| int | M, | ||
| double | freq_sep, | ||
| int | nsamp, | ||
| double | fs, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
M-ary FSK demodulator (x = fskdemod(y, M, freq_sep, nsamp, fs, symbol_order)).
Per-symbol energy detection across the M candidate tones.
| y | Complex baseband waveform. |
| M | Number of frequency tones. |
| freq_sep | Spacing between tones in Hz. |
| nsamp | Samples per symbol. |
| fs | Sample rate in Hz. |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::fskmod | ( | const Value & | x, |
| int | M, | ||
| double | freq_sep, | ||
| int | nsamp, | ||
| double | fs, | ||
| const std::string & | phase_continuity, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
M-ary FSK modulator (y = fskmod(x, M, freq_sep, nsamp, fs, phase_continuity, symbol_order)).
| x | Integer symbols in 0..M-1 (column or row). |
| M | Number of frequency tones. |
| freq_sep | Spacing between tones in Hz. |
| nsamp | Samples per symbol. |
| fs | Sample rate in Hz. |
| phase_continuity | "cont" (default) or "discont". |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::gaussdesign | ( | double | BT, |
| int | span, | ||
| int | sps, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Design a Gaussian FIR pulse-shaping filter (h = gaussdesign(BT, span, sps)).
Formula:
| BT | 3-dB bandwidth × symbol period (typical 0.1..0.5). |
| span | Filter span in symbol periods (positive integer). |
| sps | Samples per symbol (positive integer). |
| mr | Memory resource (nullptr → process default). |
| Error | On invalid BT, span, or sps. |
Parity-check matrix from a generator matrix, or vice versa (h = gen2par(g)).
Converts between the two systematic descriptions of a linear block code. The input mat is an r×c binary matrix with r < c:
| mat | Binary generator or parity-check matrix (r×c, r < c). |
| mr | Memory resource (nullptr → process default). |
| Error | if r >= c or neither the first nor the last r columns of mat form an identity matrix. |
| Value nk::comm::genqamdemod | ( | const Value & | y, |
| const Value & | constellation, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generic constellation demodulator (x = genqamdemod(y, constellation)).
Returns the integer index in [0, M-1] of the constellation point closest (squared Euclidean) to each entry of y.
| y | Received samples. |
| constellation | Length-M constellation table. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::genqammod | ( | const Value & | x, |
| const Value & | constellation, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generic constellation modulator (y = genqammod(x, constellation)).
Maps integer-coded symbols x ∈ [0, M-1] by indexing into the user-supplied constellation (length M, real or complex). Output preserves the input shape; type follows the constellation (complex if it has any imaginary content). Bit-input mode ('InputType', 'bit') is deferred.
| x | Integer symbol stream. |
| constellation | Length-M constellation table. |
| mr | Memory resource (nullptr → process default). |
| HammgenResult nk::comm::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)).
Builds the (n, k) Hamming code with n = 2^m - 1, k = n - m. The parity-check matrix h is m × n; its i-th column (1-based i, i = 0…n-1) holds the GF(2) coefficients of x^i mod p(x), ascending in the power of x, where p is the degree-m primitive polynomial. The first m columns therefore form I_m, so the code is systematic and g = gen2par(h).
| m | Number of parity bits (>= 2). |
| primPoly | Optional primitive polynomial as an ascending binary coefficient row of length m+1 (empty → the default primitive polynomial for degree m). |
| mr | Memory resource (nullptr → process default). |
| Error | if m < 2, or primPoly (when supplied) is not a binary row of length m+1. |
| Value nk::comm::huffmandeco | ( | const Value & | bits, |
| const Value & | dict, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Decode a Huffman bit stream (dec = huffmandeco(bits, dict)).
Walks bits through a prefix tree built from dict. Returns the recovered symbol vector with bits' orientation.
| bits | 0/1 bit vector to decode. |
| dict | Same dictionary used at encode time. |
| mr | Memory resource (nullptr → process default). |
| Error | On invalid bit values, mid-stream patterns not in dict, or trailing bits that do not complete a code. |
| std::pair< Value, double > nk::comm::huffmandict | ( | const Value & | symbols, |
| const Value & | probs, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Build a canonical Huffman dictionary ([dict, avglen] = huffmandict(symbols, probs)).
Returns the dictionary as a K-by-2 cell:
along with the average code length avglen = Σ p_i · length(code_i).
| symbols | Length-K vector of symbol values (any doubles). |
| probs | Length-K probability vector that must sum to 1. |
| mr | Memory resource (nullptr → process default). |
| Error | On length mismatch or non-normalised probs. |
| Value nk::comm::huffmanenco | ( | const Value & | sig, |
| const Value & | dict, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Encode a symbol sequence using a Huffman dictionary (enc = huffmanenco(sig, dict)).
Concatenates the per-symbol codes from dict into a flat 0/1 bit vector. Output preserves sig's row/column orientation.
| sig | Symbol sequence (values drawn from dict{:,1}). |
| dict | Dictionary produced by huffmandict. |
| mr | Memory resource (nullptr → process default). |
| Error | If sig contains symbols not present in dict. |
| Value nk::comm::int2bit | ( | const Value & | d, |
| int | n, | ||
| bool | msbfirst = true, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Unpack integers into a bit matrix — b = int2bit(d, n).
Inverse of bit2int: each of the numel(d) integers becomes one column of n bits, giving an n × numel(d) matrix (MSB-first by default).
| d | Integer values. |
| n | Bits per integer, in 1..64. |
| msbfirst | true (default) emits MSB-first; false LSB-first. |
| mr | Memory resource (nullptr → process default). |
| Error | if n ∉ 1..64. |
Integrate-and-dump (y = intdump(x, n)).
Averages each n consecutive samples of x along the leading non-singleton dimension. Algebraic inverse of rectpulse for length-divisible inputs.
| x | Input signal (vector or matrix, DOUBLE). |
| n | Block size (positive integer). |
| mr | Memory resource (nullptr → process default). |
| Error | If the relevant dimension is not divisible by n, or n is non-positive. |
Validate a trellis structure (tf = istrellis(S)).
Returns logical true iff S is a well-formed trellis struct: a 1×1 struct carrying numInputSymbols, numOutputSymbols, numStates (positive powers of two), and nextStates / outputs matrices of size numStates × numInputSymbols whose entries lie in [0, numStates) and [0, numOutputSymbols) respectively. Any other value → false (never throws). MATLAB's 2nd msg output is a v1 gap.
| S | Value to test. |
| mr | Memory resource (nullptr → process default). |
| std::tuple< Value, Value, double, double > nk::comm::lloyds | ( | const Value & | training_set, |
| const Value & | ini_codebook, | ||
| double | tol = 1e-7, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Lloyd-Max scalar quantizer designer ([partition, codebook, distor, rel] = lloyds(training, ini_codebook, tol)).
Iteratively alternates between optimal partition (mid-points between adjacent codebook entries) and optimal codebook (centroid of each cell) until the relative-distortion change drops below tol.
| training_set | Non-empty vector of real samples. |
| ini_codebook | Either a positive integer K (initialise K linspace-centred codebook entries spanning the training range) or an explicit codebook vector (sorted ascending internally). |
| tol | Convergence tolerance on the relative distortion change. Default 1e-7. |
| mr | Memory resource (nullptr → process default). |
| Error | On empty training set or invalid ini_codebook. |
| Value nk::comm::marcumq | ( | const Value & | a, |
| const Value & | b, | ||
| int | m, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generalised Marcum Q-function (q = marcumq(a, b, m)).
Computed via the modified-Bessel-series. m = 1 is the standard Marcum Q.
| a | Non-centrality parameter (array). |
| b | Argument (array). |
| m | Order (positive integer, default 1). |
| mr | Memory resource (nullptr → process default). |
MIL-STD-188-110 QAM demodulator (z = mil188qamdemod(y, M)).
Inverts mil188qammod via nearest-constellation-point search.
| y | Received complex samples. |
| M | Modulation order (currently must be 16). |
| mr | Memory resource (nullptr → process default). |
| Error | Unsupported M. |
MIL-STD-188-110 QAM modulator (y = mil188qammod(x, M)).
Modulates integer indices using the MIL-STD-188-110 hard-coded constellation table. Currently only M = 16 is supported (M = 32, 64, 256 deferred).
| x | Integer symbol indices in 0..M-1. |
| M | Modulation order (currently must be 16). |
| mr | Memory resource (nullptr → process default). |
| Error | Unsupported M. |
| Value nk::comm::modnorm | ( | const Value & | ref, |
| const std::string & | type, | ||
| double | target, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Constellation normalisation factor (factor = modnorm(ref, type, target)).
Returns the scalar factor such that ref · factor has the requested average or peak power.
| ref | Reference constellation. |
| type | "avpow" (average power) or "peakpow" (peak power). |
| target | Desired power level. |
| mr | Memory resource (nullptr → process default). |
| Error | Unknown type or empty ref. |
| Value nk::comm::mskdemod | ( | const Value & | y, |
| int | nSamp, | ||
| double | ini_phase, | ||
| double * | phase_out = nullptr, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Minimum-shift-keying demodulator (differential variant) (z = mskdemod(y, nSamp [, ini_phase])).
Coherent inverse of mskmod. Each bit is the sign of the symbol's accumulated phase increment: bit_k = (Σ_{within symbol k} angle(y[n]·conj(y[n-1])) > 0). Because the decision uses phase increments, it is robust to a constant phase rotation and to noise, and ini_phase does not affect the bits (it only sets the returned final-phase state). Output has numel(y) / nSamp bits per channel, in the input's row/column orientation. Non-differential variant deferred (matching mskmod).
| y | Complex baseband MSK waveform (length a multiple of nSamp). |
| nSamp | Samples per symbol. |
| ini_phase | Initial carrier phase (radians); only feeds phase_out. |
| phase_out | If non-null, receives the final phase state in [0, 2π). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::mskmod | ( | const Value & | x, |
| int | nSamp, | ||
| double | ini_phase, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Minimum-shift-keying modulator (differential variant) (y = mskmod(x, nSamp, ini_phase)).
Output length is numel(x) · nSamp. Linear-phase ramp produces the continuous-phase MSK constellation on the unit circle. Non-differential variant deferred.
| x | Symbol stream. |
| nSamp | Samples per symbol. |
| ini_phase | Initial carrier phase in radians. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::noisebw | ( | const Value & | num, |
| const Value & | den, | ||
| int | Nsamp, | ||
| double | fs, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Equivalent noise bandwidth of an LTI filter (bw = noisebw(num, den, Nsamp, fs)).
| num | Numerator coefficients. |
| den | Denominator coefficients. |
| Nsamp | Number of impulse-response samples used. |
| fs | Sample rate in Hz. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::ofdmdemod | ( | const Value & | in, |
| int | nfft, | ||
| int | cplen, | ||
| int | symoffset, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Basic OFDM demodulator (out = ofdmdemod(in, nfft, cplen, symoffset)).
symoffset (default = cplen) drops the cyclic prefix.
| in | Time-domain OFDM signal. |
| nfft | FFT length. |
| cplen | Cyclic prefix length. |
| symoffset | Sample offset within each symbol to start the FFT window. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::ofdmmod | ( | const Value & | in, |
| int | nfft, | ||
| int | cplen, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Basic OFDM modulator (y = ofdmmod(in, nfft, cplen)).
| in | nfft×Nsymbols complex matrix of subcarrier values. |
| nfft | IFFT length. |
| cplen | Cyclic prefix length. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::pamdemod | ( | const Value & | y, |
| int | M, | ||
| double | ini_phase, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
M-ary PAM demodulator — nearest-amplitude decision (x = pamdemod(y, M, ini_phase, symbol_order)).
| y | Received samples. |
| M | Modulation order. |
| ini_phase | Phase offset used at modulation time. |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::pammod | ( | const Value & | x, |
| int | M, | ||
| double | ini_phase, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
M-ary PAM modulator (y = pammod(x, M, ini_phase, symbol_order)).
Maps a symbol s ∈ 0..M-1 to a real-valued amplitude in {-(M-1), …, -1, 1, …, (M-1)}. Default: Gray ordering, no power normalisation.
| x | Integer symbols in 0..M-1. |
| M | Modulation order. |
| ini_phase | Phase offset in radians (default 0). |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::pmdemod | ( | const Value & | y, |
| double | fc, | ||
| double | fs, | ||
| double | phasedev, | ||
| double | ini_phase, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Phase demodulator — inverse of pmmod (x = pmdemod(y, fc, fs, phasedev, ini_phase)).
x = angle(hilbert(y)·exp(−j·(2π·fc·t + ini_phase))) / phasedev — the instantaneous phase of the analytic signal, down-converted by the carrier, scaled by the phase-deviation constant.
| y | Modulated signal. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| phasedev | Phase-deviation constant (radians per unit message). |
| ini_phase | Initial carrier phase in radians. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::pmmod | ( | const Value & | x, |
| double | fc, | ||
| double | fs, | ||
| double | phasedev, | ||
| double | ini_phase, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Phase modulator (y = pmmod(x, fc, fs, phasedev, ini_phase)).
y = cos(2π·fc·t + phasedev·x + ini_phase) evaluated on t = (0, 1/fs, 2/fs, …). Output preserves the input shape; row-vector input round-trips as a row vector.
| x | Real input message. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| phasedev | Phase-deviation factor (rad per unit of x). |
| ini_phase | Initial carrier phase in radians. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::poly2trellis | ( | const Value & | constraintLength, |
| const Value & | codeGenerator, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Convolutional-code trellis from polynomial generators (trellis = poly2trellis(ConstraintLength, CodeGenerator)).
Builds the MATLAB trellis struct describing a rate-1/n feed-forward convolutional encoder. Returns a 1×1 struct with fields (in MATLAB's order):
CodeGenerator entries are octal numbers (e.g. [6 7], [171 133]). The shift-register state holds the K-1 previous input bits; for each (state, input) the K-bit register reg = (input << (K-1)) | state drives output_i = parity(reg & g_i) and nextState = reg >> 1.
v1 scope: rate 1/n (scalar ConstraintLength, length-n CodeGenerator), feed-forward only. Rate k/n (vector ConstraintLength, k×n generator matrix) and feedback connections are a documented gap.
| constraintLength | Scalar constraint length K (>= 1). |
| codeGenerator | Length-n vector of octal generator polynomials. |
| mr | Memory resource (nullptr → process default). |
| Error | on a non-scalar constraintLength (rate k/n), K < 1, an empty codeGenerator, or an octal digit > 7. |
| Value nk::comm::pskdemod | ( | const Value & | y, |
| int | M, | ||
| double | ini_phase, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
M-ary PSK demodulator — nearest-phase decision (x = pskdemod(y, M, ini_phase, symbol_order)).
| y | Received complex samples. |
| M | Modulation order. |
| ini_phase | Phase reference used at modulation time. |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::pskmod | ( | const Value & | x, |
| int | M, | ||
| double | ini_phase, | ||
| const std::string & | symbol_order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
M-ary PSK modulator (y = pskmod(x, M, ini_phase, symbol_order)).
| x | Integer symbols in 0..M-1. |
| M | Modulation order. |
| ini_phase | Phase shift in radians applied to all symbols (default 0). |
| symbol_order | "gray" (default) or "bin". |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::qamdemod | ( | const Value & | y, |
| int | M, | ||
| const std::string & | symbol_order, | ||
| bool | unit_power, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Rectangular M-ary QAM demodulator (x = qamdemod(y, M, symbol_order, unit_power)).
| y | Received complex samples. |
| M | Modulation order. |
| symbol_order | "gray" (default) or "bin". |
| unit_power | If true, the modulator used unit-power scaling. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::qammod | ( | const Value & | x, |
| int | M, | ||
| const std::string & | symbol_order, | ||
| bool | unit_power, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Rectangular M-ary QAM modulator (y = qammod(x, M, symbol_order, unit_power)).
Requires M = K² (perfect square); for non-square M the implementation falls back to a rectangular grid floor(√M) × ceil(M / floor(√M)).
| x | Integer symbols in 0..M-1. |
| M | Modulation order. |
| symbol_order | "gray" (default) or "bin". |
| unit_power | If true, scale the constellation to unit average power. |
| mr | Memory resource (nullptr → process default). |
Gaussian Q-function: Q(x) = 0.5·erfc(x/√2).
| x | Input array (any shape, DOUBLE). |
| mr | Memory resource (nullptr → process default). |
Inverse Q-function: Q⁻¹(p) = √2·erfc⁻¹(2p).
| p | Input array (any shape, DOUBLE) with values in (0, 1). |
| mr | Memory resource (nullptr → process default). |
| QuantizResult nk::comm::quantiz | ( | const Value & | sig, |
| const Value & | partition, | ||
| const Value & | codebook, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Three-output form of quantiz ([indx, quantv, distor] = quantiz(sig, partition, codebook)).
| sig | Input signal. |
| partition | Strictly increasing partition vector (length K-1). |
| codebook | Codebook vector (length K). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::quantiz_indx | ( | const Value & | sig, |
| const Value & | partition, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
One-output form of quantiz — bin index per sample (indx = quantiz(sig, partition)).
indx(i) = sum(partition < sig(i)), in the range [0, length(partition)]. Output preserves sig's orientation.
| sig | Input signal (real vector). |
| partition | Strictly increasing partition vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::randerr | ( | ::nk::ops::RngContext & | rng, |
| size_t | m, | ||
| size_t | n, | ||
| const Value & | errspec, | ||
| bool | have_state, | ||
| uint32_t | state, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generate an m×n binary error pattern (out = randerr(m, n, errors, state)).
Each row contains a controlled number of 1s ("errors") at random column positions. errspec is either:
| m | Row count. |
| n | Column count. |
| errspec | Error count specification (see above). |
| have_state | If true, use the supplied seed. |
| state | Seed for the isolated MatlabMT19937 instance. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::randsrc | ( | ::nk::ops::RngContext & | rng, |
| size_t | m, | ||
| size_t | n, | ||
| const Value & | alphabet, | ||
| bool | have_state, | ||
| uint32_t | state, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generate an m×n random matrix from a finite alphabet (out = randsrc(m, n, alphabet, state)).
alphabet is either:
When have_state is true, draws come from an isolated MT19937 seeded with state (equivalent to RandStream('mt19937ar','Seed', state)); otherwise the shared engine is used.
| m | Row count. |
| n | Column count. |
| alphabet | Alphabet specification (see above). Default Value::Empty → [-1, 1] uniform. |
| have_state | If true, use the supplied seed. |
| state | Seed for the isolated MT19937. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::rayleighchan | ( | ::nk::ops::RngContext & | rng, |
| const Value & | x, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Apply iid frequency-flat Rayleigh fading (y = rayleighchan(x)).
Each sample of x is multiplied by an independent complex Gaussian h ~ CN(0, 1), giving E[|h|²] = 1 (unit-power channel). Output is always complex even when x is real.
| x | Input signal (any shape). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::rcosdesign | ( | double | beta, |
| int | span, | ||
| int | sps, | ||
| const std::string & | shape = "normal", | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Design a raised-cosine or root-raised-cosine FIR filter (h = rcosdesign(beta, span, sps, shape)).
Closed-form coefficients:
Standard l'Hôpital limits applied at t = 0 and t = ±T/(4β). Returns a row vector of length span·sps + 1. Both RC and RRC outputs are unit-energy normalised (‖h‖² = 1).
| beta | Roll-off factor, 0 ≤ β ≤ 1. |
| span | Filter span in symbol periods (positive integer). |
| sps | Samples per symbol (positive integer). |
| shape | "normal" → RC (default), "sqrt" → RRC. |
| mr | Memory resource (nullptr → process default). |
| Error | On invalid β, span, sps, or unknown shape. |
Rectangular pulse shaping (y = rectpulse(x, n)).
Repeats each sample of x n times along the leading non-singleton dimension. For an L×1 column input → (L·n)×1 output; for 1×L row → 1×(L·n); for matrices each row is repeated n times (column count unchanged).
| x | Input signal (vector or matrix, DOUBLE). |
| n | Repetition factor (positive integer). |
| mr | Memory resource (nullptr → process default). |
| Error | On non-positive n. |
| Value nk::comm::ricianchan | ( | ::nk::ops::RngContext & | rng, |
| const Value & | x, | ||
| double | K, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Apply iid frequency-flat Rician fading (y = ricianchan(x, K)).
Each sample is multiplied by h = √(K/(K+1)) + √(1/(K+1)) · g with g ~ CN(0, 1). E[|h|²] = 1 regardless of K.
| x | Input signal (any shape). |
| K | Linear K-factor (LOS / NLOS power ratio, ≥ 0). |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::scrambler | ( | const Value & | x, |
| const Value & | poly, | ||
| const Value & | initState, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Multiplicative bit scrambler (y = scrambler(x, poly, initState)).
Per-bit recursion:
Both scrambler and descrambler clock the channel bit y[k] into the shift register, which is what makes the descrambler self-synchronizing.
| x | Column of input bits (0/1, DOUBLE or LOGICAL). |
| poly | Length-(n+1) coefficient vector [g_0, g_1, …, g_n] with g_0 = 1; non-zero entries mark register taps. |
| initState | Length-n initial register contents (bits 0/1). |
| mr | Memory resource (nullptr → process default). |
| Error | On bad poly (length, g_0 = 0) or state size. |
| Value nk::comm::ssbdemod | ( | const Value & | y, |
| double | fc, | ||
| double | fs, | ||
| double | ini_phase, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Single-sideband demodulator — inverse of ssbmod (x = ssbdemod(y, fc, fs, ini_phase)).
Coherent detection: x = 2·filtfilt(butter(5, fc·2/fs), y·cos(2π·fc·t + ini_phase)). Recovers the message regardless of which sideband was transmitted.
| y | Modulated signal. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| ini_phase | Initial carrier phase in radians. |
| mr | Memory resource (nullptr → process default). |
| Value nk::comm::ssbmod | ( | const Value & | x, |
| double | fc, | ||
| double | fs, | ||
| double | ini_phase, | ||
| bool | upper, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Single-sideband modulator (y = ssbmod(x, fc, fs, ini_phase, upper)).
y = x·cos(2π·fc·t + ini_phase) ± imag(hilbert(x))· sin(2π·fc·t + ini_phase) with + for lower sideband (default, upper = false) and − for upper.
| x | Real input message. |
| fc | Carrier frequency in Hz. |
| fs | Sample rate in Hz. |
| ini_phase | Initial carrier phase in radians. |
| upper | true → upper sideband, false → lower. |
| mr | Memory resource (nullptr → process default). |
| std::pair< Value, Value > nk::comm::symerr | ( | const Value & | x, |
| const Value & | y, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Symbol-error count and rate ([number, ratio] = symerr(x, y)).
Counts element-wise inequalities between the same-shape arrays x and y. Returns { count, ratio } with ratio = count / numel.
| x,y | Same-numel arrays. |
| mr | Memory resource (nullptr → process default). |
| Error | on numel mismatch. |
Syndrome decoding table (coset-leader lookup) from a parity-check matrix (t = syndtable(H)).
For an (n-k) × n parity-check matrix H, returns the 2^(n-k) × n table whose row s+1 holds the minimum-weight error pattern (coset leader) with syndrome s = bi2de(mod(H·eᵀ, 2), 'left-msb') (row 1 of H is the MSB). Error patterns are enumerated by ascending Hamming weight, and within a weight by lexicographic bit position; the first pattern reaching each syndrome wins (so among equal-weight leaders the lowest-position one is chosen).
| H | Parity-check matrix, (n-k) × n, binary. |
| mr | Memory resource (nullptr → process default). |
| Error | if H is empty or n-k is impractically large. |
| std::pair< Value, int > nk::comm::vec2mat | ( | const Value & | v, |
| int | n, | ||
| double | padval = 0.0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Reshape a vector into an N-column matrix with padding — [m, pad] = vec2mat(v, n).
Row-major fill of v into a ceil(numel(v)/n) × n matrix, padding the last row to width n with padval. Returns the matrix and the count of pad entries added. MATLAB documents vec2mat as legacy (superseded by reshape), but it still ships in R2025b.
| v | Input vector. |
| n | Number of columns (positive). |
| padval | Pad value for the last row (default 0). |
| mr | Memory resource (nullptr → process default). |
| Error | if n <= 0. |
| Value nk::comm::vitdec | ( | const Value & | code, |
| const Value & | trellis, | ||
| long long | tblen, | ||
| const std::string & | opmode = "trunc", | ||
| const std::string & | dectype = "hard", | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Viterbi-decode a convolutional code (msg = vitdec(code, trellis, tblen, opmode, dectype)).
Hard-decision maximum-likelihood (Viterbi) decoder for the rate-1/n trellis. Runs the add-compare-select forward recursion over the numel(code)/n received symbols (branch metric = Hamming distance to each trellis output word) and traces the survivor path back to recover the message bits.
opmode:
| code | Received bit vector (length a multiple of n). |
| trellis | Trellis struct from poly2trellis. |
| tblen | Traceback depth (advisory in trunc/term). |
| opmode | "trunc" (default) or "term". |
| dectype | "hard" (default; only hard-decision supported). |
| mr | Memory resource (nullptr → process default). |
| Error | on an invalid trellis, numel(code) not a multiple of n, or an unsupported opmode/dectype. |
| Value nk::comm::wgn | ( | ::nk::ops::RngContext & | rng, |
| int | m, | ||
| int | n, | ||
| double | p, | ||
| const std::string & | type, | ||
| bool | complex_out, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generate an m×n matrix of white Gaussian noise samples (y = wgn(m, n, p, type, complex)).
| m | Row count. |
| n | Column count. |
| p | Power, interpreted per type. |
| type | "dBW" (default), "dBm", or "linear". |
| complex_out | If true, samples are circular complex Gaussian. |
| mr | Memory resource (nullptr → process default). |