Dependable algorithm for visualizing snoring duration through acoustic analysis: A pilot study

Snoring is a nuisance for the bed partners of people who snore and is also associated with chronic diseases. Estimating the snoring duration from a whole-night sleep period is challenging. The authors present a dependable algorithm for visualizing snoring durations through acoustic analysis. Both instruments (Sony digital recorder and smartphone’s SnoreClock app) were placed within 30 cm from the examinee’s head during the sleep period. Subsequently, spectrograms were plotted based on audio files recorded from Sony recorders. The authors thereby developed an algorithm to validate snoring durations through visualization of typical snoring segments. In total, 37 snoring recordings obtained from 6 individuals were analyzed. The mean age of the participants was 44.6 ± 9.9 years. Every recorded file was tailored to a regular 600-second segment and plotted. Visualization revealed that the typical features of the clustered snores in the amplitude domains were near-isometric spikes (most had an ascending–descending trend). The recorded snores exhibited 1 or more visibly fixed frequency bands. Intervals were noted between the snoring clusters and were incorporated into the whole-night snoring calculation. The correlative coefficients of snoring rates from digitally recorded files examined between Examiners A and B were higher (0.865, P < .001) than those with SnoreClock app and Examiners (0.757, P < .001; 0.787, P < .001, respectively). A dependable algorithm with high reproducibility was developed for visualizing snoring durations.


Introduction
Snoring, defined as snoring or grunting sounds during sleep, is caused by the vibration of soft tissues throughout the upper airway. Snoring is not only a nuisance for the bed partners but also associated with chronic diseases. [1] A study reported that the prevalence rate of chronic snoring is higher in adult men (40%) and lower in adult women (20%), although the variation is large. [2] The snoring prevalence is more than 40% in Asian countries, including Taiwan (59.1%), [3] Malaysia (47.3%), [4] and Turkey (40.7%). [5] One of the reasons for varying snoring prevalence might be that people of Chinese descent tend to have narrower cranial bases and flatter midface structures than do people of other races. [6] Studies have proposed the criteria that all snoring sounds measured through manual audio recording should have an audible oscillatory component and be synchronous with breathing and yet protuberant from background sounds. [7,8] Generally, sounds have 2 characteristics: sound tone (frequency) and sound intensity (amplitude). Similarly, snoring can be defined through sound intensity and frequency. A study defined snoring as a breathing sound intensity of > 25 dB. [9] Furthermore, typical breathing sound frequencies for snoring range from 110 to 190 Hz, although frequencies even from 800 to 5000 Hz have been reported. [10][11][12][13] Therefore, some researchers have transferred collected audio data to Mel-frequency cepstral coefficients and have used hidden Markov models to detect and monitor snoring by using audio data. The reported detection accuracy of snoring from using an ambient microphone range from 87% to 98%. [9,10,14,15] However, the aforementioned studies were performed in sleep laboratories.
Subsequently, a study suggested a snoring epoch method for estimating snoring duration according to a threshold level of the maximum amplitude for every 30-second segment. A 30-second sleep epoch that contained 3 or more snoring signals was deemed a snoring epoch. Total snoring duration was subsequently calculated as "the sum of the snoring epoch × 30 s," where "snoring epoch" was determined by the snoring signals from each 30-second segment during the whole-night sleep period. A shortcoming of this epoch method is that different threshold levels may output different results. [16] Nonetheless, the 30-second sleep epoch method has been used for evaluation/classification of snoring sound data nowadays. [9,17] Another method for determining snoring duration is manual listening. However, this method might yield a large variation in results due to the difficulty of concentrating on hearing over a long period.
Snore apps are software applications that run on smartphones and record sound information while the user is sleeping, and they have provided convenient and personalized sleep care. [18] With the progression of innovative monitoring mechanics and techniques, the apps can be used at home and examinations can be performed as often as every night without interruptions to the user's sleep. Studies have reported that the precision of smartphone apps for predicting snoring ranges from 93% to 96%, although apps can vary greatly among smartphone models. [19] SnoreClock was one of smartphone applications and it has a high predictive value for snoring. [20] In this study, the authors present a dependable algorithm for calculating snoring duration on the basis of the typical features of snoring frequency and amplitude and enable the visualization of snoring duration on a spectrogram. The authors compared the results of using our trusted method with those of using the home-based SnoreClock app.

