nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Communications Toolbox (comm)

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)).

Detailed Description

Digital modulation schemes (PSK, QAM, APSK, FSK, OFDM), channel models (AWGN, fading), error correction coding, and source coding.

Function Documentation

◆ amdemod()

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.)

Parameters
yModulated signal.
fcCarrier frequency in Hz.
fsSample rate in Hz.
ini_phaseInitial carrier phase in radians.
carr_ampTransmitted-carrier amplitude (subtracted after detect).
mrMemory resource (nullptr → process default).
Returns
Recovered message, same shape as y.
See also
ammod, ssbdemod

◆ ammod()

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).

Parameters
xReal input message.
fcCarrier frequency in Hz.
fsSample rate in Hz.
ini_phaseInitial carrier phase in radians.
carr_ampCarrier amplitude (0 → DSB-SC).
mrMemory resource (nullptr → process default).
Returns
Modulated signal, same shape as x.
See also
pmmod, fmmod, ssbmod

◆ apskdemod()

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.

Parameters
yReceived complex samples.
MPer-ring symbol count.
radiiPer-ring radius.
phaseoffsetOptional per-ring phase offset; Value::Empty uses the default π / M_k.
mappingOptional symbol-mapping permutation; Value::Empty uses identity.
mrMemory resource (nullptr → process default).
Returns
Integer symbol indices, same shape as y.
See also
apskmod

◆ apskmod()

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.

Parameters
xInteger symbol indices in 0..sum(M)-1.
MPer-ring symbol count (length R).
radiiPer-ring radius (length R, same as M).
phaseoffsetOptional per-ring phase offset; Value::Empty uses the default π / M_k.
mappingOptional symbol-mapping permutation; Value::Empty uses identity.
mrMemory resource (nullptr → process default).
Returns
Complex baseband samples, same shape as x.
See also
apskdemod

◆ arithdeco()

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.

Parameters
code0/1 bit vector produced by arithenco.
countsSame count vector used during encoding.
lenExpected decoded length.
mrMemory resource (nullptr → process default).
Returns
Decoded symbol sequence of length len.
Exceptions
ErrorOn bad inputs or truncated bit stream.
See also
arithenco

◆ arithenco()

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.

Parameters
seqSymbol sequence (positive integer values in 1..length(counts)).
countsPositive integer count vector (length K).
mrMemory resource (nullptr → process default).
Returns
0/1 bit vector encoding seq.
Exceptions
ErrorOn bad seq symbols or non-positive counts.
See also
arithdeco

◆ awgn()

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.

Parameters
xInput signal.
snr_dbTarget SNR in dB.
sigpower_dbSignal power in dBW, or -1 ⇒ "measured" (estimate from x).
mrMemory resource (nullptr → process default).
Returns
Noisy signal of the same shape as x.
See also
wgn, bsc

◆ berawgn()

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)).

Parameters
EbNo_dBEb/No values in dB (array).
mod"psk", "dpsk", "qam", "pam", or "fsk".
MModulation order.
mrMemory resource (nullptr → process default).
Returns
Element-wise BER.
Exceptions
ErrorUnknown modulation string or invalid M.

◆ berconfint()

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)).

Parameters
numErrsObserved error count.
numBitsTotal bit count.
levelConfidence level in (0, 1), e.g. 0.95.
mrMemory resource (nullptr → process default).
Returns
Tuple (ber, ci) where ber = numErrs / numBits and ci = [lo, hi].

◆ bi2de()

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.

Parameters
b2-D matrix of digit rows.
baseDigit base, >= 2 (default 2).
msbfirstfalse (default, 'right-msb') treats the first column as least significant; true ('left-msb') reverses.
mrMemory resource (nullptr → process default).
Returns
Column vector of per-row decimal values.
Exceptions
Errorif b is not 2-D or base < 2.
See also
de2bi, bit2int

◆ bit2int()

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.

