Analysis of Smartphone Triaxial Accelerometry for Monitoring Sleep-Disordered Breathing and Sleep Position at Home

Obstructive sleep apnea (OSA) is a sleep disorder in which repetitive upper airway obstructive events occur during sleep. These events can induce hypoxia, which is a risk factor for multiple cardiovascular and cerebrovascular diseases. OSA is also known to be position-dependent in some patients, which is referred to as positional OSA (pOSA). Screening for pOSA is necessary in order to design more personalized and effective treatment strategies. In this article, we propose analyzing accelerometry signals, recorded with a smartphone, to detect and monitor OSA at home. Our objectives were to: (1) develop an algorithm for detecting thoracic movement associated with disordered breathing events; (2) compare the performance of smartphones as OSA monitoring tools with a type 3 portable sleep monitor; and (3) explore the feasibility of using smartphone accelerometry to retrieve reliable patient sleep position data and assess pOSA. Accelerometry signals were collected through simultaneous overnight acquisition using both devices with 13 subjects. The smartphone tool showed a high degree of concordance compared to the portable device and succeeded in estimating the apnea-hypopnea index (AHI) and classifying the severity level in most subjects. To assess the agreement between the two systems, an event-by-event comparison was performed, which found a sensitivity of 90% and a positive predictive value of 80%. It was also possible to identify pOSA by determining the ratio of events occurring in a specific position versus the time spent in that position during the night. These novel results suggest that smartphones are promising mHealth tools for OSA and pOSA monitoring at home.


I. INTRODUCTION
Because of its critical role in human health, sleep is one of the most important aspects of daily life. Low-quality or disturbed sleep is associated with multiple health complications, such The associate editor coordinating the review of this manuscript and approving it for publication was Mohammad Zia Ur Rahman . as mental disorders [1]- [3], and is also a known risk factor for other health disorders, including increased cardiovascular and cerebrovascular morbidity and mortality [4]- [6].
Obstructive sleep apnea (OSA) is one of the most common diseases affecting sleep quality. OSA is characterized by the occurrence of obstructive events in which a partial or total occlusion of the upper airway is produced, which results VOLUME 8, 2020 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ in a disordered breathing pattern. This disordered breathing induces the appearance of hypoxic events and microarousals, which are a known risk factor for multiple cardiovascular diseases [7]. One of the major problems with OSA is that most patients remain undiagnosed and untreated [8], [9]. This issue, along with the high prevalence of OSA, which is estimated to affect between 9% and 38% of the overall population [10], makes OSA a substantial public health burden.
The gold-standard technique for diagnosing OSA is nocturnal polysomnography (PSG). PSG tests consist of recording multiple physiological signals while the patient is asleep in a hospital sleep lab. Assessing these physiological signals determines the patient's sleep performance and yields a sleep score index. The most common score index is the apnea/hypopnea index (AHI), which provides information about the number of apneas and hypopneas per hour of sleep. According to the American Academy of Sleep Medicine (AASM), apneas are defined as ≥90% flow reductions for ≥10 seconds [11] and hypopneas are defined as ≥30% flow reductions for ≥10 seconds which are associated with an oxygen desaturation of ≥3% or an arousal [11]. The AHI classifies patients into four different categories: healthy (AHI < 5); mild OSA (5 ≤ AHI < 15); moderate OSA (15 ≤ AHI < 30) and severe OSA (AHI ≥ 30).
However, PSG has some important limitations, such as the high cost of the diagnostic test. This is because PSG tests require a lot of equipment for full-night data acquisition as well as qualified medical staff to analyze the signals and diagnose the patient. Moreover, OSA diagnosis is usually performed with a one-night sleep assessment, which does not account for the variability of sleep performance in the patient. The reproducibility of PSG tests with regard to a patient's regular sleep performance is also low because the patient is not sleeping in his or her regular bed at home, but rather in a hospital sleep lab. The equipment the patient must be connected to in order to collect data, such as masks or electrodes, also reduces sleep comfort. All these limitations affect sleep performance assessment and diagnose of OSA.
There are multiple treatments for OSA [12] with different degrees of clinical impact. The most invasive methods consist of surgery to modify the air pathway and resolve the cause of the obstruction. Less invasive therapies include devices which aim to unblock the air pathways by regulating air pressure, such as continuous positive air pressure (CPAP) machines. The least invasive methods are based on behavioral therapy, including weight control with specific diet strategies and sleep positional therapy. The detection and monitoring of positional OSA (pOSA) provides clinical information which is highly relevant when choosing the best treatment strategy for each patient, since less invasive treatments are preferred.
To address the low diagnosis ratio of OSA and provide solutions to the limitations associated with PSG, new diagnosis and monitoring strategies are being developed. These strategies are usually based on mobile health (mHealth) technologies and aim to develop portable systems that can be used at home. In recent years, some approaches have attempted to assess sleep quality through applications that use questionnaires to assess sleep performance [13], [14] or evaluate and improve treatment adherence [15]. In addition, multiple studies have used actigraphy, a technique based on accelerometry which infers sleep stages and sleep performance by assessing how much a patient moves while sleeping [16]- [18]. Some studies have used accelerometry to estimate respiratory or flow signals [19]- [22], which could be used to assess OSA. Other studies have used audio signals to characterize breathing and snoring and to estimate OSA severity [23]- [26] and some approaches have also explored the use of pulse oximetry to estimate OSA severity [27], [28].
Smartphones have recently been proposed as potentially effective tools in the development of mHealth applications. First, smartphones are globally available, so applications that make use of them can easily reach most of the population. Second, they already include multiple embedded sensors which can be used as diagnostic tools, and additional external sensors can be incorporated to add to their potential. Some studies have already considered using smartphones to detect and monitor sleep apnea [29]- [31], including previous works by our group. These studies make use of multiple combinations of different signals to screen and monitor OSA at home, taking advantage of the multiple alternatives that smartphones provide. Nevertheless, although multiple different mHealth approaches have been proposed to improve the diagnosis and monitoring of sleep apnea at home, still more validation studies are needed to assess the clinical feasibility of this kind of system [32].
In this paper, we propose a smartphone mHealth system based on smartphone accelerometry which can detect and monitor OSA at home. We have tested our system by means of overnight data acquisition sessions using the smartphone's accelerometer to assess respiration and disordered breathing. Accelerometry was also used to obtain sleep position data and assess pOSA. The assessment of pOSA is of particular interest, as most of the mHealth applications being developed today do not provide positional assessment to help clinicians determine the best personalized treatment strategies. The objectives of this paper are: (1) to develop an algorithm for detecting thoracic movement associated with disordered breathing events; (2) to compare the performance of smartphones as OSA monitor tools with the performance of a type 3 portable sleep monitor; and (3) to explore the feasibility of smartphone accelerometry in retrieving reliable patient sleep position data and assessing pOSA.

