Enhanced Monitoring of Sleep Position in Sleep Apnea Patients: Smartphone Triaxial Accelerometry Compared with Video-Validated Position from Polysomnography

Poor sleep quality is a risk factor for multiple mental, cardiovascular, and cerebrovascular diseases. Certain sleep positions or excessive position changes can be related to some diseases and poor sleep quality. Nevertheless, sleep position is usually classified into four discrete values: supine, prone, left and right. An increase in sleep position resolution is necessary to better assess sleep position dynamics and to interpret more accurately intermediate sleep positions. This research aims to study the feasibility of smartphones as sleep position monitors by (1) developing algorithms to retrieve the sleep position angle from smartphone accelerometry; (2) monitoring the sleep position angle in patients with obstructive sleep apnea (OSA); (3) comparing the discretized sleep angle versus the four classic sleep positions obtained by the video-validated polysomnography (PSG); and (4) analyzing the presence of positional OSA (pOSA) related to its sleep angle of occurrence. Results from 19 OSA patients reveal that a higher resolution sleep position would help to better diagnose and treat patients with position-dependent diseases such as pOSA. They also show that smartphones are promising mHealth tools for enhanced position monitoring at hospitals and home, as they can provide sleep position with higher resolution than the gold-standard video-validated PSG.


Introduction
Poor sleep quality or disturbed sleep is associated with multiple health complications, including mental disorders [1][2][3] and cardiovascular and cerebrovascular diseases [4][5][6]. Obstructive sleep apnea (OSA) is one of the most common diseases affecting sleep quality. It is a condition caused by repeated episodes of upper airway collapse and obstruction during sleep, associated with arousals with or without oxygen desaturation [7][8][9][10]. These episodes can be of total occlusion (apnea) or partial occlusion (hypopnea) of the air pathways, leading to a total or partial reduction of the airflow [11].
Sleep position is an important factor to consider when analyzing sleep quality and diagnosing OSA. Previous studies highlight the role of sleep position in the appearance of apneas, a phenomenon known as positional OSA (pOSA) [12,13]. In addition, the effect of sleep position on the ocular surface has also been assessed and related to the occurrence of different diseases such as dry eye, ocular hypertension, or glaucoma [14][15][16].

Hospital Database and Acquisition Protocol
The acquisition protocol used for all of the experiments in this study was approved by the ethics committee from the Hospital Clínic of Barcelona and conducted with OSA patients. Two different devices were used simultaneously to record the sleep position during night-time acquisitions at the Sleep Lab in the Hospital Clínic of Barcelona. The reference device, a 'Grael PSG' (Compumedics, Melbourne, Australia), recorded the sleep position using the company's proprietary algorithms at a sampling frequency of 32 Hz. The equipment was positioned according to the standard procedure. The second device, a Samsung S5 SM-G900F Android 6.0.1 smartphone (Samsung, Seoul, South Korea), was used as the test device. It recorded triaxial accelerometer data with its embedded MPU-6500 sensor at a sampling frequency of 200 Hz using the Sensors Logger application [53]. This application saves the data in the smartphone memory as a text file. The smartphone was placed over the sternum and held in position with an elastic strap as seen in Figure 1a, based on the configuration proposed by Nakano et al. [35], which has been tested successfully in previous publications of our group [36][37][38]40,41]. This configuration resulted in the smartphone triaxial accelerometry providing positive values when accelerations occurred from right to left (X-axis), from toe to head (Y-axis), and from front to back (Z-axis), as seen in Figure 1b. The smartphone was used in flight mode, and with the Wi-Fi and Bluetooth options disabled.

