Liking cljdoc? Tell your friends :D

fastmath.transform

Discrete transforms of 1d (and some 2d) signals.

High-level functions work on sequences and return vectors with metadata needed by their inverses:

  • Fourier: fft, ifft - real input (single- or double-sided spectrum) and complex input (a sequence of complex numbers: anything fastmath.complex/ensure-complex accepts, e.g. Vec2, [re im] pairs)
  • Cosine: dct, idct - types I, II and III
  • Sine: dst, idst - types I, II and III
  • Hartley: dht, idht
  • Walsh-Hadamard: hadamard, ihadamard
  • Wavelets: dwt, idwt, wpt, iwpt, wpd (see also fastmath.transform.wavelets)

Fourier, cosine, sine and Hartley functions accept a :norm option with the meaning used by scipy.fft:

  • :backward - forward transform not scaled, inverse scaled by 1/N (default for fft and dht)
  • :ortho - both directions scaled to an orthonormal transform (default for dct and dst)
  • :forward - forward transform scaled by 1/N, inverse not scaled

For cosine and sine transforms N is the scipy normalization length (2N, 2(N-1) or 2(N+1) depending on the type), so the results equal scipy.fft.dct / dst with the same type and norm.

Differences from scipy.fft: dct, dst and, without metadata, idct, idst default to :ortho (scipy: backward); types IV of DCT and DST are not implemented.

Low-level transform objects are created by transformer and used with forward-1d, reverse-1d, forward-2d and reverse-2d. They wrap JTransforms (FFT, DCT-II/III, DST-II/III, DHT, also 2d), Apache Commons Math (DCT-I/DST-I of power-of-two sizes, Hadamard) and the wavelet transforms.

Fourier transforms are computed by JTransforms.

Discrete transforms of 1d (and some 2d) signals.

High-level functions work on sequences and return vectors with metadata needed by their inverses:

* Fourier: [[fft]], [[ifft]] - real input (single- or double-sided spectrum) and complex input (a sequence of complex numbers: anything `fastmath.complex/ensure-complex` accepts, e.g. `Vec2`, `[re im]` pairs)
* Cosine: [[dct]], [[idct]] - types I, II and III
* Sine: [[dst]], [[idst]] - types I, II and III
* Hartley: [[dht]], [[idht]]
* Walsh-Hadamard: [[hadamard]], [[ihadamard]]
* Wavelets: [[dwt]], [[idwt]], [[wpt]], [[iwpt]], [[wpd]] (see also `fastmath.transform.wavelets`)

Fourier, cosine, sine and Hartley functions accept a `:norm` option with the meaning used by `scipy.fft`:

* `:backward` - forward transform not scaled, inverse scaled by `1/N` (default for [[fft]] and [[dht]])
* `:ortho` - both directions scaled to an orthonormal transform (default for [[dct]] and [[dst]])
* `:forward` - forward transform scaled by `1/N`, inverse not scaled

For cosine and sine transforms `N` is the scipy normalization length (`2N`, `2(N-1)` or `2(N+1)` depending on the type), so the results equal `scipy.fft.dct` / `dst` with the same `type` and `norm`.

Differences from `scipy.fft`: [[dct]], [[dst]] and, without metadata, [[idct]], [[idst]] default to `:ortho` (scipy: `backward`); types IV of DCT and DST are not implemented.

Low-level transform objects are created by [[transformer]] and used with [[forward-1d]], [[reverse-1d]], [[forward-2d]] and [[reverse-2d]]. They wrap JTransforms (FFT, DCT-II/III, DST-II/III, DHT, also 2d), Apache Commons Math (DCT-I/DST-I of power-of-two sizes, Hadamard) and the wavelet transforms.

Fourier transforms are computed by JTransforms.
raw docstring

dctclj

(dct xs)
(dct xs {:keys [method norm] :or {method :DCT-II norm :ortho}})

Computes the discrete cosine transform (DCT) of a 1d signal.

Options:

  • :method - :DCT-I, :DCT-II (default) or :DCT-III
  • :norm - :ortho (default, orthonormal), :backward (not scaled) or :forward, as in scipy.fft.dct

