  Wavefront errors are a common artifact in laser light generation and imaging.
They can be described as an aberration from the spherical wavefront of an ideal
Gaussian beam by combinations of higher-order Hermite- or Laguerre-Gaussian
terms. Here, we present an algorithm called Beamfit to estimate the mode
composition from a series of CCD images taken over the Rayleigh range of a
laser beam. The algorithm uses a user-defined set of Hermite- or
Laguerre-Gaussian modes as the basis of its theoretical model. A novel method
reduces the number of calculations needed to compute the model's intensity
profiles. For a given model containing $N$ modes, the number of
Hermite-Gaussian complex amplitudes needed to calculate are reduced from orders
of $\mathcal{O}(N^2)$ to $\mathcal{O}(N)$ and replaced by simple
multiplications. Additionally, non-beam parameters are pre-calculated to
further reduce the search space dimension and its resulting calculation time.
It is planned to release the Beamfit software to the public under an
open-source license.
