step_measure_filter_fourier() creates a specification of a recipe step
that applies Fourier-domain low-pass filtering to remove high-frequency
noise.
Arguments
- recipe
A recipe object.
- measures
An optional character vector of measure column names.
- cutoff
The cutoff frequency as a fraction of the Nyquist frequency (0 to 0.5). Default is 0.1. Frequencies above this are attenuated. Tunable via
fourier_cutoff().- type
Type of filter:
"lowpass"(default) keeps low frequencies,"highpass"keeps high frequencies.- role
Not used.
- trained
Logical indicating if the step has been trained.
- skip
Logical. Should the step be skipped when baking?
- id
Unique step identifier.
Details
Fourier filtering transforms the spectrum to the frequency domain using FFT, applies a frequency mask, and transforms back. This is effective for:
Removing periodic noise
Smoothing with precise frequency control
Removing high-frequency detector noise
The cutoff is specified as a fraction of the Nyquist frequency. A cutoff of 0.1 keeps only the lowest 10% of frequencies.
Examples
library(recipes)
rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
update_role(id, new_role = "id") |>
step_measure_input_long(transmittance, location = vars(channel)) |>
step_measure_filter_fourier(cutoff = 0.1) |>
prep()
bake(rec, new_data = NULL)
#> # A tibble: 215 × 5
#> id water fat protein .measures
#> <int> <dbl> <dbl> <dbl> <meas>
#> 1 1 60.5 22.5 16.7 [100 × 2]
#> 2 2 46 40.1 13.5 [100 × 2]
#> 3 3 71 8.4 20.5 [100 × 2]
#> 4 4 72.8 5.9 20.7 [100 × 2]
#> 5 5 58.3 25.5 15.5 [100 × 2]
#> 6 6 44 42.7 13.7 [100 × 2]
#> 7 7 44 42.7 13.7 [100 × 2]
#> 8 8 69.3 10.6 19.3 [100 × 2]
#> 9 9 61.4 19.9 17.7 [100 × 2]
#> 10 10 61.4 19.9 17.7 [100 × 2]
#> # ℹ 205 more rows