The result equals scipy.fft.dct(xs, type, norm). :DCT-I needs at least 2 values, other types at least 1; any length is accepted.

Returns a vector of doubles. Metadata under :fastmath.transform/dct holds {:method :norm} used by idct.

Throws ex-info for an empty signal or an unknown option value.

Computes the discrete cosine transform (DCT) of a 1d signal.

Options:

* `:method` - `:DCT-I`, `:DCT-II` (default) or `:DCT-III`
* `:norm` - `:ortho` (default, orthonormal), `:backward` (not scaled) or `:forward`, as in `scipy.fft.dct`

The result equals `scipy.fft.dct(xs, type, norm)`. `:DCT-I` needs at least 2 values, other types at least 1; any length is accepted.

Returns a vector of doubles. Metadata under `:fastmath.transform/dct` holds `{:method :norm}` used by [[idct]].

Throws `ex-info` for an empty signal or an unknown option value.
raw docstring

dhtclj

(dht xs)
(dht xs {:keys [norm] :or {norm :backward}})

Computes the discrete Hartley transform H[k] = sum x[n] (cos(2 pi k n / N) + sin(2 pi k n / N)) of a 1d signal.

Option :norm: :backward (default, not scaled), :ortho (scaled by 1/sqrt(N)), :forward (scaled by 1/N).

Returns a vector of doubles with metadata {:norm} under :fastmath.transform/dht used by idht. Throws ex-info for an empty signal or an unknown :norm.

Computes the discrete Hartley transform `H[k] = sum x[n] (cos(2 pi k n / N) + sin(2 pi k n / N))` of a 1d signal.

Option `:norm`: `:backward` (default, not scaled), `:ortho` (scaled by `1/sqrt(N)`), `:forward` (scaled by `1/N`).

Returns a vector of doubles with metadata `{:norm}` under `:fastmath.transform/dht` used by [[idht]]. Throws `ex-info` for an empty signal or an unknown `:norm`.
raw docstring

dstclj

(dst xs)
(dst xs {:keys [method norm] :or {method :DST-II norm :ortho}})

Computes the discrete sine transform (DST) of a 1d signal.

Options:

  • :method - :DST-I, :DST-II (default) or :DST-III
  • :norm - :ortho (default, orthonormal), :backward (not scaled) or :forward, as in scipy.fft.dst

The result equals scipy.fft.dst(xs, type, norm). Any length of at least 1 is accepted.

Returns a vector of doubles. Metadata under :fastmath.transform/dst holds {:method :norm} used by idst.

Throws ex-info for an empty signal or an unknown option value.

Computes the discrete sine transform (DST) of a 1d signal.

Options:

* `:method` - `:DST-I`, `:DST-II` (default) or `:DST-III`
* `:norm` - `:ortho` (default, orthonormal), `:backward` (not scaled) or `:forward`, as in `scipy.fft.dst`

The result equals `scipy.fft.dst(xs, type, norm)`. Any length of at least 1 is accepted.

Returns a vector of doubles. Metadata under `:fastmath.transform/dst` holds `{:method :norm}` used by [[idst]].

Throws `ex-info` for an empty signal or an unknown option value.
raw docstring

dwtclj

(dwt xs wavelet)
(dwt xs wavelet {:keys [level mode flat?] :or {mode :symmetric}})

Computes the multilevel discrete wavelet transform of a 1d signal, as pywt.wavedec.

  • xs - signal, any length
  • wavelet - name from fastmath.transform.wavelets/wavelet-names (e.g. "db4", "sym8", :daubechies-4) or a wavelet object
  • options:
    • :level - number of decomposition levels, default: the maximum useful level floor(log2(N / (L - 1))) (pywt.dwt_max_level)
    • :mode - boundary extension, default :symmetric; see fastmath.transform.wavelets for all modes, :periodization keeps the total length
    • :flat? - return one concatenated vector instead of bands (default false)

Returns a vector of bands [cA_n cD_n cD_n-1 ... cD_1] (approximation at the coarsest level followed by details from coarsest to finest), each a vector of doubles; with :level 0 the only band is the signal. Metadata under :fastmath.transform/dwt holds {:wavelet :mode :level :n} (and :lengths of the bands for flat output), used by idwt.

