nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Wavelet Toolbox (wavelet)

1D/2D Discrete Wavelet Transform (DWT), Stationary Wavelet Transform (SWT), filter banks, wavelet denoising, and continuous wavelets. More...

Files

file  denoise.hpp
file  dwt.hpp
file  dwt2.hpp
file  dyad.hpp
file  haart.hpp
file  ihaart.hpp
file  multilevel.hpp
file  multilevel2.hpp
file  wkeep_wextend.hpp
file  families.hpp
file  qmf.hpp
file  wfilters.hpp
file  shape.hpp
file  swt.hpp

Classes

struct  nk::wavelet::DdencmpResult
 Default denoising / compression parameters ([thr, sorh, keepapp] = ddencmp(opt, type, x)). More...
struct  nk::wavelet::Dwt2Result
 Result of dwt2 ([cA, cH, cV, cD] = dwt2(X, wname)). More...
struct  nk::wavelet::HaartResult
 Result of haart — [a, d]. More...
struct  nk::wavelet::WenergyResult
 Energy distribution of a wavelet decomposition. More...
struct  nk::wavelet::Wavedec2Result
 Result of wavedec2 ([C, S] = wavedec2(X, N, wname)). More...
struct  nk::wavelet::OrthfiltResult
 The four orthogonal-wavelet filter banks produced by orthfilt. More...
struct  nk::wavelet::FilterBank
 Filter bank for an orthogonal wavelet family. More...
struct  nk::wavelet::WFiltersResult
 Result of wfilters ([…] = wfilters(wname[, kind])). More...

Functions

Value nk::wavelet::wthresh (const Value &X, const std::string &sorh, double T, std::pmr::memory_resource *mr=nullptr)
 Element-wise wavelet coefficient thresholding (Y = wthresh(X, sorh, T)).
Value nk::wavelet::wnoisest (const Value &C, const Value &L, const Value &S, std::pmr::memory_resource *mr=nullptr)
 Per-level noise σ estimate (σ = wnoisest(C, L, S)).