Hospital Database and Acquisition Protocol
The acquisition protocol used for all of the experiments in this study was approved by the ethics committee from the Hospital Clínic of Barcelona and conducted with OSA patients. Two different devices were used simultaneously to record the sleep position during night-time acquisitions at the Sleep Lab in the Hospital Clínic of Barcelona. The reference device, a 'Grael PSG' (Compumedics, Melbourne, Australia), recorded the sleep position using the company's proprietary algorithms at a sampling frequency of 32 Hz. The equipment was positioned according to the standard procedure. The second device, a Samsung S5 SM-G900F Android 6.0.1 smartphone (Samsung, Seoul, South Korea), was used as the test device. It recorded triaxial accelerometer data with its embedded MPU-6500 sensor at a sampling frequency of 200 Hz using the Sensors Logger application [53]. This application saves the data in the smartphone memory as a text file. The smartphone was placed over the sternum and held in position with an elastic strap as seen in Figure  1a, based on the configuration proposed by Nakano et al. [35], which has been tested successfully in previous publications of our group [36][37][38]40,41]. This configuration resulted in the smartphone triaxial accelerometry providing positive values when accelerations occurred from right to left (X-axis), from toe to head (Y-axis), and from front to back (Z-axis), as seen in Figure 1b. The smartphone was used in flight mode, and with the Wi-Fi and Bluetooth options disabled. including the direction of the accelerometry X axis (red), Y axis (yellow) and Z axis (green) as well as the X-Z plane, where the sleep angle is calculated, and the Y-Z plane, where the stand angle is calculated. Explanation of the rules used to discretize the sleep angle (c) and stand angle (d). The sleep angle was classified into the four sleep positions: supine, prone, left and right. The stand angle into two categories: standing (either stand or headstand) and lying. The stand category also had a second constraint (3).
The acquisition protocol described above was used to register 20 different OSA patients. The inclusion criteria were based upon medical examination of the medical doctors from the sleep lab in the Hospital Clínic of Barcelona. This medical examination aimed to obtain a gender-age-balanced database with patients with different AHI severity indexes. At random, 20 patients were included with mild to severe obstructive sleep apnea diagnosed by a full PSG performed in the previous 2 months. The exclusion criteria were: Patients with hypoventilation, central sleep apnea (Cheyne Stokes), uvulopalatopharyngoplasty, very severe nasal obstruction or in those who refused their consent. For technical reasons, one of the patients had to be discarded. Therefore, the database used for analysis is composed of 9 men and 10 women, with an average age of 60  and an average AHI of 34 . Automatic PSG sleep positions were video-validated by sleep technicians, and automatic and validated positions were both saved separately. The patients Figure 1. Picture of the smartphone and PSG device placement (a) and representation of the smartphone placement (b) including the direction of the accelerometry X axis (red), Y axis (yellow) and Z axis (green) as well as the X-Z plane, where the sleep angle is calculated, and the Y-Z plane, where the stand angle is calculated. Explanation of the rules used to discretize the sleep angle (c) and stand angle (d). The sleep angle was classified into the four sleep positions: supine, prone, left and right. The stand angle into two categories: standing (either stand or headstand) and lying. The stand category also had a second constraint (3).
The acquisition protocol described above was used to register 20 different OSA patients. The inclusion criteria were based upon medical examination of the medical doctors from the sleep lab in the Hospital Clínic of Barcelona. This medical examination aimed to obtain a gender-age-balanced database with patients with different AHI severity indexes. At random, 20 patients were included with mild to severe obstructive sleep apnea diagnosed by a full PSG performed in the previous 2 months. The exclusion criteria were: Patients with hypoventilation, central sleep apnea (Cheyne Stokes), uvulopalatopharyngoplasty, very severe nasal obstruction or in those who refused their consent. For technical reasons, one of the patients had to be discarded. Therefore, the database used for analysis is composed of 9 men and 10 women, with an average age of 60  and an average AHI of 34 . Automatic PSG sleep positions were video-validated by sleep technicians, and automatic and validated positions were both saved separately. The patients were asked to Sensors 2021, 21, 3689 4 of 21 rest in the supine position for some minutes at the beginning of the test. The minimum final valid duration for each patient was five hours of sleep.

Signal Preprocessing
The automatic and video-validated sleep positions obtained from the PSG were exported in .edf file format and the smartphone triaxial accelerometry was stored in .txt files. The three position signals were processed and analyzed using custom developed algorithms in MATLAB r2019b (Mathworks Inc., Natick, MA, USA).
The PSG signals were upsampled to 200 Hz and the signals from the two devices were automatically synchronized with the beginning and end timestamps of each file. Initial and final regions with no overlap between signals were discarded. The first and last 10 min were also removed due to artifacts related to equipment placement and displacement, respectively.

Sleep Position Monitoring: Sleep and Stand Angles
The algorithm described in this subsection aims to retrieve the sleep position angle, which allows us to obtain a more precise sleep position with better control of the position shifts. To calculate the sleep angle from the triaxial accelerometry the following steps were performed:

1.
Each of the triaxial accelerometer signals (X, Y, and Z) was filtered with a median filter with a window of 60 s to remove high-frequency noise and keep the signal baseline containing the gravity acceleration.

2.
For each sample of the triaxial accelerometry, two different angles were calculated using (1): the sleep position angle and the stand angle.
2.1. The sleep position angle was used to determine the four sleep positions (supine, prone, left and right). It was calculated by (1), where → a = (X n , Z n ), with X n and Z n being the values of the X and Z axis of the triaxial accelerometry at each specific timestamp; → b = (1, 0), which is a static reference aligned with the left sleep position; and c = Z n , to be able to differentiate supine and prone positions. This angle explains the orientation of the accelerometry in the X-Z plane as shown in Figure 1b.