A. HOME DATABASE ACQUISITION PROTOCOL
The data acquisition protocol and all the experiments were approved by the ethics committee of Hospital Clínic of Barcelona. Two different devices were used simultaneously to record multiple signals during overnight data acquisition. The first device, a Samsung S5 SM-G900F Android 6.0.1 smartphone, was used as the test device. It recorded accelerometric data with its embedded MPU-6500 triaxial accelerometer sensor at a sampling frequency of 200 Hz using the Sensor Logger application. The second device, the Apnealink TM Air from ResMed, was used as the reference device. It recorded thoracic effort with a chest band at a sampling frequency of 10 Hz; pulse oximetry with a wired finger clip at a sampling frequency of 1 Hz; and airflow with a nasal cannula at a sampling frequency of 100 Hz.
The smartphone device was placed over the sternum based on the configuration proposed by Nakano et al. [25], which Siqueira et al. [33] found to be the best location for assessing respiration using triaxial accelerometry when the subject is lying down. The Apnealink device was also placed over the sternum, below the smartphone, based on that described in the Apnealink guidelines. This device placement configuration had already been tested successfully in previous studies by our group [30], [31], [34], [35].
This data acquisition protocol was used to compile the database used in this paper to analyze sleep-disordered breathing and pOSA. The same database was used by Castillo-Escario et al. [30] in a previous study by our group. The database is composed of 13 different subjects, eight men and five women, with an average age of 48 [24]-[83] and an average BMI of 27 [20]- [34], containing three healthy, three mild, four moderate and three severe OSA subjects as detected by the manually reviewed Apnealink events.

