IoT Healthcare: Design of Smart and Cost-Effective Sleep Quality Monitoring System

Getting quality sleep is important for every person to get better physical health. Irregular sleep patterns may indicate the illness resulting in chronic depression, which makes the evaluation of the sleep cycle mandatory for a healthy body and mind. In the arena of globalization, along with the increased facilities, various other challenges have been probed to provide the quality health care facilities with the use of economical instruments and technology. The development of the Internet of Things (IoT) technology purports the preambles to build a consistent and cost-effective system to monitor the sleep quality of patients. Several other systems are available for this purpose; however, such systems are very costly and difficult to implement. To overcome the issue, this study suggests an inventive system to monitor and analyze the sleep patterns using ambient parameters. The proposed system is effective enough that it can proficiently monitor patient’s sleep using Commercial off the Shelf (COS) sensors as well as predicts the results using the intelligent capability of the random forest model. The patient’s bio status including physical movement of the body, heartbeat, SPO2 level (oxygen saturation in the blood for the proper functioning of the body), and snoring patterns could be measured through this system, in which recorded data is transmitted to the computer system in a real-time environment. This system consists of two parts. One part consists of analyzing the behavior of data using the intelligent technique of the random forest model and decision rules in a real-time environment. This real-time analysis notifies the caretaker about the situation of the patient. In the second part, batch data processing is performed which allows the detailed analysis of data using statistical methods to produce the overall condition of the patient in a specified interval of time. Through the proposed system, we can easily measure the sleep patterns of patients and provide them with better treatment by using this simple and cost-effective system. The result of the conducted research shows that the proposed technique provides 95% accuracy. The patient’s sleep data is used to test this method through the validation of manual results, which provides the minimum error rate. This study highlights the implementation of an intelligent and smart sleep quality monitoring system using IoT on a variant number of people with minimum expense rate.


