Breathing Monitoring and Pattern Recognition with Wearable Sensors

This chapter introduces the anatomy and physiology of the respiratory system, and the reasons for measuring breathing events, particularly, using wearable sensors. Respiratory monitoring is vital including detection of sleep apnea and measurement of respiratory rate. The automatic detection of breathing patterns is equally important in other respiratory rehabilitation therapies, for example, magnetic resonance exams for respiratory triggered imaging, and synchronized functional electrical stimulation. In this context, the goal of many research groups is to create wearable devices able to monitor breathing activity continuously, under natural physiological conditions in different environments. Therefore, wearable sensors that have been used recently as well as the main signal processing methods for breathing analysis are discussed. The following sensor technologies are presented: acoustic, resistive, inductive, humidity, acceleration, pressure, electromyography, impedance, and infrared. New technologies open the door to future methods of noninvasive breathing analysis using wearable sensors associated with machine learning techniques for pattern detection.

The creation of these wearable devices requires understanding the anatomy and physiology of the respiratory system. The knowledge about its structure and function leads to the development of devices that do not interfere with respiratory mechanics or daily life activities. It also allows selecting the best sensors in each case. Therefore, it is important to have an overview of the main types of electronic sensors used in recent years and how they have been applied, as well as signal processing and machine learning methods.
This chapter covers these topics concisely as a guide for people interested in developing wearable devices for respiratory monitoring. The next section introduces the anatomy and physiology of the respiratory system. The sections 3, 4, and 5 discuss, respectively, the electronic sensors, signal processing methods, and machine learning techniques applied to respiratory signals for pattern recognition.

Anatomy and physiology: mechanics of respiration
When one thinks of breathing, the airways and the airflow come to mind. Therefore, an understanding starting with the structures involved in this process is very important.

Respiratory system
The respiratory system consists of the following structures [12,13] (Figure 1): • Nose: nasal fossae; nasal cavity; pharynx (muscle tube); larynx (cartilage tube); trachea-bifurcates into two primary bronchi, which enter the pulmonary lobes, then subdivided into progressively smaller structures: bronchioles, ducts, and alveoli (where gas exchange occurs). • Airways: space from the nose to the bronchioles (where no gas exchange occurs). The structures up to the trachea are responsible for conducting, filtering, heating, and humidifying the air.
• Lungs: the principal organs of the respiratory system, surrounded by a membrane of connective-elastic tissue called visceral pleura. There are also the parietal pleura, which cover the thoracic cavity. Between them, there is pleural fluid, which contributes to respiratory mechanics.
Not only structures play an important role in respiration. Airflow direction delimits the breathing phases. Breathing comprises two steps. The first is the transport of oxygen (O 2 ) through inhalation, from the environment to the cells. The second is the transport of carbon dioxide (CO 2 ) from the intracellular to the environment. Breathing aims to supply the cells with adequate amounts of O 2 and withdraw CO 2 from the body to maintain homeostasis [13].
The lungs are positioned in an airtight space, and the oscillation of their pressure volume is the basis for respiratory control. The intrathoracic pressure is negative compared to the lung pressure. The lung functions as an elastic structure that resists deformation. The ability of the lung to expand is called compliance [14] and is expressed as Eq. (1).
Compliance requires a respiratory effort under conditions of normality. When compliance is reduced, more effort is demanded from the respiratory system, and, in more severe cases, it may lead to respiratory insufficiency.
Thorax compliance (C T ), lung compliance (C L ), and lung-thorax system compliance (C LT ) may be expressed by Eqs. (2), (3) and (4), respectively, according to [14]. Wearable Devices -The Big Wave of Innovation Breathing also involves air diffusion, exchange from a more concentrated to a less concentrated medium. Poiseuille's law governs the flow resistance as expressed by Eq. (5).
Where R is the flow resistance, L is the length, η is the viscosity of air, and r is the radius of the tubes. Figure 1 shows the main structures and processes involved in breathing.

