  We consider the generation of samples of a mean-zero Gaussian random field
with Mat\'ern covariance function. Every sample requires the solution of a
differential equation with Gaussian white noise forcing, formulated on a
bounded computational domain. This introduces unwanted boundary effects since
the stochastic partial differential equation is originally posed on the whole
$\mathbb{R}^d$, without boundary conditions. We use a window technique, whereby
one embeds the computational domain into a larger domain, and postulates
convenient boundary conditions on the extended domain. To mitigate the
pollution from the artificial boundary it has been suggested in numerical
studies to choose a window size that is at least as large as the correlation
length of the Mat\'ern field. We provide a rigorous analysis for the error in
the covariance introduced by the window technique, for homogeneous Dirichlet,
homogeneous Neumann, and periodic boundary conditions. We show that the error
decays exponentially in the window size, independently of the type of boundary
condition. We conduct numerical experiments in 1D and 2D space, confirming our
theoretical results.
