In recent years, effective recognition and accurate assessment of psychological stress have been the focus of research. Because of the objectivity and authenticity of physiological signals, psychological stress recognition from physiological signals has become an important research content in the field of psychological stress recognition. As an important physiological signal, electrocardiogram has been proved to contain reliable physiological response to psychological stress. This paper designs a psychological stress analysis algorithm based on particle swarm optimization (PSO). The wavelet transform algorithm was used to filter and detect the ECG signal. RR interval was calculated from the detected R wave to obtain the ECG signal. An improved particle swarm optimization (PSO) algorithm was proposed, which introduced a particle swarm optimization model with contraction factor to eliminate the speed limit and realize the detection of psychological stress. Experimental results show that the recognition rate of the improved particle swarm optimization algorithm is significantly higher than that of the traditional method, which shows the effectiveness of the algorithm. On the one hand, the research of this paper has optimized the algorithm, which has theoretical significance; on the other hand, it can provide reference for the real psychological stress test, which has practical significance.