# A Phase Correction Model for Fourier Transform Spectroscopy
## 4 All-Pass Filter and PCM-APF Model
### Filter Parameter Optimization Strategy
#### 4.3.4 All-Pass Filter Parameter Optimization Steps  
For an \(N\)th-order all-pass filter, it has \(N\) zeros, and to ensure the stability of the filter, these zeros must lie outside the unit circle. These zeros may be on the real axis or not on the real axis. If they are not on the real axis, it requires two dimensions of a population individual to represent one zero. However, when there is a complex zero, there is always a conjugate zero symmetric about the real axis. Therefore, using two dimensions of a particle can represent a pair of complex zeros. So, for \(N\) zeros, an \(N\)-dimensional vector is needed for representation. If \(N\) is even, the odd dimensions represent the real parts of the zeros, and the even dimensions represent the imaginary parts of the zeros. If \(N\) is odd, then the first \(N-1\) dimensions represent complex zeros, and the last dimension represents a real zero.  
The algorithm steps are as follows:  
Step 1: Calculate residual phase by using Equation (8).  
Step 2: Set the population size \(M\), the dimension \(N\) of the individual in the population (the order of the filter), the allowable error \(e\), and the maximum number of iterations \(n_{max}\)  
Figure 5: Flowchart of GS-SABO, combining SABO and Gold-SA.  
If \(N\) is even, the number of complex zeros \(N_{cc}=N/2\), the number of real zeros \(N_{r}=0\); if \(N\) is odd, the number of complex zeros \(N_{cc}=(N-1)/2\), the number of real zeros \(N_{r}=1\). Set the order \(N_{shift}\) of the delay line in the all-pass filter system. Set the current number of iterations \(t=0\).  
Step 3: Set \(M\times N\) initial values, and use Equation (15) to calculate the chaotic initial individual position.  
Step 4: Construct complex zeros: \(z_{k}=X_{i}(2k-1)+X_{i}(2k)j\), \((k=1,2,...N_{cc})\); \(i=1,2,...M)\); if \(N\) is odd, then there is also a real zero \(x_{i}(N)\). Calculate the magnitude of each zero, and if the magnitude is less than 1 take its reciprocal as the new zero.  
Step 5: Calculate the response function \(Q(z)\) for each individual:  
\[Q(z)=\prod_{i=1}^{N_{r}}\left(z_{i}-z^{-1}\right)\prod_{j=1}^{N_{cc}}\left(z_ {j}-z^{-1}\right)\left(z_{j}^{*}-z^{-1}\right) \tag{18}\]  
Calculate the output phase error by Equations (7), (8), (10), and (11).  
Step 6: Calculate the inverse population of the initial population and repeat steps 4-5 using the inverse population to calculate the error function of each individual in the inverse population. Optimize a new initial population by comparing it with the size of the error function of the individuals in the initial population.  
Step 7: Construct a new complex zero matrix (same as step 4). Record the size of the error function for each individual of the new initial population. Set the best individual position as \(X_{best}\) and the smallest error as \(f_{best}\).  
Step 8: Calculate the new position of each individual in the population by using Equations (12) and (13). Calculate and record the new error function value of each individual based on the new position. And also record \(X_{best}\) and \(f_{best}\).  
Step 9: Use Equation (14) to determine whether to update the individual position by step 8. If yes, skip to step 13.  
Step 10: Calculate the new position of the current individual by using Equation (16).  
Step 11: Similar to step 7, calculate the error and record the new \(X_{best}\) and \(f_{best}\), if possible.  
Step 12: Update the Gold-SA coefficients by referring to the coefficient update method in [16].  
Step 13: Compare \(f_{best}\) with \(e\). If \(f_{best}<e\), skip to step 15.  
Step 14: Let \(t=t+1\). If the value of t reaches the maximum number of iterations \(n_{max}\), skip to step 14; otherwise, skip to step 8.  
Step 15: End the iteration to obtain the optimal calibration results and filter parameter settings.