B. SIGNAL PREPROCESSING
The smartphone triaxial accelerometry information was stored in.txt files which were loaded into the MATLAB R programming environment (r2019b, Mathworks Inc.) to be processed and analyzed using custom algorithms.
The Apnealink signals were automatically analyzed by their proprietary software to extract information regarding apneas, hypopneas and desaturations (≥3%). These signals were also manually scored and validated by sleep experts from Hospital Clínic of Barcelona to verify the sleep events of each subject. These sleep experts followed the same criteria for sleep scoring as those used for PSG. Signals were then exported to.edf format for further analysis.
The signals from the two devices were manually synchronized with the beginning and ending timestamps of the files. The smartphone accelerometry signals were analyzed to detect artifacts linked to the subjects' body movements or position changes. These artifacts were automatically detected with a custom-made algorithm which analyzed six-second windows overlapped sample by sample. For each window it calculated the amplitude of the signal by retrieving the difference between the maximum value and the minimum value for each of the triaxial accelerometry channels separately. If the amplitude of the signal on any of the channels was greater than 2 (m/s 2 ), the sample belonging to the central value of the window was labelled as an artifact. Then, artifact regions closer than three seconds were merged and artifacts greater than one second were kept. These artifact regions were excluded from our study.
The artifacts from the Apnealink device consisted principally of nasal cannula and pulse oximeter malfunctions leading to a loss of signal or a low signal. Those regions were also excluded from analysis. The final valid duration for each subject ranged from four to five hours of sleep.
C. HOME EVENT DETECTION 1) ALGORITHM FOR DETECTING RESPIRATORY EVENTS THROUGH ACCELEROMETRY The automatic event detector we propose in this section aims to retrieve abnormal respiratory behavior which could be linked to disordered breathing and OSA. To retrieve these events, angular variations were calculated from triaxial accelerometry signals as follows: 1. Each of the signals of the raw triaxial accelerometry was cut into different segments to discard the artifact regions. 2. Each of the signals was lowpass filtered at a cutoff frequency of 0.8 Hz with an 8 th order Butterworth filter to remove high frequency noise and keep frequencies associated with respiration. To avoid filter edge effects, the signal segments were value padded at the edges. 3. Triaxial accelerometry filtered signals were used to calculate the angular variation in relation to the unity gravity vector [0 0 1]. 4. The angle variation vector was bandpass filtered at the frequency range of 0.1Hz-0.8Hz to remove the baseline and keep frequencies associated with respiration. 5. Local maxima and minima values were calculated upon the angle variation signal. Then the upper and lower envelopes were retrieved from them and used to calculate the total amplitude signal, which represents the angle variation amplitude. 6. Two signals (coefficients 1 and 2) were extracted from the total amplitude signal. These coefficients were used to detect lower amplitude regions, associated with lower angle variations, which would indicate disordered breathing. The coefficient 1 signal evaluates angle variability amplitude versus its previous performance, and the coefficient 2 signal evaluates the angle variability amplitude versus its posterior performance. To calculate both coefficients, a window of 45 seconds (one and a half standard 30s-epoch window used in clinical environment) was used, overlapped sample by sample. Within this window, and for each coefficient signal, each value of the angle variation amplitude was compared to the maximum value of the window. This process allowed us to retrieve the percentage of reduction of the angle variation at each time compared to the previous and posterior behavior. This approach was chosen to mimic the flow reduction assessment established by the AASM for sleep scoring [11], in which a local reduction in flow must occur at a specific time point. 7. Raw events were then detected when both coefficients scored a reduction of at least 70%. This threshold was also established according to the AASM hypopnea criteria for flow reduction. 8. Next, the events were expanded to the left by the coefficient 1 signal to determine the event start time according to the 70% reduction rule. The events were also expanded to the right by coefficient 2 to determine the end time. Then, overlapping events or events closer than two seconds apart were merged. This two-second threshold was chosen to allow the events separated by less than a fast respiration to be merged. In addition, events shorter than 10 seconds were discarded, again, as recommended by the AASM, and the remaining events were kept as possible disordered breathing candidates. 9. Finally, events that were not followed by a desaturation detected by the Apnealink pulse oximeter were discarded, as is done in the clinical praxis and in the AASM guidelines for sleep scoring for hypopneas. An example of the event detection algorithm can be seen in Fig. 1, where the raw events detected have been processed to obtain the final events by means of the procedure explained in this section.