Muscles involved in breathing and their functions
The diaphragm is the most important muscle of inspiration. When it contracts, there is a decrease in intrapleural pressure and an increase in lung volume [13]. Simultaneously, an increase in abdominal pressure is transmitted to the chest through the apposition zone to expand the lower thoracic cavity. When the diaphragm contracts, the lower rib cage expands. One may observe the bucket handle movement that causes an increase in thorax transverse diameter due to the elevation of the ribs during inspiration [15]. Elevation and sternum forward movement during inspiration causes the increase of thorax anteroposterior diameter. Diaphragm contraction also contributes to increasing the longitudinal thorax diameter [12].
Scalene muscle, sternocleidomastoid muscle, and intercostal muscle are inspiration auxiliary muscles. During forced expiration, the abdominal muscles contract, and the diaphragm is pushed upward, thus causing a decrease in chest diameters. Abdominal muscle is also important for coughing [16].

Different etiologies, types, and characteristics of pathological respiratory patterns
If structural and/or functional changes occur, then adequate air transport to and from the lungs can be compromised. There are different etiologies, types, and pathological respiratory patterns in which wearable systems may assist in the characterization of movement patterns [1]. This capacity helps in the analysis of the health condition of patients, providing important additional information.
Thoracic mobility is related to the integrity of the nerve pathways and respiratory muscles [13]. In clinical practice, thoracic and abdominal amplitude measurements during respiratory movement may provide information on changes in the respiratory system or eventual diseases [17]. Some paradoxical movements may occur when patients present weakness, muscle paralysis, or chronic obstructive pulmonary disease (COPD), with pulmonary hyperinflation, among other commitments [18]. Another example is Cheyne-Stokes breathing, which is a type of central sleep apnea with an unstable breathing pattern throughout the night. It can cause changes in respiratory frequency and depth of patients with congestive heart failure [19]. Other impairments may cause changes in the thoracic and abdominal mobility relation such as dyspnea, orthopnea, alternate breathing, forced expiration, etc. Wearable systems capable of monitoring the contribution of different muscles and changes in mobility patterns can help monitor the evolution of the respiratory functional condition of a person.

Pulmonary auscultation: sounds in healthy and diseased lungs
Lung sounds occur because of air turbulence in the larger airways [15,20]. They are the results of pulmonary vibrations and the respective airways transmitted to the thoracic wall. Sounds that occur during natural breathing differ depending on where they are acquired as well as the moment of the ventilatory cycle [20]. So, controlling where to place wearable devices and their sampling frequency and duration allows obtaining significant data from lung sounds.
Normal pulmonary sounds are classified into: • Tracheal sound: it is audible in the region of the trachea from cervical to sternal height, having an intense and tubular sound. Inspiration is slightly shorter than expiration, with a pause between events [21].
• Bronchial sound: it is audible in the region of the bronchi, at the height of the sternal manubrium, having less intensity than the tracheal sound. The duration of inspiration and expiration is similar, with a pause between events [22].
• Bronchovesicular sound: it is audible in the first and second intercostal spaces and between the scapulae. The duration of inspiration and expiration is similar, with no pause between events [22].
• Vesicular murmur: it is audible in the peripheral regions of the lungs, having less intensity than the bronchial sound. Inspiration is longer than expiration, with no pause between events [21].
The anatomical structures may influence the sound heard during normal breathing [21].
Pathological changes in the lungs directly affect the perception of lung sounds from the airways to the thoracic surface. Abnormal lung sounds, also called adventitious noises, are classified into: • Wheezing: it occurs with the oscillations of the bronchial pathways [22].
• Rhonchus: similar to snoring, it can be heard during inspiration and/or expiration [21].
• Crackles: they are discontinuous sounds, presented in a short and explosive manner, usually classified considering their duration and loudness, during the respiratory cycle [22].
There are other sounds and more details about each of them, and wearable systems contribute to distinguishing the different sounds in clinical practice.
The concepts presented in this section are very important for understanding the respiratory system in healthy and unhealthy conditions. Depending on the event one aims to observe, this information helps to identify the best location for sensor placement. It also contributes to a better interpretation of the respiratory signals obtained.
After this brief overview of the main concepts involving respiratory anatomy and physiology, the next section explains how wearable devices for respiratory monitoring have been made.

Respiratory wearable sensors
Wearable sensors for respiratory monitoring employ various types of electronic sensors that can be mounted into clothes [23], attached to belts [5,24], fixed on the skin [3,7], etc. There are many ways to make wearable devices and some of them are described separately by the type of primary sensor in the following sections.