Introduction
In broad-spectrum, sleep is related to "brain activity," and this brain activity helps in to pull through brain exhaustion [1]. Quality sleep provides good mental health as it minimizes fatigue of daily routine and sleepiness, which leaves a positive impact on the body. Any disruption in the sleep cycle results in poor physical and mental health, as various other internal and external factors contribute to sleep abnormalities. However, major categories are mental/psychological factors, biological factors, and environmental factors [2]. Sleeping illness triggered through the physiological factors results in different mental problems like anxiety and depression. Nowadays, anxiety is the number one cause of many problems. Short-term illness fluctuates the biological system that interrupts the sleep of a person, consequently leading to the long-term effects. This may also happen due to disturbance in the body's nervous system, metabolism, and cardiac system. The last one is the environmental factor, which contains physical features, as these factors include environmental temperature, brightness in the room, moisture, and other ambient features such as comfort level of room and quietness in the room [2]. Several tools are available in the market to monitor the sleep pattern, which works with these three factors. In Figure 1, there are four categories, in which we can classify modern sleep monitoring technologies, currently under study.
Modern sleep monitoring tools practice diverse sensing technologies. These sensors can also be used for sleep staging. We do not cover sleep stages in the proposed system. PSG (polysomnography) is a type of sleep observing technology, which measures physiological factors such as breathing, temperature, muscle fluctuation, and oxygen saturation (SPO2) [3]. With the help of this technology, researchers can classify sleep-onset and wake-up time [4]. A device has been attached to the wrist of the patient during his sleep to analyze the physical parameters or changes. It is investigated that there is a solid relationship between wrist movement and the sleep status of the user [5]. In another method, there is the use of audio-video recording together with a Passive Infrared (PIR) sensor to detect the patient's sleep status [6].
The current study shows an ambient sleep observation method using sensors that are installed in homes. This study comprises of PIR sensors for motion detection, interaction sensors, which are connected to windows and doors, environment temperature monitors to measure the temperature of a room, and some other devices, which can detect heat and energy Several devices are also available which are currently used for sleep evaluation at home as shown in Table 1. Many of these are accessible in the market for purchase. The following table shows the comparison between various sleep monitoring devices where REM (rapid eye movement) and NREM (nonrapid eye movement) are sleep stages.
The iBrain encompasses the headband, which registers solo front lead EEG signals. Zeo is another device that comprises the headband of plastic and cloth material placed on the forehead, which measures electroencephalogram (EEG), electromyography muscle electromyogram (EMG), and electrooculogram (EOG) signals, where these signals are transferred to mobile phone through Wi-Fi or bluetooth [14]. The Heally system encloses embedded sensors within a shirt, which is used to calculate the respiratory and cardiac movement of the patient. The SleepTracker is another device fixed on a watch. This wristwatch captures human activity during sleep. WakeMate consists of a band, which is worn on the wrist of the patient. This band sends actigraphy information to a mobile phone. This information consists of total sleep duration, how many times the patient is awake during sleep, and a "sleep quality" information based on physical activity [15]. Air cushion consists of an air-filled beanbag, which can calculate several ambient and physical parameters. Emfit Bed Sensor consists of Emfit foil electrodes, which locates under a mattress to calculate parameters like respiration, heart rate, and body movement.
Nowadays, mobile devices are commonly used in everyday routine, which also provides several apps to monitor the sleep of patients. A system called ubiquitous architecture uses heart rate signals, sound signals, and accelerometer data for sleep monitoring. This idea works combining with the monitoring system through a smartwatch or smartphone. It also suggests an innovative and intelligent algorithm for the signal organization.
Even though, the abovementioned methods and tools have their benefits for analyzing patient's sleep. There are many drawbacks as well. Most of them are not grounded on the IoT and machine learning. The IoT model consists of many sensing devices, data transfer protocols, and cloud computing tools, which is trending and emerging nowadays. Data processing is performed on devices like mobile devices, which requires a lot of energy that is why such models can only be feasible for a little time.
There are many studies that focus on sleep quality monitoring, commonly based on wearable technology integrated into handheld devices. Such systems are good to monitor physiological factors, i.e., heartbeat and oxygen level. These systems are not suitable for long-term sleep quality monitoring. Several of the technologies are based on mobile phone processing. For this reason, available systems cannot be used at home because such monitoring requires a lot of processing. Such processing can have a large influence on mobile phone usage. A mobile phone cannot be used as a processing device for long-term sleep quality monitoring. Due to these factors, there is a need to use a system that can be used for long-term sleep quality monitoring.
In this paper, we will use a personal computer as an alternative to a mobile phone to perform complex processing and analysis to measure the sleep quality of patients. The reason behind using the computer is that we do not need too much mobility during sleep as well as mobile phone requires a lot of energy for processing data. Previous studies proposed the systems that are costly as well. These systems comprise of those components that are not commercially available in the market. The proposed sleep observing system consists of commercially available sensors and an ARDUINO controller. This system monitors the ambient factors of patient and physical movement during sleep. The main purpose of this study is to propose a sleep observing system, which can be used for patients at homes or in hospitals cost-effectively  (v) The proposed system is intelligent enough that it works accurately with a minimum error rate This system contributes to medical science technology by helping people to enjoy better sleep. The main objective of this work is to offer a system that should be inexpensive as well as easy to use for patients with a better level of accuracy. This system employs an intelligent technique of analyzing the sleep patterns that is not previously used in research work. This paper is aimed at proposing a low-cost and intelligent method of monitoring sleep patterns using IoT. The rest of the paper is structured into a set of units: unit 2 discusses the related work of sleep monitoring technologies and methods. Unit 3 consists of the structural design and functioning of the proposed methodology. Unit 4 describes the implementation and experiments. Unit 5 entails the results and discussion, whereas unit 6 concludes the whole research.