Parameters
bBit values (numel divisible by n).
nBits per integer, in 1..64.
msbfirsttrue (default) packs MSB-first; false LSB-first.
mrMemory resource (nullptr → process default).
Returns
Column vector of numel(b) / n packed integers.
Exceptions
Errorif n ∉ 1..64 or numel(b) is not divisible by n.
See also
int2bit

◆ biterr()

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.)

Parameters
x,ySame-numel non-negative integer arrays.
kBits per symbol; <= 0 (default) → smallest covering width.
mrMemory resource (nullptr → process default).
Returns
Pair { number, ratio } (total bit errors and error rate).
Exceptions
Erroron numel mismatch, or negative inputs on the auto-k path.
See also
symerr

◆ bsc()

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)).

Parameters
xInput bit array (logical or 0/1 numeric).
pBit-flip probability in [0, 1].
mrMemory resource (nullptr → process default).
Returns
Output array of the same shape as x.
See also
awgn

◆ compand()

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:

  • μ-law compress: y = sign(x) · V · log(1 + μ|x|/V) / log(1 + μ)
  • μ-law expand: x = sign(y) · (V/μ) · (exp(|y|/V · log(1+μ)) - 1)
  • A-law compress, |x|/V ≤ 1/A: y = sign(x) · A·|x| / (1 + log A)
  • A-law compress, else: y = sign(x) · V · (1 + log(A·|x|/V)) / (1 + log A)

Output preserves input shape.

Parameters
xInput signal (any shape).
paramμ for μ-law (typical 255) or A for A-law (typical 87.6).
VPeak magnitude.
method"mu/compressor", "mu/expander", "A/compressor", or "A/expander".
mrMemory resource (nullptr → process default).
Returns
Companded signal of the same shape as x.
Exceptions
ErrorUnknown method string.

◆ convenc()

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.

Parameters
msgInput bit vector (0/1).
trellisTrellis struct from poly2trellis (k = 1 / rate 1/n).
mrMemory resource (nullptr → process default).
Returns
Encoded bit vector (length n * numel(msg)).
Exceptions
Errorif trellis is not a valid 1×1 trellis struct.
See also
poly2trellis, vitdec

◆ convertSNR()

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.

Parameters
snr_inInput SNR in dB (array).
in_type"ebno", "esno", or "snr".
out_typeDestination type (same set).
bits_per_symbolk, bits per symbol.
mrMemory resource (nullptr → process default).
Returns
Converted SNR (dB) of the same shape as snr_in.

◆ cyclgen()

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).

  • opt = "system" (default) — systematic matrices g = [I_k | P], h = [Pᵀ | I_(n-k)] formed from the parity remainders x^(n-k+i) mod genpoly.
  • opt = "nonsystem" (or "no…") — the classic cyclic-shift matrices: rows are successive single-position rotations of the reversed parity / generator polynomials.
Parameters
nCodeword length.
genpolyGenerator polynomial (ascending binary row).
opt"system" (default) or "nonsystem".
mrMemory resource (nullptr → process default).
Returns
CyclgenResult (h, g, k).
Exceptions
Errorif genpoly does not divide x^n - 1, or opt is unknown.

◆ cyclpoly()

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:

  • "" (default) — the first generator polynomial found;
  • "min" — the generator polynomial with the fewest terms;
  • "max" — the generator polynomial with the most terms;
  • "all" — every generator polynomial, one per row. Each polynomial is a binary row in ascending powers of x.
Parameters
nCodeword length (>= 1).
kMessage length (1 <= k <= n).
optSelection flag ("", "min", "max", "all").
mrMemory resource (nullptr → process default).
Returns
Generator polynomial row (or rows for "all"); empty if no valid generator polynomial exists.
Exceptions
Erroron non-integer / out-of-range n or k, or an unknown opt.

◆ de2bi()

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).

Parameters
dInteger values.
nDigit width; <= 0 (default -1) auto-sizes from max(d).
baseDigit base, >= 2 (default 2).
msbfirstfalse (default, 'right-msb') puts the least significant digit first; true ('left-msb') reverses.
mrMemory resource (nullptr → process default).
Returns
numel(d) × n matrix of digit rows.
Exceptions
Errorif base < 2.
See also
bi2de, int2bit