Pressure sensors
We can take advantage of the events of diaphragm contraction (as shown in Figure 1b) and relaxation (as illustrated in Figure 1c) to create wearable devices based on pressure sensors. As an example, researchers have used an electromechanical film (EMFit) to develop a respiratory rate sensor designed as a belt [24] (as shown in Figure 2a). They attached the sensor to the belt so that the expansion of the chest during breathing applies a force to the sensor, and produces a voltage change proportional to this movement. EMfit is a capacitive pressure sensor that has a thin porous polypropylene film structure with a sensitivity of 30-170 pC/N.
Another way to use pressure sensors is to use them directly in contact with the inhaled and exhaled air pressure during breathing. The facemask introduced in [8] measures the respiratory impedance and was targeted to home and clinical applications. The solution consists of two pressure transducers, two low power consumption fans, a field-programmable gate array, and a real-time processing engine. The device is based on the forced oscillation technique (FOT), which is a nonstandardized lung function test. The idea is to use fans to input a periodic sinusoidal air pressure signal and measure the opposite force produced by the respiratory tract. With these data, respiratory resistance and compliance, as shown in Eq. (1), can be calculated and sent via Bluetooth to a smartphone (Figure 2b).
The EMFit sensor is less intrusive and performed well in the detection of respiratory rate. However, body movements affect the accuracy of the measurement, so the sensor only worked well for still or moderate moving patients [24]. The facemask sensor also performed well and estimated the respiratory impedance satisfactorily. Nevertheless, it was a prototype and its use was not comfortable [8].

Acoustic sensors
As seen in Section 2.4, it is possible to monitor lung sounds using acoustic sensors. Acoustic signals related to breathing are usually obtained with the sensors located close to the nose, mouth, throat, and suprasternal notch [3,25,26]. Figure 3a shows a wireless microphone that is a portable, cheap, and easy-to-use wearable device positioned next to the nose [3]. The purpose was to measure the respiratory rate in sleep. The microphone is fixed near the nose with a tape, and the signals are sent to a smartphone via wireless communication.
BodyScope was developed to record the sounds produced by the throat region in order to classify them into the following categories [25]: eating, drinking, speaking, laughing, and coughing. The developers modified a wireless headset attaching a microphone and a stethoscope chestpiece to minimize external source audio, as illustrated in Figure 3b. The position selected to place the sensor was close to the carotid artery region as indicated the preliminary test results. The device sends the audio signals to a computer or smartphone likewise solution shown in Figure 3a [3]. Figure 3c shows a real-time wheeze detector that consists of a wireless sound acquisition module, a wearable mechanical design and a host system [23]. The sensor module was an omnidirectional condenser microphone and a stethoscope bell.
A commercial repository of normal and abnormal lung sounds (referred to as the R.A.L.E lung repository) was used to implement and evaluate a wearable sensor that monitors lung sounds continuously for asthma attack detection [27]. The sensor is a microphone array for pre-filtered acoustic signal acquisition. It is an acoustic resonator array consisting of 13 paddle-shaped piezoelectric cantilevers. The results showed that accessing a repository to test for event detections did not hinder its application as a wearable system.  [24]; (b) system developed by [8] for respiratory impedance measurement based on the forced oscillation technique. Acoustic devices for respiratory monitoring: (a) a wireless microphone connected to a smartphone application [3]; (b) BodyScope system: Bluetooth headset attached with a microphone and a stethoscope chestpiece [25]; (c) a wireless acquisition module embedded into a wearable mechanical design [23] and placed over the right chest.
Acoustic wearable sensors can be very practical. However, some challenges are faced during the project design phase such as determining the optimal sensor position, canceling the acoustic ambient noise and the detection of movement artifacts. Depending on the setting, its use is not possible.

Humidity sensors
Wearable humidity sensors based on the porous graphene network (a chemical structure capable of detecting moisture) have been tested for breathing analysis [4]. The sensors are capable of sensing the human respiration, apnea, speaking, and whistle rhythm. The sensors are attached to the body with a facemask, as shown in Figure 4. The disadvantage of using this sensor is that long time use is also uncomfortable. It still needs some improvements to further commercialization.

