# Optimized Detection Algorithm for Vertical Irregularities in Vertical Curve Segments
## 4 Optimization of Detection Algorithms for Vertical Curve Segments
### Reference Cancellation Method  
The acceleration integration method establishes a unified inertial reference framework to calculate track irregularities, reflecting the characteristics of track alignment variations within inertial space. As indicated by the above analysis, this reference framework impacts the detection accuracy of long-wavelength vertical irregularities in vertical curve segments along the longitudinal profile. To address this, we propose a reference cancellation method that removes track alignment components from the acceleration integration results, preserving only the track irregularity information. High-pass filtering is then applied to enhance the detection accuracy of long-wavelength vertical irregularities in vertical curve segments. The pitch angle  
The core of the reference cancellation method lies in obtaining an ideal pitch angle dataset that accurately represents the track alignment, thereby minimizing its impact on detection accuracy. The spatial curve of the ideal pitch angle is a horizontal line on level and straight gradient sections, and a line with a constant, non-zero slope in vertical curve segments. The measured pitch angle comprises a low-frequency component induced by the track alignment (the ideal pitch angle) and high-frequency disturbances caused by track irregularities. To eliminate high-frequency interference from track irregularities, a low-frequency-response inclinometer is employed to measure the pitch angle of the detection beam. The measured results are processed using mean filtering, which approximates the filtered output \(\hat{y}_{\text{b}}\) as the angle between the track and the ground reference line. The mean filtering process can be represented as follows:  
\[\hat{y}_{\text{b}}(i)=\frac{1}{2N+1}(\psi_{\text{b}}(i-N)+\dots+\psi_{\text{b} }(i+N)) \tag{9}\]  
Figure 10 presents a comparison of the spatial curves for the actual and ideal pitch angles, where the difference lies in the presence or absence of track irregularities. In the figure, the sections from 1000-1200 m, 1900-2300 m, and 3000-3200 m represent vertical curves, while 1200-1900 m and 2300-3000 m are straight gradient segments, with the remaining sections being level track. After smoothing, the actual pitch angle closely approximates the ideal pitch angle, providing an intuitive representation of the track's alignment in the longitudinal profile. Although the smoothed results exhibit a high degree of smoothness, some undulations caused by long-wavelength irregularities remain, creating minor deviations from the ideal pitch angle spatial curve. To achieve a close approximation of the smoothed pitch angle to the ideal pitch angle and further reduce the impact of track irregularities on the reference cancellation method, a piecewise linear fitting approach is employed for the smoothed pitch angle. This method substitutes the smoothed pitch angle with linear segments, enhancing algorithm precision. The core of this approach lies in accurately identifying segmentation points that reflect changes in track alignment, allowing linear segments to replace the smoothed curves. Figure 9: Amplitude–frequency characteristics of H (s). Figure 10 indicates that the longitudinal profile alignment changes significantly at segmentation points. Therefore, a threshold is established. A segment of data approximately 50 m in length is then selected for linear fitting, starting from a horizontal line. Subsequently, the distances from new data points to the fitted line are iteratively calculated. If three consecutive new data points exceed the specified threshold distance from the line, the second point is marked as a track alignment segmentation point. Upon completing the identification of all segmentation points, orthogonal least squares (OLS) linear fitting is performed for each segment to approximate the ideal pitch angle. It is important to note that the established threshold is related to the magnitude of the track gradient. The steps for the OLS linear fitting process are as follows [30]:  
1.