Throws ex-info for an empty signal, an unknown wavelet or mode, a negative level, or a one-sample signal with :reflect / :antireflect and :level at least 1 (the default level of a one-sample signal is 0, the result is [[x]], as in PyWavelets).

Computes the multilevel discrete wavelet transform of a 1d signal, as `pywt.wavedec`.

* `xs` - signal, any length
* `wavelet` - name from `fastmath.transform.wavelets/wavelet-names` (e.g. `"db4"`, `"sym8"`, `:daubechies-4`) or a wavelet object
* `options`:
    * `:level` - number of decomposition levels, default: the maximum useful level `floor(log2(N / (L - 1)))` (`pywt.dwt_max_level`)
    * `:mode` - boundary extension, default `:symmetric`; see `fastmath.transform.wavelets` for all modes, `:periodization` keeps the total length
    * `:flat?` - return one concatenated vector instead of bands (default `false`)

Returns a vector of bands `[cA_n cD_n cD_n-1 ... cD_1]` (approximation at the coarsest level followed by details from coarsest to finest), each a vector of doubles; with `:level 0` the only band is the signal. Metadata under `:fastmath.transform/dwt` holds `{:wavelet :mode :level :n}` (and `:lengths` of the bands for flat output), used by [[idwt]].

Throws `ex-info` for an empty signal, an unknown wavelet or mode, a negative level, or a one-sample signal with `:reflect` / `:antireflect` and `:level` at least 1 (the default level of a one-sample signal is 0, the result is `[[x]]`, as in PyWavelets).
raw docstring

ensure-complex-vec-with-metaclj

(ensure-complex-vec-with-meta xs)

Converts every element of xs to a complex number and keeps the metadata of xs.

Used for complex input of fft, ifft and the spectrum functions of fastmath.signal, so that the :fastmath.transform/fft metadata survives the conversion.

  • xs - a sequence of values accepted by fastmath.complex/ensure-complex (e.g. Vec2, [re im] pairs, numbers, Apache Commons Math Complex, double arrays of length 2).

Returns a vector of Vec2 with the metadata of xs (an empty vector for an empty or nil xs). The output of fft, a vector of Vec2 with :fastmath.transform/fft metadata, is returned as is. The ex-info thrown by ensure-complex for an element which cannot be converted is passed unchanged.

Converts every element of `xs` to a complex number and keeps the metadata of `xs`.

Used for complex input of [[fft]], [[ifft]] and the spectrum functions of `fastmath.signal`, so that the `:fastmath.transform/fft` metadata survives the conversion.

- `xs` - a sequence of values accepted by `fastmath.complex/ensure-complex` (e.g. `Vec2`, `[re im]` pairs, numbers, Apache Commons Math `Complex`, `double` arrays of length 2).

Returns a vector of `Vec2` with the metadata of `xs` (an empty vector for an empty or `nil` `xs`). The output of [[fft]], a vector of `Vec2` with `:fastmath.transform/fft` metadata, is returned as is. The `ex-info` thrown by `ensure-complex` for an element which cannot be converted is passed unchanged.
raw docstring

fftclj

(fft xs)
(fft xs {:keys [spectrum norm] :or {spectrum :single-sided norm :backward}})

Computes the discrete Fourier transform of a 1d signal.

Input xs is a sequence of numbers (real signal) or a sequence of complex numbers: anything fastmath.complex/ensure-complex accepts, e.g. Vec2, [re im] pairs, Apache Commons Math Complex or double arrays of length 2. The first element decides: a number starts a real signal (all elements should be numbers), anything else a complex signal (no element can be a number). A single complex sample is written [[re im]]: a flat [re im] is a real signal of length 2.

Options:

  • :spectrum - for a real signal: :single-sided (default) returns the N/2+1 non-negative frequency coefficients (as numpy.fft.rfft), :double-sided returns all N coefficients (as numpy.fft.fft). Ignored for complex input.
  • :norm - :backward (default, not scaled), :ortho (scaled by 1/sqrt(N)), :forward (scaled by 1/N).