◆ decode()

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.

Parameters
codeReceived codeword bits (or integers for decimal).
nCodeword length.
kMessage length.
methodCoding method (default "hamming/binary").
optMethod option (as in encode), or empty.
mrMemory resource (nullptr → process default).
Returns
DecodeResult (msg, err).
Exceptions
Erroron a bad n/k, an unknown method, or a missing / malformed opt.
See also
encode, hammgen, cyclgen

◆ descrambler()

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:

  • fb = XOR over i=1..n where g_i = 1 of state[i-1]
  • x[k] = y[k] XOR fb
  • shift state right by 1, store y[k] (channel bit) at state[0] — not x[k].

Round-trip with scrambler using the same poly and initState recovers the original bit sequence exactly.

Parameters
yColumn of scrambled bits.
polySame coefficient vector as the scrambler.
initStateSame initial state as the scrambler.
mrMemory resource (nullptr → process default).
Returns
Column of recovered DOUBLE bits in {0, 1}.
Exceptions
ErrorOn bad poly or state size.
See also
scrambler

◆ dpcmdeco()

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.

Parameters
indxIndex sequence from dpcmenco.
codebookQuantization codebook (length K).
predictorSame [0, p1, …, pM] used at encode time.
mrMemory resource (nullptr → process default).
Returns
Tuple (sig, quanterr).
See also
dpcmenco

◆ dpcmenco()

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.

Parameters
sigReal input vector.
codebookQuantization codebook (length K).
partitionStrictly increasing partition (length K − 1).
predictor[0, p1, …, pM].
mrMemory resource (nullptr → process default).
Returns
Tuple (indx, quanterr) — index sequence and quantisation error per sample.
See also
dpcmdeco, dpcmopt

◆ dpcmopt()

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)).

  • predictor: length-(ord+1) row vector [0, p1, …, pM] obtained from the Levinson-Durbin solution to the Yule-Walker autocorrelation system, then negated to match dpcmenco's convention.
  • codebook + partition: optional outputs from running lloyds on the prediction residual; emitted only when ini_codebook is supplied (integer K or explicit initial codebook vector).
Parameters
training_setTraining signal (real vector).
ordPredictor order ≥ 0.
ini_codebookOptional initial codebook (or codebook size). Pass Value::Empty to skip codebook design.
mrMemory resource (nullptr → process default).
Returns
DpcmOptResult with the new predictor and (optionally) codebook + partition.
See also
dpcmenco, dpcmdeco, lloyds

◆ dpskdemod()

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)).

Parameters
yReceived complex samples.
MModulation order.
phase_rotSame per-step rotation used at modulation.
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Integer symbol indices, same shape as y.
See also
dpskmod

◆ dpskmod()

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.

Parameters
xInteger symbols in 0..M-1.
MModulation order.
phase_rotPer-step phase rotation in radians.
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Complex baseband samples, same shape as x.
See also
dpskdemod, pskmod

◆ encode()

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:

  • "hamming/binary" (default) — Hamming (n, k); opt may give an alternative primitive polynomial.
  • "linear/binary" — generic linear code; opt is the k × n generator matrix (required).
  • "cyclic/binary" — cyclic code; opt is the generator polynomial (defaults to cyclpoly(n, k)). A …/decimal suffix takes / returns one integer per word instead of a bit stream. BCH / RS methods (which need a gf type) are a gap.
Parameters
msgMessage bits (or integers for the decimal format).
nCodeword length.
kMessage length.
methodCoding method (see above; default "hamming/binary").
optMethod option (primitive poly / generator matrix / generator polynomial), or empty.
mrMemory resource (nullptr → process default).
Returns
EncodeResult (code, added).
Exceptions
Erroron a bad n/k, an unknown method, or a missing / malformed opt where the method requires one.
See also
decode, hammgen, cyclgen