Participants and methods
Six individuals with habitual snoring voluntarily participated in this study. The study was conducted over different periods at their respective homes in Taiwan. Informed consent had been obtained from all participants before their participation into this study. The study protocol had been reviewed and approved by the Research Ethics Committee of the Buddhist Dalin Tzu Chi Hospital in Taiwan (No. B10703013).
Similar to our previous study, [20] all participants placed their smartphones and digital recorders (Sony ICD-SX 2000, Sony Electronics Inc., Tokyo, Japan) away from them yet within arm's reach before going to sleep. The smartphones and recorders were placed at the cranial side of the shoulder within 30 cm from the head to optimally record the snoring sounds of patients. Snoring rates were then determined through measurement of snoring durations over the wholenight sleep period. In this study, the recognized snoring durations were composed of both snoring signals and interval pauses not exceeding 100 seconds.

Snoring rates obtained using our dependable algorithm
The dependable algorithm was obtained through analysis of files obtained from Sony recorders. Snoring sounds throughout the night were recorded using portable digital sound recorders with linear pulse-code modulation (ICD-SX 2000, Sony Electronics Inc., Tokyo, Japan). The manufacturer of the sound recorder was not involved in this study. This recorder has 2 built-in high-performance electric dynamic microphones. These microphones were moved to a 90-degree "X-Y pattern." The low-cut filter and limiter switches were set to the "OFF" position. The acquired audio signals were then digitalized at a sampling frequency of 44.1 kHz, pulse-code modulation, and 16 bits per sample. The authors subsequently moved these files to our computer for further evaluation. The files were records taken every 600 seconds. Dominant frequencies for each 0.01-second segment were analyzed and plotted. Simultaneously, Hilbert amplitude envelopes were smoothed using a sample-moving average of 1000 samples with a 25% overlapping sliding window. [9,10,21,22] The R codes (R Foundation for Statistical Computing, Vienna, Austria) used are presented as follows.
To read the audio file (190402_0310.wav in E disc, for example): >library(tuneR) >file.1 <-readWave("E:/190402_0310.wav") To cut the file into 600-s segments: >file.1.600sec <-cutw(file.1, from = 0, to = 600, output="Wave") The first part of the 600-s segment was, for example: For the frequency domain: >df.plot <-dfreq(file.600sec.1, at = seq(1, 599, by = 0.01)) For the amplitude domain: >amp.plot <-timer(file.600sec.1, threshold = 70, msmooth = c(1000,25), dmin = 0.001, envt="hil," plot = TRUE) Visualization revealed that the clustered snores in the amplitude domains generally exhibited near-isometric spikes with a trend of initial ascension and subsequent descension. Moreover, the frequency domains of the snoring records exhibited one or more visibly fixed frequency bands. Thus, the authors combined the correspondent 2 figures (matched amplitude domains and frequency domains) as snoring clusters. Notably, intervals (no more than 100 s) lay between the snoring clusters, and they were all incorporated into the whole-night snoring duration. Plots with typical amplitude domains and frequency domains classified as snoring that did not meet our criteria were classified as "noises." The "noise" patterns did not possess the aforementioned typical features of snoring sounds. Therefore, the authors could easily differentiate noises (e.g., those from a fan, an air-conditioner, a toilet, outdoors, coughing, and groaning) from genuine snoring sounds. In the case that snoring durations were ambiguous, the authors again carefully listened to the recorded files for confirmation.
As the aforementioned, the authors set these guidelines, which enabled visualization of snoring durations. Thereby, the authors could visualize typical snoring durations according to the typical frequency and amplitude of snoring on spectrograms. All snoring durations were summed, and snoring rates were determined. To test the reproducibility of the method of calculating snoring duration by using Sony digital recorders, 2 independent researches thoroughly examined the digitally recorded files.

