Box averaging filter (source code)

= Box averaging filter
{title2=$G_\Delta(r)=\Delta^{-1}\mathbf1_{\{|r|\leq\Delta/2\}}$}

A <box averaging filter> gives equal weight to all positions within a specified window and zero weight outside it. In one spatial dimension, its normalized kernel and action are
$$
G_\Delta(r)=\frac1\Delta\mathbf1_{\{|r|\leq\Delta/2\}},\qquad
\bar f(x)=\frac1\Delta\int_{x-\Delta/2}^{x+\Delta/2}f(y)\,dy.
$$
This is a <spatial averaging filter> expressed as a <convolution>. In several dimensions, averaging over an axis-aligned rectangular box uses the product of the one-dimensional kernels.

The discrete counterpart averages a fixed number of samples. On an infinite sequence that is zero except for value ten at index zero, a centred five-sample box average produces value two at indices $-2,-1,0,1,2$ and zero elsewhere. The total remains ten, while the isolated peak spreads. On a finite array, boundary extension must be specified; reflection, zero padding and wrapping can give different edge values.<uniform_filter1d in the SciPy documentation>[Parameters size, mode and origin: window length, boundary extension and centring]{ref}

Applying the same box average twice is not the same operation as applying it once. The new kernel is the <convolution> of the two kernels:
$$
(G_\Delta*G_\Delta)(r)=\frac{\max(\Delta-|r|,0)}{\Delta^2}.
$$
Indeed, the integral counts the length of overlap of two intervals, divided by $\Delta^2$. The resulting support has width $2\Delta$, and the weight decreases away from its centre.

For a <Fourier mode> $\cos(kx)$, one application multiplies the amplitude by $\sin(k\Delta/2)/(k\Delta/2)$; two applications square this multiplier. The <sinc function> response explains why a box average smooths a signal without implementing an ideal sharp frequency cutoff. In <large eddy simulation>, that distinction matters when relating a <grid filter> to a coarser <test filter>.