◆ fmdemod()

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))).

Parameters
yModulated signal.
fcCarrier frequency in Hz.
fsSample rate in Hz.
freqdevFrequency-deviation factor (Hz per unit message).
ini_phaseInitial carrier phase in radians.
mrMemory resource (nullptr → process default).
Returns
Recovered message, same shape as y.
See also
fmmod, pmdemod

◆ fmmod()

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).

Parameters
xReal input message.
fcCarrier frequency in Hz.
fsSample rate in Hz.
freqdevFrequency-deviation factor (Hz per unit of x).
ini_phaseInitial carrier phase in radians.
mrMemory resource (nullptr → process default).
Returns
Modulated signal, same shape as x.
See also
ammod, pmmod, ssbmod

◆ fskdemod()

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.

Parameters
yComplex baseband waveform.
MNumber of frequency tones.
freq_sepSpacing between tones in Hz.
nsampSamples per symbol.
fsSample rate in Hz.
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Integer symbol vector of length numel(y) / nsamp.
See also
fskmod

◆ fskmod()

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)).

Parameters
xInteger symbols in 0..M-1 (column or row).
MNumber of frequency tones.
freq_sepSpacing between tones in Hz.
nsampSamples per symbol.
fsSample rate in Hz.
phase_continuity"cont" (default) or "discont".
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Complex baseband waveform of length numel(x)·nsamp.
See also
fskdemod

◆ gaussdesign()

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:

  • α = √(log 2 / 2) / BT
  • h(t) = (√π / α) · exp(−(πt/α)²), evaluated on t = ((1:N) − mean(1:N)) / sps with N = span·sps + 1.
  • Output is sum-normalised (Σh = 1).
Parameters
BT3-dB bandwidth × symbol period (typical 0.1..0.5).
spanFilter span in symbol periods (positive integer).
spsSamples per symbol (positive integer).
mrMemory resource (nullptr → process default).
Returns
Row vector of length span·sps + 1, sum-normalised.
Exceptions
ErrorOn invalid BT, span, or sps.
See also
rcosdesign

◆ gen2par()

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)).

Converts between the two systematic descriptions of a linear block code. The input mat is an r×c binary matrix with r < c:

  • if its last r columns form I_r (i.e. mat = [P | I_r]), the result is [I_(c-r) | Pᵀ];
  • if its first r columns form I_r (i.e. mat = [I_r | P]), the result is [Pᵀ | I_(c-r)]. The map is an involution: gen2par(gen2par(mat)) == mat. Applying it to a generator matrix yields the parity-check matrix and the reverse.
Parameters
matBinary generator or parity-check matrix (r×c, r < c).
mrMemory resource (nullptr → process default).
Returns
The complementary (c-r)×c binary matrix.
Exceptions
Errorif r >= c or neither the first nor the last r columns of mat form an identity matrix.

◆ genqamdemod()

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.

Parameters
yReceived samples.
constellationLength-M constellation table.
mrMemory resource (nullptr → process default).
Returns
Integer indices, real, same shape as y.
See also
genqammod

◆ genqammod()

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.

Parameters
xInteger symbol stream.
constellationLength-M constellation table.
mrMemory resource (nullptr → process default).
Returns
Modulated samples, same shape as x.
See also
genqamdemod

◆ hammgen()

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).

Parameters
mNumber of parity bits (>= 2).
primPolyOptional primitive polynomial as an ascending binary coefficient row of length m+1 (empty → the default primitive polynomial for degree m).
mrMemory resource (nullptr → process default).
Returns
HammgenResult (h, g, n, k).
Exceptions
Errorif m < 2, or primPoly (when supplied) is not a binary row of length m+1.

◆ huffmandeco()

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.

Parameters
bits0/1 bit vector to decode.
dictSame dictionary used at encode time.
mrMemory resource (nullptr → process default).
Returns
Decoded symbol vector.
Exceptions
ErrorOn invalid bit values, mid-stream patterns not in dict, or trailing bits that do not complete a code.
See also
huffmandict, huffmanenco