Literature Review
Sleep analysis methods are very useful in monitoring persons' health and fitness. The paper [16] stated that electrocardiogram-based EDR (electrocardiographically derived respiration) signal is used to determine the heartbeat and respiration of patients during apnea. Actual respiratory signals provide an accuracy of about 85%. Chest movement can be determined to monitor the breathing patterns of the patient. Other than that, movement of the chest can be used to detect the breathing phase. This pattern provides information on ontogenetic alteration [17]. The continuity is measured using the sleep duration of the patient, which consists of noninterrupt sleep phases. A person's physical movement during sleep can be measured with two important factors, which are termed as movement time (MT) and movement events (ME).
Polysomnography (PSG) is considered as the "medical gold standard" to monitor sleep stages and sleep patterns of a person [18]. PSG is conducted in a fully controlled atmosphere like a sleep lab. This method diagnoses several sleeprelated problems, which include breathing problems and sleep apneas. In PSG, sensors are attached to the patient's body. These sensors record psychological and biological parameters, i.e., brain activity, heartbeat, and oxygen saturation during sleep. The sleep monitor converts this sleep data into different sleep quality categories accordingly. PSG is limited to short-term sleep sensing since it is performed in a lab and thus may not be an accurate representation of a patient's typical sleep habits. The WatchPAT is easy-to-use device that can be moved easily. This device records Peripheral Arterial Tone (PAT) and nervous system signals during sleep. No lab is required in this sleep monitoring mechanism. Even though this device provides sleep apnea monitoring in our homes, but still this is not a very useful method, as a user has to wear the device at night. [19] EEG is known as an authentic sleep monitor, but there are also other sleep sensors available in the market, which are easy to use [20]. Sleep monitors such as Zeo measures sleep patterns by calculating the signals in the brain. These electrical signals provide information of the nervous system of a patient during sleep. This device consists of a headband that a user wears during the night, but there are also the chances of a sense of uncomfortable being felt by the user due to the sensors on the body during sleep [21]. To overcome this issue, several devices were introduced, which are less disturbing. The body movement of patients can be measured through an easy technique called actigraphy. This study provides the quality of sleep using body movement [5]. It is very easy to calculate the physical movement of a patient using an accelerometer [22]. Due to this reason, actigraphy is considered an easy method to calculate sleep 3 Journal of Sensors quality using different commercially available devices such as Fitbit and jawbone. Mobile phones can also be used to ease this process: all instruments, which are based on a built-in gyroscope. Continuously, monitored accelerometer records are categorized into different classes [23]. These classes are based on the type of study, for example, rotation, sitting, and twisting. However, the user has to carry a band while sleeping during which a mobile phone is also needed. Tracing only one physiological factor is also the disadvantage of this approach. This can cause the wrong result due to overrate or underrate values of some parameters of sleep such as sleep quality and sleep time [24].
It has been believed that the sound sleep could be monitored for grownups through actigraphy [25], but various limitations have been observed for use of kids, old peoples, and persons with sleep abnormalities. In modern research, community people are focusing more on noncontact sleep monitors, which work by obtaining the psychological and physiological parameters related to a person's sleep. In [26], Lullaby was introduced which monitors environmental factors that can affect the quality of sleep. The proposed system consists of several sensors that include the environmental sensors and physical movement recorders. In many pieces of researches, sensors were embedded in smartphones to perform the sleep monitoring. iSleep [27] records the patient's sound using a built-in microphone amplifier. These sounds include snoring patterns and the body's physical activity. Sleep Hunter introduced by Gu et al. [28] consists of a mobile phone. This smartphone is used to monitor the physiological and environmental factors to monitor sleep stages using a built-in microphone, accelerometer, and light sensor. Recording the sleep-related parameters can cause privacy issues as sleep is considered as a private activity [26].
Medical research shows that fundamental signals vary from person to person during sleep, which includes wakeful-ness, REM, and non-REM [29]. For this reason, respiratory signals and heartbeat parameters can be considered as signs of sleep stages evolution. Recently, developed sensors called Aura consist of a bed, which is pressure sensitive. This bed records the physical movements and biological parameters. However, a limitation has been seen in these kinds of sensors, as they are very costly and not easily available to use. Figure 2 outlines the comparison of various sleep sensing technologies [30][31][32][33].
In this research, a smart and intelligent sleep monitoring system has been proposed which monitors the patient's vital elements like a heartbeat, oxygen saturation, body movement, and snoring patterns. By detecting variations in vital signs, the proposed systems classify them into different sleep quality classes. The proposed system is efficient in terms of result accuracy and cost as compared to other devices and systems.

