How this calculation works
Fit real normalized Zernike modes to positively weighted scalar samples inside the unit disk using rank-checked least squares.
Z_n^m=N_nm R_n^|m|(r) cos(mθ) for m≥0, and N_nm R_n^|m|(r) sin(|m|θ) for m<0; N_n0=sqrt(n+1), N_nm=sqrt(2(n+1)) otherwise. Minimize Σw_i(Σc_j Z_j(x_i,y_i)-v_i)².A worked example
The default samples follow v=1+2x-y. Through radial order one, coefficients in (n,m) order (0,0),(1,-1),(1,1) are 1,-0.5,1 and the weighted residual RMS is zero up to rounding.
Good to know
Radial order0–6, real OSA-sign sine/cosine modes with explicit orthonormal-on-unit-disk normalization, 3–200 weighted (x,y,value) samples inside unit disk and at least as many independent samples as modes. Scaled QR fit and rank rejection; no Noll-index ambiguity, masked-annulus orthogonality claim, clinical optical diagnosis or regularization.
Reference: pyzernike definitions and conventions (opens in a new tab) ↗
Place samples in the unit disk
Each row contains x, y, observed value and a strictly positive weight. Coordinates must satisfy x²+y²≤1. The origin is the center of the modeled aperture and the radius is one, so physical coordinates must be centered and scaled before entry. An off-center or wrongly scaled aperture changes the fitted functions rather than merely changing the axis labels.
Weights describe relative importance in the least-squares objective. Multiplying every weight by the same positive constant leaves the fitted coefficients unchanged, although an unnormalized residual sum scales. The page does not infer weights from sample density, measurement uncertainty or sensor geometry. If a dense patch is meant to represent a small physical area, suitable area weights must be provided deliberately.
Compare this with the Real spherical harmonic expansion calculator from weighted samples. Existing spherical-harmonic fitter operates on directions on a sphere using associated Legendre functions. Fit a planar disk field in radial/azimuthal Zernike modes, returning optical mode coefficients and reconstructed disk samples in a fully declared normalization.
Make the mode convention explicit
Radial order n is nonnegative, the azimuthal index m ranges from minus n to n, and n minus the absolute value of m is even. Negative m denotes the positive sine of |m| times the polar angle, while nonnegative m denotes cosine. Different software packages exchange signs, sine labels or mode ordering, so coefficient tables are comparable only after these choices agree.
The normalization used here makes the modes orthonormal with respect to disk area divided by π. Piston is one, horizontal tilt is 2x and vertical tilt is 2y. The unnormalized area integral of each squared mode is therefore π. This explicit measure convention prevents confusion with an alternative normalization whose squared integral is one over ordinary disk area and whose coefficients differ by a factor of sqrt(π).
Build a weighted linear fit
For every sample, evaluate all modes through the requested radial order and place them in a design-matrix row. Multiply that row and its observed value by the square root of the sample weight. The resulting ordinary least-squares problem is solved through scaled QR rather than forming normal equations, which would square the condition number and amplify numerical sensitivity.
The number of samples must be at least the number of modes, but that count alone does not ensure a unique fit. Sample geometry can make columns dependent; for example, points on a single line can fail to identify some azimuthal modes. A rank check is essential. The page rejects an underdetermined or numerically rank-deficient fit rather than returning arbitrary coefficients disguised as a uniquely identified surface.
Verify the default tilted plane
The five default observations lie at the origin and halfway along each coordinate axis. Their values are generated by the plane 1+2x-y. Through radial order one, the basis functions in the stated ordering are 1, 2y and 2x. Thus the coefficient vector is exactly (1,-1/2,1), reproducing every sample without using a higher-order mode.
At (0.5,0), the fitted value is two; at (-0.5,0), it is zero. At (0,0.5), it is one half, and at (0,-0.5), it is one and one half. The origin supplies the piston value one. These five direct substitutions check the sign convention and normalization, which a residual-only check could miss if both the fitter and the displayed basis used the same wrong convention.
Interpret coefficients and residuals
A coefficient is the amplitude of a particular normalized basis function under the selected convention. Its physical units are the same as the sample values. A fitted coefficient does not become a uniquely diagnosed physical aberration merely because it has a familiar optical mode name. The model describes the entered scalar data and its chosen coordinate system.
The weighted RMS is the square root of the weighted squared residual sum divided by the sum of weights. A small residual indicates agreement at the observations, not independent predictive accuracy between them. Increasing radial order usually reduces training residuals while potentially amplifying noise or poorly supported boundary behavior. Compare rank, conditioning and sampling coverage alongside the residual before deciding that additional modes improve the model.
Read the disk and coefficient illustration
The unit-disk picture shows how a selected mode changes sign and magnitude across the aperture. Sample markers indicate where information enters the fit, while coefficient bars describe the algebraic expansion. A region with no observations is still assigned a value by the fitted polynomial, but that assignment is extrapolation within the chosen basis rather than new measurement evidence.
Continuous orthogonality on the complete disk does not imply discrete orthogonality at arbitrary sample points. It also does not imply orthogonality on a masked pupil or annulus. Such sampling patterns can yield correlated fitted coefficients even though the underlying full-disk modes are analytically orthogonal. The QR solve handles the discrete design matrix, but it does not turn a partial aperture into a full-disk observation.
Respect fitting limits and application scope
Maximum radial order six gives twenty-eight modes, and the page accepts three through two hundred samples. High order requires enough independent spatial information, not merely many repeated observations at the same position. Strictly positive weights avoid silently excluded rows; remove unwanted observations explicitly so that the effective data set is visible. No regularization is added behind the scenes.
Use the fit for mathematical surface representation, numerical experiments and convention-aware coefficient comparisons. It does not make clinical optical diagnoses or infer the correct aperture geometry from the samples. Save coordinate scaling, mode ordering, normalization and weights with the coefficient vector. Without those details, another program can produce a different-looking coefficient table for the same fitted surface even when both numerical solutions are internally correct.
A few questions, answered
What normalization is used?
Modes have mean squared value one over the unit disk, equivalently squared area integral π.
Are negative m modes negative sine?
No. Negative m uses +sin(|m|θ) under the stated OSA sign convention.
Are enough sample rows sufficient?
No. Their design matrix must also have full numerical column rank.
Can weights be zero?
No. Remove excluded observations explicitly; retained weights must be positive.