◆ huffmandict()

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:

  • dict{k, 1} = symbol value (scalar)
  • dict{k, 2} = bit code (1×L row vector of 0/1 doubles)

along with the average code length avglen = Σ p_i · length(code_i).

Parameters
symbolsLength-K vector of symbol values (any doubles).
probsLength-K probability vector that must sum to 1.
mrMemory resource (nullptr → process default).
Returns
Pair (dict, avglen).
Exceptions
ErrorOn length mismatch or non-normalised probs.
See also
huffmanenco, huffmandeco

◆ huffmanenco()

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.

Parameters
sigSymbol sequence (values drawn from dict{:,1}).
dictDictionary produced by huffmandict.
mrMemory resource (nullptr → process default).
Returns
Flat 0/1 bit vector.
Exceptions
ErrorIf sig contains symbols not present in dict.
See also
huffmandict, huffmandeco

◆ int2bit()

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).

Parameters
dInteger values.
nBits per integer, in 1..64.
msbfirsttrue (default) emits MSB-first; false LSB-first.
mrMemory resource (nullptr → process default).
Returns
n × numel(d) bit matrix.
Exceptions
Errorif n ∉ 1..64.
See also
bit2int

◆ intdump()

Value nk::comm::intdump ( const Value & x,
int n,
std::pmr::memory_resource * mr = nullptr )

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.

Parameters
xInput signal (vector or matrix, DOUBLE).
nBlock size (positive integer).
mrMemory resource (nullptr → process default).
Returns
Averaged signal with same orientation as x.
Exceptions
ErrorIf the relevant dimension is not divisible by n, or n is non-positive.
See also
rectpulse

◆ istrellis()

Value nk::comm::istrellis ( const Value & S,
std::pmr::memory_resource * mr = nullptr )

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.

Parameters
SValue to test.
mrMemory resource (nullptr → process default).
Returns
Logical scalar.
See also
poly2trellis

◆ lloyds()

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.

Parameters
training_setNon-empty vector of real samples.
ini_codebookEither a positive integer K (initialise K linspace-centred codebook entries spanning the training range) or an explicit codebook vector (sorted ascending internally).
tolConvergence tolerance on the relative distortion change. Default 1e-7.
mrMemory resource (nullptr → process default).
Returns
Tuple (partition, codebook, distor, rel): final partition + codebook, achieved distortion, and last-step relative change.
Exceptions
ErrorOn empty training set or invalid ini_codebook.
See also
quantiz, dpcmopt

◆ marcumq()

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.

Parameters
aNon-centrality parameter (array).
bArgument (array).
mOrder (positive integer, default 1).
mrMemory resource (nullptr → process default).
Returns
Element-wise Marcum Q values, broadcasting a & b.

◆ mil188qamdemod()

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)).

Inverts mil188qammod via nearest-constellation-point search.

Parameters
yReceived complex samples.
MModulation order (currently must be 16).
mrMemory resource (nullptr → process default).
Returns
Integer symbol indices, same shape as y.
Exceptions
ErrorUnsupported M.
See also
mil188qammod

◆ mil188qammod()

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)).

Modulates integer indices using the MIL-STD-188-110 hard-coded constellation table. Currently only M = 16 is supported (M = 32, 64, 256 deferred).

Parameters
xInteger symbol indices in 0..M-1.
MModulation order (currently must be 16).
mrMemory resource (nullptr → process default).
Returns
Complex baseband samples, same shape as x.
Exceptions
ErrorUnsupported M.
See also
mil188qamdemod

◆ modnorm()

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.

Parameters
refReference constellation.
type"avpow" (average power) or "peakpow" (peak power).
targetDesired power level.
mrMemory resource (nullptr → process default).
Returns
Real scalar scaling factor.
Exceptions
ErrorUnknown type or empty ref.
See also
qammod, pammod

◆ mskdemod()

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).