Returns a vector of Vec2. Metadata under :fastmath.transform/fft holds {:kind :n :norm :real?} used by ifft: :kind is :real for a single-sided spectrum and :complex otherwise, :n is the signal length, :real? is true for the double-sided spectrum of a real signal.

Throws ex-info for an empty signal, a real signal with a non-number or a complex signal with a number (:index and :value of the first such element), an element which is not a complex number (the ensure-complex error) or an unknown option value.

Computes the discrete Fourier transform of a 1d signal.

Input `xs` is a sequence of numbers (real signal) or a sequence of complex numbers: anything `fastmath.complex/ensure-complex` accepts, e.g. `Vec2`, `[re im]` pairs, Apache Commons Math `Complex` or `double` arrays of length 2. The first element decides: a number starts a real signal (all elements should be numbers), anything else a complex signal (no element can be a number). A single complex sample is written `[[re im]]`: a flat `[re im]` is a real signal of length 2.

Options:

* `:spectrum` - for a real signal: `:single-sided` (default) returns the `N/2+1` non-negative frequency coefficients (as `numpy.fft.rfft`), `:double-sided` returns all `N` coefficients (as `numpy.fft.fft`). Ignored for complex input.
* `:norm` - `:backward` (default, not scaled), `:ortho` (scaled by `1/sqrt(N)`), `:forward` (scaled by `1/N`).

Returns a vector of `Vec2`. Metadata under `:fastmath.transform/fft` holds `{:kind :n :norm :real?}` used by [[ifft]]: `:kind` is `:real` for a single-sided spectrum and `:complex` otherwise, `:n` is the signal length, `:real?` is `true` for the double-sided spectrum of a real signal.

Throws `ex-info` for an empty signal, a real signal with a non-number or a complex signal with a number (`:index` and `:value` of the first such element), an element which is not a complex number (the `ensure-complex` error) or an unknown option value.
raw docstring

forward-1dclj

(forward-1d t xs)
(forward-1d t xs options)

Forward transform of a sequence or array with a transform object created by transformer.

options are passed to the transform object, see transformer. Returns a double-array (raw layout of the underlying library).

Forward transform of a sequence or array with a transform object created by [[transformer]].

`options` are passed to the transform object, see [[transformer]]. Returns a `double-array` (raw layout of the underlying library).
raw docstring

forward-2dclj

(forward-2d t xss)
(forward-2d t xss options)

Forward 2d transform of a sequence of rows with a transform object created by transformer.

options are passed to the transform object, see transformer. Returns an array of double-array rows (raw layout of the underlying library).

Forward 2d transform of a sequence of rows with a transform object created by [[transformer]].

`options` are passed to the transform object, see [[transformer]]. Returns an array of `double-array` rows (raw layout of the underlying library).
raw docstring

hadamardclj

(hadamard xs)

Computes the fast Walsh-Hadamard transform (natural / Sylvester ordering, not normalized) of a 1d signal.

The length must be a power of 2. Returns a vector of doubles. Throws ex-info for an empty signal or another length.

Computes the fast Walsh-Hadamard transform (natural / Sylvester ordering, not normalized) of a 1d signal.

The length must be a power of 2. Returns a vector of doubles. Throws `ex-info` for an empty signal or another length.
raw docstring

idctclj

(idct xs)
(idct xs options)

Computes the inverse discrete cosine transform, the inverse of dct.

:method and :norm are read from the metadata attached by dct; options override them. Without metadata the defaults are :DCT-II and :ortho. The result equals scipy.fft.idct(xs, type, norm).

Returns a vector of doubles. Throws ex-info for an empty input or an unknown option value.

Computes the inverse discrete cosine transform, the inverse of [[dct]].

`:method` and `:norm` are read from the metadata attached by [[dct]]; `options` override them. Without metadata the defaults are `:DCT-II` and `:ortho`. The result equals `scipy.fft.idct(xs, type, norm)`.

Returns a vector of doubles. Throws `ex-info` for an empty input or an unknown option value.
raw docstring

idhtclj

(idht xs)
(idht xs options)