Oximetry sensors
Oximetry is the technique used to measure oxygen saturation. It consists, basically, of a small infrared emitter that illuminates a small portion of the skin and a receiver that measures the light absorption depending on the oxygenated and deoxygenated blood levels [28]. Wearable oximetry sensors can be worn on the wrist, finger, head, earphones, earlobe, thigh, and ankle, and they have been widely commercialized [1] (Figure 5).

Acceleration sensors
Accelerometers can be used to capture the respiratory movements during inhalation and exhalation events [29]. An adhesive sensor (called BiostampRC®) made of a triaxial accelerometer that can be placed on the chest wall (Figure 6b) has been used [29].
Researchers adapted the EMFit-based sensor to evaluate MEMS (microelectro mechanical system) high-resolution capacitive accelerometers for the detection of respiratory rate at the same time [24]. They attached two monoaxial accelerometers to the belt as shown in Figure 6a.
A better signal can be obtained depending on the location of the sensor [30,31], because people may have disorders that affect muscle contraction during breathing [32], as seen in Section 2.3. Accelerometers have found application in many areas, recently, since sensors operate in a wide spectral range and have small dimensions   [33,34]. In spite of that, in the clinical setting, body movement seriously influences them [35]. The sensitivity can be set to measure vibrations with amplitude varying from gross body movements to small artery pulsation [36]. Therefore, likewise applications with acoustic sensors, unwanted artifacts have to be detected in order to prevent taking decisions based on contaminated lung signals [37]. The activation of synchronized functional electrical stimulation should consider these undesirable artifacts.

Resistive sensors
Another work used a textile sensor to detect talk events based on changes in breathing patterns [10]. The solution consisted of resistive stretch sensors that are made with a conductive material and a polymer mixture. These components were attached to three different belts: upper chest, lower chest, and abdomen as illustrated in Figure 7a. The events of thoracic or abdominal expansion and relaxation result in variation in the resistance of the stretch sensor with this sensor configuration. The idea is that the sensor can be directly integrated into the clothing in the future.
Piezoresistive sensors can also be used for the production of wearable devices. Figure 7b shows an example in which a smart textile fabric for respiratory rate monitoring was developed using a conductive piezoresistivity-based yarn garment [5].
Movement artifacts are also a problem for this kind of sensor. Researchers are working on improvements to incorporate these sensors in clothes and allow for activities such as running and cycling in the future [5,38,39].

Multimodal sensing platforms
Low-power multimodal wearable systems for the continuous monitoring of respiratory activity have been developed. Figure 8 shows a system with a sensing platform that consists of a chest-patch, a wristband, and a handheld spirometer [7]. Its aim is to monitor health and the environment for asthma management. The chest-patch measures electrocardiogram (ECG), skin impedance, photoplethysmography (PPG), movement, and acoustic signals. The spirometer can measure forced expiratory volume in 1 s (FEV1), peak expiratory flow (PEF), and forced expiratory capacity (FVC). The wristband sensors are intended to measure ozone exposure, ambient temperature, relative humidity, PPG, and movement. The idea is to create a system for continuous long-term monitoring of the state of health and the environmental factors relevant to respiratory problems such as asthma.
This brief overview revealed that different sensors can monitor the same respiratory event and there are different ways to apply them. The sensors discussed are not limited to the applications mentioned in this chapter; they can be used in many other applications and combinations. One of the most difficult tasks is to develop a respiratory wearable device that is low cost, low power consuming, and immune to movement artifacts other than the pulmonary ones.

Amplification
Some sensor signals have very low amplitude and need to be processed. The sensitivity of the EMFit, for example, is about 2.2-7 mV/mmHg. For signals so small, high-impedance voltage amplifiers must be used [24]. Multimodal system [7].

Filtering
Depending on the signal, filtering is advantageous for processing [40]. Filters are quite common in biomedical engineering applications to emphasize the spectral contents of electrophysiological signals [41]. There are signals with a well-known spectrum that researchers have extensively investigated. Once the frequency range of the signal is determined, an electronic circuit prevents unwanted energy from contributing to the processing and decision-making [42]. As an example, if the acoustic signal band frequency of interest of a solution is between 500 and 900 Hz, then a band-pass filter encompassing this spectrum is inserted into the circuit [43]. For each sensor, one filter should be placed.
Filters can be applied to minimize high-frequency noise, preserving the shape of the respiratory signal [29]. A band-pass filter with cutoff frequencies of 0.1 and 1.5 Hz was applied to compensate for possible drifts and to reduce the total noise level in the signals [10]. Table 1 shows some types of filters used by the researchers in this area.