Parameters
yComplex baseband MSK waveform (length a multiple of nSamp).
nSampSamples per symbol.
ini_phaseInitial carrier phase (radians); only feeds phase_out.
phase_outIf non-null, receives the final phase state in [0, 2π).
mrMemory resource (nullptr → process default).
Returns
Demodulated bit stream ({0,1}).

◆ mskmod()

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.

Parameters
xSymbol stream.
nSampSamples per symbol.
ini_phaseInitial carrier phase in radians.
mrMemory resource (nullptr → process default).
Returns
Complex baseband waveform of length numel(x) · nSamp.

◆ noisebw()

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)).

Parameters
numNumerator coefficients.
denDenominator coefficients.
NsampNumber of impulse-response samples used.
fsSample rate in Hz.
mrMemory resource (nullptr → process default).
Returns
Scalar noise bandwidth in Hz.

◆ ofdmdemod()

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.

Parameters
inTime-domain OFDM signal.
nfftFFT length.
cplenCyclic prefix length.
symoffsetSample offset within each symbol to start the FFT window.
mrMemory resource (nullptr → process default).
Returns
nfft×Nsymbols complex matrix of subcarriers.
See also
ofdmmod

◆ ofdmmod()

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)).

Parameters
innfft×Nsymbols complex matrix of subcarrier values.
nfftIFFT length.
cplenCyclic prefix length.
mrMemory resource (nullptr → process default).
Returns
Column vector of length (nfft + cplen)·Nsymbols.
See also
ofdmdemod

◆ pamdemod()

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)).

Parameters
yReceived samples.
MModulation order.
ini_phasePhase offset used at modulation time.
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Integer symbol indices, same shape as y.
See also
pammod

◆ pammod()

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.

Parameters
xInteger symbols in 0..M-1.
MModulation order.
ini_phasePhase offset in radians (default 0).
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Real amplitudes, same shape as x.
See also
pamdemod, qammod

◆ pmdemod()

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.

Parameters
yModulated signal.
fcCarrier frequency in Hz.
fsSample rate in Hz.
phasedevPhase-deviation constant (radians per unit message).
ini_phaseInitial carrier phase in radians.
mrMemory resource (nullptr → process default).
Returns
Recovered message, same shape as y.
See also
pmmod, fmdemod

◆ pmmod()

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.

Parameters
xReal input message.
fcCarrier frequency in Hz.
fsSample rate in Hz.
phasedevPhase-deviation factor (rad per unit of x).
ini_phaseInitial carrier phase in radians.
mrMemory resource (nullptr → process default).
Returns
Modulated signal, same shape as x.
See also
ammod, fmmod

◆ poly2trellis()

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):

  • numInputSymbols = 2 (one input bit, k = 1)
  • numOutputSymbols = 2^n (n = numel(CodeGenerator))
  • numStates = 2^(K-1) (K = ConstraintLength)
  • nextStates = numStates × 2 next-state index per (state, input)
  • outputs = numStates × 2 output word (decimal of the n output bits, first generator = MSB)

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.

Parameters
constraintLengthScalar constraint length K (>= 1).
codeGeneratorLength-n vector of octal generator polynomials.
mrMemory resource (nullptr → process default).
Returns
1×1 trellis struct.
Exceptions
Erroron a non-scalar constraintLength (rate k/n), K < 1, an empty codeGenerator, or an octal digit > 7.

◆ pskdemod()

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)).

Parameters
yReceived complex samples.
MModulation order.
ini_phasePhase reference used at modulation time.
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Integer symbol indices, same shape as y.
See also
pskmod

◆ pskmod()

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)).

Parameters
xInteger symbols in 0..M-1.
MModulation order.
ini_phasePhase shift in radians applied to all symbols (default 0).
symbol_order"gray" (default) or "bin".
mrMemory resource (nullptr → process default).
Returns
Complex baseband samples, same shape as x.
See also
pskdemod, dpskmod, qammod

◆ qamdemod()

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)).

