## 3 Experiment Setup
### HR and RR Extraction
The voluntary motion from the driver or the involuntary motion caused by uneven roads changes the distance between the driver's face and the light source, resulting in intensity artifacts that could corrupt the HR measurements. Because the ToF camera measures both intensity and depth information, the depth information can be used to compensate for the motion-induced artifacts. The depth information obtained from ROI-1, \(D_{raw}\) should contain no heart rate component (heartbeats do not cause depth change detectable by ToF camera), while the raw grayscale information from ROI-1, \(I_{raw}\) contains both the heartbeat induced intensity change as well as the motion-induced intensity change. After the motion artifacts are compensated, the compensated signal \(I_{comp}\) should have minimum correlation with \(D_{raw}\). \(I_{comp}\) is calculated using Equation (1), where a and b are the coefficients. We iterated through a range of a and b to find the minimum correlation between \(D_{raw}\) and \(\frac{I_{raw}}{a*(D_{raw})^{-g}}\). In this study, the range of the nonlinear coefficient is set between 0.2 to 5 while the linear coefficient is set as 1 for all measurements taken in this study. More details on the motion compensation method can be found in [28]. \[I_{comp}=\frac{I_{raw}}{a*(D_{raw})^{-b}};\text{where }a,b=\underset{a,b}{ \text{argmin }}Correlation(\frac{I_{raw}}{a*(D_{raw})^{-b}},D_{raw}) \tag{1}\]  
Figure 3: (**a**) Raw intensity (red) and depth (blue) captured by the ToF camera. Depth change induced by motion (blue rectangle) is inversely proportional to the intensity, which is a key source of erroneous HR reading. (**b**) When motion artifacts are present, they create artifact frequency components that overwhelm the actual HR signal. After the motion artifacts have been compensated for, we then assess the quality of different sections within the 20 s video using both the depth information and Short Time Fourier Transform (STFT). The goal of the quality assessment is to find the sections of videos that either suffer lower interference from motion or contain stronger HR signal. Ideally, for clean HR measurements without artifacts and noise, the measured signal in the frequency domain will contain one peak in the frequency domain (which we select as HR). However, in real-life measurements, various motion artifacts/noise create additional frequency peaks in the frequency domain. Even though we try to compensate for motion-induced artifacts in step 2, some large motion or head rotation cannot be effectively compensated [28]. These large motions can come from the driver turning their head or from driving across potholes on the road. If those types of motion are large enough, the amplitude of artifact frequency peak can be higher than the HR frequency component, creating erroneous results. Therefore, we use the depth information to determine if such artifacts could exist in a particular section of the recorded signal. The quality assessment is implemented with following steps: 1. The 20 s measurements are split into eleven 10 s windows with a 9 s overlap between two consecutive windows. 2. We perform Fourier transform to the 10 s window and find the amplitudes of highest peak (\(A_{1 st}\)) and the second highest peak (\(A_{2 nd}\)) in the frequency domain. 3. We calculate a motion score of this 10 s window using Equation (2), where \"var\" stands for the variance and \"depth\" represent the average depth measured by the ToF camera in ROI-1. 4. The final spectrum is calculated as the weighted average of the spectrum of every window with the inverse of the motion score being the weights (Equation (3)). \(X_{i}\)_(_f_) is the  
Figure 4: Processes to extract HR while driving using depth and grayscale information from a ToF camera. spectral content of each time window and \(n\) is the total number of windows (in this study \(n=11\)).