Determining snoring rates by using smartphone apps
Because smartphone apps are accessible and portable, the SnoreClock app for smartphones were used according to its high accuracy upon snoring detection in the home environment. [20] The snoring time and rates were displayed on the screens of smartphones. The developers of SnoreClock app were not involved in this study.

Highlights
1. The snoring duration had characteristics as following: isometric spikes (amplitude domain) and the corresponding fixed frequency bands (frequency domain) were paired and then grouped into isolated clusters, generally at intervals (typically <100 s). 2. Visualization revealed that the typical features of the clustered snores in the amplitude domains were near-isometric spikes (most had an ascendingdescending trend). 3. The correlative coefficients of snoring rates from digitally recorded files examined between 2 physicians were higher. www.md-journal.com

Statistical analysis
The R statistical software, version 3.4.1, was used for all statistical analyses. The seewave package for R was applied. Hilbert amplitude envelopes were smoothed using a sample movement average of 1000 samples, with a 25% overlapping sliding window based on the timers' function. Dominant frequencies were processed every 0.01 seconds through fast Fourier transform using the dfreq function of the R package. Statistical significance was set at P < .05, and all tests were 2-tailed. Continuous variables were presented as mean ± standard deviation where t test or Wilcoxon test were indicated by cases. Correlation analysis was performed to evaluate associations in snoring rates between methodologies and examiners. ANOVA was used to test the differences between 3 groups of continuous variables.

Results
In total, 37 recordings from 6 participants (2 female and 4 male) were used for the analysis. Their mean age was 44.6 ± 9.9 years. The mean recording time was 5.73 ± 1.18 hours. (Table 1) The sound files captured with a digital recorder were transferred to a computer for analysis. The depicted bands of typical snoring frequency could vary during the recording period at the intraindividual and interindividual level. For better understanding of our concept to visualize snoring, we had demonstrated a spectrogram with dominant frequency bands and amplitude spikes of the typical snoring. The 3 mean frequency bands of snoring presented on the spectrogram were 4694, 2713, and 1083 Hz. The fourth mean frequency band of snoring was hidden in background noise (Fig. 1).
Every recorded file was segmented at 600-second (10 min) intervals. The dominant frequencies for every 0.01 seconds were calculated through fast Fourier transformation and plotted, and the Hilbert amplitude envelopes were plotted as well. Under this time scale, the matched 10-minute plots of frequency bands and amplitude spikes were combined to estimate snoring durations. Isometric spikes (amplitude domain) that formed during participants' snoring and the corresponding fixed frequency bands (frequency domain) were paired and then grouped into isolated clusters, generally at intervals (typically <100 s). Therefore, the repeated "cluster-interval-cluster-interval" pattern must be identified to calculate snoring duration while "noises" are simultaneously excluded. The amplitudes could vary with time. Figure 2. shows an example of the typical duration of a 600-s (10 min) snore.
The entire snoring duration was composed of summed interspersed signals and intervals (typically <100 s). Noises (such as those from walking, changing position in bed, doors opening or closing, waterflow, talking, and curtains opening or closing) did not have typically featured fixed frequency bands and repeated amplitudes (Fig. 3).
To test for the reproducibility of our algorithm in calculating snoring durations, the authors examined the files digitally recorded by Examiners A and B. The differences in the scatterplots of snoring rates between those produced by the SnoreClock app and those obtained by Examiners A and B are shown in Figs. 4a-c.
The correlative coefficient of snoring rates calculated between Examiners A and B was 0.865 (P < .001), which is higher than that calculated by the SnoreClock app ( Table 2). The difference between the means of snoring rates calculated by the 2 examiners was small. Additionally, both examiners obtained values that were lower than those obtained by the SnoreClock app. However, the 3 calculated snoring rate values exhibited no statistically significant difference (P = .738; Fig. 5.).

