Function for fitting a surface with Zernike polynomials
Author: Yiwen Fan (yfan22@ur.rochester.edu)
Institute of Optics, University of Rochester
Usage:
[output_coeff, z_recon_map] = ZernikeLegendreFit(z_map, index_type, coeff_max,
J, K, center_x, center_y)
12/01/2025 Ver 1.2.1 update - Clarify the X, Y coordinate mapping of the input z_map. No functional update
01/20/2025 Ver 1.2 update - Support rectangular input matrices z_map (raw and column number does not have to be equal)
10/26/2024 Ver 1.1 update - Support Fringe Zernike index
Description:
This function fits a given surface to Zernike polynomials, supporting up to hundreds of terms. It returns the coefficients of the fit and the reconstructed map.
Inputs:
z_map - The sag table of the freeform surface. Please note that z_map(1, 1) corresponding to normalized x = -1, y = -1 position: first row corresponding to y = -1 horizontal line (the bottom line in Cartesian coordinate system), first column corresponding to x = -1 vertical line.
index_type - A string presenting the Zernike type. Currently support "2indices" (default) and "fringe".
coeff_max - The highest fitting order.
1) if index_type == "2indices", this should be a 1x2 cell where ~{1} = M, ~{2} = N.
2) if index_tyoe == "fringe", this shoule an integer J.
J - The sampling number on azimuthal direction, default: 2*M+1
K - The sampling number on radial direction, default: 2*(N+1)
center_x, center_y - The center of the freeform surface, default: will be calculated by FindCenter function.
Outputs:
output_coeff - The fitted coefficients,
1) if index_type == "2indices", this should be a 1x2 cell, where ~{1} = amn, ~{2} = bmn.
2) if index_type == "fringe", this should be a 1x1 cell, where ~{1} = cj.
z_recon_map - The reconstructed surface
Acknowledgments:
This work was inspired by the research of Greg Forbes and funded by the National Science Foundation I/UCRC Center for Freeform Optics (IIP-1822026, IIP-1822049).
Part of this work was contributed by Ilhan Kaya in 2010, who wrote the initial jacobiZernike function. This function was later revised by Yiwen Fan and renamed jacobiZernike_table.