ZernikeLegendreFit: Fast, precise, high-capacity fitting
Version 1.2.0 (4.52 KB) by
Yiwen Fan
Rapid and accurate surface fitting via orthogonality and Legendre quadrature, supporting thousands of Zernike terms.
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)
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.
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.
Cite As
Yiwen Fan (2025). ZernikeLegendreFit: Fast, precise, high-capacity fitting (https://se.mathworks.com/matlabcentral/fileexchange/132713-zernikelegendrefit-fast-precise-high-capacity-fitting), MATLAB Central File Exchange. Retrieved .
Fan, Yiwen, et al. “Fast Zernike Fitting of Freeform Surfaces Using the Gauss-Legendre Quadrature.” Optics Express, vol. 32, no. 11, Optica Publishing Group, May 2024, p. 20011, doi:10.1364/oe.523022.
MATLAB Release Compatibility
Created with
R2023a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
