Most automatic focusing methods are based on a sharpness function, which delivers a real-valued estimate of an image quality. In this paper, we study an L 2-norm derivative-based sharpness function, which has been used before based on heuristic consideration. We give a more solid mathematical foundation for this function and get a better insight into its analytical properties. Moreover an efficient autofocus method is presented, in which an artificial blur variable plays an important role. We show that for a specific choice of the artificial blur control variable, the function is approximately a quadratic polynomial, which implies that after the recording of at least three images one can find the approximate position of the optimal defocus. This provides the speed improvement in comparison with existing approaches, which usually require recording of more than ten images for autofocus. The new autofocus method is employed for the scanning transmission electron microscopy. To be more specific, it has been implemented in the FEI scanning transmission electron microscope and its performance has been tested as a part of a particle analysis application.