Computes the inverse discrete Hartley transform, the inverse of dht.

:norm is read from the metadata attached by dht; options override it (default :backward, the result is divided by N).

Returns a vector of doubles. Throws ex-info for an empty input or an unknown :norm.

Computes the inverse discrete Hartley transform, the inverse of [[dht]].

`:norm` is read from the metadata attached by [[dht]]; `options` override it (default `:backward`, the result is divided by `N`).

Returns a vector of doubles. Throws `ex-info` for an empty input or an unknown `:norm`.
raw docstring

idstclj

(idst xs)
(idst xs options)

Computes the inverse discrete sine transform, the inverse of dst.

:method and :norm are read from the metadata attached by dst; options override them. Without metadata the defaults are :DST-II and :ortho. The result equals scipy.fft.idst(xs, type, norm).

Returns a vector of doubles. Throws ex-info for an empty input or an unknown option value.

Computes the inverse discrete sine transform, the inverse of [[dst]].

`:method` and `:norm` are read from the metadata attached by [[dst]]; `options` override them. Without metadata the defaults are `:DST-II` and `:ortho`. The result equals `scipy.fft.idst(xs, type, norm)`.

Returns a vector of doubles. Throws `ex-info` for an empty input or an unknown option value.
raw docstring

idwtclj

(idwt coeffs)
(idwt coeffs wavelet)
(idwt coeffs wavelet options)

Reconstructs a signal from the dwt bands, as pywt.waverec.

  • coeffs - vector of bands [cA_n cD_n ... cD_1], or a flat vector together with :lengths
  • wavelet - the wavelet used by dwt; default (nil or 1-arity): the :wavelet of the metadata
  • options (merged over the metadata attached by dwt):
    • :mode - boundary mode used by dwt (default :symmetric)
    • :n - length of the original signal; without it the result can be one sample longer, as in PyWavelets
    • :lengths - band lengths, required for flat coefficients

At every level an approximation one sample longer than the next detail band is trimmed (as in PyWavelets). Returns a vector of doubles.

Throws ex-info for empty input or empty bands, a missing wavelet, a wavelet other than the one in the metadata, an unknown wavelet or mode, flat coefficients without :lengths, or band lengths that do not fit together.

Reconstructs a signal from the [[dwt]] bands, as `pywt.waverec`.

* `coeffs` - vector of bands `[cA_n cD_n ... cD_1]`, or a flat vector together with `:lengths`
* `wavelet` - the wavelet used by [[dwt]]; default (`nil` or 1-arity): the `:wavelet` of the metadata
* `options` (merged over the metadata attached by [[dwt]]):
    * `:mode` - boundary mode used by [[dwt]] (default `:symmetric`)
    * `:n` - length of the original signal; without it the result can be one sample longer, as in PyWavelets
    * `:lengths` - band lengths, required for flat coefficients

At every level an approximation one sample longer than the next detail band is trimmed (as in PyWavelets). Returns a vector of doubles.

Throws `ex-info` for empty input or empty bands, a missing wavelet, a wavelet other than the one in the metadata, an unknown wavelet or mode, flat coefficients without `:lengths`, or band lengths that do not fit together.
raw docstring

ifftclj

(ifft xs)
(ifft xs options)

Computes the inverse discrete Fourier transform, the inverse of fft.

xs is a sequence of complex coefficients: anything fastmath.complex/ensure-complex accepts, e.g. Vec2, [re im] pairs or numbers (zero imaginary part); a flat [re im] is two coefficients, a single one is written [[re im]]. The way it is inverted is read from the metadata attached by fft; options override the metadata:

  • :kind - :real for a single-sided spectrum (N/2+1 coefficients) of a real signal, :complex for a full spectrum.
  • :n - length of the original signal, required for :real (N cannot be inferred from a single-sided spectrum). For :complex it must equal the number of coefficients (no padding or truncation).
  • :real? - for :complex, return only real parts (default false).
  • :norm - :backward (default, scaled by 1/N), :ortho (scaled by 1/sqrt(N)), :forward (not scaled).

Returns a vector of doubles for :real (or :real? true), otherwise a vector of Vec2.