Analog to digital processing
Despite the advances in digital technologies, we still live in a world full of analog phenomena and human physiology is no exception. Almost all electronic biomedical devices use some kind of quantity conversion, from analog to digital. The exceptions are those devices that work entirely in analog mode.
Key factors of analog to digital conversion need to be considered in order to understand the operation of mobile wearable devices. One factor relates to Claude Shannon's [46] and Harry Nyquist's theories [47]. The sampling theory helps to determine the acquisition frequency (or sampling frequency f s ) of analog signals. To digitize a pure sinusoidal wave properly, an acquisition frequency of at least twice the maximum frequency of the analog signal must be used. Knowledge of the spectral range is therefore crucial for determining f s .
Human electrophysiological signals are not purely sinusoidal so that the developers of biomedical systems should be far more conservative in determining f s . Knowing the maximum frequency of the bandwidth ( f max ) is useful, because the theory indicates to set f s at least twice that value ( f s ≥ 2 × f max ). In some cases, however, f s must be high enough to keep the signal's significant energy depending on the frequencies of interest. Acoustic sounds, for instance, revealed that signal power was mainly distributed below 5000 Hz [25]. The researchers, therefore, set f s = 22,050 Hz, which covers up to 11,025 Hz, because the range was considered enough for their application. Table 2 shows some of the sampling rates used.
Other equally important factors affect the quality of the acquisition, operation, and energy efficiency of wearable devices, such as the duration of acquisition, signal conditioning, conversion resolution, etc. However, these are not explored in this chapter.

Fast Fourier transform (FFT)
Fast Fourier Transform (FFT) is an algorithm that converts the signal from the time domain to the frequency domain and vice versa [40,48]. This algorithm is important because it is the first step to extract spectral features, which can be used by machine learning algorithms and other algorithms for signal processing.

Machine learning for respiratory signal pattern detection
Machine Learning is the result of pattern recognition and the assumption that computers can learn to execute a task. As a field of artificial intelligence, machine learning is the ability of a machine to learn, identify, and classify from being exposed to specific data in an interactive way, and to not only learn and make reliable decisions but also to adapt when exposed to new data. This technique can be useful for automatic pattern recognition in respiratory signals such as sleep apnea, respiratory patterns, and talking detection [10,49,50]. The steps to implement a machine learning algorithm are introduced in the following sections.

Feature extraction
First, for machine learning classification, some features must be given to the classification algorithm. These features must be extracted from the original signal, and they must be well chosen for better results.  Table 2.
Examples of sampling rates.
For example, when working with a wearable acoustic sensor [50] aiming to recognize activity patterns like sitting, eating, and drinking and respiratory patterns such as whispering, deep breath, and coughing, the features extracted from the sensor signals were related to time, frequency, and cepstral: • Time domain features: these features were obtained using the zero-crossing rate, that is, the rate of sign changes along a signal.
• Frequency domain features: to obtain these features, the FFT needs to be calculated. The features include total spectrum power, subband powers (summed power signal in logarithmically divided bands), brightness (frequency centroid), spectral roll-off (skewness of the spectral distribution), and spectral flux (L2-norm of the spectral amplitude difference of two adjacent frames, representing how drastically the sound changes between two frames).
• Cepstral features: commonly used for speech recognition and audio, the melfrequency cepstral coefficients are extracted with the application of a discrete cosine transform to the log-scaled outputs of the FFT coefficients filtered by a triangular band-pass filter bank.
It is also possible to use a tool that automatically extracts the features of the signals being studied. With the purpose of identifying talking in respiratory signals [10], more than 10 features were extracted using the Python library "tsfresh" [51]; those that presented more than 10% of recurrence between the tests were manually selected in order to use that feature for classification in the algorithm.
It is common to extract a variety of features in a study, but the effectiveness of a machine learning algorithm strongly depends on which one will be selected and how the data will be selected for training and validation.

