相机采集的N步相移图案可以表示为

\begin{equation} \begin{split} I_n &=a+b \cos(\varphi+\Delta\varphi_n)\\ &=a+b\cos\varphi\cos\Delta\varphi_n-b\sin\varphi\sin\Delta\varphi_n \end{split} \end{equation}

bcosφb\cos\varphi记作cc,将bsinφb\sin\varphi记作ss,那么

\begin{equation} I_n=a+c\cos\Delta\varphi_n-s\sin\Delta\varphi_n \end{equation}

我们需要从N个公式(2)中求取未知量a,ca,css,很自然地采用最小二乘法求解,最优化以下偏差:

\begin{equation} \varepsilon=\sum_{n=1}^N \big(I_n-(a+c\cos\Delta\varphi_n-s\sin\Delta\varphi_n)\big)^2 \end{equation}

由偏导εa=0\frac{\partial\varepsilon}{\partial a}=0可得

\begin{equation} \sum_{n=1}^{N}I_n=aN+c\sum_{n=1}^{N}\cos\Delta\varphi_n-s\sum_{n=1}^{N}\sin\Delta\varphi_n \end{equation}

由偏导εc=0\frac{\partial\varepsilon}{\partial c}=0可得

\begin{equation} \sum_{n=1}^{N}I_n\cos\Delta\varphi_n=a\sum_{n=1}^{N}\cos\Delta\varphi_n+c\sum_{n=1}^{N}\cos^2\Delta\varphi_n-s\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n \end{equation}

由偏导εs=0\frac{\partial\varepsilon}{\partial s}=0可得

\begin{equation} \sum_{n=1}^{N}I_n\sin\Delta\varphi_n=a\sum_{n=1}^{N}\sin\Delta\varphi_n+c\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n-s\sum_{n=1}^{N}\sin^2\Delta\varphi_n \end{equation}

综合公式(4),公式(5)和公式(6),整理成矩阵形式,为

\begin{equation} \begin{pmatrix}N&\sum_{n=1}^{N}\cos\Delta\varphi_n&-\sum_{n=1}^{N}\sin\Delta\varphi_n & \\\sum_{n=1}^{N}\cos\Delta\varphi_n & \sum_{n=1}^{N}\cos^2\Delta\varphi_n & -\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n \\ \sum_{n=1}^{N}\sin\Delta\varphi_n & \sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n & -\sum_{n=1}^{N}\sin^2\Delta\varphi_n \end{pmatrix}\begin{pmatrix}a\\c\\s\end{pmatrix}=\begin{pmatrix}\sum_{n=1}^{N}I_n\\\sum_{n=1}^{N}I_n\cos\Delta\varphi_n\\\sum_{n=1}^{N}I_n\sin\Delta\varphi_n\end{pmatrix} \end{equation}

由于n=1NcosΔφn=0\sum_{n=1}^{N}\cos\Delta\varphi_n=0, n=1NsinΔφn=0\sum_{n=1}^{N}\sin\Delta\varphi_n=0,n=1NsinΔφncosΔφn=0\sum_{n=1}^{N}\sin\Delta\varphi_n\cos\Delta\varphi_n=0, n=1Ncos2Δφn=N2\sum_{n=1}^{N}\cos^2\Delta\varphi_n=\frac{N}{2}, n=1Nsin2Δφn=N2\sum_{n=1}^{N}\sin^2\Delta\varphi_n=\frac{N}{2}, 代入公式(7)中可得,

\begin{equation} \begin{pmatrix}N&0&0 \\0&\frac{N}{2}&0 \\ 0&0&-\frac{N}{2}\end{pmatrix}\begin{pmatrix}a \\ c \\ s \end{pmatrix}=\begin{pmatrix}\sum_{n=1}^{N}I_n\\\sum_{n=1}^{N}I_n\cos\Delta\varphi_n\\\sum_{n=1}^{N}I_n\sin\Delta\varphi_n\end{pmatrix} \end{equation}

此时,易得

\begin{equation} \begin{split} a&=\frac1N\sum_{n=1}^{N}I_n\\ c&=\frac2N\sum_{n=1}^{N}I_n\cos\Delta\varphi_n\\ s&=-\frac2N\sum_{n=1}^{N}I_n\sin\Delta\varphi_n \end{split} \end{equation}

由于bcosφ=cb\cos\varphi=c, bsinφ=sb\sin\varphi=s,可得

\begin{equation} \begin{split} \tan\varphi&=-\frac{\sum_{n=1}^{N}I_n\sin\Delta\varphi_n}{\sum_{n=1}^{N}I_n\cos\Delta\varphi_n}\\ b&=\frac2N\sqrt{(\sum_{n=1}^{N}I_n\sin\Delta\varphi_n)^2+(\sum_{n=1}^{N}I_n\cos\Delta\varphi_n)^2} \end{split} \end{equation}

推导完毕。