Discussion
In terms of acoustics, snoring originates from "the vibration of palatal soft tissue from obstruction of air movement on breathing during sleeping." [23] Besides, snoring is widely defined as snorting or grunting sounds while asleep and would be presented with typical frequency and amplitude waves upon analysis. [11,21] Since our previous study has validated the snoring rate determined by the SnoreClock app to be with high accuracy (95%), the snoring rate reported by the SnoreClock app was then defined as the reference for judgement of snoring in our current study within home environment. [20] Subsequently, acoustic input from the same individual during his/her wholenight sleep period was then further reported by SnoreClock app, Examiner A or Examiner B.
In our current study, snoring duration was determined according to signals and intervals (typically within 100 s). The featured signals of snores in the amplitude domains shared a similar ascension-descension pattern. Through Hilbert transformation, each individual ascension-descension snoring signal unit was processed to identify individual spikes, which were subsequently grouped to form near-isometric spike clusters. The intervals between clustered spikes were then determined. In the frequency domain, one or more fixed corresponding frequency bands in the snoring signals were also observed. In this study, the authors could visualize snoring durations according to typical spectrograms from the audio files and thereby calculate the duration of snoring for each file. Noise patterns were easily identified and visualized because of their differences from the aforementioned typical features of snoring. With the use of a digital recorder at 44.1 kHz and R software, this dependable algorithm can be reliably used again. From our results, the correlation coefficient of snoring rates calculated by Examiners A and B was higher than that calculated by the SnoreClock app. The difference between the mean snoring rates calculated by the Table 1 The demographics of subjects For validation of snoring sounds, the acquired audio files were digitalized at a sampling frequency of 44.1 kHz, pulse-code modulation, and 16 bits per sample, in accordance with previous research. [9] In Dafna's study, all audio files were down sampled to 16 kHz, and each audio file underwent an adaptive noise suppression process based on the Weiner filter. Accordingly, they could detect snoring sounds with an accuracy of > 98%. [9] However, the authors did not perform down sampling, and the noise durations presented were not suppressed. In our study, the authors validated snoring sounds on the spectrogram by identifying matching typical amplitude and frequency domains. Snoring signals generally exhibited one or more discrete frequency bands, and their spiked amplitudes occurred in groups at characteristic near-isometric intervals. From the results, our dependable algorithm can be considered reliable for detecting snoring durations through visualization.
The analysis of snoring through audio recording with a microphone was applied and serves as a convenient option. Studies have reported the advantages of audio recording as its unobtrusiveness, portability, and low cost. [11,14] However, data sets of audio recordings require further analysis to define snoring durations because this algorithm is inaccessible for people who did not have R software applications.
Smartphone apps provide convenient and personalized sleep care, and their accuracy in predicting snoring rates ranges from 93% to 96%. [19] Nevertheless, snoring does not have fixed and constant audio characteristics; the authors compared the rates of snoring durations between smartphone apps and sound recorders. Studies have reported that snoring duration measurements obtained using smartphone apps are highly similar with those obtained through polysomnography. [23] In the current study, the authors compared the spectrograms of audio files obtained using a smartphone app (SnoreClock) with those obtained using the proposed dependable algorithm for detecting snoring duration.  The clustered spikes exhibit a unique ascensiondescension pattern regarding its amplitude, with intervals (typically <100 s) in between. www.md-journal.com Furthermore, in the event of visualizing snoring duration through our developed algorithm, so would the application of machine learning classifiers to identify the snoring in the future work.

Limitations
This study has the following limitations. First, because of the small sample size of 36 files from 6 subjects (male = 4 vs female = 2), our future study with a large sample size is warranted to confirm the results. Second, since our current study had been performed in the home environment, the gold standard for detection of snoring by polysomnography is not feasible. [24] Third, time spent before falling asleep was not omitted; therefore, the rates of snoring durations may have been underestimated. Finally, snoring apps might be unable to distinguish between snoring sounds from different individuals in the same room.

Conclusion
In this study, the examiners determined a higher correlation than those between the SnoreClock app's calculation and the digitally recorded files (by a Sony recorder) on snoring duration. Therefore, we provide a dependable algorithm that can be conveniently used to measure snoring rates. From this present study, a dependable algorithm for detecting snoring sounds for