2) HOME EVENT COMPARISON
To compare the performance of the smartphone in detecting events linked to disordered breathing and OSA, two different types of comparisons were made: a general subject performance comparison and an event-to-event comparison.
The general subject event performance comparison aims to verify that the information extracted for each subject regarding their overall sleep performance score is in concordance with the commercial reference device Apnealink. To this end, the AHI was estimated from the smartphone automatic event detector and compared to the manually reviewed Apnealink AHI. Additionally, the AHI from both devices were used to stratify the subjects into the different patient severity categories used in the clinical environment. The classifications from the two devices were then compared. Finally, the concordance correlation coefficient [36] between the AHI from both devices was calculated with the following formula: where σ xy is the covariance of x n and y n , σ 2 x and σ 2 y are the variances of x n and y n , andx andȳ are the means of x n and y n , respectively. In our study, x n corresponds to a vector containing the AHI from Apnealink and y n to a vector containing the AHI estimated from the smartphone.
The event-to-event comparison aims to check that the events found by the automatic event detector through smartphone accelerometry agree with the events recorded by the reference device. We did this to determine whether the events recorded by the two systems occurred at the same time position, meaning that both systems were detecting the same abnormal behavior at the same time. This type of comparison allowed us to determine the true positive (TP) matches when two events completely or partially overlapped; the false positive (FP) matches when an event was found by the smartphone automatic event detector but not by the reference device; and the false negative (FN) matches when an event was found by the reference device but not by the smartphone test device.
From the TP, FP and FN values, it was possible to calculate the sensitivity (Se) and positive predictive value (PPV) of the comparison with the following formulas: Specificity (Sp) and negative predictive value (NPV) could not be calculated because they rely on information provided by true negative (TN) matches. These TN matches could not be calculated because there was no option to match and count events not happening in both systems.
Finally, from all the apneas and hypopneas detected with the reference device, the ratio of how many of those events were also found with the smartphone (SmP) system was calculated using the following formulas: %Apn = 100 · SmP events matching an apnea Reference system apnea count (4) %Hpn = 100 · SmP events matching a hypopnea Reference system hypopnea count (5)

D. POSITION DETECTION
To detect sleep position, each of the three signals belonging to the triaxial accelerometry was filtered separately with an 8 th order Butterworth low-pass filter at a cutoff frequency of 0.01 Hz. This was done to remove high-frequency activity and maintain the baseline of each signal, which contains information on the acceleration caused by gravity. Afterwards, the components of each of the accelerometry axes were used to retrieve the supine, left, right, prone and standing positions. Since the cartesian system for triaxial accelerometry moves in accordance with the subject's sleep position, and since the placement and orientation of the phone is known, it is possible to determine the subject's orientation by assessing the magnitude and sign of each of the three channels in each sample.
The position is retrieved for each sample according to the following formula: where X, Y and Z are the values of the triaxial accelerometry of each sample from the triaxial accelerometry vectors.
An additional database was acquired to validate the determination of sleep position obtained through smartphone triaxial accelerometry, since we could not retrieve position from the Apnealink. This database consisted of six different subjects (five men and one woman) with an average age of 56 [38]-[74] who underwent a PSG test in the sleep lab at Hospital Clínic of Barcelona. The sleep position was obtained from each PSG test and then synchronized and compared to that determined by smartphone accelerometry. The standing position was not used in this study because it is not associated with a sleep position. Two different comparisons were made to validate smartphone position detection. The first comparison was the sleep position assessment for each of the subjects, which determined the percentage of position agreement by means of the following formula: where Pos H i is the position vector from the hospital, Pos SmP i is the position vector obtained from smartphone accelerometry and N is the total number of samples of the overlapped regions from both signals.
The second comparison was the overall position assessment when specifying each PSG position. To calculate it, the PSG position from all the subjects together was used as the reference, and the percentage of occurrence of each smartphone position for each of the positions of the PSG was calculated according to the following formula:  (3) is shown together with the automatic events (green boxes) detected from smartphone accelerometry linked to disordered breathing. The information provided by the oxygen saturation signal (4) from the Apnealink device when desaturation event information was present (grey boxes) was needed to detect both event subsets.
The percentage of events occurring in each position was also retrieved from the smartphone accelerometry position detection data by linking each event to its position of occurrence with the following formula: %Event pos = 100 × number of events in a certain position total number of events (10) And the ratio of occurrence of an event linked to the time spent in each position was retrieved with the following formula: Ratio Event−Position = %Pos %Event pos (11) These variables were calculated for all the subjects with an AHI >5. Healthy subjects were excluded because they had a very low number of events, and were therefore not good candidates for pOSA assessment.
Finally, to assess the performance of the smartphone device in detecting events in a certain sleep position, we calculated the Se and PPV of the event detection for each position. For this purpose, all the events used in the event-by-event comparison of the smartphone event detector were labelled with their position. Then, all the events were grouped by position rather than by patient to retrieve the Se and PPV of the smartphone detector data in different sleep positions.

