## 3 Filtering Algorithm  
### Gauss Elimination  
An accurate and efficient solution to the approximating spline equation plays an important role in surface topography filtering. However, the solution to the spline function in engineering technology is often obtained by solving linear algebraic equations. As shown in Equation (4), the approximate spline partial differential equation is transformed into a system of linear algebraic equations by means of the difference method and derivation. As shown in Equation (5), \(A\) represents the coefficient matrix of the approximating spline. It can be found that the coefficient matrix of approximating spline filter is a kind of sparse matrix (that is, the number of non-zero elements in the matrix is far less than the total number of matrix elements). \(A\) is consistent with the order of the original data. The principle of the Gauss elimination method is to eliminate the unknown number step-by-step and transform the linear equation system \(Aw=z\) into an equivalent triangular linear equation system. In order to save the computer storage capacity, three one-dimensional arrays that are denoted as \(a\), \(b\), and \(c\) were used in this work to store five diagonal elements of matrix \(A\) in MATLAB as shown in Equation (6). \(A\) is transformed into an upper triangular matrix by row transformation; namely, the second row represents a product of the difference between the second and first rows and \(b_{1}/a_{1}\) and the first-column element in the second row becomes zero. The third row represents a product of the difference between the third and first rows and \(c_{1}/a_{1}\), and the first-column element of the third row becomes zero. The same operation is performed on all matrix rows, and the same operation is performed on all rows:  
Figure 5: The deviation of amplitude-frequency characteristics between Gaussian filter and cascade approximating spline filter (\(n=2\)). \[A_{1,1}w_{1}+A_{1,2}w_{2}+\cdots\cdots+A_{1,n}w_{n}=z\] \[A_{2,1}w_{1}+A_{2,2}w_{2}+\cdots\cdots+A_{2,n}w_{n}=z\] \[\vdots w=\left[ \begin{array}{c}w_{1}\\ w_{2}\\ w_{3}\\ \vdots\\ w_{n-1}\\ w_{n}\end{array} \right],z=\left[ \begin{array}{c}z_{1}\\ z_{2}\\ z_{3}\\ \vdots\\ z_{n-1}\\ z_{n}\end{array} \right], \tag{4}\] \[A=\left[ \begin{array}{ccccc}1+\mu+\sqrt{\mu}&-2\mu-\sqrt{\mu}& \mu\\ -2\mu-\sqrt{\mu}&1+5\mu+2\sqrt{\mu}&-4\mu-\sqrt{\mu}&\mu\\ \mu&-4\mu-\sqrt{\mu}&1+6\mu+2\sqrt{\mu}&-4\mu-\sqrt{\mu}&\mu\\ &\ddots&\ddots&\ddots&\ddots\\ &&\mu&-4\mu-\sqrt{\mu}&1+6\mu+2\sqrt{\mu}&-4\mu-\sqrt{\mu}&\mu\\ &&&&\mu&-4\mu-\sqrt{\mu}&1+5\mu+2\sqrt{\mu}&-2\mu-\sqrt{\mu}\\ &&&&\mu&-2\mu-\sqrt{\mu}&1+\mu+\sqrt{\mu}\end{array} \right], \tag{5}\]  
\[A=\left[ \begin{array}{ccccccccc}a_{1}&b_{1}&c_{1}&&&&\\ b_{1}&a_{2}&b_{2}&c_{2}&&&&\\ c_{1}&b_{2}&a_{3}&b_{3}&c_{3}&&&\\ &\ddots&\ddots&\ddots&\ddots&\ddots&&\\ &&c_{n-4}&b_{n-3}&a_{n-2}&b_{n-2}&c_{n-2}\\ &&&c_{n-3}&b_{n-2}&a_{n-1}&b_{n-1}\\ &&&&c_{n-2}&b_{n-1}&a_{n}\end{array} \right], \tag{6}\]  
In short, the Gauss order elimination method is used to transform the pentadiagonal matrix \(A\) into an upper triangular matrix as shown in Equation (7). The last waviness \(w_{n}\) is solved, and then the remaining waviness is obtained by back substitution. As shown in Figure 6, Gaussian elimination method includes two steps which are elimination and back substitution. This work estimates the calculation times of the two steps. The elimination of lower triangle elements \(b_{i}\) requires one division, two multiplications, and two subtractions for each element. For \(b_{n-1}\), there are only two elements in the \((n-1)\)th row, so computer repeats it three times to eliminate \(b_{n-1}\). However, when \(c_{i}\) is eliminated, it needs one division, one multiplication, and one subtraction. At the same time, the original data \(z\) participates in the elimination process, but the first element of these data is not included in the elimination process, while the second element is eliminated only once, and each following element starting from the third element is eliminated twice.