In order to improve the analytical accuracy and applicability of infrared gas sensors, this paper examines the need to integrate a pressure compensation algorithm into the infrared gas analyzer, identifying appropriate compensation methods and optimizing test data accuracy. First, a test platform was constructed to evaluate the accuracy of three types of infrared sensors for trace gases in industrial environments. The sensors were tested in the following order: CO2 at concentrations of 0.5%-4.5%; CH4 at concentrations of 2%-18%; and CO at 100-900ppm standard gas concentrations, found that the maximum value of the test error were 48%, 44.5%, 45%, respectively, do not meet the error range specified in the standard. Secondly, the constant-pressure accuracy test was carried out by selecting the same concentration of CO2, CH4 and CO standard gases and substituting them into the optimized least squares compensation model, and it was found that the maximum errors of the three gas tests were 16%, 9% and 24%, which were superior to the standard error ranges. Thirdly, the pressure compensation was verified for the three infrared gas analyzers after algorithmic compensation within the pressure compensation device. Based on this, the optimized least squares-wavelet transform soft threshold coupling model were established to integrate the ambient pressure, the test concentration and the standard gas concentration with the optimization model, and it was found that the maximum measurement errors after optimization with the optimized least squares-wavelet transform soft thresholding coupling method were 0.2%, 0.05% and 1%. In summary, this paper develops an error optimization model for various environmental pressure conditions, and provides a theoretical framework for the research and development of infrared gas analyzers and other spectroscopic gas detecting instruments. Additionally, it establishes a technical foundation for constructing in-situ on-line monitoring systems for trace gases in industrial environments.