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)). | |
1D/2D Discrete Wavelet Transform (DWT), Stationary Wavelet Transform (SWT), filter banks, wavelet denoising, and continuous wavelets.
| 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.
| C | Coefficient row from wavedec. |
| L | Bookkeeping row. |
| wname | Wavelet name. |
| level | Target level (or -1 for default = coarsest). |
| mr | Memory resource (nullptr → process default). |
| Error | on out-of-range level. |
| 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.
| 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.
| C | Coefficient row from wavedec. |
| L | Bookkeeping row. |
| Lo_R | Synthesis lowpass filter coefficients. |
| Hi_R | Synthesis highpass filter coefficients. |
| level | Target level (or -1 for default = coarsest). |
| mr | Memory resource (nullptr → process default). |
| 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.
| name | Candidate family name (e.g. "bior2.2", "rbio4.4"). |
| out | Filled with the four filter vectors on success. |
name is a known bior/rbio family, else false. | 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.
| name | Wavelet name "coifK" (e.g. "coif2"). |
| mr | Memory resource (nullptr → process default). |
| Error | if name is not "coifK", or the family is unsupported. |
| 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.
| name | Wavelet name, "haar" or "dbN" (e.g. "db4"). |
| mr | Memory resource (nullptr → process default). |
| Error | if name is not "haar"/"dbN", or the family is unsupported by the underlying filter table. |
| 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):
keepapp = 1 in both cases. Only type = "wv" (wavelet) is supported; "wp" (wavelet packet) is not yet implemented.
| opt | "den" (denoise) or "cmp" (compress). |
| type | "wv" (wavelet); "wp" is rejected. |
| x | Input signal. |
| mr | Memory resource (nullptr → process default). |
| Error | on an unknown opt/type or "wp". |
| 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.
| C | Coefficient row from wavedec. |
| L | Bookkeeping row. |
| level | 1-based level (1 = finest). |
| mr | Memory resource (nullptr → process default). |
| Error | on out-of-range 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)).
| type | "h" (horizontal), "v" (vertical) or "d" (diagonal). |
| C | Coefficient vector from wavedec2. |
| S | Size bookkeeping matrix from wavedec2. |
| level | Decomposition level (1 = finest … N = coarsest). |
| mr | Memory resource. |
| 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.
| x | Input signal (vector). |
| wname | Wavelet name — "haar", "db1".."db10", "sym2".."sym10", "coif1".."coif5". |
| mr | Memory resource (nullptr → process default). |
| Error | on unknown wavelet name. |
| 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.
| X | Input image (2-D matrix). |
| wname | Wavelet name (see wavelet_filters for the supported family list). |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input signal (vector). |
| Lo_D | Analysis lowpass filter coefficients. |
| Hi_D | Analysis highpass filter coefficients. |
| mr | Memory resource (nullptr → process default). |
| 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.
| x | Input vector or matrix. |
| odd | 0 (default, keep even) or 1 (keep odd). |
| type | Matrix axis 'c' (default) / 'r' / 'm'. |
| mr | Memory resource (nullptr → process default). |
| 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].
| x | Input vector or matrix. |
| odd | 0 or 1 (default 1). |
| type | Matrix axis 'c' (default) / 'r' / 'm'. |
| mr | Memory resource (nullptr → process default). |
| 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.
| p | Derivative order ≥ 1. |
| 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.
| x | Input vector or matrix (even length per column). |
| level | Number of levels; <= 0 (default) → the maximum level (largest k with 2^k | length). |
| integer | false (default) → orthogonal; true → integer lifting (not supported for complex input). |
| mr | Memory resource (nullptr → process default). |
| Error | on empty/odd-length input, level above the maximum, or integer == true with complex input. |
| 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).
| cA | Approximation coefficients (from dwt). |
| cD | Detail coefficients. |
| wname | Wavelet name (must match the one used in dwt). |
| len | Output length (-1 for the natural default). |
| mr | Memory resource (nullptr → process default). |
| 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.
| cA | Approximation band (LL). |
| cH | Horizontal detail band (LH). |
| cV | Vertical detail band (HL). |
| cD | Diagonal detail band (HH). |
| wname | Wavelet name (must match decomposition). |
| outRows | Output rows (-1 for natural). |
| outCols | Output cols (-1 for natural). |
| mr | Memory resource (nullptr → process default). |
| 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.
| cA | Approximation coefficients. |
| cD | Detail coefficients. |
| Lo_R | Synthesis lowpass filter coefficients. |
| Hi_R | Synthesis highpass filter coefficients. |
| len | Output length (-1 for natural). |
| mr | Memory resource (nullptr → process default). |
| 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.
| a | Approximation coefficients (column / matrix). |
| d | Detail — a matrix (1 level) or a cell column (multi-level). |
| level | Finest detail bands to suppress, in [0, Nlevels) (default 0 → lossless). |
| integer | false (default) → orthogonal; true → integer lifting. |
| mr | Memory resource (nullptr → process default). |
| Error | on empty a/d, complex d, level outside [0, Nlevels), or integer == true with complex a. |
| 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.
| swc | (n+1) × N coefficient matrix from swt. |
| wname | Wavelet name (must match the forward transform). |
| mr | Memory resource (nullptr → process default). |
| 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} \).
| lb | Left endpoint of the grid. |
| ub | Right endpoint. |
| N | Number of samples (≥ 0). |
| mr | Memory resource (nullptr → process default). |
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.
| x | Element-wise input. |
| mr | Memory resource (nullptr → process default). |
| 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.
Periodic boundary.
| x | Input signal. |
| n | Decomposition depth. |
| wname | Wavelet name. |
| mr | Memory resource (nullptr → process default). |
| 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.
| W | Scaling filter (non-empty; conventionally sum(W) = 1). |
| mr | Memory resource (nullptr → process default). |
| Error | if W is empty. |
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].
| x | Input filter (real). |
| p | Parity, 0 (default) or 1 (collapsed mod 2). |
| mr | Memory resource (nullptr → process default). |
| 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} \).
| lb,ub | Grid endpoints. |
| N | Number of samples. |
| fb | Bandwidth parameter (> 0). |
| fc | Centre frequency (> 0). |
| mr | Memory resource (nullptr → process default). |
| 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.
Boundary: periodic (the default for swt).
| x | Input signal, length must divide \( 2^n \). |
| n | Decomposition depth (≥ 1). |
| wname | Wavelet name. |
| mr | Memory resource (nullptr → process default). |
| Error | if length(x) is not a multiple of \( 2^n \). |
| 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.
| name | Wavelet name "symN" (e.g. "sym4"). |
| mr | Memory resource (nullptr → process default). |
| Error | if name is not "symN", or the family is unsupported. |
| 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.
| type | "a" (approximation) or "d" (detail). |
| X | Coefficient row to reconstruct. |
| wname | Wavelet name. |
| n | Number of reconstruction levels (≥ 0; n = 0 returns X). |
| len | Central length to keep (< 0 → full result, no trim). |
| mr | Memory resource (nullptr → process default). |
| Error | on a bad type, negative n, or unknown wavelet. |
| 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)
| x | Input signal (vector). |
| n | Decomposition depth (≥ 1). |
| wname | Wavelet name. |
| mr | Memory resource (nullptr → process default). |
| Error | if n < 1. |
| 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.
| X | Input image (2-D matrix). |
| n | Number of decomposition levels (≥ 1). |
| wname | Wavelet name (see wavelet_filters). |
| mr | Memory resource (nullptr → process default). |
| 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.)
| name | Wavelet family name. |
| Error | on unsupported name. |
| 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.
| C | Coefficient row from wavedec. |
| L | Bookkeeping row from wavedec. |
| wname | Wavelet name (must match decomposition). |
| mr | Memory resource (nullptr → process default). |
| Error | if length(L) < 3 or C/L sizes are inconsistent. |
| 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:
Defaults: level = min(floor(log2(N)), 5), wname = "sym4". Pass level ≤ 0 or empty wname to request the default.
| x | Noisy input signal. |
| level | Decomposition depth (≤ 0 → default). |
| wname | Wavelet name (empty → "sym4"). |
| mr | Memory resource (nullptr → process default). |
| 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.
| C | Coefficient row from wavedec. |
| L | Bookkeeping row (length(L) − 2 detail levels). |
| mr | Memory resource (nullptr → process default). |
| Error | if C / L are inconsistent. |
| 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):
| X | Coefficient vector (any shape; flattened). |
| type | Entropy type (case-insensitive). |
| param | P for threshold / sure / norm (ignored otherwise). |
| mr | Memory resource (nullptr → process default). |
| Error | on an unknown type or norm exponent < 1. |
| 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'.
| type | Extension type: 1, 2, 'ar', or 'ac'. |
| mode | Boundary mode string (see list above). |
| x | Input vector or matrix. |
| lf | Extension length per active end (>= 0). |
| side | "b" (default), "l", or "r". |
| mr | Memory resource (nullptr → process default). |
| Error | on an unknown type/mode/side or negative lf. |
| 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] |
| name | Wavelet family name (see wavelet_filters). |
| kind | Selector — "", "d", "r", "l", or "h". |
| mr | Memory resource (nullptr → process default). |
| Error | on unknown wavelet name or unknown kind. |
| 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.
| x | Input vector or matrix. |
| len | Length n (1-D) or [R C] (2-D). |
| opt | Keep-mode: Value::Empty (centered, default), the strings 'c'/'l'/'r', a numeric 1-based start (1-D), or the corner [fr fc] (2-D). |
| mr | Memory resource (nullptr → process default). |
| Error | on an out-of-range window or an unknown opt string. |
| 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.
| N | Signal length (scalar) or size vector (min is used). |
| wname | Wavelet name (e.g. "db2"). |
| mr | Memory resource (nullptr → process default). |
| Error | if N is empty or the filter length is < 2. |
| 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.
| C | Coefficient row from wavedec. |
| L | Bookkeeping row. |
| S | Row of 1-based detail levels (1 = finest). |
| mr | Memory resource (nullptr → process default). |
| 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)).
Pass n = -1 to use the default (n = N = length(l) - 2).
| type | "a" or "d". |
| c | Coefficient row from wavedec. |
| l | Bookkeeping row. |
| wname | Wavelet name. |
| n | Level (or -1 for default). |
| mr | Memory resource (nullptr → process default). |
| Error | on bad type, level out of range, or C/L mismatch. |
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.
| x | Input array (real or complex). |
| mr | Memory resource (nullptr → process default). |
| 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:
Shape of X is preserved; output type is always DOUBLE.
| X | Input coefficients (any numeric Value). |
| sorh | "h" or "s". |
| T | Non-negative threshold. |
| mr | Memory resource (nullptr → process default). |
| Error | if sorh is not "h"/"H"/"s"/"S". |