Value nk::wavelet::wdenoise (const Value &x, int level, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 VisuShrink-style soft-threshold denoising (y = wdenoise(x, level, wname)).
Value nk::wavelet::wentropy (const Value &X, const std::string &type, double param=0.0, std::pmr::memory_resource *mr=nullptr)
 Entropy of a coefficient vector (E = wentropy(X, T[, P])).
DdencmpResult nk::wavelet::ddencmp (const std::string &opt, const std::string &type, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Default threshold / settings for wavelet denoising or compression.
std::pair< Value, Value > nk::wavelet::dwt (const Value &x, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Single-level discrete wavelet transform ([cA, cD] = dwt(x, wname)).
std::pair< Value, Value > nk::wavelet::dwt_with_filters_pub (const Value &x, const std::vector< double > &Lo_D, const std::vector< double > &Hi_D, std::pmr::memory_resource *mr=nullptr)
 Internal entry: dwt with explicit analysis filters.
Value nk::wavelet::idwt (const Value &cA, const Value &cD, const std::string &wname, long long len, std::pmr::memory_resource *mr=nullptr)
 Inverse single-level discrete wavelet transform.
Value nk::wavelet::idwt_with_filters_pub (const Value &cA, const Value &cD, const std::vector< double > &Lo_R, const std::vector< double > &Hi_R, long long len, std::pmr::memory_resource *mr=nullptr)
 Internal entry: idwt with explicit synthesis filters.
Dwt2Result nk::wavelet::dwt2 (const Value &X, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 2-D separable single-level wavelet transform.
Value nk::wavelet::idwt2 (const Value &cA, const Value &cH, const Value &cV, const Value &cD, const std::string &wname, long long outRows, long long outCols, std::pmr::memory_resource *mr=nullptr)
 2-D inverse single-level wavelet transform.
Value nk::wavelet::dyaddown (const Value &x, int odd=0, char type='c', std::pmr::memory_resource *mr=nullptr)
 Dyadic downsampling — y = dyaddown(x, odd, type).
Value nk::wavelet::dyadup (const Value &x, int odd=1, char type='c', std::pmr::memory_resource *mr=nullptr)
 Dyadic upsampling with zero insertion — y = dyadup(x, odd, type).
Value nk::wavelet::wmaxlev (const Value &N, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Maximum wavelet decomposition level — L = wmaxlev(N, wname).
HaartResult nk::wavelet::haart (const Value &x, int level=0, bool integer=false, std::pmr::memory_resource *mr=nullptr)
 1-D Haar wavelet transform ([a, d] = haart(x, level, integerflag)).
Value nk::wavelet::ihaart (const Value &a, const Value &d, int level=0, bool integer=false, std::pmr::memory_resource *mr=nullptr)
 1-D inverse Haar wavelet transform (xrec = ihaart(a, d, level, integerflag)).
std::pair< Value, Value > nk::wavelet::wavedec (const Value &x, int n, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Multi-level 1-D DWT ([C, L] = wavedec(x, n, wname)).
Value nk::wavelet::waverec (const Value &C, const Value &L, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Inverse of wavedec.
Value nk::wavelet::appcoef (const Value &C, const Value &L, const std::string &wname, int level, std::pmr::memory_resource *mr=nullptr)
 Extract approximation coefficients at a given level (appcoef).
Value nk::wavelet::appcoef_with_filters_pub (const Value &C, const Value &L, const std::vector< double > &Lo_R, const std::vector< double > &Hi_R, int level, std::pmr::memory_resource *mr=nullptr)
 Internal entry: appcoef with explicit synthesis filters.
Value nk::wavelet::detcoef (const Value &C, const Value &L, int level, std::pmr::memory_resource *mr=nullptr)
 Extract detail coefficients at a given level (detcoef(C, L, level)).
Value nk::wavelet::wrcoef (const std::string &type, const Value &c, const Value &l, const std::string &wname, int n, std::pmr::memory_resource *mr=nullptr)
 Single-band reconstruction (wrcoef(type, c, l, wname, n)).
WenergyResult nk::wavelet::wenergy (const Value &C, const Value &L, std::pmr::memory_resource *mr=nullptr)
 Percentage of energy in the approximation and detail bands ([Ea, Ed] = wenergy(C, L)).
Value nk::wavelet::upcoef (const std::string &type, const Value &X, const std::string &wname, int n, long long len=-1, std::pmr::memory_resource *mr=nullptr)
 Direct reconstruction of a single coefficient branch (Y = upcoef(O, X, wname, N[, L])).
Wavedec2Result nk::wavelet::wavedec2 (const Value &X, int n, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 2-D multilevel wavelet decomposition.
Value nk::wavelet::waverec2 (const Value &C, const Value &S, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Full 2-D multilevel reconstruction (waverec2(C, S, wname)), i.e.
Value nk::wavelet::appcoef2 (const Value &C, const Value &S, const std::string &wname, int level=-1, std::pmr::memory_resource *mr=nullptr)
 Extract / reconstruct the approximation coefficients at level (appcoef2(C, S, wname, level)).
Value nk::wavelet::detcoef2 (const std::string &type, const Value &C, const Value &S, int level, std::pmr::memory_resource *mr=nullptr)
 Extract a 2-D detail sub-band (detcoef2(type, C, S, level)).
Value nk::wavelet::wkeep (const Value &x, const Value &len, const Value &opt=Value::Empty, std::pmr::memory_resource *mr=nullptr)
 Keep part of a vector / a sub-matrix (y = wkeep(x, len, opt)).
Value nk::wavelet::wextend (const Value &type, const std::string &mode, const Value &x, long long lf, const std::string &side="b", std::pmr::memory_resource *mr=nullptr)
 Extend a signal at its boundaries (y = wextend(type, mode, x, lf, side)).
Value nk::wavelet::dbwavf (const std::string &name, std::pmr::memory_resource *mr=nullptr)
 Daubechies scaling filter — F = dbwavf(name).
Value nk::wavelet::coifwavf (const std::string &name, std::pmr::memory_resource *mr=nullptr)
 Coiflet scaling filter — F = coifwavf(name).
Value nk::wavelet::symwavf (const std::string &name, std::pmr::memory_resource *mr=nullptr)
 Symlet scaling filter — F = symwavf(name).
OrthfiltResult nk::wavelet::orthfilt (const Value &W, std::pmr::memory_resource *mr=nullptr)
 Orthogonal filter quadruple from a scaling filter — [Lo_D, Hi_D, Lo_R, Hi_R] = orthfilt(W).
Value nk::wavelet::wrev (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Reverse a vector / flip each column — y = wrev(x).
Value nk::wavelet::qmf (const Value &x, int p=0, std::pmr::memory_resource *mr=nullptr)
 Quadrature mirror filter — y = qmf(x, p).
FilterBank nk::wavelet::wavelet_filters (const std::string &name)
 Return the four filter banks for a named orthogonal wavelet.
bool nk::wavelet::bior_filterbank (const std::string &name, FilterBank &out)
 Fill out with the four filters of a biorthogonal (bior*) or reverse-biorthogonal (rbio*) family.
WFiltersResult nk::wavelet::wfilters (const std::string &name, const std::string &kind="", std::pmr::memory_resource *mr=nullptr)
 Build the named wavelet's filters as nk Value rows.
std::tuple< Value, Value > nk::wavelet::mexihat (double lb, double ub, size_t N, std::pmr::memory_resource *mr=nullptr)
 Mexican-hat wavelet sampled on a grid ([psi, x] = mexihat(LB, UB, N)).
std::tuple< Value, Value > nk::wavelet::morlet (double lb, double ub, size_t N, std::pmr::memory_resource *mr=nullptr)
 Real Morlet wavelet ([psi, x] = morlet(LB, UB, N)).
Value nk::wavelet::meyeraux (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Meyer auxiliary function (y = meyeraux(x)).
std::tuple< Value, Value > nk::wavelet::shanwavf (double lb, double ub, size_t N, double fb, double fc, std::pmr::memory_resource *mr=nullptr)
 Shannon wavelet ([psi, x] = shanwavf(LB, UB, N, fb, fc)).
std::tuple< Value, Value > nk::wavelet::cmorwavf (double lb, double ub, size_t N, double fb, double fc, std::pmr::memory_resource *mr=nullptr)
 Complex Morlet wavelet ([psi, x] = cmorwavf(LB, UB, N, fb, fc)).
std::tuple< Value, Value > nk::wavelet::fbspwavf (double lb, double ub, size_t N, int m, double fb, double fc, std::pmr::memory_resource *mr=nullptr)
 Frequency B-spline wavelet ([psi, x] = fbspwavf(LB, UB, N, m, fb, fc)).
std::tuple< Value, Value > nk::wavelet::gauswavf (double lb, double ub, size_t N, int p, std::pmr::memory_resource *mr=nullptr)
 Real Gaussian wavelet of order p ([psi, x] = gauswavf(LB, UB, N, p)).
std::tuple< Value, Value > nk::wavelet::cgauwavf (double lb, double ub, size_t N, int p, std::pmr::memory_resource *mr=nullptr)
 Complex Gaussian wavelet of order p ([psi, x] = cgauwavf(LB, UB, N, p)).
Value nk::wavelet::swt (const Value &x, int n, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Stationary (à trous) discrete wavelet transform (swc = swt(x, n, wname)).
Value nk::wavelet::iswt (const Value &swc, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Inverse stationary DWT (x = iswt(swc, wname)).
Value nk::wavelet::modwt (const Value &x, int n, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Maximal-overlap discrete wavelet transform (swc = modwt(x, n, wname)).
Value nk::wavelet::imodwt (const Value &swc, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
 Inverse MODWT (x = imodwt(swc, wname)).

Detailed Description

1D/2D Discrete Wavelet Transform (DWT), Stationary Wavelet Transform (SWT), filter banks, wavelet denoising, and continuous wavelets.

Function Documentation

◆ appcoef()

Value nk::wavelet::appcoef ( const Value & C,
const Value & L,
const std::string & wname,
int level,
std::pmr::memory_resource * mr = nullptr )

Extract approximation coefficients at a given level (appcoef).

The appcoef(C, L, wname, level) operation.

  • level == nMax = length(L) - 2 (the default if level == -1) returns the coarsest cA stored verbatim at the front of C.
  • level < nMax rebuilds the approximation by running idwt nMax - level times.
Parameters
CCoefficient row from wavedec.
LBookkeeping row.
wnameWavelet name.
levelTarget level (or -1 for default = coarsest).
mrMemory resource (nullptr → process default).
Returns
Row vector of approximation coefficients.
Exceptions
Erroron out-of-range level.
See also
detcoef, wrcoef

◆ appcoef2()

Value nk::wavelet::appcoef2 ( const Value & C,
const Value & S,
const std::string & wname,
int level = -1,
std::pmr::memory_resource * mr = nullptr )

Extract / reconstruct the approximation coefficients at level (appcoef2(C, S, wname, level)).

level == N returns the stored coarsest approximation directly; level < N reconstructs down through idwt2 using the stored detail bands; level == 0 is the full reconstruction. Default level = -1 → the coarsest level N.

See also
wavedec2, waverec2

◆ appcoef_with_filters_pub()

Value nk::wavelet::appcoef_with_filters_pub ( const Value & C,
const Value & L,
const std::vector< double > & Lo_R,
const std::vector< double > & Hi_R,
int level,
std::pmr::memory_resource * mr = nullptr )

Internal entry: appcoef with explicit synthesis filters.

Used by the appcoef(C, L, Lo_R, Hi_R[, level]) custom-filter form so the register TU can invoke it without re-resolving filters by name. Public so other toolboxes/wavelet TUs can call it; not commonly needed by end users.

Parameters
CCoefficient row from wavedec.
LBookkeeping row.
Lo_RSynthesis lowpass filter coefficients.
Hi_RSynthesis highpass filter coefficients.
levelTarget level (or -1 for default = coarsest).
mrMemory resource (nullptr → process default).
Returns
Row vector of approximation coefficients.
See also
appcoef

◆ bior_filterbank()

bool nk::wavelet::bior_filterbank ( const std::string & name,
FilterBank & out )

Fill out with the four filters of a biorthogonal (bior*) or reverse-biorthogonal (rbio*) family.

Unlike the orthogonal families these have distinct analysis/synthesis pairs, so all four are tabulated independently (see filter/biorfilt.cpp). Used by wavelet_filters.

Parameters
nameCandidate family name (e.g. "bior2.2", "rbio4.4").
outFilled with the four filter vectors on success.
Returns
true if name is a known bior/rbio family, else false.

◆ cgauwavf()

std::tuple< Value, Value > nk::wavelet::cgauwavf ( double lb,
double ub,
size_t N,
int p,
std::pmr::memory_resource * mr = nullptr )

Complex Gaussian wavelet of order p ([psi, x] = cgauwavf(LB, UB, N, p)).

Like gauswavf but complex-valued and normalised by trapezoidal quadrature on the requested grid (a grid-dependent normalisation).

See also
gauswavf

◆ cmorwavf()

std::tuple< Value, Value > nk::wavelet::cmorwavf ( double lb,
double ub,
size_t N,
double fb,
double fc,
std::pmr::memory_resource * mr = nullptr )

Complex Morlet wavelet ([psi, x] = cmorwavf(LB, UB, N, fb, fc)).

\( \psi(t) = \frac{1}{\sqrt{\pi f_b}}\,e^{2\pi i f_c t}\,e^{-t^2/f_b} \).

See also
morlet, shanwavf

◆ coifwavf()

Value nk::wavelet::coifwavf ( const std::string & name,
std::pmr::memory_resource * mr = nullptr )

Coiflet scaling filter — F = coifwavf(name).

Returns the Coiflet synthesis lowpass scaling filter Lo_R / sqrt(2) (length 6K for coifK) as a row vector.

Parameters
nameWavelet name "coifK" (e.g. "coif2").
mrMemory resource (nullptr → process default).
Returns
Row vector of scaling-filter coefficients.
Exceptions
Errorif name is not "coifK", or the family is unsupported.
See also
dbwavf, symwavf, orthfilt

◆ dbwavf()

Value nk::wavelet::dbwavf ( const std::string & name,
std::pmr::memory_resource * mr = nullptr )

Daubechies scaling filter — F = dbwavf(name).

Returns the Daubechies synthesis lowpass scaling filter Lo_R / sqrt(2) (length 2N for dbN, sum = 1) as a row vector.

Parameters
nameWavelet name, "haar" or "dbN" (e.g. "db4").
mrMemory resource (nullptr → process default).
Returns
Row vector of scaling-filter coefficients.
Exceptions
Errorif name is not "haar"/"dbN", or the family is unsupported by the underlying filter table.
See also
coifwavf, symwavf, orthfilt

◆ ddencmp()

DdencmpResult nk::wavelet::ddencmp ( const std::string & opt,
const std::string & type,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Default threshold / settings for wavelet denoising or compression.

Estimates the noise level from the finest-detail coefficients of a 1-level db1 DWT — σ̂ = median(|cD₁|)/0.6745 — and returns the default parameters for opt = "den" (denoising) or opt = "cmp" (compression):

  • den: thr = sqrt(2·log(n))·σ̂ (universal threshold), sorh = 's'.
  • cmp: thr = median(|cD₁|), sorh = 'h'.

keepapp = 1 in both cases. Only type = "wv" (wavelet) is supported; "wp" (wavelet packet) is not yet implemented.

Parameters
opt"den" (denoise) or "cmp" (compress).
type"wv" (wavelet); "wp" is rejected.
xInput signal.
mrMemory resource (nullptr → process default).
Returns
{thr, sorh, keepapp} (see DdencmpResult).
Exceptions
Erroron an unknown opt/type or "wp".
See also
wentropy, wthresh, wdenoise

◆ detcoef()

Value nk::wavelet::detcoef ( const Value & C,
const Value & L,
int level,
std::pmr::memory_resource * mr = nullptr )

Extract detail coefficients at a given level (detcoef(C, L, level)).

level is 1-based: level = 1 is the finest detail, level = length(L) - 2 the coarsest. Returns a row vector slice of C.

The detcoef(C, L, levels, 'cells') multi-level form is reachable through the engine-level adapter; the C++ helper here keeps the simple single-level form.

Parameters
CCoefficient row from wavedec.
LBookkeeping row.
level1-based level (1 = finest).
mrMemory resource (nullptr → process default).
Returns
Row vector of detail coefficients.
Exceptions
Erroron out-of-range level.
See also
appcoef, wrcoef

◆ detcoef2()

Value nk::wavelet::detcoef2 ( const std::string & type,
const Value & C,
const Value & S,
int level,
std::pmr::memory_resource * mr = nullptr )

Extract a 2-D detail sub-band (detcoef2(type, C, S, level)).

Parameters
type"h" (horizontal), "v" (vertical) or "d" (diagonal).
CCoefficient vector from wavedec2.
SSize bookkeeping matrix from wavedec2.
levelDecomposition level (1 = finest … N = coarsest).
mrMemory resource.
Returns
The requested detail band, shaped to its 2-D size.
See also
wavedec2

◆ dwt()

std::pair< Value, Value > nk::wavelet::dwt ( const Value & x,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Single-level discrete wavelet transform ([cA, cD] = dwt(x, wname)).

Decomposes the 1-D signal x into an approximation band cA (lowpass) and a detail band cD (highpass), each downsampled by 2. The extension mode is fixed at 'sym' (whole-point symmetric reflection).

Output length per band: \( \lfloor (N + L_f - 1)/2 \rfloor \) where \( L_f \) is the filter length.

Parameters
xInput signal (vector).
wnameWavelet name — "haar", "db1".."db10", "sym2".."sym10", "coif1".."coif5".
mrMemory resource (nullptr → process default).
Returns
(cA, cD); bind via auto [cA, cD] = dwt(x, wname);.
Exceptions
Erroron unknown wavelet name.
auto [cA, cD] = dwt(signal, "db4");
std::pair< Value, Value > dwt(const Value &x, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
Single-level discrete wavelet transform ([cA, cD] = dwt(x, wname)).
See also
idwt, wavedec, wfilters

◆ dwt2()

Dwt2Result nk::wavelet::dwt2 ( const Value & X,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

2-D separable single-level wavelet transform.

Composes the 1-D dwt: a row pass first (each row of X analysed into lo + hi halves), then a column pass on each half. Returns the four bands packaged in Dwt2Result.

Parameters
XInput image (2-D matrix).
wnameWavelet name (see wavelet_filters for the supported family list).
mrMemory resource (nullptr → process default).
Returns
Dwt2Result; bind via auto r = dwt2(X, wname);.
auto r = dwt2(image, "db2");
// r.cA is the LL band, r.cH/cV/cD are the detail bands.
Dwt2Result dwt2(const Value &X, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
2-D separable single-level wavelet transform.
See also
idwt2, dwt

◆ dwt_with_filters_pub()

std::pair< Value, Value > nk::wavelet::dwt_with_filters_pub ( const Value & x,
const std::vector< double > & Lo_D,
const std::vector< double > & Hi_D,
std::pmr::memory_resource * mr = nullptr )

Internal entry: dwt with explicit analysis filters.

Mirrors idwt_with_filters_pub for the forward transform — lets the dwt(x, Lo_D, Hi_D) custom-filter form be invoked without re-resolving filters by name. Public so the register TU (and other toolboxes/wavelet TUs) can call it; not commonly needed by end users.

Parameters
xInput signal (vector).
Lo_DAnalysis lowpass filter coefficients.
Hi_DAnalysis highpass filter coefficients.
mrMemory resource (nullptr → process default).
Returns
(cA, cD) approximation / detail bands.
See also
dwt, idwt_with_filters_pub

◆ dyaddown()

Value nk::wavelet::dyaddown ( const Value & x,
int odd = 0,
char type = 'c',
std::pmr::memory_resource * mr = nullptr )

Dyadic downsampling — y = dyaddown(x, odd, type).

Keeps every other sample. odd == 0 (default) keeps the even-indexed samples (1-based, x(2:2:end)); odd == 1 keeps the odd-indexed samples (x(1:2:end)). For a matrix, type selects the axis: 'c' (default) columns, 'r' rows, 'm' both. Vectors ignore type and preserve orientation.

Parameters
xInput vector or matrix.
odd0 (default, keep even) or 1 (keep odd).
typeMatrix axis 'c' (default) / 'r' / 'm'.
mrMemory resource (nullptr → process default).
Returns
Downsampled array.
See also
dyadup

◆ dyadup()

Value nk::wavelet::dyadup ( const Value & x,
int odd = 1,
char type = 'c',
std::pmr::memory_resource * mr = nullptr )

Dyadic upsampling with zero insertion — y = dyadup(x, odd, type).

Inserts zeros between samples. odd == 0: [x1 0 x2 0 … xN] (length 2N-1); odd == 1 (default): [0 x1 0 x2 … xN 0] (length 2N+1). Matrix type axis as in dyaddown. Verified vs MATLAB R2025b: dyadup([1 2 3], 0) = [1 0 2 0 3], dyadup([1 2 3], 1) = [0 1 0 2 0 3 0].

Parameters
xInput vector or matrix.
odd0 or 1 (default 1).
typeMatrix axis 'c' (default) / 'r' / 'm'.
mrMemory resource (nullptr → process default).
Returns
Upsampled array.
See also
dyaddown

◆ fbspwavf()

std::tuple< Value, Value > nk::wavelet::fbspwavf ( double lb,
double ub,
size_t N,
int m,
double fb,
double fc,
std::pmr::memory_resource * mr = nullptr )

Frequency B-spline wavelet ([psi, x] = fbspwavf(LB, UB, N, m, fb, fc)).

\( \psi(t) = \sqrt{f_b}\,\text{sinc}^m(f_b t/m)\,e^{2\pi i f_c t},\ m \in \mathbb{N}_{+} \).

Parameters
mSpline order (positive integer).
fb,fcBandwidth and centre frequency.
See also
cmorwavf, shanwavf

◆ gauswavf()

std::tuple< Value, Value > nk::wavelet::gauswavf ( double lb,
double ub,
size_t N,
int p,
std::pmr::memory_resource * mr = nullptr )

Real Gaussian wavelet of order p ([psi, x] = gauswavf(LB, UB, N, p)).

\( \psi_p(t) \) is a normalised p-th derivative of \( e^{-t^2} \) (default p = 1). The L² norm is analytical.

Parameters
pDerivative order ≥ 1.
See also
cgauwavf

◆ haart()

HaartResult nk::wavelet::haart ( const Value & x,
int level = 0,
bool integer = false,
std::pmr::memory_resource * mr = nullptr )

1-D Haar wavelet transform ([a, d] = haart(x, level, integerflag)).

Decomposes x (vector or per-column matrix; output is column-oriented) into level Haar levels. noninteger mode (default) uses the orthogonal pair (factor 1/√2); integer mode uses the lifting integer Haar (d = x2 - x1, a = x1 + floor(d/2)). The data length must be even and divisible by 2^level.

Parameters
xInput vector or matrix (even length per column).
levelNumber of levels; <= 0 (default) → the maximum level (largest k with 2^k | length).
integerfalse (default) → orthogonal; true → integer lifting (not supported for complex input).
mrMemory resource (nullptr → process default).
Returns
HaartResult { a, d }.
Exceptions
Erroron empty/odd-length input, level above the maximum, or integer == true with complex input.

◆ idwt()

Value nk::wavelet::idwt ( const Value & cA,
const Value & cD,
const std::string & wname,
long long len,
std::pmr::memory_resource * mr = nullptr )

Inverse single-level discrete wavelet transform.

Reconstructs the original signal from an approximation / detail pair. len (when ≥ 0) crops the result to that length; pass -1 to use the natural reconstruction length 2·length(cA) - L_f + 2 (natural length for 'sym' extension mode).

Parameters
cAApproximation coefficients (from dwt).
cDDetail coefficients.
wnameWavelet name (must match the one used in dwt).
lenOutput length (-1 for the natural default).
mrMemory resource (nullptr → process default).
Returns
Reconstructed row vector of length len (or natural).
See also
dwt, idwt_with_filters_pub

◆ idwt2()

Value nk::wavelet::idwt2 ( const Value & cA,
const Value & cH,
const Value & cV,
const Value & cD,
const std::string & wname,
long long outRows,
long long outCols,
std::pmr::memory_resource * mr = nullptr )

2-D inverse single-level wavelet transform.

Reconstructs the image from the four bands produced by dwt2. Optional outRows / outCols (≥ 0) crop the reconstruction to the requested size; pass -1 to use the natural length 2·la - L_f + 2 in each dim.

Parameters
cAApproximation band (LL).
cHHorizontal detail band (LH).
cVVertical detail band (HL).
cDDiagonal detail band (HH).
wnameWavelet name (must match decomposition).
outRowsOutput rows (-1 for natural).
outColsOutput cols (-1 for natural).
mrMemory resource (nullptr → process default).
Returns
Reconstructed outRows × outCols matrix.
See also
dwt2

◆ idwt_with_filters_pub()

Value nk::wavelet::idwt_with_filters_pub ( const Value & cA,
const Value & cD,
const std::vector< double > & Lo_R,
const std::vector< double > & Hi_R,
long long len,
std::pmr::memory_resource * mr = nullptr )

Internal entry: idwt with explicit synthesis filters.

Used by appcoef to support the (c, l, Lo_R, Hi_R) custom-filter form without re-resolving filters by name on every cascade step. Public so other toolboxes/wavelet TUs can call it; not commonly needed by end users.

Parameters
cAApproximation coefficients.
cDDetail coefficients.
Lo_RSynthesis lowpass filter coefficients.
Hi_RSynthesis highpass filter coefficients.
lenOutput length (-1 for natural).
mrMemory resource (nullptr → process default).
Returns
Reconstructed row vector.
See also
idwt, appcoef

◆ ihaart()

Value nk::wavelet::ihaart ( const Value & a,
const Value & d,
int level = 0,
bool integer = false,
std::pmr::memory_resource * mr = nullptr )

1-D inverse Haar wavelet transform (xrec = ihaart(a, d, level, integerflag)).

Reconstructs the signal from the approximation a and detail d (a plain matrix for a single-level transform, else a length-Nlevels cell column with d{1} the finest scale — matching haart's output). level (default 0 = lossless) zeroes the finest level detail bands before reconstruction. integer selects the lifting integer inverse (x0 = a - floor(d/2), x1 = x0 + d), unavailable for complex a. d must be real.

Parameters
aApproximation coefficients (column / matrix).
dDetail — a matrix (1 level) or a cell column (multi-level).
levelFinest detail bands to suppress, in [0, Nlevels) (default 0 → lossless).
integerfalse (default) → orthogonal; true → integer lifting.
mrMemory resource (nullptr → process default).
Returns
Reconstructed signal (column for vector input).
Exceptions
Erroron empty a/d, complex d, level outside [0, Nlevels), or integer == true with complex a.
See also
haart

◆ imodwt()

Value nk::wavelet::imodwt ( const Value & swc,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Inverse MODWT (x = imodwt(swc, wname)).

Exact left-inverse of modwt (imodwt(modwt(x)) == x up to rounding).

Parameters
swc(n+1) × N coefficient matrix from modwt.
wnameWavelet name.
mrMemory resource (nullptr → process default).
Returns
Reconstructed row vector of length N.
See also
modwt

◆ iswt()

Value nk::wavelet::iswt ( const Value & swc,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Inverse stationary DWT (x = iswt(swc, wname)).

Recovers the original signal from the swc matrix produced by swt by inverting the cascade level-by-level and averaging shift variants at each step.

Parameters
swc(n+1) × N coefficient matrix from swt.
wnameWavelet name (must match the forward transform).
mrMemory resource (nullptr → process default).
Returns
Reconstructed row vector of length N.
See also
swt

◆ mexihat()

std::tuple< Value, Value > nk::wavelet::mexihat ( double lb,
double ub,
size_t N,
std::pmr::memory_resource * mr = nullptr )

Mexican-hat wavelet sampled on a grid ([psi, x] = mexihat(LB, UB, N)).

\( \psi(t) = \frac{2}{\sqrt{3}\,\pi^{1/4}}\,(1 - t^2)\,e^{-t^2/2} \).

Parameters
lbLeft endpoint of the grid.
ubRight endpoint.
NNumber of samples (≥ 0).
mrMemory resource (nullptr → process default).
Returns
(psi, x); bind via auto [psi, x] = mexihat(lb, ub, N);.
See also
morlet, meyeraux

◆ meyeraux()

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

Meyer auxiliary function (y = meyeraux(x)).

\( y(x) = 35x^4 - 84x^5 + 70x^6 - 20x^7 \). The function is defined on \( [0, 1] \) where it interpolates from 0 to 1, but the polynomial is applied without clipping.

Parameters
xElement-wise input.
mrMemory resource (nullptr → process default).
Returns
y of the same shape as x.

◆ modwt()

Value nk::wavelet::modwt ( const Value & x,
int n,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Maximal-overlap discrete wavelet transform (swc = modwt(x, n, wname)).

Like swt but the filters are scaled by \( 1/\sqrt{2} \) per level so the transform is energy-preserving (Parseval's identity holds), and the signal length does not need to divide \( 2^n \) (a true shift-invariant transform).

Output layout: (n+1) × N matrix.

  • rows 1..n : wavelet coefficients \( W_j \) at levels 1..n.
  • row n+1 : scaling coefficients \( V_n \) (final approximation).

Periodic boundary.

Parameters
xInput signal.
nDecomposition depth.
wnameWavelet name.
mrMemory resource (nullptr → process default).
Returns
(n+1) × N coefficient matrix.
See also
imodwt, swt

◆ morlet()

std::tuple< Value, Value > nk::wavelet::morlet ( double lb,
double ub,
size_t N,
std::pmr::memory_resource * mr = nullptr )

Real Morlet wavelet ([psi, x] = morlet(LB, UB, N)).

\( \psi(t) = e^{-t^2/2}\,\cos(5t) \) (centre frequency 5).

Parameters
lb,ubGrid endpoints.
NNumber of samples.
mrMemory resource (nullptr → process default).
Returns
(psi, x).
See also
mexihat, cmorwavf

◆ orthfilt()

OrthfiltResult nk::wavelet::orthfilt ( const Value & W,
std::pmr::memory_resource * mr = nullptr )

Orthogonal filter quadruple from a scaling filter — [Lo_D, Hi_D, Lo_R, Hi_R] = orthfilt(W).

Given a unit-normalised scaling filter W (sum(W) = 1), emits the four orthogonal-wavelet filter banks via the standard QMF construction: Lo_R = W*sqrt(2), Lo_D = reverse(Lo_R), Hi_R[k] = (-1)^k * Lo_R[N-1-k], Hi_D = reverse(Hi_R) — all row vectors, in MATLAB's documented output order.

Parameters
WScaling filter (non-empty; conventionally sum(W) = 1).
mrMemory resource (nullptr → process default).
Returns
OrthfiltResult { Lo_D, Hi_D, Lo_R, Hi_R }.
Exceptions
Errorif W is empty.
See also
dbwavf, coifwavf, symwavf

◆ qmf()

Value nk::wavelet::qmf ( const Value & x,
int p = 0,
std::pmr::memory_resource * mr = nullptr )

Quadrature mirror filter — y = qmf(x, p).

y(k) = (-1)^(k-1) * x(N-k+1) for p == 0 (default); the whole result is negated for p == 1. Verified vs MATLAB R2025b: qmf([1 2 3 4]) = [4 -3 2 -1], qmf([1 2 3 4], 1) = [-4 3 -2 1].

Parameters
xInput filter (real).
pParity, 0 (default) or 1 (collapsed mod 2).
mrMemory resource (nullptr → process default).
Returns
Quadrature mirror filter, same shape as x.
See also
wrev

◆ shanwavf()

std::tuple< Value, Value > nk::wavelet::shanwavf ( double lb,
double ub,
size_t N,
double fb,
double fc,
std::pmr::memory_resource * mr = nullptr )

Shannon wavelet ([psi, x] = shanwavf(LB, UB, N, fb, fc)).

Complex-valued: \( \psi(t) = \sqrt{f_b}\,\text{sinc}(f_b t)\,e^{2\pi i f_c t} \).

Parameters
lb,ubGrid endpoints.
NNumber of samples.
fbBandwidth parameter (> 0).
fcCentre frequency (> 0).
mrMemory resource (nullptr → process default).
Returns
(psi, x); psi is COMPLEX.
See also
cmorwavf, fbspwavf

◆ swt()

Value nk::wavelet::swt ( const Value & x,
int n,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Stationary (à trous) discrete wavelet transform (swc = swt(x, n, wname)).

Computes n levels of the non-decimated wavelet transform. Each level uses upsampled-by-2 filters instead of downsampling the signal, so every band has length N (shift-invariant).

Output layout: (n+1) × N matrix.

  • rows 1..n : detail coefficients \( D_j \) at levels 1..n (level 1 = finest).
  • row n+1 : approximation \( A_n \) at the coarsest level.

Boundary: periodic (the default for swt).

Parameters
xInput signal, length must divide \( 2^n \).
nDecomposition depth (≥ 1).
wnameWavelet name.
mrMemory resource (nullptr → process default).
Returns
(n+1) × N matrix of coefficients.
Exceptions
Errorif length(x) is not a multiple of \( 2^n \).
See also
iswt, modwt

◆ symwavf()

Value nk::wavelet::symwavf ( const std::string & name,
std::pmr::memory_resource * mr = nullptr )

Symlet scaling filter — F = symwavf(name).

Returns the Symlet synthesis lowpass scaling filter Lo_R / sqrt(2) (length 2N for symN) as a row vector.

Parameters
nameWavelet name "symN" (e.g. "sym4").
mrMemory resource (nullptr → process default).
Returns
Row vector of scaling-filter coefficients.
Exceptions
Errorif name is not "symN", or the family is unsupported.
See also
dbwavf, coifwavf, orthfilt

◆ upcoef()

Value nk::wavelet::upcoef ( const std::string & type,
const Value & X,
const std::string & wname,
int n,
long long len = -1,
std::pmr::memory_resource * mr = nullptr )

Direct reconstruction of a single coefficient branch (Y = upcoef(O, X, wname, N[, L])).

Reconstructs the approximation (O = "a") or detail (O = "d") coefficient vector X up N levels through the synthesis filter bank: each level interleaves zeros ([x0, 0, x1, 0, …]) and convolves with the reconstruction lowpass Lo_R — except the first level for O = "d", which uses the highpass Hi_R. No idwt-style trimming: a level grows the length to 2·n − 1 + |F| − 1. The optional L keeps the central L samples of the result.

Parameters
type"a" (approximation) or "d" (detail).
XCoefficient row to reconstruct.
wnameWavelet name.
nNumber of reconstruction levels (≥ 0; n = 0 returns X).
lenCentral length to keep (< 0 → full result, no trim).
mrMemory resource (nullptr → process default).
Returns
Reconstructed row vector.
Exceptions
Erroron a bad type, negative n, or unknown wavelet.
See also
wrcoef, waverec, detcoef

◆ wavedec()

std::pair< Value, Value > nk::wavelet::wavedec ( const Value & x,
int n,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Multi-level 1-D DWT ([C, L] = wavedec(x, n, wname)).

Runs n successive single-level dwt passes on the running approximation band. Packs the result into the canonical (C, L) layout:

C = [cA_n, cD_n, cD_{n-1}, ..., cD_1] (concatenated row) L = [|cA_n|, |cD_n|, ..., |cD_1|, |x|] (length n+2)

Parameters
xInput signal (vector).
nDecomposition depth (≥ 1).
wnameWavelet name.
mrMemory resource (nullptr → process default).
Returns
(C, L); bind via auto [C, L] = wavedec(x, n, wname);.
Exceptions
Errorif n < 1.
auto [C, L] = wavedec(signal, 3, "sym4");
// appcoef(C, L, "sym4", 3) ≈ coarsest approximation
// detcoef(C, L, 1) ≈ finest detail
std::pair< Value, Value > wavedec(const Value &x, int n, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
Multi-level 1-D DWT ([C, L] = wavedec(x, n, wname)).
See also
waverec, appcoef, detcoef, wrcoef

◆ wavedec2()

Wavedec2Result nk::wavelet::wavedec2 ( const Value & X,
int n,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

2-D multilevel wavelet decomposition.

Iterates dwt2 n times on the running approximation (LL) band and packs the [C, S] layout.

Parameters
XInput image (2-D matrix).
nNumber of decomposition levels (≥ 1).
wnameWavelet name (see wavelet_filters).
mrMemory resource (nullptr → process default).
Returns
Wavedec2Result.
See also
waverec2, appcoef2, detcoef2

◆ wavelet_filters()

FilterBank nk::wavelet::wavelet_filters ( const std::string & name)

Return the four filter banks for a named orthogonal wavelet.

Recognised families: "haar" / "db1", "db2".."db10", "sym2".."sym10", "coif1".."coif5". (More can be added without touching dwt/idwt — they only consume the four returned vectors.)

Parameters
nameWavelet family name.
Returns
FilterBank with all four arrays populated.
Exceptions
Erroron unsupported name.
See also
wfilters

◆ waverec()

Value nk::wavelet::waverec ( const Value & C,
const Value & L,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Inverse of wavedec.

Iteratively applies idwt from coarsest to finest, using the length bookkeeping in L to set each reconstruction target.

Parameters
CCoefficient row from wavedec.
LBookkeeping row from wavedec.
wnameWavelet name (must match decomposition).
mrMemory resource (nullptr → process default).
Returns
Reconstructed row vector of length L(end).
Exceptions
Errorif length(L) < 3 or C/L sizes are inconsistent.
See also
wavedec

◆ waverec2()

Value nk::wavelet::waverec2 ( const Value & C,
const Value & S,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Full 2-D multilevel reconstruction (waverec2(C, S, wname)), i.e.

the approximation at level 0. Inverts wavedec2 via repeated idwt2.

See also
wavedec2, appcoef2

◆ wdenoise()

Value nk::wavelet::wdenoise ( const Value & x,
int level,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

VisuShrink-style soft-threshold denoising (y = wdenoise(x, level, wname)).

Pipeline:

  1. [C, L] = wavedec(x, level, wname) — multi-level DWT.
  2. \( \hat\sigma = \text{median}(|cD_1|) / 0.6745 \) on the finest detail band.
  3. Universal (VisuShrink) threshold \( T = \hat\sigma\,\sqrt{2\ln N} \) where N = length(x).
  4. Soft-threshold every detail band in-place; leave cA untouched.
  5. y = waverec(C', L, wname) — reconstruct.

Defaults: level = min(floor(log2(N)), 5), wname = "sym4". Pass level ≤ 0 or empty wname to request the default.

Parameters
xNoisy input signal.
levelDecomposition depth (≤ 0 → default).
wnameWavelet name (empty → "sym4").
mrMemory resource (nullptr → process default).
Returns
Denoised signal of the same shape as x.
auto y = wdenoise(noisy, 0, ""); // defaults: 5 levels, sym4
Value wdenoise(const Value &x, int level, const std::string &wname, std::pmr::memory_resource *mr=nullptr)
VisuShrink-style soft-threshold denoising (y = wdenoise(x, level, wname)).
See also
wthresh, wnoisest, wavedec

◆ wenergy()

WenergyResult nk::wavelet::wenergy ( const Value & C,
const Value & L,
std::pmr::memory_resource * mr = nullptr )

Percentage of energy in the approximation and detail bands ([Ea, Ed] = wenergy(C, L)).

For a 1-D wavelet decomposition (C, L) (from wavedec), returns the energy of the approximation band as a percentage of the total (Ea = 100·‖cA_N‖² / ‖C‖²) and the per-level detail percentages Ed(i) = 100·‖cD‖² / ‖C‖² ordered as C packs them (coarsest level N first, finest level 1 last). Ea + sum(Ed) = 100.

Parameters
CCoefficient row from wavedec.
LBookkeeping row (length(L) − 2 detail levels).
mrMemory resource (nullptr → process default).
Returns
{Ea, Ed} (see WenergyResult).
Exceptions
Errorif C / L are inconsistent.
See also
wavedec, detcoef, appcoef

◆ wentropy()

Value nk::wavelet::wentropy ( const Value & X,
const std::string & type,
double param = 0.0,
std::pmr::memory_resource * mr = nullptr )

Entropy of a coefficient vector (E = wentropy(X, T[, P])).

Closed-form additive entropy over the elements of X (a "cost" used by wavelet-packet best-tree selection):

  • "shannon": −Σ sᵢ²·log(sᵢ²) (terms with sᵢ=0 contribute 0).
  • "log energy": Σ log(sᵢ²) (nonzero sᵢ only).
  • "threshold" (P = threshold): #{i : |sᵢ| > P}.
  • "sure" (P = threshold): n − 2·#{i : |sᵢ| ≤ P} + Σ min(sᵢ², P²).
  • "norm" (P = exponent ≥ 1): Σ |sᵢ|ᴾ.
Parameters
XCoefficient vector (any shape; flattened).
typeEntropy type (case-insensitive).
paramP for threshold / sure / norm (ignored otherwise).
mrMemory resource (nullptr → process default).
Returns
Scalar entropy.
Exceptions
Erroron an unknown type or norm exponent < 1.
See also
wthresh, wdenoise

◆ wextend()

Value nk::wavelet::wextend ( const Value & type,
const std::string & mode,
const Value & x,
long long lf,
const std::string & side = "b",
std::pmr::memory_resource * mr = nullptr )

Extend a signal at its boundaries (y = wextend(type, mode, x, lf, side)).

1-D (type 1) extends a vector; 2-D (type 2 / 'ar' / 'ac') extends a matrix (both axes, columns-only for 'ar', rows-only for 'ac') by lf samples per active end. mode is the boundary rule: sym/symh (half-point symmetric), symw (whole-point), asym/asymh/asymw (antisymmetric), sp0/sp1 (order-0/1 spline), per (periodic, edge- padded on odd length), zpd (zero), ppd (pure periodic). side selects which end(s): 'b' (both, default), 'l', or 'r'.

type stays a Value because MATLAB accepts 1/2/'1'/'ar'/'ac'.

Parameters
typeExtension type: 1, 2, 'ar', or 'ac'.
modeBoundary mode string (see list above).
xInput vector or matrix.
lfExtension length per active end (>= 0).
side"b" (default), "l", or "r".
mrMemory resource (nullptr → process default).
Returns
The extended signal.
Exceptions
Erroron an unknown type/mode/side or negative lf.
See also
wkeep

◆ wfilters()

WFiltersResult nk::wavelet::wfilters ( const std::string & name,
const std::string & kind = "",
std::pmr::memory_resource * mr = nullptr )

Build the named wavelet's filters as nk Value rows.

wfilters(wname[, kind]). The kind selector:

kind populated fields call form
"" all four [LoD, HiD, LoR, HiR]
"d" Lo_D, Hi_D [LoD, HiD]
"r" Lo_R, Hi_R [LoR, HiR]
"l" Lo_D, Lo_R [LoD, LoR]
"h" Hi_D, Hi_R [HiD, HiR]
Parameters
nameWavelet family name (see wavelet_filters).
kindSelector — "", "d", "r", "l", or "h".
mrMemory resource (nullptr → process default).
Returns
WFiltersResult with the requested subset populated.
Exceptions
Erroron unknown wavelet name or unknown kind.
auto r = wfilters("db4"); // all four filters
auto r2 = wfilters("db4", "d"); // analysis only — Lo_D, Hi_D
WFiltersResult wfilters(const std::string &name, const std::string &kind="", std::pmr::memory_resource *mr=nullptr)
Build the named wavelet's filters as nk Value rows.
See also
wavelet_filters

◆ wkeep()

Value nk::wavelet::wkeep ( const Value & x,
const Value & len,
const Value & opt = Value::Empty,
std::pmr::memory_resource * mr = nullptr )

Keep part of a vector / a sub-matrix (y = wkeep(x, len, opt)).

1-D form (len is a scalar n): keep n elements of the vector x — centered (default, or opt == 'c'), the first n ('l'), the last n ('r'), or n starting at the 1-based index given by a numeric opt. 2-D form (len == [R C]): extract an R × C sub-matrix of x — centered (default) or anchored at the 1-based corner opt == [fr fc].

This is a genuinely polymorphic MATLAB function (the second and third arguments switch shape and type), so the public entry takes Value arguments and dispatches internally rather than splitting into overloads.

Parameters
xInput vector or matrix.
lenLength n (1-D) or [R C] (2-D).
optKeep-mode: Value::Empty (centered, default), the strings 'c'/'l'/'r', a numeric 1-based start (1-D), or the corner [fr fc] (2-D).
mrMemory resource (nullptr → process default).
Returns
The kept vector / sub-matrix.
Exceptions
Erroron an out-of-range window or an unknown opt string.

◆ wmaxlev()

Value nk::wavelet::wmaxlev ( const Value & N,
const std::string & wname,
std::pmr::memory_resource * mr = nullptr )

Maximum wavelet decomposition level — L = wmaxlev(N, wname).

L = floor(log2(N / (Lf - 1))), where Lf is the decomposition-filter length of wname. N may be a scalar or a vector (the minimum is used, e.g. for a 2-D image size [r c]). Verified vs MATLAB R2025b: wmaxlev(64, 'db2') = 4, wmaxlev([8 8], 'db1') = 3.

Parameters
NSignal length (scalar) or size vector (min is used).
wnameWavelet name (e.g. "db2").
mrMemory resource (nullptr → process default).
Returns
Scalar maximum decomposition level (>= 0).
Exceptions
Errorif N is empty or the filter length is < 2.

◆ wnoisest()

Value nk::wavelet::wnoisest ( const Value & C,
const Value & L,
const Value & S,
std::pmr::memory_resource * mr = nullptr )

Per-level noise σ estimate (σ = wnoisest(C, L, S)).

Uses the median-absolute-deviation rule on each requested detail band:

\[ \hat\sigma_k = \text{median}(|cD_k|) / 0.6745 \]

This is the standard robust estimator.

Parameters
CCoefficient row from wavedec.
LBookkeeping row.
SRow of 1-based detail levels (1 = finest).
mrMemory resource (nullptr → process default).
Returns
Row of σ̂ estimates, one per element of S.
See also
wthresh, wdenoise

◆ wrcoef()

Value nk::wavelet::wrcoef ( const std::string & type,
const Value & c,
const Value & l,
const std::string & wname,
int n,
std::pmr::memory_resource * mr = nullptr )

Single-band reconstruction (wrcoef(type, c, l, wname, n)).

Reconstructs the approximation (type = "a") or a single detail band (type = "d") of (c, l) at level n, with all other bands zeroed out before running waverec. Output is a row of length |x| (= l(end)).

  • type = "a": n ∈ [0, N]. n = 0 reconstructs the full signal (identity); n = N reconstructs only the coarsest approximation.
  • type = "d": n ∈ [1, N]. Reconstructs only the detail at level n.

Pass n = -1 to use the default (n = N = length(l) - 2).

Parameters
type"a" or "d".
cCoefficient row from wavedec.
lBookkeeping row.
wnameWavelet name.
nLevel (or -1 for default).
mrMemory resource (nullptr → process default).
Returns
Row vector of reconstructed band.
Exceptions
Erroron bad type, level out of range, or C/L mismatch.
See also
appcoef, detcoef, waverec

◆ wrev()

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

Reverse a vector / flip each column — y = wrev(x).

Row vector → element reverse; column vector → element reverse; matrix (M×N) → per-column reverse (= flipud). Complex input preserves its imaginary part.

Parameters
xInput array (real or complex).
mrMemory resource (nullptr → process default).
Returns
Reversed array, same shape as x.
See also
qmf

◆ wthresh()

Value nk::wavelet::wthresh ( const Value & X,
const std::string & sorh,
double T,
std::pmr::memory_resource * mr = nullptr )

Element-wise wavelet coefficient thresholding (Y = wthresh(X, sorh, T)).

Applies one of two thresholding rules at level T:

  • sorh = "h" (hard): \( Y = X\,\cdot\,\mathbb{1}(|X| > T) \) — zero out coefficients below the threshold, leave the rest unchanged.
  • sorh = "s" (soft): \( Y = \text{sign}(X)\,\max(|X|-T,\,0) \) — shrink every coefficient toward zero by T.

Shape of X is preserved; output type is always DOUBLE.

Parameters
XInput coefficients (any numeric Value).
sorh"h" or "s".
TNon-negative threshold.
mrMemory resource (nullptr → process default).
Returns
Thresholded coefficients.
Exceptions
Errorif sorh is not "h"/"H"/"s"/"S".
See also
wnoisest, wdenoise