step_wavelet_denoise: Wavelet Denoising Recipe Step

View source: R/wavelet_denoise.R

step_wavelet_denoiseR Documentation

Wavelet Denoising Recipe Step

Description

step_wavelet_denoise() creates a specification of a recipe step that denoises the spectra with wavelet_denoise().

Usage

step_wavelet_denoise(
  recipe,
  ...,
  wavelet = "la8",
  level = 2,
  threshold = "sure",
  rule = "hard",
  segments = TRUE,
  role = NA,
  trained = FALSE,
  columns = NULL,
  skip = FALSE,
  id = recipes::rand_id("wavelet_denoise")
)

Arguments

recipe

A recipe object. The step will be added to the sequence of operations for this recipe.

...

One or more selector functions to choose the predictors (for example, the spectral channels). See recipes::selections().

wavelet

The wavelet: "la8" (default; Daubechies' least asymmetric wavelet with 8 coefficients, whose nearly symmetric shape suits spectral lines), "haar", "d4", "d6" or "d8" (see wavelet_features()).

level

The number of levels thresholded. Default is 2: the scales of 2 to 4 channels.

threshold

The threshold: "sure" (default) or "universal".

rule

The thresholding rule: "hard" (default) or "soft".

segments

A logical: denoise the segments between gaps of the wavelength axis separately (TRUE, default). Needs wavelengths as names.

role

Not used by this step, since no new variables are created.

trained

A logical indicating whether the step has been trained.

columns

The names of the selected columns, stored once the step has been trained.

skip

A logical. Should the step be skipped when the recipe is baked by recipes::bake()? Keep the default FALSE, so that new data are corrected with the same filter as the training data.

id

A character string that is unique to this step.

Details

The selected columns form one spectrum per row, and are replaced by the denoised values. Nothing is estimated from the training data: the noise and thresholds are those of each spectrum. The level can be tuned with tune::tune() (dials parameter wavelet_level(), from 1 to 4 by default). tidy() returns the terms, wavelet, level, threshold, rule and id.

Value

An updated version of recipe with the new step added to the sequence of existing steps.

See Also

wavelet_denoise(), step_savgol(), step_wavelet()

Examples

if (rlang::is_installed("recipes")) {
  data(forageShots)
  rec <- recipes::recipe(K ~ ., data = forageShots[-c(1:4)]) |>
    step_wavelet_denoise(recipes::all_predictors()) |>
    recipes::prep()
  recipes::tidy(rec, number = 1)
}

specProc documentation built on Nov. 20, 2026, 5:11 p.m.