Parameters
yReceived complex samples.
MModulation order.
symbol_order"gray" (default) or "bin".
unit_powerIf true, the modulator used unit-power scaling.
mrMemory resource (nullptr → process default).
Returns
Integer symbol indices, same shape as y.
See also
qammod

◆ qammod()

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)).

Parameters
xInteger symbols in 0..M-1.
MModulation order.
symbol_order"gray" (default) or "bin".
unit_powerIf true, scale the constellation to unit average power.
mrMemory resource (nullptr → process default).
Returns
Complex baseband samples, same shape as x.
See also
qamdemod, pammod, genqammod

◆ qfunc()

Value nk::comm::qfunc ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Gaussian Q-function: Q(x) = 0.5·erfc(x/√2).

Parameters
xInput array (any shape, DOUBLE).
mrMemory resource (nullptr → process default).
Returns
Element-wise Q(x).
See also
qfuncinv

◆ qfuncinv()

Value nk::comm::qfuncinv ( const Value & p,
std::pmr::memory_resource * mr = nullptr )

Inverse Q-function: Q⁻¹(p) = √2·erfc⁻¹(2p).

Parameters
pInput array (any shape, DOUBLE) with values in (0, 1).
mrMemory resource (nullptr → process default).
Returns
Element-wise Q⁻¹(p).
See also
qfunc

◆ quantiz()

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)).

Parameters
sigInput signal.
partitionStrictly increasing partition vector (length K-1).
codebookCodebook vector (length K).
mrMemory resource (nullptr → process default).
Returns
QuantizResult with index, quantised values, and mean-square distortion.
See also
quantiz_indx, lloyds

◆ quantiz_indx()

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.

Parameters
sigInput signal (real vector).
partitionStrictly increasing partition vector.
mrMemory resource (nullptr → process default).
Returns
Bin index per sample.
See also
quantiz, lloyds

◆ randerr()

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:

  • a scalar (exact count per row),
  • a row vector of possible counts (uniform), or
  • a 2-row matrix [counts; probabilities].
Parameters
mRow count.
nColumn count.
errspecError count specification (see above).
have_stateIf true, use the supplied seed.
stateSeed for the isolated MatlabMT19937 instance.
mrMemory resource (nullptr → process default).
Returns
m×n binary error matrix.
See also
randsrc

◆ randsrc()

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:

  • a row vector (uniform probability over its entries), or
  • a 2-row matrix [symbols; probabilities] where probabilities lie in [0, 1] and sum to 1 (within sqrt(eps)).

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.

Parameters
mRow count.
nColumn count.
alphabetAlphabet specification (see above). Default Value::Empty → [-1, 1] uniform.
have_stateIf true, use the supplied seed.
stateSeed for the isolated MT19937.
mrMemory resource (nullptr → process default).
Returns
m×n matrix of drawn symbols.
See also
randerr

◆ rayleighchan()

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.

Parameters
xInput signal (any shape).
mrMemory resource (nullptr → process default).
Returns
Faded signal of the same shape as x, COMPLEX.
See also
ricianchan

◆ rcosdesign()

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:

  • RC: p(t) = sinc(t/T) · cos(πβt/T) / (1 − (2βt/T)²)
  • RRC: h(t) = (4β/π√T) · [cos((1+β)πt/T) + sin((1−β)πt/T)/(4βt/T)] / (1 − (4βt/T)²)

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).

Parameters
betaRoll-off factor, 0 ≤ β ≤ 1.
spanFilter span in symbol periods (positive integer).
spsSamples per symbol (positive integer).
shape"normal" → RC (default), "sqrt" → RRC.
mrMemory resource (nullptr → process default).
Returns
Row vector of length span·sps + 1.
Exceptions
ErrorOn invalid β, span, sps, or unknown shape.
See also
gaussdesign

◆ rectpulse()

Value nk::comm::rectpulse ( const Value & x,
int n,
std::pmr::memory_resource * mr = nullptr )

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).