Throws ex-info when xs is empty, when a coefficient is not a complex number (the ensure-complex error), when there is no metadata and :kind is not given, when :n is missing for :kind :real or does not match the spectrum length.

Computes the inverse discrete Fourier transform, the inverse of [[fft]].

`xs` is a sequence of complex coefficients: anything `fastmath.complex/ensure-complex` accepts, e.g. `Vec2`, `[re im]` pairs or numbers (zero imaginary part); a flat `[re im]` is two coefficients, a single one is written `[[re im]]`. The way it is inverted is read from the metadata attached by [[fft]]; `options` override the metadata:

* `:kind` - `:real` for a single-sided spectrum (`N/2+1` coefficients) of a real signal, `:complex` for a full spectrum.
* `:n` - length of the original signal, required for `:real` (`N` cannot be inferred from a single-sided spectrum). For `:complex` it must equal the number of coefficients (no padding or truncation).
* `:real?` - for `:complex`, return only real parts (default `false`).
* `:norm` - `:backward` (default, scaled by `1/N`), `:ortho` (scaled by `1/sqrt(N)`), `:forward` (not scaled).

Returns a vector of doubles for `:real` (or `:real? true`), otherwise a vector of `Vec2`.

Throws `ex-info` when `xs` is empty, when a coefficient is not a complex number (the `ensure-complex` error), when there is no metadata and `:kind` is not given, when `:n` is missing for `:kind :real` or does not match the spectrum length.
raw docstring

ihadamardclj

(ihadamard xs)

Computes the inverse fast Walsh-Hadamard transform (the forward transform divided by N).

The length must be a power of 2. Returns a vector of doubles. Throws ex-info for an empty signal or another length.

Computes the inverse fast Walsh-Hadamard transform (the forward transform divided by `N`).

The length must be a power of 2. Returns a vector of doubles. Throws `ex-info` for an empty signal or another length.
raw docstring

iwptclj

(iwpt coeffs)
(iwpt coeffs wavelet)
(iwpt coeffs wavelet options)

Reconstructs a signal from the wpt nodes of one level.

  • coeffs - vector of 2^level nodes in natural order, or a flat vector together with :level
  • wavelet - the wavelet used by wpt; default (nil or 1-arity): the :wavelet of the metadata
  • options (merged over the metadata attached by wpt):
    • :mode - boundary mode used by wpt (default :symmetric)
    • :level - required for flat coefficients
    • :n - length of the original signal; every reconstructed node is trimmed to its length in the tree (as PyWavelets does with a known data shape), without it nodes can be one sample longer

Returns a vector of doubles. Throws ex-info for empty input or empty nodes, a missing wavelet, a wavelet other than the one in the metadata, an unknown wavelet or mode, a node count which is not a power of two, nodes of different lengths or lengths which do not match :n.

Reconstructs a signal from the [[wpt]] nodes of one level.

* `coeffs` - vector of `2^level` nodes in natural order, or a flat vector together with `:level`
* `wavelet` - the wavelet used by [[wpt]]; default (`nil` or 1-arity): the `:wavelet` of the metadata
* `options` (merged over the metadata attached by [[wpt]]):
    * `:mode` - boundary mode used by [[wpt]] (default `:symmetric`)
    * `:level` - required for flat coefficients
    * `:n` - length of the original signal; every reconstructed node is trimmed to its length in the tree (as PyWavelets does with a known data shape), without it nodes can be one sample longer

Returns a vector of doubles. Throws `ex-info` for empty input or empty nodes, a missing wavelet, a wavelet other than the one in the metadata, an unknown wavelet or mode, a node count which is not a power of two, nodes of different lengths or lengths which do not match `:n`.
raw docstring

reverse-1dclj

(reverse-1d t xs)
(reverse-1d t xs options)

Reverse (inverse) transform of a sequence or array with a transform object created by transformer.

options are passed to the transform object, see transformer. Returns a double-array.

Reverse (inverse) transform of a sequence or array with a transform object created by [[transformer]].

`options` are passed to the transform object, see [[transformer]]. Returns a `double-array`.
raw docstring

reverse-2dclj