2.2.
The stand angle was used to determine whether the patient is in a standing or lying position. It was calculated by (1), where → a = (Y n , Z n ), with Y n and Z n being the values of the Y and Z axis of the triaxial accelerometry at each specific timestamp; → b = (1, 0), which is a static reference aligned with the stand position; and c = Z n , to be able to differentiate stand and headstand positions. This angle explains the orientation of the accelerometry in the Y-Z plane, as shown in Figure 1b

3.
Two different corrections were made to ensure that the angles calculated provided the real patient position: 3.1.
Module correction: to avoid unreal position angle calculations, due to small angle value variations in close-to-zero module vectors, both the sleep and stand angle values were replaced with their last module-correct angle value if the following criteria was found true: where Thld1 is a threshold with a value of 0.5; → a belongs to the → a vectors declared for the sleep and stand angles in the steps 2.1 and 2.2 of this subsection; and → r = (X n , Y n , Z n ), with X n , Y n and Z n being the values of the X, Y and Z axis of the triaxial accelerometry at each specific timestamp.

3.2.
Initial position correction: the supine positions in the first 10 min of the triaxial accelerometer signals were used to automatically self-correct the differences in smartphone placement due to anatomical variations in patients. The correction consisted of detecting the values of the angles associated with the supine positions within these initial 10 min and subtracting these values to correct the sleep and stand angles of the remaining data. Both the initial sleep and stand angles of the corrected position were 90 • after the correction for the supine sleep position.

Discretization of Sleep and Stand Angles
The discretization of the sleep and stand position monitoring angles was performed to compare the positions obtained from the smartphone with the video-validated positions from the PSG system. To classify the angles into the four sleep positions, threshold values of −140 • , −40 • , 60 • and 120 • were used to segment the 360 • circle in the X-Z plane, as described in Figure 1b Figure 1b) and classify the stand angles into two categories: standing (either stand or headstand) and lying. The thresholds used for the discretization of the X-Z and Y-Z planes were empirically set to mimic the criteria used by the sleep technicians to score the sleep position from the PSG video. Since a sleep position could not occur at the same time as a standing position, classification as standing overrides a simultaneously classified sleep position. For this reason, an extra rule was applied to determine the stand position to ensure that it was calculated with a non-close-to-zero vector module in the Y-Z plane. This rule was based on the following equation: where Thld2 and Thld3 equal 0.8; → a XZ is the vector → a described in step 2.1; → a YZ is the vector → a described in step 2.2; and → r is the vector → r described in step 3.1, all of them in the subsection "Sleep Position Monitoring: Sleep and Stand Angles".

Sleep Position Validation: Agreement by Patient
To investigate the agreement between the PSG and the smartphone, and the effect of the discretization (detailed in subsection "Discretization of Sleep and Stand Angles"), the smartphone initial correction (detailed in step 3.2 of the subsection "Sleep Position Monitoring: Sleep and Stand Angles" in this study) and the PSG video correction, we made three different comparisons for each patient: 1.
The automatic smartphone accelerometry position vs. the validated hospital position: this analysis was made to compare the position obtained from the discretized smartphone angles, without the initial position correction, to the hospital video-validated reference position.

2.
The automatic smartphone accelerometry corrected position vs. the validated hospital position: this analysis was made to compare the position obtained from the discretized smartphone angles with the initial position correction to the hospital video-validated reference position.

3.
The automatic hospital position vs. the validated hospital position: this comparison served to understand how the corrections introduced by sleep technicians can improve the automatic sleep position from the PSG system. For each of these pairwise comparisons, the percentage agreement between the two sleep positions was calculated for each patient. The sleep position vectors were compared sample-by-sample with the following equation: where Pos test i is the vector with the position to be tested from the three comparisons; Pos ref i is the reference position vector, which is the hospital video-validated position; and N is the total number of samples.