Parameters
xInput signal (vector or matrix, DOUBLE).
nRepetition factor (positive integer).
mrMemory resource (nullptr → process default).
Returns
Expanded signal with same orientation as x.
Exceptions
ErrorOn non-positive n.
See also
intdump

◆ ricianchan()

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.

Parameters
xInput signal (any shape).
KLinear K-factor (LOS / NLOS power ratio, ≥ 0).
mrMemory resource (nullptr → process default).
Returns
Faded signal of the same shape as x, COMPLEX.
See also
rayleighchan

◆ scrambler()

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:

  • fb = XOR over i=1..n where g_i = 1 of state[i-1]
  • y[k] = x[k] XOR fb
  • shift state right by 1, store y[k] at state[0]

Both scrambler and descrambler clock the channel bit y[k] into the shift register, which is what makes the descrambler self-synchronizing.

Parameters
xColumn of input bits (0/1, DOUBLE or LOGICAL).
polyLength-(n+1) coefficient vector [g_0, g_1, …, g_n] with g_0 = 1; non-zero entries mark register taps.
initStateLength-n initial register contents (bits 0/1).
mrMemory resource (nullptr → process default).
Returns
Column of numel(x) DOUBLE bits in {0, 1}.
Exceptions
ErrorOn bad poly (length, g_0 = 0) or state size.
See also
descrambler

◆ ssbdemod()

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.

Parameters
yModulated signal.
fcCarrier frequency in Hz.
fsSample rate in Hz.
ini_phaseInitial carrier phase in radians.
mrMemory resource (nullptr → process default).
Returns
Recovered message, same shape as y.
See also
ssbmod, amdemod

◆ ssbmod()

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.

Parameters
xReal input message.
fcCarrier frequency in Hz.
fsSample rate in Hz.
ini_phaseInitial carrier phase in radians.
uppertrue → upper sideband, false → lower.
mrMemory resource (nullptr → process default).
Returns
Modulated signal, same shape as x.
See also
ammod

◆ symerr()

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.

Parameters
x,ySame-numel arrays.
mrMemory resource (nullptr → process default).
Returns
Pair { count, ratio }.
Exceptions
Erroron numel mismatch.
See also
biterr

◆ syndtable()

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)).

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).

Parameters
HParity-check matrix, (n-k) × n, binary.
mrMemory resource (nullptr → process default).
Returns
2^(n-k) × n coset-leader table.
Exceptions
Errorif H is empty or n-k is impractically large.
See also
hammgen, gen2par, decode

◆ vec2mat()

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.

Parameters
vInput vector.
nNumber of columns (positive).
padvalPad value for the last row (default 0).
mrMemory resource (nullptr → process default).
Returns
{ matrix, padCount } — the reshaped matrix and the number of pad entries added to fill the final row.
Exceptions
Errorif n <= 0.

◆ vitdec()

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:

  • "trunc" (default) — start at state 0, trace back from the minimum-metric final state.
  • "term" — the encoder was terminated, so trace back from state 0. dectype must be "hard" (soft / unquantised decisions are a v1 gap). tblen (traceback depth) is accepted for MATLAB compatibility; this v1 always performs a full traceback ("cont" continuous mode is deferred).
Parameters
codeReceived bit vector (length a multiple of n).
trellisTrellis struct from poly2trellis.
tblenTraceback depth (advisory in trunc/term).
opmode"trunc" (default) or "term".
dectype"hard" (default; only hard-decision supported).
mrMemory resource (nullptr → process default).
Returns
Decoded message bits (numel(code)/n).
Exceptions
Erroron an invalid trellis, numel(code) not a multiple of n, or an unsupported opmode/dectype.
See also
convenc, poly2trellis

◆ wgn()

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)).

Parameters
mRow count.
nColumn count.
pPower, interpreted per type.
type"dBW" (default), "dBm", or "linear".
complex_outIf true, samples are circular complex Gaussian.
mrMemory resource (nullptr → process default).
Returns
m×n matrix of noise samples.
See also
awgn