 Unweighted sliding-average or rectangular Smoothing.

## Usage

smooth_rectangular(x, y, ...)

# S4 method for numeric,numeric
smooth_rectangular(x, y, m = 3)

# S4 method for ANY,missing
smooth_rectangular(x, m)

## Arguments

x, y

A numeric vector. If y is missing, an attempt is made to interpret x in a suitable way (see grDevices::xy.coords()).

...

Currently not used.

m

An odd integer giving the window size (i.e. the number of adjacent points to be used; see window_sliding()).

## Value

Returns a list with two components x and y.

## Details

It replaces each point in the signal with the average of $$m$$ adjacent points.

## Note

There will be $$(m - 1) / 2$$ points both at the beginning and at the end of the data series for which a complete $$m$$-width window cannot be obtained. To prevent data loss, progressively wider/narrower windows are used at both ends of the data series.

Other smoothing methods: smooth_loess(), smooth_savitzky(), smooth_triangular(), smooth_whittaker()

N. Frerebeau

## Examples

## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)

## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "") ## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "") ## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "") ## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "") ## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "") ## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "") 