This 2-d spatial kernel smoother applies a kernel smoother to a spatial field (see Hastie and Tibshirani, 1990 sec. 2.6; Ritter and Wilson, 2001, chapter 8; Barrett and Myers, 2004 for details about this type of convolution smoothing). Specifically, if X is a matrix of grid points, then the returned field, denoted by Ebert (2008) as <X>s, is a smoothed field such that the value at each grid point <X>s[i,j] is given by: <X>s[i,j] = sum_k sum_l X[i + k - 1, j + l - 1]*K[i, j], where k,l = 1, ..., n, and K[i, j] is the kernel matrix. In order to be fast, loops are avoided. Instead, the convolution theorem is applied with a Fast Fourier Transform (FFT). If the weights 'W' are supplied, then you will save one FFT in computation time.
The convolution theorem says that the Fourier transform of a convolution between two functions f and g is equal to the product of the Fourier transformed functions. That is, if F denotes the Fourier transform, and * the convolution operator, F( f*g ) = k F(f)F(g), where 'k' is a scaling factor. The neighborhood smooth is given by a convolution between the field and a boxcar kernel (i.e., a square around a point with constant value 1/n^2). Because of the FFT, this enables a fast way to compute this convolution.
In order to zero-pad the field, and perform a cyclic convolution, it is necessary to expand the field, 'x', and re-arrange the kernel (or else it will not be centered on the points). If zero padding is not desired, then a field that has been extrapolated to an appropriate size in another way should be used, and a subset going back to the original size could be used. Alternatively, a subset of an appropriate size could be taken from the resulting smoothed field in order to avoid edge effects. The latter is probably a wise move. The image is expanded to the nearest power of two above the dimension of N=x + dimension of K - 1 in each direction, if N <= 1024, and N is rounded up to the nearest multiple of 512 otherwise. This is to ensure that the FFT is fast.
In order to get the neighborhood type of smoothing of Roberts and Lean (2008) and Ebert (2008), use the boxcar kernel with the argument n giving the neighborhood length. The resulting kernel is n by n with elements 1/n^2 at each point. The result is that each grid point of the returned field is an average of the n^2 nearest neighbors. Alternatively, one might prefer to use a disk kernel, which takes the radius, r, as an argument. This gives a similar type of kernel, but ensures an average over a uniform distance from the center point. The disk kernel is also that which is used in the smoothing step of Davis et al (2006a,2006b). See the help file for kernel2dmeitsjer for other smoothing options.