Design of Proposed System
The designed system is smart and intelligent enough that it has been used for the assessment of a person's sleep. Through this system, it can be identified that when a person is sleeping peacefully and when he is not peaceful. Using real-time data of patients, we can propose that whether a person had peaceful sleep or not. Ambient data of patients is recorded from sensors and then send to a computer system for storage and analysis. An algorithm called the random forest then analyzes the data. This algorithm intelligently classifies the data into five different categories. These categories are "peaceful, very peaceful, medium, un-peaceful and very un-peaceful." "Peaceful" means the patient is sleeping peacefully [34]. "Very peaceful" means the patient is getting very comfortable sleep. The "Medium" category means the patient is having normal sleep. The "Un-peaceful" category suggests that the patient is unpeaceful during sleep. The "Very un-peaceful"   Journal of Sensors category indicates the very restless sleep of the patient. The structural design of the projected system is shown in Figure 3 as given below.
The proposed system works with external sensors, which are communicating with a microcontroller. This is a threelayer architecture; in the first step, data is transferred from sensors to the Arduino microcontroller. In the second step, the Arduino microcontroller sends this data to the computer system. Data is stored in the file and used for training and testing of the classifier, which is trained with this data. After that, in a real-time environment, the patient's data is collected, and the system tells about the quality of sleep.
3.1. Data Collection from Sensors. The first step in this approach is to collect data from the sensors. This data includes the heart rate, SPO2 (peripheral capillary oxygen saturation), snoring detection, and accelerometer data. All sensors are connected to the microcontroller. The following Figure 4 shows how the system works in real-time.
The Figure 4 represents the hardware integration of the proposed system. The accelerometer and pulse oximeter are connected to the microcontroller. The microphone is also attached to the Arduino microcontroller, which serves as a basis for the whole system. The microcontroller is then attached to the computer system. The data recorded from sensors forwarded to the microcontroller. The microcontroller further sends data to the computer system. The computer processes the data using an intelligent classifier named as random forest. This model makes the predictions and presents the result to the user mobile.

Supervised Model.
In supervised modelling, we know the labels of input data. The whole data is being classified within the set of labels that are available concerning the data. Firstly, we train the algorithm with the input dataset, which is labelled data (training data). Based on this, we test the model using test data. The algorithm makes predictions appropriately on input data and estimates the ground truths iteratively until the desired level of accuracy is reached. The working of the model is explained in Figure 5.
In Figure 5, supervised learning model working starts with two values. One value is the original data, and second is its attribute. Attribute is the classified value (class) which is assigned to the instances. This data is further divided into two sets, i.e., training data and test data. This data is passed to the model builder which prepares the data for modeling.

Journal of Sensors
The supervised learning model is then applied to the data, and evaluation is performed on the data to generate the results. The evaluation shows the accuracy of the model achieved after training the model on training data.

Random Forest
Classification. Classification (grouping) is the process of assigning the values to different classes according to their properties and attribute values. A random forest is a supervised classification algorithm. It is composed of multiple decision trees. Randomly chosen subgroups of the training data and explanatory variables are used to train these models. These models work by making predictions using different prediction mechanisms. Mode or mean of the predictions of their subtrees is usually used to classify the values. Decision trees are more likely to overfitting than random forest because of the property that on its own no tree can obtain knowledge through all examples and informative variables. This means that all clatters during demonstration cannot be remembered by any single tree [35].
Decision trees are very popular for learning-based tasks in machine learning. Deeper trees are highly capable of learning the irregular patterns in data [36]. Training sets are overfitted in decision trees, which means that it has low bias and increased variance. Random forest model works by averaging the multiple deep trees, which are trained on diverse parts (groups) of the same training data [37]. The basic purpose of this is to minimize variance, which may result in a small rise in biasness and significantly boosts the performance in the resultant model. The actual working of decision trees is described in Figure 6.
In the above tree (Figure 6), the weather forecast is done using the decision tree model. All the relevant factors of weather are recorded, and the decision is made using the factors. If Outlook is sunny and Humidity is high, then the weather is not suitable to play a game, e.g., badminton. Similarly, if Wind is weak, then weather is good to play a particular game. Random forest involves a large number of individual decision trees that could work collectively in the model. For the distinct trees, random forest polls out a class estimate, and the class with the maximum votes develops our model's expectation (resultant value) [38].
The most significant concept behind this procedure is the knowledge of crowds. This means that the great quantity of moderately uncorrelated model (trees) functioning (as a group) will outperform any of the distinctive important models. The lower the association among these models developed, the higher the rate of accuracy of predictions.
Some trees can forecast values incorrectly, and several of them are precise; so with majority voting, trees done predictions in the right direction. Fundamentals for the random forest model to attain the correct precision are as follows: (1) There must be some given random features. Based on the features, models can be produced instead of arbitrarily predicting the values (2) There must be a very low association between models (trees) so that one incorrect calculation does not affect other model's (trees) predictions Specifically, a random forest uses the divide and conquers method for decision trees, which is useful on randomly fragmented subsections of data. The regular value of all trees is considered as the result of a regression problem whereas majority voting procedures are used in the classification problem. We can identify the parameters like leaf size, depth, and partition criteria in random forest classifiers in Rapid Miner [39,40]. The number of base trees can also be stated in Rapid Miner using the number of trees parameter. (1) Initially, random samples are selected from the specified dataset (2) For each sample, a decision tree is produced, and the result is predicted for each decision tree Random forest is an organization method, which creates relations between multiple tree predictors. This relation shows each tree depends upon the value of the vector, which is selected randomly. This random vector is scattered between all trees in the forest in the same manner. So, the basic mechanism is, a random vector say θ k is generated which is not related to previous random vectors. This random vector is distributed among all trees. Each tree is expanded based on the training set and vector θ k . It is a collection of randomly distributed classifiers which is denoted as fhðx, θkÞ, k = 1, ⋯g in which x is the input value which is to be classified [31].
Strength and correlation were two constraints to measure the correctness of each classifier and need between them. Random forest is created by obtaining the input values on each node. This random forest is based on random features. In the proposed methodology, the random forest model has 21 random subtrees. Every subtrees is accumulated together while considering five random classes (peaceful, very peaceful, medium, unpeaceful, and very unpeaceful). Random features and trees obtained the optimal results by considering the different values and features that are estimated by the model. Classification accurateness is used as a suitable fitting method. Consequently, 21 subtrees provided the finest precision results.