Sleep Position Validation: Agreement by Position
To validate how accurately each position was detected, we calculated the confusion matrix comparing sample-by-sample the four sleep positions and the stand position between the automatic smartphone accelerometry corrected position (test) and the validated hospital position (reference). The confusion matrix explains how many minutes were correctly and incorrectly classified for each position.
To assess how well each position was detected, we calculated the sensitivity (Se), specificity (Sp), positive predictive value (PPV), negative predictive value (NPV), and accuracy (Acc) from the information in the confusion matrix with the equations below: where TP denotes the minutes in which the position is correctly detected in both the smartphone and PSG devices (e.g., Right PSG & Right Smartphone ); TN the minutes in which the position is correctly not detected in both devices (e.g., not − Right PSG & not − Right Smartphone ); FN the minutes in which the position is incorrectly detected as another position in the test device (e.g., Right PSG & not − Right Smartphone ); and FP the minutes in which the position is incorrectly detected as the specific position in question in the test device (e.g.,

Sleep Position Characterization: Angle Distribution
To understand the interaction between the sleep and stand angles and the discretization limits described in the subsection "Discretization of Sleep and Stand Angles", we used the discretized automatic smartphone corrected position to group each sample of the sleep angle into four categories (supine, prone, left, and right) and the samples of the stand angle, which belonged to the stand position into one category (stand).
For each of these five categories, we calculated the mean angle, the standard deviation (std), and the percentage of time spent by the patient around a window of ±5 • , ±10 • , ±15 • , ±20 • , and ±25 • from the corresponding PSG reference angle. These PSG reference angles were set according to the axis direction of the smartphone accelerometry used in this study. The reference angles were 90 • in the supine position, 0 • in the left position, ±180 • in the right position, and −90 • in the prone position for the sleep angle ( Figure 1c); and 0 • and ±180 • for the stand angle ( Figure 1d). The equation used to calculate the percentage of angles recorded around these windows centered at the reference angle position is as follows: where Win low and Win high are the limits of the reference threshold ± the window value in degrees; N the number of angle samples; and Angle i each of the samples with an angle value.

OSA Events Related to Sleep Position Angle
To address the relevance of the sleep position to the occurrence of OSA events, we used the OSA events from the simultaneous PSG study and assessed their distribution across the different sleep positions in the database.
For each patient, we calculated the percentage of time spent in a specific sleep position angle with the following formula: where %Position θ provides the percentage of time spent in a specific sleep angle θ; N is the number of sleep position samples available; Position i represents each sleep position sample matching the criteria between brackets; and the Angle low θ and Angle high θ are the thresholds used around each sleep angle θ, forming a window of 15 • (θ ± 7.5 • ). The evaluated sleep angles θ ranged from −180 • to 180 • with 1 • increase.
We also calculated the percentage of OSA events in a specific sleep position angle for each patient. To do this, we took each PSG event in the database and assigned to the event the median angle value from all sleep position angle samples which occurred during the event. We then determined the percentage of events occurring at a particular angle with the following formula: where %Event θ is the percentage of events in a specific sleep angle θ; N is the number of events available; Event i represents the median angle linked to an event matching the criteria between brackets; and the Angle low θ and Angle high θ are the thresholds used around each sleep angle θ with the same window and resolution as (11).
Finally, to determine the relationship between the occurrence of the events and the sleep position, two variables were calculated linked to their angle of occurrence: the local AHI and the ratio between the percentage of events and the percentage of position. These variables allowed us to estimate the severity of the OSA and to determine the sleep position angles with a greater incidence of events in comparison to the amount of time spent in that sleep position. The formulas used to calculate these two variables were as follows: Ratio-%Event/%Position θ = %Event θ %Position θ (14) Sensors 2021, 21, 3689 where the Local AHI θ provides an estimation of the AHI in a specific sleep angle θ; N is the number of events available; Event i represents the median angle linked to an event matching the criteria between brackets; Angle low θ and Angle high θ are the thresholds used around this angle with the same window and resolution as (11); the coefficient 1 720,000 is used to normalize the position to hours, taking into account the sampling frequency of the smartphone (200 Hz) and the conversion from seconds to hours (1 h = 3600 s); M is the number of sleep position samples available; Position i represents each sleep position sample matching the criteria between brackets; the Ratio-%Event/%Position θ provides information about the occurrence of events at a specific sleep angle θ; and %Event θ and %Position θ are the results from Equations (11) and (12) for each specific angle θ.
To avoid high-value artifacts due to denominators being close to 0 in both the Local AHI θ and Ratio-%Event/%Position θ variables, a minimum denominator value is used in both equations, which is 10 min for the Local AHI θ and 1% for the Ratio-%Event/%Position θ . Moreover, the Local AHI θ is smoothed with the mean value calculated from the window containing the previous and following two values.

Sleep Position: Angles and Discretization
Two examples of the sleep angle calculated from the smartphone are shown in the polar plots for patients 3 and 14 in Figure 2 and overlaid onto the video-validated hospital position for patient 14 in Figure 3. The smartphone discretized angle from patient 3 ( Figure 2a) shows perfect alignment with the manually video-validated position from the hospital PSG. Moreover, the sleep angle showed multiple subtle position changes which were not observable from the discrete validated hospital position data. Similar alignment is observed in patient 14 (Figure 2b), a complex case with multiple position shifts that were all properly detected. Figure 3a plots the sleep angle and the hospital video-validated position, with close agreement observed between the two. However, the changes detected by the smartphone accelerometry are of greater resolution than those recorded as the video-validated position. The agreement between the automatic discretized smartphone corrected position and the hospital video-validated position can be seen in Figure 3b. Again, the smartphone detected some small stand and supine positions which were not defined in the validated hospital position. Nevertheless, most of the sleep positions were well identified by both devices. Table 1 shows the amount of time, in minutes and as a percentage, that patients spent in each position for the discretized automatic smartphone corrected position and the manually video-validated hospital position. The prone position occurs infrequently, whereas the supine position is the most common (1.9% vs. 53.8% total prevalence). The same pattern is seen in the smartphone corrected position, with a prevalence of 0.8% and 55% for prone and supine positions, respectively. All patients slept for between 5 and 9 h, which is enough time to extract conclusions from the recorded data.       Table 2 shows the percentage of agreement between the three different comparisons made with the validated hospital position (reference) data. The automatic smartphone corrected position presents an average agreement of 95.9% with the reference data, ranging from 67.4% to 100%. Table 2 also shows the effect of the self-correction of the initial position, which increases the average agreement with the reference data by 1.5%. This is of relevance in patient 14, whose agreement varies from 81.6% to 96%. We can also see that the automatic hospital position agrees, on average, only 83.1% of the time with the video-validated hospital position, ranging from 52.5% to 100%, indicating that video validation was needed to properly detect the patients' sleep position.

Sleep Position Performance: Position Overlap
To evaluate the detection of each position and the differences that appeared between them, a confusion matrix was built (Table 3) to compare the automatic smartphone corrected position and the video-validated hospital position. This confusion matrix shows the minutes spent at each position by all patients. Table 3 allows us to determine the interactions within the positions. For instance, it is possible to see that 8155.3 min (almost 136 h) of sleep were used to validate the performance of smartphones as sleep position monitors. It is of note that the diagonal of the table contains the larger values, representing 95.6% of the total minutes. This indicates that the correlation between the smartphone and the PSG is very high. To determine the agreement between positions in greater detail, the Se, Sp, PPV, NPV, and Acc were calculated and are shown as percentages in Table 4. This table illustrates Table 5, with the supine position being the only position having the mean value centered at its reference discrete angle. The mean value is 90.6 • , while the reference supine value is 90 • . The supine position also presents the lowest dispersion (smallest standard deviation). All other sleep positions have mean values that differ from the reference and higher standard deviations. This explains the wider range of different orientations observed for those positions. The stand position has a closer mean value (166.9 • ) to its reference value (180 • ), and its standard deviation is low enough for the positions to be not much dispersed. Figure 4 illustrates how the angles calculated for the sleep position are distributed within a 360° circle. The 5° regions used show how the supine position has a centered distribution, whereas both the left and right, and prone, positions are more dispersed. This pattern is also apparent in Table 5, with the supine position being the only position having the mean value centered at its reference discrete angle. The mean value is 90.6°, while the reference supine value is 90°. The supine position also presents the lowest dispersion (smallest standard deviation). All other sleep positions have mean values that differ from the reference and higher standard deviations. This explains the wider range of different orientations observed for those positions. The stand position has a closer mean value (166.9°) to its reference value (180°), and its standard deviation is low enough for the positions to be not much dispersed.   The mean values and their high variability can also be seen in the percentage of angles found around the different windows for the reference angles each position should have. These values in Table 5 demonstrate how only 27.9% of the right positions, 35.4% of the left positions, and 2.6% of the prone positions were found in a ±25 • window around their reference value, whereas 97.8% of the supine angles and 94.4% of the stand angles were found in the same window.

OSA Events Related to Sleep Position Angle
A total of 4047 events were recorded in the database. The lowest number of events, 47, occurred in subject 4, and the highest number of events, 633, occurred in subject 7. Of the 4047 events, 2439 (60%) occurred in the discrete supine position, 1039 (26%) in the discrete left position and 564 (14%) in the right position. Only five events occurred in the prone position, all in subject 4. Figure 5 shows the distribution of events in the whole database and the sleep position time distribution. In Figure 5a, it can be observed that most of the events occurred in the supine position, even though a lower percentage of the sleep time was spent in that position. Overall, most events and sleep time were spent in the discrete supine and left sleep positions. Of note is the fact that most events occurring in the left discrete position were very close to the threshold value used to differentiate between left and supine discrete positions, whereas the percentage of sleep time is more distributed within the left discrete position. In addition, three examples of different subjects from the database are shown (Figure 5b-d). Subject 1 is a clear case of non-pOSA, since the local AHI does not vary depending on the sleep position. In this case, we can see that the local AHI from the whole night is almost the same as the local AHI for both the supine and right sleep positions, and the local AHI for the left position could be neglected, since less than 2% of the time was spent at that position. Subject 17 is a clear case of pOSA, since the local AHI for the supine sleep position is much higher than the local AHI for the left sleep position. Finally, subject 4 is a non-clear case of pOSA, with differences between the supine position, with a local AHI of 20, and non-supine positions with a local AHI between 5 and 10.    Figure 6 shows the distribution of OSA events and sleep position time as percentages, as well as the two variables used to detect pOSA and OSA severity: the ratio between the percentage of events and the percentage of sleep position time, and the local AHI, both as a function of specific sleep angle. In Figure 6a, showing the percentage of events, we can see that many subjects have most events in the supine position, with the examples of subjects 6,8,9,13,17, and 18 having almost 100% of events in this position. Conversely, there are subjects, such as 11 and 14, that have approximately 60% of events in the left position. Figure 6c shows that there is a higher dispersion of sleep position time compared to the percentage of events. There are subjects, such as 8 and 9, who favor a supine sleep position, but more lateral sleep positions are also apparent. Figure 6d shows the local AHI, allowing us to distinguish the severity variability in the database. There are subjects with very severe OSA, such as 7, 14, and 15, and healthy subjects, such as 11. To complement this, Figure 6b shows the ratio between the percentage of events and the percentage of sleep position time spent as a function of angle. This variable allows us to determine the sleep position angles where the occurrence of events is higher than the percentage of time spent in that sleep position. For some subjects, this ratio is over 2, meaning that the number of events for that sleep position angle is, at least, doubled. Moreover, most of the high values of this ratio appear in the supine position, which agrees with the information in Figure 5a, where we can see more events in the supine position for the whole database than time spent in this position.

Sleep Position: Discrete PSG vs. Discrete Sleep Angle
The aim of our study was to understand and quantify the reliability of retrieving sleep position using a smartphone and compare our results to those achieved with the goldstandard, video-validated PSG. We obtained a high average sleep position classification agreement of 95.9%, shown in Table 2. Although this agreement is true for most patients, two exceptions were patients 4 and 7, with agreement values of 67.4% and 89.4%, respectively. From Table 1, we can see that the difference in position designation for patient 4 was a result of an underestimation of the prone position in favor of the left position, and an underestimation of the supine position in favor of the right position. This mixed scoring happened because the angles associated with these left-prone misclassified positions and to the right-supine misclassified positions were very close to the position decision edge of the PSG. This resulted in the sleep technicians making a binary decision opposite to that of the smartphone. This situation suggests that more precise sleep position technology is desirable, since it would provide additional information to sleep technicians and would allow a more accurate detection of the sleep position. The same reasoning applies to the lower-than-average level of agreement observed in patient 7, whose case also belongs to the right-supine misclassification.
This binary-decision difference between the technicians and the smartphone system described for patients 4 and 7 also contributes to the lower sensitivity calculated for the right and prone positions observed in Tables 3 and 4. Since the total number of minutes for the right position is higher, the impact of this misclassification is attenuated, but the impact on the prone position is very relevant, resulting in a Se value of 38.9%. Since the PSG promotes the supine sleep position [26,27] due to the multiple wires and equipment used for the test, it is likely that pure prone sleep positions do not occur. For this reason, the prone positions assessed in this study were close to the decision edge angle for the lateral positions. This situation produced a situation in which the sleep technicians made an opposite decision to the one that our smartphone system did. Yet, if more pure prone positions had occurred, the sensitivity of the prone position would have been increased and better numbers would have been achieved. This situation reveals the need to monitor sleep position with a higher resolution, as we propose in our study, in order to avoid possible misclassification and to provide the sleep technicians with more objective measures to assess sleep position.
In addition, the results shown in Tables 2 and 4 confirm the excellent results seen in Table 1, where the average agreement value is high. The diagonal of the confusion matrix represents 95.6% of the total minutes assessed, indicating that the detection of the sleep position was reliable. This statement is reinforced by the values from Table 4, where the values of Se, Sp, PPV, NPV, and Acc are very high. Moreover, considering that the prevalence of the prone sleep position is very low in the population [54], the high accuracy found in this study is representative of the general population.
Finally, the small percentage and time differences observed in Tables 2 and 3 for each patient and position can be explained by the sleep position transition differences between the automatic smartphone algorithm and the manual video-validated corrections on the PSG. Since the precision for manual correction is limited to the resolution which the proprietary software of the PSG system allowed, there exists an accumulated error at the exact moment of the position shift. This error accounts for there not being 100% agreement between each of the different comparisons in Table 2, and why some small time values between different positions appear in the confusion matrix (Table 3).
These results indicate that the position obtained from the smartphone accelerometry could be reliably used to monitor sleep position, since the agreement with the videovalidated PSG was excellent.

Enhanced Sleep Position Monitoring
Although sleep position has been shown to be an important factor in sleep quality, few studies aim to evaluate the position distribution beyond the four-position classification used in the PSG [52,55].
The concept of enhanced sleep position monitoring refers to the increase of position resolution provided by the calculation of the sleep and stand angles. It is enhanced because the PSG only gives four discrete position values, and the angles allow us to assess all possible intermediate positions.
In this study, we demonstrated how the discretized positions conceal small position shifts, such as those seen in Figure 2, which can be observed with the sleep angle.
The higher resolution of our smartphone data allowed us to illustrate the variability of the values in both lateral positions ( Figure 4 and Table 5). Therefore, there could be right and left positions close to the supine position, where the risk of apneas occurring is increased in patients with pOSA. Additionally, most of the right and left positions detected in this study were not recorded within a ±25 • window around the reference value for those positions. This pattern is easily seen in Figure 4, where the mean values for the left, right, and prone positions are outside the boundaries of the ±25 • window. This indicates that the four-position classification system used in the PSG might not have a high enough resolution to properly characterize the different sleep positions, which is very important for determining the effect of position in sleep diseases such as OSA [52].
This idea is reinforced when analyzing the distribution of OSA events along the different sleep angles. In Figure 5a, we can observe that approximately 30% of events which happened in the database occurred in the discrete left sleep position, but most of them were very close to the threshold value between left and supine sleep positions. This indicates that the assessment of pOSA could be misleading when only four discrete sleep positions are used, since OSA events occurring at 60 • and at 0 • in the left position are classified as the same. The use of the sleep position angle would be a more robust and powerful measure, allowing the occurrence of events to be linked to a more accurate sleep orientation. The three images in Figure 5 corresponding to subjects 1, 4 and 17 are good examples of how powerful the sleep angle can be to assess pOSA. Images such as these would allow a clinician to directly compare the local AHI to the sleep position angle of occurrence. For instance, subject 1 is a clear case of a non-pOSA patient, since the local AHI does not vary depending on the sleep position, and the patient slept at least 30% of the time in a non-supine position (around 130 min from Table 1). Subject 17 is a clear case of a pOSA patient, since the variation of the local AHI is significant when comparing the supine position to the lateral positions. This subject would be classified as severe OSA (AHI > 30) if he slept only in supine position, whereas he would be classified as healthy (AHI < 5) if he slept only in the left or right positions. According to Table 1, this subject slept for approximately 140 min in non-supine positions, which is sufficient time to assess this differential behavior to determine pOSA. Finally, subject 4 is an example of a patient in whom the assessment of pOSA would be challenging. The subject exhibits different behavior in the supine position compared to the lateral and prone positions. Nevertheless, there are sleep orientations at approximately −40 • in which no events occurred, and other orientations, such as −70 • or 30 • , in which many events occurred. Although the overall AHI for this patient was 5.62, we can see that the local AHI in the supine position would be approximately 15. In this case, the increased sleep position resolution provided by the sleep angle would allow a clinician to perform a better assessment of the severity of the patient.
In Figure 6, we complemented the local AHI information for each patient (Figure 6c) with the ratio between the percentage of events (Figure 6a) and percentage of sleep position time (Figure 6c). This ratio (Figure 6b) provides the information of the occurrence of events related to a specific sleep angle. This variable does not consider the severity of the illness, as the AHI does, but helps to better understand the increased or decreased occurrence of events related to a specific sleep angle. Ratio values below 1 indicate that fewer events occur compared to the time spent at that specific sleep position angle, whereas ratio values over 1 indicate the opposite. In Figure 6b it is possible to see that many subjects have ratio values over 2, indicating that the occurrence of events in this position is more than doubled. We can observe in subject 3, for example, that the ratio increases when going closer to the supine position. This behavior can only be seen with the increase of resolution provided by the sleep angle. The more detailed information allows us to observe that subject 3 would not have the same amount of events when sleeping in the right position with an angle of 180 • , scoring a ratio value between 0 and 1, or close to 120 • , which is the threshold between supine and right position, which scores a ratio value between 1.5 and 2. The increase of resolution proposed in this article, with the use of the sleep angle, would help clinicians to decide which treatment strategies would be most suitable for each patient, since it would allow more accurate determination of the severity of the OSA, as well as deeper insights into the effect of sleep position.

Smartphone Sleep Monitors: Portable mHealth Tools
In recent years, there have been multiple attempts to develop mHealth tools to monitor sleep-related breathing disorders. These attempts aim to reduce the number of sensors used in the PSG to provide similar information related to sleep quality. Some authors have proposed determining sleep quality by analyzing only the pulse oximetry [47,48]. These approaches obtained very good results, but lacked the ability to determine the breathing pattern, which is an important factor for differentiating between apneas and hypopneas [11]. To improve this situation, other studies tried to use only audio, or audio combined with a pulse oximeter to determine the breathing pattern [35,38,46]. In parallel, accelerometry has also played an important role in the mHealth field. Actigraphy has been used to monitor sleep stages and sleep quality [39,44,45], but other authors have used it to monitor respiration [41,[56][57][58][59]. In our study, to determine the sleep position and calculate the sleep and stand angles we decided to use a smartphone, placed over the sternum with an elastic band, to acquire triaxial accelerometry.
The use of smartphones attached to the chest may discourage subjects from adopting a prone sleep position, due to their physical presence. Nevertheless, population studies show that the prone position has a small prevalence (7.3%) within the different sleep positions [54], so we would not expect the smartphone to have a large effect on the sleep position choice. Despite this, in previous studies with the same smartphone system we observed patients who slept a considerable amount of time in the prone position [41], and it is very likely that the reason for not sleeping in prone-like positions is the use of the PSG system [26,27], which has a lot of wires and promotes supine-like sleep positions. The size and weight of today's smartphones are, at worst, similar to those of several pieces of commercial OSA monitoring equipment, and they are the same size and weight as the PSG equipment. As can be seen from Figure 1a, the smartphone used in our system, which measures 142 × 72.5 × 8.1 mm, is of similar size and characteristics to the PSG system used, and is smaller and lighter than multiple home sleep apnea monitors. We chose smartphones as they are available worldwide and contain many embedded sensors that are useful for this kind of analysis. Moreover, they already have multiple tools which make it possible to easily develop applications, which is very favorable for designing and implementing new technologies and algorithms. We are aware that there are some potential risks to using smartphones placed over the chest, including emissions and the heat which can be generated. For this reason, we used the smartphone in airplane mode and with Wi-Fi and Bluetooth deactivated, to reduce the emissions and heat generated, and to avoid any harm to the patient. None of the patients reported any issues related to these risks and reported a better comfort than when using the PSG. The elastic band used for this study allowed good sleep comfort and was tight enough to prevent any smartphone shift during the night, ensuring that the sleep position detection was not biased. Additionally, with the configuration used in this study, we consider that there would be no further risk beyond that entailed by the PSG system or any portable sleep apnea device.
In this study, we proposed an approach for using smartphones to reliably monitor sleep position. The results we obtained demonstrate that the performance of smartphones in detecting sleep position is, at a minimum, equivalent to the current gold-standard PSG. Moreover, we establish that smartphones are able to provide the sleep position with a higher resolution than the current PSG position evaluation.
Also of note is the fact that the algorithms proposed in this study incorporate the ability to self-calibrate the initial position. This is important because of the variation in patient anatomies.
In the future, smartphones could have the potential to precisely monitor sleep position while, at the same time, providing diagnosis for OSA [38,41,52]. Furthermore, they could even incorporate the ability to verify or apply positional therapy for several days, similar to what other devices already do [60,61]. Monitoring a patient's sleep position for multiple days would allow the effect of any treatment to be assessed, and modified if necessary, in a timely manner.

Conclusions
Assessment of sleep position is an important step in polysomnographic (PSG) studies, since there is evidence that certain sleep positions or excessive position changes influence sleep quality. Nevertheless, sleep position is usually classified as one of only four different values: supine, prone, left, and right. In this study, we demonstrated how smartphones could be used as sleep monitoring devices. We calculated two different angles, which allowed us to determine the four sleep positions and the stand position with a higher resolution when compared to the PSG test. To validate the positions found with the smartphone, we performed simultaneous PSG-smartphone acquisitions in 19 patients. We then discretized the information from the smartphone angles into the four sleep positions to compare them with the manually video-validated positions from the PSG. We obtained a high average agreement (95.6%) in the detection of the positions and showed the dispersion of positions adopted by subjects for the non-supine sleep positions. In addition, we observed that the occurrence of OSA events in the lateral sleep positions varied depending on the distance of the sleep position from the supine position threshold. This highlights the fact that a higher resolution of sleep position is required to better assess pOSA.
The novel results presented in this study suggest that smartphones are promising mHealth tools for enhanced position monitoring at hospitals and at home.

Patents
The algorithms explained in this manuscript are under a process to recognize the industrial property.

Informed Consent Statement:
Informed consent was obtained from all subjects involved in the study and written informed consent has been obtained from the patients to publish this paper.

Acknowledgments:
We thank the patients who accepted to participate in this study as well as all the technicians from the Hospial Clínic who helped us in the management to acquire this database.

Conflicts of Interest:
The authors declare no conflict of interest.