III. RESULTS
A. HOME EVENT DETECTION PERFORMANCE Fig. 2 shows a five-minute time sample of the alignment between the events obtained from the reference device and the events retrieved with the automatic event detector based on smartphone accelerometry when the subject was sleeping in the supine position. Both devices detected almost the same number of events, with similar start and end times. The only significant differences between the two systems are the start time of the first event, and the FP event detected by the smartphone system.
To evaluate the smartphone system's potential to detect events in agreement with the reference device, an eventto-event comparison was performed.
This comparison determined the number of TP, FP and FN event detections as well as the Se and PPV between the two systems. The results from this comparison can be seen in Table 1, which shows that the smartphone automatic detector performed very well overall with a Se of 90% and a PPV of 80%. Similar values were found for each of the subjects in the database, except for the subjects with few events, for whom the influence of a mislabeled event is more heavily penalized. The data in this table also show that the smartphone system is more sensitive to apneas (93%) than to hypopneas (86%).
In addition to the event-to-event comparison, we calculated the AHI for each of the subjects. The AHI values were retrieved from both devices at the same time to compare the performance of the automatic event detector according to the clinical standard. The AHI values from the reference device and the AHI values estimated from the automatic disordered-breathing event detector can be seen in Table 1 and a graphic representation is shown in Fig. 3. Additionally, the concordance correlation coefficient was calculated to assess  the similarity between the AHI retrieved from the two systems. This coefficient provides information about how similar the paired AHI values are for each subject in the database. The value obtained for the concordance correlation coefficient is 0.96, which indicates a high correlation and similarity.
Finally, from the AHI obtained from the reference device, each of the subjects in the database was classified according to the four different AHI severity categories: healthy, mild, moderate and severe. The same procedure was performed with the AHI estimated from the automatic disordered-breathing event detector. The confusion matrix was then calculated from both classifications to determine the agreement found between the two devices for the classification of all the subjects from the database. The results of this classification can be seen in Table 2 and show that the classification was satisfactory for 10 of the 13 subjects in the database, and in two of the misclassified subjects, the AHI values were very close to the threshold values for AHI classification.

B. SLEEP POSITION ASSESSMENT
Sleep positions were obtained by means of smartphone accelerometry and were compared with the positions from hospital PSG for six different subjects. This was done by calculating the percentage of agreement between the position obtained from the two devices for all six subjects. This percentage of agreement was calculated sample by sample from the overlapping time between the two signals during the overnight tests. The average position agreement for the six subjects was 97%, ranging from 90% to 100% agreement. An example of the comparison between the two positions can be seen in Fig. 4, showing that the position obtained through smartphone accelerometry matched the position from hospital PSG. In addition, the positions from the hospital data included some artifacts which were not present in the positions retrieved from the smartphone accelerometry signals.   The overall performance of agreement, separated by PSG position, was also calculated to assess the accuracy of the smartphone's ability to detect each position compared to the PSG reference. In this comparison, the position given by the PSG for all six subjects was used as a reference and we calculated the percentage of agreement with the positions obtained from the accelerometry signals for all six subjects. The results of this comparison can be found in Table 3 in the form of a confusion matrix with the percentage of agreement. The total amount of time spent in each position is also provided. The agreement was very good for almost all positions, with very good results for the detection of supine and left positions. However, the detection of the prone position was not satisfactory, but as shown in Fig. 4, some of the PSG prone positions could be artifacts.

C. HOME pOSA PERFORMANCE
The separate results of the pOSA assessment for each device can be seen in Table 4 for the Apnealink device and in Table 5 for the smartphone device.
Using the pOSA ratio of the supine position, it is possible to determine that six of the ten non-healthy subjects assessed by the Apnealink device were suspected to have pOSA, since their coefficient was over 1, indicating that more events occurred in the supine position than the time spent sleeping in that position. A remarkable result of the pOSA assessment from the Apnealink device can be found in subject 4, whose pOSA ratio indicates that this subject is 2.5 times more likely to experience apneas or hypopneas in the supine position. Other ratio coefficients over 1 can be found for the right and left positions, although these ratios might be influenced by the low percentage of time spent in each position.
The pOSA assessment performed by the smartphone device shown in Table 5 together with the pOSA ratio of the supine position suggests that four of the ten non-healthy subjects may have pOSA, since their coefficients were higher than 1. Although fewer pOSA subjects were detected with smartphone accelerometric signals than with the Apnealink device, the overall assessment of pOSA is satisfactory, as the misclassified values were very close to the threshold value 1, which indicates that the presence of events is based on the time slept in each position. It is noteworthy that the assessment of pOSA for the subject 4 was also detected by means of the smartphone system.
In addition to the pOSA assessment for each of the devices separately, the information from the event-by-event comparison in Table 1 was linked to the sleep position obtained through smartphone accelerometry. The results of this comparison are shown in Table 6. The overall Se and PPV for all of the different sleep positions were good, although there is a clear differential performance between the supine and the right and left positions. The Se is higher in the lateral positions, with very similar values, compared to the Se in the supine position. The opposite occurs with the PPV, which had a higher value in the supine position and was reduced in the left and right positions.
The same differential behavior was observed when comparing the sensitivity to apnea and hypopnea values by position. Apneas were better detected with the smartphone in the supine position, while hypopneas were better detected in the lateral positions. Finally, the prone position could not be assessed due to the low number of events that occurred in that position.