Performance Criteria of Random Forest Classification.
The performance of machine learning methods can be defined using different techniques. The most commonly used technique is to partition the complete data into different parts. We divided the data into three parts: training set, vali-dation set, and testing set. These sets were selected randomly. First of all, data is trained using the training dataset; classifier parameters are improved using the validation set, and lastly, unseen data is tested with this classifier. Errors and inaccuracies of the model were identified using the test data. Nowadays, this approach is not considered as accurate. Another reason is training samples are not so much demonstrative because there must be one class which have equally divided into portion in training and test set.
To overcome this problem, a more well-organized procedure is cross-validation. In this method, the multiple folds of data are produced, as these folds are slices of supplied data. These folds are used for training, testing, and validation of the model [32]. This process is repeated any number of times and in each training and testing elements of folds change. This process is repeated according to the number of folds defined [33]. In the proposed methodology, 10-fold crossvalidation was performed on data. In this, the dataset is distributed into 10 folds. Training and testing are performed 10 times; in each iteration, the model is tested with onefold from all folds called k. Model is trained with k-1 folds. After that, the mean accurateness of cross-validation is obtained with the following equation: In this equation (1), CVAE means cross-validation accuracy error rate, where k is the total number of folds and Ei shows test experiments of every fold [40].

Implementation Details
This cost-effective method for sleep analysis was executed in Rapid Miner. This system implemented in the lab practices the Arduino mega (2560) controller as a central microcontroller. This controller takes real-time records from sensors and forwards them to the random forest model in the computer system. This model is primarily based on the main computer that is attached to the microcontroller. A brief explanation of the sensors and techniques used in this sleep monitoring approach is below.

Hardware Used.
The projected sleep monitoring technology uses different sensors to collect data from the patient's body. For body movement, we used the ADXL345 accelerometer, which perceives the physical movement of the body. For the heartbeat and SPO2 level, we used a pulse oximeter and heart rate sensor module MAX30100. For snoring detection, we have used the MAX9814 Microphone Amplifier. Detail of these sensors is given below.

