# Derivation RMS wavefront error Zernike polynomials

I measured some wavefront aberrations using a Shack-Hartmann sensor. The output is a finite set of Zernike coefficients $$\{c_{ij}\}$$. My wavefront is $$W(\rho, \theta) = \sum_{ij}c_{ij}Z_i^j$$ with $$Z_i^j$$ the Zernike polynomials.

The definition of the RMS error (in the above link, and also in general) is $$\sigma^2 = \int d\theta \int d\rho \rho (W(\rho, \theta) - \bar{W}(\rho, \theta))^2 = \langle W^2 \rangle - \langle W \rangle^2$$ where $$\bar{W} = \langle W \rangle = \int_0^{2\pi} d\theta \int_0^{1} d\rho \rho (W(\rho, \theta)$$

The link then says that this evaluates to $$\sigma^2 = \sum_{ij}|c_{ij}|^2$$

I see that the first term evaluates to that due to orthogonality relations. But I think $$\langle W \rangle \neq 0$$, since $$Z_n^m(\rho, \theta) = R_n^m(\rho, \theta)\cos{(m\theta)}$$ (or for a different $$m$$ with sine instead of cosine) and I know that $$\int_0^{2\pi} cos^2 = \int sin^2 = \pi$$

Where am I wrong?

The perfect wavefront should be flat i.e. $$W_{\text{perfect}}(\rho, \theta) = 0$$. However, your flat wavefront can be tilted and shifted with respect to your measurement plane, which is expressed by the first three Zernike polynomials: $$Z_0^0$$, $$Z_1^{-1}$$, $$Z_1^1$$. For this reason, the authors of the paper you have linked are suggesting that: $$\sigma^2 = \sum_{j=3}C^2_j$$ (notice that summation starts from 3). The "$$\bar{W}$$" in the integral that they've presented stands for "mean wavefront optical path difference" in a given point which accounts for a "displacement" of your wavefront from a flat surface of your aperture/measurement plane. Numerically you could implement $$\bar{W}(\rho, \theta)$$ as a "z" value of a surface fitted to your measured wavefront.
$$\sigma^2 = \int_\text{unit disk} (W(\rho, \theta)-W_{\text{perfect}})^2 \rho \text{d}\rho\text{d}\theta = \int_\text{unit disk} (W(\rho, \theta))^2 \rho \text{d}\rho\text{d}\theta$$.
Please notice here, that I've rescaled the radius of the aperture to 1 as the Zernike polynomials are orthogonal in those boundaries. Your decomposition should take that into account. Also please remember that the Zernike polynomials are not orthonormal, i.e. $$\langle Z_i^j , Z_k^l\rangle = C_{ijkl} \delta_{ik}\delta_{jl}$$, where constant can be different from 1 for different polynomials. This fact should also be included in your decomposition (for details see Wikipedia article). If you used a commercially available device your coefficients are probably correctly processed. If so, they should be prompted with a correct unit, for example $$\mu$$m.
$$\sigma^2 = \int_\text{unit disk} (W(\rho, \theta))^2 \rho \text{d}\rho\text{d}\theta = \langle W, W \rangle = \sum C_j^2$$.