# Real-Time Psychological Stress Detection According to ECG Using Deep Learning
## 2 Materials and Methods  
### Experiments and Data Acquisition  
To acquire ECG signal acquisition, storage, management, and real-time analysis, we built an emotional stress-monitoring platform that contained server and front-ends. After receiving the ECG data through the 4G net, the server could analyze and then send the results back to the front-end in a timely manner. We designed the server based on Flask and used MongoDB [14] for the database, Nginx [15] for a reverse proxy, and Gunicorn [16] for concurrent processing. The software supervisor was also used to monitor the programs of the main program and the database so the system could automatically restart for continuous running when stopped for any bugs. The structure of the server is shown in Figure 1.  
The front end consists of sticky devices and mobile apps. The sticky devices we used were created by our lab using the chip ADS1292 for ECG signal collection and CC2640 for data transmission as shown in Figure 2. Compared to other devices, the two-electrode structure makes the device more comfortable to wear due to small volume and a light weight. When using the sticky device was placed horizontally on the center of the chest in the fourth rib or fifth rib area. The ECG sampled at 250 Hz would be transmitted to the mobile app via Bluetooth 4.0, and finally. The server would receive the data through the 4G net. Common methods for stress inducement include color word experiments, ice water simulation, public speaking mathematical calculations, and watching horror videos. In view of the experimental feasibility and controllability of the induced degree, we chose the Montreal stress model with calculations as the main method [17]. The Montreal Imaging Stress Model was originally designed by psychologists to assess psychological stress, and it contains three processes--rest, moderate stress, and high stress inducing. The experimental procedures were developed by the group from the Institute of Psychology, Chinese Academy of Sciences. It contained three periods which last as long as 15 min, the first five minutes are a rest phase, and then a light stress phase, and heavy stress phase alternately arranged. The detailed process is shown in Figure 3. The VAS (visual analogue scale) report [18] of psychological stress was gathered from the subjects every 30 seconds as the ground truth for labeling the data. Figure 1: The server based on Flask for data collecting and processing with Nginx, Gunicorn MongoDB and Supervisor technology. Figure 2: Front and back surface of the sticky device. None of the computing tasks were scheduled during the rest period. At that time, we played melodious music and humorous moving pictures to the subjects to make them as relaxed as possible. This design could simulate the none-stress situations that the subjects encountered in daily life. During the moderate stress phase, we improved the Montreal stress model by incorporating more evoking factors. Among these, we made the background color gray to give the participants a psychological hint of negativity. The subjects were asked to participate in simple double-digit addition and subtraction. The formula contained four variables, each variable ranged from a negative 20 to 20, the operators (\(-\), \(+\), \(-\)) are fixed. To cause moderate stress in the participant, below the formula was a result prompt, a correct rate and a 5 s time bar that implies sufficient time. If the time ran out and the subject still has not answered, the system would judge the answer wrong and let the timing bar recount. This design simulated the moderate-stress situations encountered by the subjects when working or studying. Therefore, it is easy to finish the tasks with moderate difficulty and the time required is sufficient.