ADXL345 Triple Axis Accelerometer Module.
This sensor is used to perceive the physical body movement of a human being. It offers improved readings than other accelerometers. It is simple and easy to use. ADXL345 is a costeffective sensor that is easily available in the market. Figure 8 shows a picture of this module. The following are the main features of the ADXL345 sensor module.     Figure 9. Figure 10 shows picture of MAX30100 pulse oximeter.
The main features of the MAX30100 sensor are as follows.
(i) The design of this pulse oximeter consists of an incorporated LED, photo sensor, and analog system, which is high in performance (ii) It is small in size and easy to use (iii) A low power management system enables an increase in battery timing for wearable devices (iv) The sample rate in this device can be programmed according to the requirement for power saving 4.1.3. MAX9814 Microphone Amplifier. The MAX9814 is a cheap, first-class microphone, which provides the functionality of a low noise signal detection. This microphone amplifier module provides high sensitivity. This module support 20 to 20 kHz frequency. Besides, thanks to the MAX9814 amp, it implements a spontaneous expansion regulator, escaping irresistible and distortion of the amplifier when sound levels can change arbitrarily, as in the scenario proposed in this paper [20]. This microphone amplifier is good to use when audial data is required. This is useful when the audio frequency changes rapidly and changing the amp increase is not possible every time. The amount of data produced is 2 Vpp; hence, analog/digital conversion is easy with the MAX9814 module that ranges up to 3.3 V input. Figure 11 shows the amplifier module used in this study.
Main features of MAX9814 are as follows: (i) It has an automatic shut down on low power mode (ii) It is small in size which saves a lot of space while using (iii) It has an increased range of supporting temperature, which is -40°C to +85°C The research is being conducted in a small room with a usual temperature as shown in Figure 12, where the physical environmental variables are normal. Sensors are connected to the bed where the patient has been laid. The computer system is positioned near the person on which data is recorded in real-time. The patient's body movement, heartbeat, blood saturation level, and snoring patterns are recorded in this experiment.
Data of the patient is gathered on various days/nights during sleep; the model then calculates the result from collected data to anticipate whether a person sleeps peacefully or not. It also calculates the unpeaceful and very unpeaceful night sleep of a patient.

Results and Discussion
The result section shows that the system is working correctly without any physical damage and functioning well. The pulse oximeter and accelerometer obtain the correct readings and send the data to Arduino. This

Arduino and sensors
Results forwarded to the physician/doctor Record 1 LAN or internet Figure 12: Sleep monitoring experiment. 9 Journal of Sensors microcontroller communicates with the server and stores the data in it. The results were shown on the server computer as well as on mobile app.
This cost-effective technique of sleep monitoring is an intellectual system applied to the latest and inexpensive technology. This system uses intellectual decision-making random forest classification procedure. In the previous section, we have considered the implementation detailed with all hardware descriptions used the proposed sleep quality monitoring system. Now in the testing procedure of the system, we have employed the sensors (accelerometer, heartbeat oximeter, and microphone amplifier). Input data is collected from the patient and analyzed on the computer, as well as on the mobile so that doctors can take actions according to the given results.

Dataset.
For experiments, we have used day/night-time sleep data. This dataset consists of sleep patterns of day/night-time sleep patterns. This real-time data is initially divided into two random subsets. 2/3 part is used for training, and 1/3 was used for testing. This process is repeated 10 times so that 10 different datasets are obtained for training the model.
Our datasets shown in Table 2 contain three columns: one for dataset type, one for the number of instances, and one for classes. There are five different classes in which data is classified. This data is stored in an Excel file on the computer. The following table is being used for classification purposes. Table 3 shows classes of sound levels perceived by the microphone amplifier, the MAX9814. Table 3 shows various levels of sound during sleep. We have classified the data into five different categories according to their values. Pulse oximeter Max30100 gives values in the range of Bpm.
Heartbeat data shown in Table 4 is collected through pulse oximeter MAX30100 that provides numerical values in Bpm. As shown in the following Figure 13, the heartbeat against its values is plotted with red lines. Sound data provide a sound level of the patient during sleep. This data is collected during the day and night to observe the sleep pattern of patients. Day-and night-time sleep data are almost the same that is why it is considered as one in this study. There is not much difference seen in day and night sleep patterns. The following graph ( Figure 14) shows the sound data.
Accelerometer data consist of x-, y-, and z-axis. These axis values provide direction for the patient's movement during sleep. This data is collected while the patient is sleeping. A higher difference between these values shows that patient is moving too much during sleep and does not have peaceful night. The following graph ( Figure 15) shows accelerometer data.
The following graph ( Figure 16) provides the collective illustration of data which is collected from patients during sleep. It is an overall picture of data. Figures 17 and 18 show the classification of data in the bar graph. All sensors were originated for the experiment. Table 5 shows five different classes of sleep levels. These classes are peaceful, very peaceful, medium, unpeaceful, and very unpeaceful. A sample of data collected from all sensors is shown in Table 5: Table 5 shows the variety of collected data that is used in the research. The data acknowledged by sensors is standardized. Table 6 displays the standardized result of sensor data and the estimate done by the acclaimed random forest classification model.
Once the collected data is regulated, the random forest classification procedure is used to forecast the sleep quality of the patient using collected physiological constraints. Table 6 displays the structured output of the sensors' record and the results of the random forest classifier with the given accuracy of the classifier. This technique assures the accuracy of almost 95.67% as shown in Table 7.
The accuracy of the system is tested with two different datasets. This system delivers an accuracy of about 95.67%, which is the finest to measure the sleep quality of the patient. These results show that the use of a smart and intelligent method for monitoring sleep quality with low-cost sensors and technology helps the analysis to be very proficient. The proposed approach is reasonable as compared to other sleep quality monitoring technologies in terms of cost and accuracy. This methodology has the following creativities and specialties.
(i) This approach is cost-effective as compared to other technologies of sleep monitoring (ii) Random forest decision-making delivers as much precision as it is essential in the analysis procedure (iii) The results of the proposed sleep quality monitoring system show that our system is more capable and effective in determining the sleep quality    Table 7 shows the accuracy of the model after applying to real-time data. This accuracy is calculated using two different factors. Class precision and class recall are the two factors that help in analyzing the accuracy of the model.

