Skip to contents

Sliding-window mean after trimming alpha fraction of values from each tail of the sorted window. Robust to both Gaussian and impulsive noise; reduces to the mean filter when alpha = 0 and to the median filter as alpha -> 0.5.

Usage

morie_dsp_alpha_trimmed_mean(x, window = 5L, alpha = 0.2)

Arguments

x

Numeric vector.

window

Window length. Default 5.

alpha

Trim fraction (0 <= alpha < 0.5). Default 0.2.

Value

Filtered vector, length(x).

References

Rangayyan & Krishnan (2015), Ch. 3, sec. 3.4.

Examples

set.seed(2)
t <- seq(0, 199) / 200
x <- sin(2 * pi * 4 * t) + rnorm(200, sd = 0.3)
x[seq(20, 200, by = 20)] <- 10  # impulse contamination
y <- morie_dsp_alpha_trimmed_mean(x, window = 9L, alpha = 0.3)
head(y)
#> [1] 0.1807880 0.3192331 0.4219925 0.4911453 0.5379250 0.6744056