Classification selection
After the selection of features to be used in the algorithm, it is important to decide which the classes are and how the data will be processed. It is important to select what will be used to train the algorithm and what will be used to validate it. There are several ways of separating the acquired data so that the network is trained without the risk of overfitting.
For instance, in Yatani and Tuong [25], two approaches were carried out: • "Leave-one-participant-out": they worked with 9 samples of data, training the chosen algorithm and using one participant to validate the results.
• "Leave-one-sample-per-participant": an example of each class of each participant was left out for validation and the rest used for training.
A different approach was used by Ejupi and Menon [10]: the data were obtained executing different activities such as walking, standing, and sitting, and an algorithm was trained for each one. For classification, 70% of the database was used for training and 30% for validation.
These techniques prevent the major problem in machine learning, overfitting [52]. In case an algorithm is overfitted, it will produce inaccurate results creating unrealistic patterns. It is always wise to select which data will be used to train the algorithm and which will be used to validate the results, never using all dataset to just one task. DOI: http://dx.doi.org/10.5772/intechopen.85460

Machine learning algorithms
The strategy or algorithm to be used in a project as well as its effectiveness and performance are strongly dependent on the problem domain (e.g., data structure, database size, etc.) [53]. It is therefore impossible to choose a method as the best one regardless of domain intricacies. Some popular machine learning algorithms are presented in the following topics.

Support Vector Machines
In order to identify speech pattern using a wearable textile-based sensor [10], the best results were obtained with Support Vector Machines (SVMs). The basic approach for SVM algorithms is to give a set of basic examples and their weight, generally understood as positive and negative (binary) examples for the algorithm, interpreted as classes, where there is a degree of similarity between them, a kernel function, as a means of comparison [52].
SVM was applied for identifying activities using an acoustic sensor [50]. They used more than two classes, comparing one against the other as a strategy to obtain results, using the Radial Basis Function (RBF) as a kernel function. All the implementation using a library "LIBSVM" [54] reaches almost 80% of accuracy.

Naïve Bayes
The Naïve Bayes algorithm can be used when it is necessary to recognize the user activities in real time [25]. The theorem is based on the Bayes statistical theorem that describes the probability of an event based on conditions or previous knowledge. The "naïve" comes from the naivety of the assumption that the results are independent given the cause [52].
From the Bayes' theorem, we have Eq. (6): where, P(A|B) is the probability that hypothesis A is true given data of type B. P(B|A) is the probability of data B given that hypothesis A was true. P(A) is the probability that A is true independently of data, and P(B) is the probability of data B regardless of the hypothesis.
The algorithm uses this probability structure to classify at least two independent sets, which can lead to another set of classification or decision and, at the same time, to another independent set. This algorithm is simple, computationally cost-effective and can be used for small datasets, as it was used to identify activity patterns such as speaking, laughing, and coughing, presenting good results of accuracy [25].

Artificial neural networks
An artificial neural network (ANN) is a technique based on a series of connected inputs and outputs. Its structure resembles neurons, each one connected and with associated weights. The weights represent information being used by the net to solve the problem and can be adjusted as required. The networks can be supervised or not, the fundamental difference is that in supervised learning, the target vectors indicate what is wanted from the network.
For example, the application of an ANN in talking [10,25] recognition through respiratory patterns [10] is of supervised learning as the targets to classify are provided to the algorithm.
The neural networks can also be more complex, which depends of the problems intricacies. Aiming to recognize activity patterns such as respiratory effort, using a wearable piezo sensor [25] it was applied networks with up to 17 layers and inputs, a very complex ANN, to achieve the best classification.
Overall, the use of machine learning has become increasingly common in health implementations and has proved a very beneficial tool in classifying and recognizing respiratory activities and patterns when combined with wearable sensors [10,25,55].

Conclusion
Wearable devices for breathing monitoring and pattern detection are not simple devices. They must not interfere with the respiratory system activities and need to be highly immune to external perturbations. The understanding of the respiratory mechanics is crucial to the development of wearable sensors, and to know how to connect them in an optimal way. The methods, whether manual processing or the use of machine learning algorithms, depend substantially on the type of the signal studied and are a crucial step for a study development.
© 2019 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/ by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.