Patient's Sleep Quality
Results. The proposed classifier will provide the results of the patient's sleep. These results will show the quality of sleep during day/night. The model will predict the quality and store the results in an Excel file. This file contains the overall sleep status of the patient.
In the above graph (see Figure 19), data of sleep is represented. This graph shows how many times a patient was        tion is calculated by finding the difference between true labels and predicted labels. As the true labels are manually derived by analyzing the whole data, so the following graph ( Figure 21) shows the number of true and false predictions made by the classifier.     14 Journal of Sensors

Mobile Application.
A small android app is also developed which shows the status of a patient's sleep quality. This app aids in effectively visualizing the sleep quality of the patient. Calculated results accessed by the app and shown in a pie chart will make it easy to know the overall sleep status of the patient. A screenshot of the app is shown in Figure 22. In Figure 22, the patient's sleep data is shown in a pie graph, as the graph depicts that patient's sleep data is categorized into five different classes. Sleep quality for that patient is peaceful as shown in the graph. The peaceful sleep has been represented in blue colour in this graph.

Conclusion
In this paper, the proposed system sensed the patient's sleep patterns using different sensors, which are cheap and easy to use. These sensors include an accelerometer, a pulse oximeter, and a microphone amplifier. This data transmitted through Arduino to the server for analysis and results with great effects and a small cost. These sensors were operated through the microcontroller. The heartbeat is calculated by placing the finger on it. These recorded values are stored in a computer system. Moreover, the results were shown on the computer screen as well as on a mobile phone.
To determine the human body movement, ADXL345 senses data and transmits to the receiving module which is a microcontroller. It transfers the data to the computer. The recorded data in the computer will be presented to a specialist or surgeon for advanced analysis to deliver better treatment.
The human voice was recognized for snoring detection. MAX30100 sensor is used which measure the voice to identify if a person has peaceful sleep or is feeling discomfort during sleep.
The intelligent random forest classification method was used for the classification and predictions of data. Results show that this classifier gives accurate results, which are far more reliable than other models. This intelligent and smart sleep quality monitoring system projects the sleep of patients into different classes with an accuracy of 95%. The researched result shows that the sleep monitoring system is accurate, user-responsive, consistent, inexpensive, and easy to use for monitoring patient's sleep with cost-effective technology.
The limitation of the proposed system is that it works with three sensors by assembling the four parameters, as more parameters help in better sleep pattern recognition.
In this study, three sensors were used with the Arduino microcontroller. In the future, more sensors will be used for this purpose, which will provide the results with greater accuracy. The following issues could also be highlighted for research in the future:  15 Journal of Sensors (i) A portable patient's sleep quality monitoring system can be proposed through wireless sensors and microcontrollers (ii) Raspberry Pie can be used in the replacement of Arduino for the independent working of the system, in which results could be shown on a mobile app

Data Availability
The datasets used in the experiments and discussed in the paper will be available if requited.