A. ACCELEROMETRY: SLEEP-DISORDERED BREATHING ASSESSMENT
Accelerometry is a technique used in multiple applications for sleep performance assessment. Most of these applications are based on actigraphy, which consists of analyzing movement to estimate rest and activity cycles. However, accelerometry can be used to determine movement of any kind, extending its potential use beyond that of actigraphy. In this line of action, Bates et al. [19] estimated the flow waveform and respiratory rate through triaxial accelerometry. Recently, several other studies have followed in the same  vein, using triaxial accelerometry to derive respiration data and assess sleep apnea [21], [37]. Studies published by our group have also shown that smartphone accelerometers are effective tools with great potential to assess respiration and to monitor sleep apnea at home [22], [31], [34].
In this work we proposed using accelerometry to automatically detect disordered breathing linked to OSA. We detected disordered breathing by determining the times when reductions in local chest angular variation amplitude occurred, indicating that the respiration pattern had changed, and ventilation might be reduced for that specific time. According to the AASM, apneas and hypopneas are events in which respiration is completely or partially reduced [11], which indicates that the events we found with our automatic event detector should correspond to an apnea or hypopnea episode.
We assessed our sleep-disordered breathing detector in 13 different subjects. We are aware our sample size (13 subjects) does not allow to extract general gender-or age-related conclusions. Nevertheless, we consider this limitation to be beyond the scope of this work, as we do not intend to perform a population study, but rather a proof-of-concept study of the feasibility to use smartphones as OSA screening and monitoring tools.
To assess the disordered-sleep events identified with our automatic detector, two different comparisons were made against data from an Apnealink device. Apnealink device is not the gold-standard technique for sleep apnea diagnosis, which is PSG. This implies that the smartphone device will be, at maximum, as good as the Apnealink device, which is a limitation of the study. Nevertheless, the Apnealink events we used in this study were manually validated by sleep experts, which has been reported to increase the agreement with PSG [38]. Also, the Apnealink has been reported to have a good agreement with PSG [39]. For the first comparison, and to determine overall sleep performance, the AHI was calculated for each subject from the events found by each device. As the results in Fig. 3 show, the AHI values from the two devices agree and their correlation coefficient is 0.96, indicating a high degree of correlation and similarity. A subject-by-subject review shows that the AHI is correctly estimated for almost all subjects. There were three cases in which the AHI estimation was not as good as the others, but the reason for this over-or underestimation of the AHI is linked to the detection of event start and end times. In some cases, the automatic algorithm defined an event which encompassed two different events on the reference device and vice versa. Since the AHI is calculated from the total number of events, when this happened, the AHI showed greater differences compared to the behavior of most of the subjects in the database. However, as shown in Table 2, almost all of the subjects in the database were correctly classified into the different categories used in the clinical environment for sleep apnea assessment, which indicates that the estimation of overall sleep performance as determined in the clinical environment was accurate.
Even though the determination of overall sleep performance was successful, we still had to ascertain whether both devices were detecting the same events at the same time position. This is because the AHI considers the total number of events that happened while sleeping, but it does not pinpoint when those events occurred. It is possible that two identical AHI values from the same subject on the same night were calculated from events happening at different points in time, which would mean that the performance of the two devices did not coincide, even though the result would be the same. To address this issue, we performed an event-by-event comparison, the results of which are shown in Table 1. Almost all of the events found with the Apnealink reference device were also found with the automatic smartphone disordered-breathing detector at the same time position (Se = 90%). In addition, the PPV was 80%, indicating that an event found with the smartphone system was very likely to also be found with Apnealink, so the smartphone device events agreed with those recorded by Apnealink. The Se and PPV values are also consistent across all the subjects in the database, except for those with very few events, in which the influence of FP or FN is higher in the Se and PPV calculation. Despite these good results, there are differences between the two methods, which can be explained by the limitations of each system. In a recent study conducted by our group, Castillo-Escario et al. [30] demonstrated the potential of smartphone audio in the detection of oral and nasal breathing. These findings exposed a limitation of the Apnealink device, which assesses airflow only by means of a nasal canula. Therefore, if the subject breathes only through the mouth during a specific time of the night, it could lead to false positive detections of events. On the other hand, the resolution of the smartphone accelerometer and their behavior in characterizing respiration may also affect detection accuracy. Nevertheless, despite the limitations of the two systems, the results obtained were very satisfactory.
Pulse oximetry was needed to determine which of the events detected through accelerometry affected blood oxygenation. This step was taken to mimic clinical praxis and to be able to discard the events recorded by the accelerometry detector which did not produce oxygen desaturation. According to the AASM guidelines for hypopnea and apnea [11], pulse oximetry is a commonly used tool to detect hypopneas, but it is not necessary to detect apneas, even though apneas, by their definition, are more likely to produce oxygen desaturation. Although the use of pulse oximetry could lead the smartphone accelerometry to fail to detect apneas not followed by desaturation, according to the results shown in Table 1, the accelerometry detector has a greater sensitivity to apneas (Se = 93%) than hypopneas (Se = 86%). This may be because the definition of hypopnea is more controversial than that of apnea [40], and apneas are expected to produce more acute symptoms than hypopneas with regard to ventilation efficiency. Nevertheless, sensitivity to both types of events is very high, and we proved that accelerometry-based assessment from a smartphone device can reproduce event detection behavior that is very similar to that of the Apnealink commercial portable device used in the clinical environment.

