FWHM minimization
From a series of images, the FWHM of a single star is determined. The focus is then the position of minimal FWHM. Propbaly the easiest method to calculate the FWHM of a star (or a measure close enough to it), is by assuming a Gaussian point-spread-function (PSF):
psf(r)=I0·exp(-r2/2σ2), summing psf(r) as Σ and psf2(r) as ΣΣ over the entire range and simply writing
FWHM=√(2ln(2)/π)·Σ2/ΣΣ
Outliers should be rejected to stabilize the search, an initial focal position can be derived from a temperture-depending model.

f=42.97mm

f=43.05mm

f=43.12mm

f=43.20mm

f=43.35mm

f=43.42mm
Measuring the FWHM is strongly affected by varying seeing conditions, thus a parabola is fitted through the points. Outlier removal is advisable (in the example the measurement with FWHM≈14px, f≈43.25 has to be discarded) . The minimum of the fitting parabola is called the optimal focus.

'Long' focal sequence, taken in robotic mode on WiFSIP, 2011-07-17