(reverse-2d t xss)
(reverse-2d t xss options)

Reverse (inverse) 2d transform of a sequence of rows with a transform object created by transformer.

options are passed to the transform object, see transformer. Returns an array of double-array rows.

Reverse (inverse) 2d transform of a sequence of rows with a transform object created by [[transformer]].

`options` are passed to the transform object, see [[transformer]]. Returns an array of `double-array` rows.
raw docstring

transformercljmultimethod

Creates a low-level transform object, used with forward-1d, reverse-1d, forward-2d and reverse-2d.

Prefer the high-level functions (fft, dct, dst, dht, hadamard, dwt, wpt) unless you need the raw layout or a 2d transform.

First argument selects the family, second the variant:

  • :real
    • :fft - real FFT in the JTransforms packed layout (1d and 2d)
    • :dct - DCT-II forward, DCT-III reverse (1d and 2d)
    • :dst - DST-II forward, DST-III reverse (1d and 2d)
    • :dht - discrete Hartley transform (1d and 2d)
    • :sine, :cosine - DST-I / DCT-I from Apache Commons Math, options {:normalization :orthogonal} (default) or :standard; size must be a power of two (:sine, first value must be 0) or a power of two plus one (:cosine)
    • :hadamard - Walsh-Hadamard transform, size must be a power of two
  • :complex
    • :fft - complex FFT of interleaved [re0 im0 re1 im1 ...] data (1d and 2d)
    • :fftr (alias :rfft) - forward: full complex spectrum of real data; reverse: complex inverse of interleaved data
  • :sine, :cosine - with second argument :standard or :orthogonal, Apache Commons Math DST-I / DCT-I with fixed normalization
  • :dwt, :wpt - wavelet transforms (dwt, wpt) with flat double-array coefficients, second argument is a wavelet name, see fastmath.transform.wavelets/wavelet-names; options :level and :mode as in dwt, the reverse transform also needs the signal length :n (and the same :level and :mode). 1d only.

JTransforms based objects take the option :scale? (default true): when true the reverse FFT/DHT is divided by N and DCT/DST are orthonormal; with false the raw JTransforms scaling is used (for DCT/DST it differs between power-of-two and other sizes). The high-level functions use :norm instead.

2d transforms need more than one row and column, the real 2d FFT (:real :fft) also power-of-two sizes; JTransforms throws IllegalArgumentException otherwise.

Throws ex-info for an unknown family or variant.

Creates a low-level transform object, used with [[forward-1d]], [[reverse-1d]], [[forward-2d]] and [[reverse-2d]].

Prefer the high-level functions ([[fft]], [[dct]], [[dst]], [[dht]], [[hadamard]], [[dwt]], [[wpt]]) unless you need the raw layout or a 2d transform.

First argument selects the family, second the variant:

* `:real`
    * `:fft` - real FFT in the JTransforms packed layout (1d and 2d)
    * `:dct` - DCT-II forward, DCT-III reverse (1d and 2d)
    * `:dst` - DST-II forward, DST-III reverse (1d and 2d)
    * `:dht` - discrete Hartley transform (1d and 2d)
    * `:sine`, `:cosine` - DST-I / DCT-I from Apache Commons Math, options `{:normalization :orthogonal}` (default) or `:standard`; size must be a power of two (`:sine`, first value must be 0) or a power of two plus one (`:cosine`)
    * `:hadamard` - Walsh-Hadamard transform, size must be a power of two
* `:complex`
    * `:fft` - complex FFT of interleaved `[re0 im0 re1 im1 ...]` data (1d and 2d)
    * `:fftr` (alias `:rfft`) - forward: full complex spectrum of real data; reverse: complex inverse of interleaved data
* `:sine`, `:cosine` - with second argument `:standard` or `:orthogonal`, Apache Commons Math DST-I / DCT-I with fixed normalization
* `:dwt`, `:wpt` - wavelet transforms ([[dwt]], [[wpt]]) with flat `double-array` coefficients, second argument is a wavelet name, see `fastmath.transform.wavelets/wavelet-names`; options `:level` and `:mode` as in [[dwt]], the reverse transform also needs the signal length `:n` (and the same `:level` and `:mode`). 1d only.