B. ACCELEROMETRY: HOSPITAL PATIENT SLEEP POSITION MONITORING
The detection of a subject's sleep position provides important information that is invaluable in sleep studies. The gold-standard PSG test records sleep position, and clinicians use this information to understand how the patient moves while sleeping to recommend the most suitable course of treatment based on his or her sleep score. Since PSG tests usually include video recording, the position information provided by the polysomnograph can be compared with the video to corroborate the patient's movement in the event of uncertainty.
In this work, we proposed a smartphone-based position detector using accelerometry. Position was obtained by determining which of the triaxial channels of the accelerometry was better aligned with gravity, which allowed the device to detect five different positions: standing, supine, prone, left and right. Among these positions, the standing position was not used because only sleep positions were of interest. To validate the detection of the sleep position, the smartphone accelerometry data were compared to the positions obtained from six PSG tests in which smartphones and PSG were recorded simultaneously. As shown in Fig. 4, the method proposed here was in very close alignment with the positions yielded by the PSG test, and this behavior was common in all six records, as the average position alignment was 97%, ranging from 90% to 100% agreement between the two devices. In parallel, the information in Table 3 makes it possible to compare the agreement between the smartphone accelerometry positions and the PSG positions in each sleep position. The supine position was extremely well detected, with an agreement of 100% in over 35 hours of supine position testing. Similarly, the left (94%) and right (87%) positions also achieved high agreement values. The prone position assessment was not as good as that for the other sleep positions for two main reasons: there were only around 30 minutes to be tested, so errors heavily affected the percentage of agreement; and some PSG prone positions were noisy. These noisy episodes can be seen in Fig. 4, which shows that the accelerometry signal was perfectly steady, indicating an appropriate sleep position, which could mean that the PSG position sensor moved, leading to a misdetection of the position. Therefore, we would need more time in prone position to validate the resolution of the smartphone to discriminate between prone and lateral positions. Nevertheless, position detection through smartphone accelerometry was satisfactory and the comparison with PSG demonstrated that is possible to retrieve sleep position data with smartphone accelerometers, which opens up the possibilities for the detection and monitoring of pOSA at home. Furthermore, the smartphone device was able to retrieve sleep position data in a simple and non-invasive way, which is better for the patient.

