Wavefront method and matlab implementation