JTransforms based objects take the option `:scale?` (default `true`): when `true` the reverse FFT/DHT is divided by `N` and DCT/DST are orthonormal; with `false` the raw JTransforms scaling is used (for DCT/DST it differs between power-of-two and other sizes). The high-level functions use `:norm` instead.

2d transforms need more than one row and column, the real 2d FFT (`:real :fft`) also power-of-two sizes; JTransforms throws `IllegalArgumentException` otherwise.

Throws `ex-info` for an unknown family or variant.
raw docstring

wpdclj

(wpd xs wavelet)
(wpd xs wavelet {:keys [level mode flat?] :or {mode :symmetric}})

Computes the full wavelet packet decomposition: the wpt nodes of every level from 0 (the signal) to :level.

  • xs - signal, any length
  • wavelet - name from fastmath.transform.wavelets/wavelet-names or a wavelet object
  • options:
    • :level - deepest level, default the maximum useful level (as for dwt)
    • :mode - boundary extension, default :symmetric
    • :flat? - every level as one concatenated vector instead of nodes (default false)

Returns a vector of levels; level k holds 2^k nodes in natural order, as wpt with :level k. Metadata under :fastmath.transform/wpd holds {:wavelet :mode :level :n}.

Throws ex-info for an empty signal, an unknown wavelet or mode, or a negative level.

Computes the full wavelet packet decomposition: the [[wpt]] nodes of every level from 0 (the signal) to `:level`.

* `xs` - signal, any length
* `wavelet` - name from `fastmath.transform.wavelets/wavelet-names` or a wavelet object
* `options`:
    * `:level` - deepest level, default the maximum useful level (as for [[dwt]])
    * `:mode` - boundary extension, default `:symmetric`
    * `:flat?` - every level as one concatenated vector instead of nodes (default `false`)

Returns a vector of levels; level `k` holds `2^k` nodes in natural order, as [[wpt]] with `:level k`. Metadata under `:fastmath.transform/wpd` holds `{:wavelet :mode :level :n}`.

Throws `ex-info` for an empty signal, an unknown wavelet or mode, or a negative level.
raw docstring

wptclj

(wpt xs wavelet)
(wpt xs wavelet {:keys [level mode flat?] :or {mode :symmetric}})

Computes the wavelet packet transform of a 1d signal at one level, as the level nodes of pywt.WaveletPacket.

Every node is split into approximation and detail by one level of the discrete wavelet transform, down to :level.

  • xs - signal, any length
  • wavelet - name from fastmath.transform.wavelets/wavelet-names or a wavelet object
  • options:
    • :level - decomposition level, default the maximum useful level (as for dwt)
    • :mode - boundary extension, default :symmetric
    • :flat? - return one concatenated vector instead of nodes (default false)

Returns the 2^level nodes of the level in natural order (paths a...a, a...ad, ..., d...d, approximation before detail at every split), each a vector of doubles of the same length. Metadata under :fastmath.transform/wpt holds {:wavelet :mode :level :n}, used by iwpt.

Throws ex-info for an empty signal, an unknown wavelet or mode, or a negative level.

Computes the wavelet packet transform of a 1d signal at one level, as the level nodes of `pywt.WaveletPacket`.

Every node is split into approximation and detail by one level of the discrete wavelet transform, down to `:level`.

* `xs` - signal, any length
* `wavelet` - name from `fastmath.transform.wavelets/wavelet-names` or a wavelet object
* `options`:
    * `:level` - decomposition level, default the maximum useful level (as for [[dwt]])
    * `:mode` - boundary extension, default `:symmetric`
    * `:flat?` - return one concatenated vector instead of nodes (default `false`)

Returns the `2^level` nodes of the level in natural order (paths `a...a`, `a...ad`, ..., `d...d`, approximation before detail at every split), each a vector of doubles of the same length. Metadata under `:fastmath.transform/wpt` holds `{:wavelet :mode :level :n}`, used by [[iwpt]].

Throws `ex-info` for an empty signal, an unknown wavelet or mode, or a negative level.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close