C. ACCELEROMETRY: pOSA ASSESSMENT
The detection and monitoring of pOSA is of great interest for clinical sleep apnea assessment. Among all the possible treatments for sleep apnea [12], positional treatment is one of the least invasive methods for improving sleep quality. Recent studies shown that PSG tests could lead to an overestimation of OSA severity [41], with extreme differences in pOSA patients, whereas the benefit of positional treatment helps to reduce the AHI index by six points in average while keeping a high satisfaction with the treatment [42]. These findings indicate that a solution including non-invasive methods is required to improve the detection, monitoring and treatment of OSA patients, and especially those who suffer from pOSA.
In this work, we attempted to combine the information from our method for detecting sleep-disordered breathing events, which are associated with apneas and hypopneas, with sleep position data. Sleep-disordered breathing and sleep position data were both obtained from the accelerometry of a smartphone placed over the sternum, which allowed us to non-invasively assess sleep performance and position. To detect pOSA, we calculated the percentage of time a subject slept in each position and compared it to the percentage of events a subject experienced in each position. This allowed us to calculate a ratio which indicates whether a subject was more likely to experience episodes in a specific position, and we used the supine position to determine the existence of pOSA. To assess our pOSA performance, the events obtained from the Apnealink device were also associated with sleep position, and the event occurrence by position ratio coefficients were obtained for both devices. Since the smartphone pOSA is assessed vs the Apnealink device, the potential to detect pOSA from smartphone accelerometry is limited to the potential of Apnealink to detect pOSA. The results of the pOSA assessment can be found in Table 4 for Apnealink and in Table 5 for the smartphone detector. Healthy subjects were excluded because they had a very low number of events, and were therefore unsuitable candidates for pOSA assessment.
The results of the pOSA assessment showed that, according to the Apnealink device, six of the ten non-healthy subjects in the database may suffer from pOSA because their ratio was over 1, whereas the smartphone determined that there were four out of ten. Differences between the two systems in detecting pOSA can be explained by how the threshold for the event occurrence by position ratio is chosen. Values over 1 indeed reveal a higher percentage of events in that position than time spent in it, but greater values may be required to unquestionably establish the likelihood of more events in a certain position. In our study, subject 1, with an Apnealink pOSA ratio of 1.4 and smartphone pOSA of 1.5; subject 4, with ratio values of 2.5 and 2.4; and subject 8, with ratio values of 1.6 and 1.6, might be pOSA patients. These three subjects would surely benefit from positional treatment since they showed an event occurrence of at least 40% greater than regular performance, with the extreme case of subject 4 who experienced around 150% more events while sleeping in the supine position. Therefore, the detection of pOSA performed in this study would provide relevant clinical information to doctors who could then choose the best treatment option for each specific need.
Because the pOSA assessment described in this article depends on the agreement between the events detected by Apnealink and those detected by the smartphone sleep-disordered breathing detector, an event-to-event comparison of the two devices was also conducted in relation to sleep position. The results of this comparison can be seen in Table 6, which shows the Se and PPV calculations for each of the different sleep positions. The data indicate that the smartphone device performed very well in detecting apneas in all positions, with extremely good results in the supine position (93%). The lower values in the lateral positions are explained by the fact that there were very few apneas in these positions, and the influence of a missed event is higher. In parallel, hypopneas were also very well detected in all positions, especially in the lateral positions. The smartphone device had higher Se values in the lateral positions when compared to the supine position, whereas the PPV value was higher in the supine position compared to the lateral. This indicates that the smartphone devices detect more events in the lateral position than in the supine position. This differential behavior could be explained by the limitations of the two devices described previously. Further analysis would be required to better understand the physiological factors involved and their prevalence in the different sleep positions. Even so, the Se and PPV values obtained in each position separately were satisfactory, indicating that smartphone accelerometry is a powerful tool for screening and monitoring pOSA at home.

V. CONCLUSION
In this work, we aimed to assess sleep-disordered breathing, which is associated with apneas and hypopneas, and to obtain sleep position data. In addition, we linked these two types of information in order to assess positional OSA. The detection of pOSA is of great interest to the medical community, because it allows more suitable treatment strategies to be devised for each patient. The most common OSA treatment in use today is CPAP, but detecting pOSA indicates which patients might derive greater benefits from positional treatment, one of the least invasive treatments for OSA.
To accomplish these goals, our first objective was to develop an algorithm for detecting thoracic movement associated with disordered breathing events. To this end, we assessed the angle variations obtained from the triaxial accelerometry of a smartphone placed over the sternum. These angle variations allowed us to determine abnormal breathing patterns that produced lower angle variations, which indicated that the breathing pattern was altered.
To verify the events found, our second objective was to compare the performance of smartphones as OSA monitoring tools with the performance of a type 3 portable sleep monitor, specifically, the Apnealink device. The events found by the Apnealink device were manually reviewed by sleep experts from hospital Clinic, which has been reported to increase the agreement with PSG. This comparison allowed us to assess two main aspects: the overall sleep performance with the calculation of the AHI and the event-to-event agreement between the two devices. Our results showed that the smartphone performed very well in obtaining the AHI and the event-to-event agreement demonstrated that both devices were capable of finding the same events occurring at the same times.
Our third objective was to explore the feasibility of smartphone accelerometry to retrieve reliable patient sleep position data and assess pOSA. Position was also retrieved from the smartphone accelerometry and was corroborated against PSG with very good alignment. Afterwards, the events from both devices were associated with their corresponding sleep positions and the ratio between the percentage of occurrence of an event in a specific position versus the percentage of time spent sleeping in that position was calculated. This ratio was used to detect patients who experienced more events in the supine position than the time spent sleeping in the supine position and allowed us to assess pOSA.
These results showed that smartphones are promising mHealth tools and that accelerometry is a feasible technique for the assessment of OSA and pOSA.