Contactless Respiration Monitoring Using Wi-Fi and Artificial Neural Network Detection Method

Detecting respiration in a non-intrusive manner is beneficial not only for convenience but also for cases where the traditional ways cannot be applied. This paper presents a novel simple low-cost system where ambient Wi-Fi signals are acquired by a third-party tool (Nexmon) installed in a Raspberry Pi and is able to detect the respiration time domain waveform of a person. This tool was selected as it uses 80 MHz bandwidth of the Wi-Fi signal and supports the latest implementations that are widely used, such as 802.11ac. A neural network is developed to detect the respiration frequency of the waveform. Generated waves emulating respiration waveforms were used for training, validating, and testing the model. The model can be applied to unseen real measurement data and successfully determine the breathing frequency with a very low average error of 4.7% tested in 20 measurement datasets.


I. INTRODUCTION
T HE traditional approaches for respiration detection require physical contact with the person being monitored.This is often inconvenient and uncomfortable for the person being monitored.Also, there are cases where monitoring is extremely challenging such as patients with compromised skin and increased risk of contamination from viruses in hospitals.Enabling non-contact continuous monitoring allows for high user mobility, reduced stress, better sleep monitoring and making domestic healthcare more feasible.It is then becoming very important to be able to monitor human vital signs in a contactless manner.
During breathing, air enters and exits lungs resulting in muscular contractions that cause chest wall displacement, described in Fig. 1.When air is inhaled, the chest moves outwards and The authors are with the Institute of Sensors, Signals and Systems, Heriot-Watt University, EH14 4AS Edinburgh, U.K. (e-mail: pk44@hw.ac.uk; s.ben_smida@hw.ac.uk; d.anagnostou@hw.ac.uk).
Digital Object Identifier 10.1109/JBHI.2023.3337001when air is exhaled the chest moves inwards again.Peak to peak motion due to respiration is about 4 -12 mm.The traditional approaches to measure breathing rate (BR) are usually limited to clinical usage as they have a high cost.These methods include a temperature sensor or attaching sensors to a patient such as a pulse oximeter, a spirometer or plethysmography with electrocardiograph (ECG) electrodes to diagnose certain lung conditions.According to [1], for healthy adults the normal respiration rates are between 12 and 20 breaths per minute, which is 0.2 Hz to 0.33 Hz.However, based on [2] for an infant until the age of 1, the respiration rate can be up to 55 breaths per minute, which is 0.92 Hz.
Real time monitoring systems that are used in clinical practice can be deployed in a home environment.However, this requires trained staff which is not practical and rather costly.Technological advancements have enabled wearable devices such as smartwatches or smartphones to use built-in microphones or accelerometers for sleep monitoring [3], [4], [5].They are required to be worn or close to a person when they are sleeping.Detection of snoring or body movements is feasible, nevertheless, the BR cannot be determined.Fitbit can record an average BR during sleep.The time between heartbeats shortens during inhale and increases during exhale.Fitbit uses the optical heart-rate sensor to track these small differences in the intervals and determine the BR while the person is asleep for at least 3 hours [6].
Non-contact methods have been proposed to avoid using intrusive wearable devices.These include pressure sensors [7] that can be attached to a mattress to track respiration during sleep that require professional installation, or the use of a camera 2168-2194 © 2023 IEEE.Personal use is permitted, but republication/redistribution requires IEEE permission.
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
which raises privacy issues.Other non-contact methods use radio frequency (RF) waves that are transmitted through the air and can be modulated by the chest movement caused by breathing.Consequently, the reflection signal can contain important information regarding vital signs.RF-based methods are mainly based on radars and Wi-Fi techniques.Wireless signals captured by Wi-Fi routers to monitor health information are particularly useful for this application.
In this paper, a simple, low-cost system that can capture Channel State Information (CSI) from a Wi-Fi network using a Raspberry Pi (RPi) 4 and the Nexmon tool is presented.The system is accompanied by a simple, shallow, artificial neural network to detect the frequency of a respiration waveform that is obtained by the Wi-Fi system.More specifically, a two-layer artificial neural network was designed and trained with digitally generated data -181 waveforms were used to train, validate and test the model.This generated data emulated BR rates spanning over a frequency range of 0.1 to 1 Hz.Next, the model is tested with previously unseen real respiration measurement data and is proven successful with an average error below 4.7% when compared to Fast Fourier Transform (FFT) peak-search method results.
The contributions of this work can be summarized in two main categories, one hardware based, and the other proposed methodology based.
i) The proposed system uses existing Wi-Fi signal to detect a person's respiration rate using widely available costeffective platform (RPi is about $80 as of 2022 and the Nexmon tool is an open-source firmware).The tools used can work with the newest Wi-Fi technologies, such as the 802.11a/n/ac.These Wi-Fi technologies operate at 80 MHz bandwidth.ii) The innovation from the methodology point of view is the extraction of the respiration doppler effect from the most relevant subcarriers in an OFDM modulated signal combined with the use of a trained neural network with a specifically designed "dummy" data.This shows that the training strategy emulated efficiently the characteristics of the Wi-Fi signal.

II. RELATED WORK
Radars have been used for vital signs detection since the 1970s [8].Doppler radar has been successful in BR and heart rate (HR) detection [9].Additionally, frequency modulated continuous wave (FMCW) radar has been used to detect BR and HR [10].However, radars need customized hardware that could be expensive and limit the range where a radar performs well.
Communication between two devices can be affected by movement.Wi-Fi techniques re-use the existing Wi-Fi network without the need of any other sensors or wireless infrastructure.Recently, IEEE 802.11 has become very popular due to low cost and the ability to use it not only for communication but also for positioning applications.The localization is achieved through distance-prediction-based techniques, which use the received signal-strength indicator (RSSI) measurements from an IEEE802.11 to predict the distance of a subject from an access point (AP).RSSI is coarse-grained information regarding the communication link.It is a single measurement of the total power over the whole channel bandwidth at the receiver that can also detect the BR.UbiBreathe [11] proposed to use RSSI to detect BR however there is a main limitation that the users have to keep the Wi-Fi device very close to their chest.Another approach to detect BR is described in [12] that requires additional dedicated sensor nodes.However, RSSI is easily varied by the multipath effect which is even more severe in indoor environments and monotonically decreases with increasing distance from the source.More recently, CSI has become popular to detect vital signs.Unlike RSSI, it is fine grained information [13] that can be extracted from commercial off-the-shelf (COTS) Wi-Fi network interface cards (NICs).
The logic behind using CSI signals to detect BR is based on processing the received signal.A transmitter transmits a wireless signal which travels in a straight line and finds the receiver, described as line-of-sight (LOS) propagation.A non-line-ofsight (NLOS) propagation is when an obstacle exists anywhere in this straight line, the signal will be reflected, diffracted, and scattered and it is known as multipath propagation.The received signal from these scenarios will have different CSI data.The breathing of a person which causes the chest to move, will change the NLOS paths, and a sinusoid-like pattern in the CSI values can be the result of that.
There are several available tools that have been developed over the last years that are able to capture CSI data, summarized in Table I .Linux 802.11nCSI Tool [14] was released in 2011 using Intel Wi-Fi Link (IWL) 5300 wireless NIC with 3 antennas.The Intel 5300 NIC can collect CSI for 20 MHz and 40 MHz channels.Specifically, for 30 out of the 56 groups of subcarriers for the 20 MHz channel and 114 carriers in the 40 MHz channel are used.Atheros-CSI-Tool [15] was released in 2015 and is an open-source 802.11n measurement and experimentation tool that enables extraction of detailed PHY wireless communication information from the Atheros Wi-Fi NICs.The resolution is 10 bits which a better than Linux 802.11nCSI Tool which uses 8 bits.Nexmon CSI Extractor Tool [16] was released in 2019, it is an open-source project that allows to extract Channel State Information (CSI) of OFDM-modulated Wi-Fi frames (802.11a/(g)/n/ac) on a per frame basis with up to 80 MHz bandwidth in both 2.4 GHz and 5 GHz bands on several Broadcomm Wi-Fi chips.CSI can be captured from off-the-shelf Wi-Fi devices and can lead to BR detection.
Most works are using the Intel Wi-Fi Link 5300 card to capture CSI with the tool described in [14] from wireless routers that operate mainly at 5 GHz.CSI data has made it feasible to successfully track BR and sleeping postures (SP) of one person.
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.

TABLE II SUMMARY OF WI-FI-BASED APPROACHES FOR BR AND HR EXTRACTION
Wi-Sleep [17] is the first monitoring system that achieved this.The work in [13] demonstrates an algorithm that uses CSI data in time and frequency domain to successfully detect BR of one or two people and heart rate (HR) of one person.CSI phase difference from different packets, subcarriers and antenna pairs was exploited in TensorBeat [18] that is capable of detecting BR of a single or multi person scenario.PhaseBeat [19] is considering the CSI phase difference data between two antennas of the receiver and is able to track BR and HR.TR-BREATH [20] proposed time-reversal (TR) technique that makes use of both CSI amplitudes and phases to monitor multi-person BR.CardioFi [21] presents a new technique for subcarrier choice and amplify the signal that leads to HR detection with 1.1 beats per minute (bpm) error.[22] shows that CSI data processing except BR, HR can also distinguish between sleep events and monitor SP.BreathTrack [23] deals with the phase offset performing conjugate multiplication of CSI from the two receiver antennas and is successful in BR detection.WiCovid [24] introduces the combination of advanced signal pre-processing and highresolution spectrogram to monitor BR and shortness of breath indicator of covid-19 patients who are self-isolating.CSI has also been used for gesture recognition by WiFinger [25] and human activity recognition [26].Table II summarises all the described work.
One of the main challenges in signal processing is the approximation of the frequency f of sinusoidal waves [27].This is used in many applications such as communications [28] and radars [29].Fourier Transform [30], least squares methods [31] and other techniques have been suggested as a solution.Artificial Neural Networks (ANNs) have been recently used successfully for many applications spanning from antenna design [32] to autonomous driving [33].The combination of ANNs and Wi-Fi signals has been recently explored in many applications.Gesture recognition [26], human presence detection [34], user behavior [35], sleep apnoea detection [36], sleep stages extraction [37] and even user verification [38] are some examples of recent research.
Authors in [37] use a single input multiple output convolutional neural network (CNN) to determine the heart rate (HR) and BR from CSI Wi-Fi data by taking advantage of the inner relationship between BR and HR.ResFi [39] utilizes a CNN to estimate the BR by inputting the waveforms of all subcarriers to the CNN.The CNN has two components, the feature encoder, which downscales the amplitude of the CSI data and the classifier, which extracts features.Therefore, in ResFi the respiration frequency extraction is treated as a classification problem and has an accuracy of 96.05%.ResFi collected data with only 6 different respiration rates.Our approach works for any breathing rate.
In this work, the Nexmon tool is selected to capture the CSI information to enable respiration detection for the first time.Compared to the other available tools, Nexmon supports the most modern and widely available wireless technologies such as 802.11ac with 80 MHz bandwidth.This additional frequency space and subcarriers could improve the accuracy of the BR detection.The tool needs to be installed on an RPi which supports these new technologies, and it is also an inexpensive solution.This is an improvement compared previous work where authors were obliged to use specific laptops/desktops equipped with the Intel 5300 NIC in order to install the Linux tool, for example in [18], [20].This is not necessary anymore with our system, thus providing additional freedom to researchers.One potential limitation in terms of data quality according to [26] comes from the fact that RPi uses one pair of transmit and receiving antennas.Additionally, apart from the proposed new implementation, this work investigates the suitability of neural network (NN) methods to process the measurement data.Here, an ANN is used as an alternative to extract autonomously the BR of a user directly from the sensed data obtained by the Wi-Fi system after the pre-processing.Results show that the NN approach achieves accurate BR detection with the advantage of not having to implement computationally intensive FFTs or potentially unreliable peak search methods.

A. CSI From WiFi
Wi-Fi (i.e., IEEE 802.11a/g/n) transmits and encodes data using orthogonal frequency division multiplexing (OFDM).This means that the total channel spectrum is partitioned into multiple orthogonal subcarriers on different frequencies.Each subcarrier is used to encode and transmit data independently.The hardware configuration used for transmitting and receiving as well as, the bandwidth of the channel, define the number of available subcarriers.Some subcarriers operate as guard carriers and not used in purpose to reduce interference [26].
CSI captures signal strength and phase information about the channel at the level of the subcarriers for each antenna pair [14].CSI is the frequency response of a communication channel and depends on the propagation environment.CSI data describe how a signal propagates from the transmitter to the receiver [40].Even slight disturbances in the environment can be identified using the CSI of the received Wi-Fi frames [41].Wi-Fi devices use this metric to evaluate the quality of their connection [26].Moreover, CSI represents combined effects of scattering, fading and power decay with distance [40].
For each channel in the spectrum, the device collects the measured phase and gain of the signal at each antenna [26].In each packet transmission, a vector of complex CSI values csi = a + bj, is obtained for each OFDM subcarrier instead of a single value RSS [40].
In the frequency domain, in a narrowband channel, the channel model can be expressed [19]: where x and y are the transmitted and received signals respectively and n is the additive white Gaussian noise.All terms are complex values.
CSI is different for each subcarrier.In a configuration with t transmit antennas and r receiving antennas for a transmission i, CSI can be represented as a matrix: H t,r represents a vector containing complex values for each subcarrier.If S is the number of the available subcarriers, a given H t,r pair can be expressed as: The complex number h s is generated for each subcarrier and can be expressed as: Therefore, the phase response θ and amplitude response |h s | of the subcarrier i can be extracted.
As indicated, CSI h s is a complex number that has amplitude and phase.CSI data is obtained from COTS Wi-Fi devices and there will be an unknown random offset in the extracted phase which varies from packet to packet [21].This is mainly caused by the asynchronous times and frequencies of the transmitter and receiver [18].CardioFi [21] proposed to subtract the phase measurements from the two antennas of the NIC card.
This leads to the removal of this undetermined offset as it will be the same for all the antennas due to the same system clock and same down converter frequency that is used on the same network interface card (NIC).Further signal processing was applied including outlier removal, de-trending, and de-noising to obtain the respiration waveform TensorBeat [18] deals with this problem by firstly obtaining the CSI phase difference between the pairs of antennas and then applies canonical polyadic (CP) decomposition that leads to the extraction of the breathing signal.Other works that are dealing with the phase offset have showed that at least two antennas for transmitting and two antennas for receiving are required.In this proposed work, the amplitude of the CSI is considered as the RPi has one antenna, as a result it is not feasible to subtract the data to eliminate the phase offset.Despite this limitation, i.e., only using magnitude information in the CSI, the proposed signal processing resulted in successful BR detection.

B. ANN
An Artificial Neural Network (ANN) is a computing system that is inspired by the biological neural networks.It consists of neurons, which are interconnected simple elements that represent a mapping.A perceptron is a simple network architecture in which the input layer is connected to the output layer with a linear relationship.A Multi-Layer Perceptron (MLP) is when more layers are added between the input and the output.The MLP is also called Feed Forward Neural Network (FFNN), where the signal goes from the input to the additional layer called hidden layer, in the weighted form [42].
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.As it is depicted in Fig. 2, the input nodes are combined in different ways to generate new features which are then used to predict the output.The weights (w) of the hidden layer are basically the connection between the nodes of the input and the neurons of the hidden layer.The hidden layer is taking the product of the input times the w and it is summing all those terms plus the bias (b) then it feeds that to an activation function.The activation function acts as an identity mapping so that the output will be in the same form as the input.All the neurons of the hidden layer are connected with some weights to the output.Then the output layer is going to predict the output of the model.
To ensure the ANN works for any previously unseen data, three datasets are required.A training, a validation, and a testing dataset.The training set trains the model, and the initial weights and bias are generated and optimized.Therefore, the model learns from the data at this stage.The validation set is the first unseen data that check the model at each step.The architecture of the model is optimized as well as other parameters are tuned to get the lowest possible error.The test dataset can be used to assess how well the model is performing on any unknown data and was not biased to work for the validation set.
In this project, the breaths per minute were found by estimating the frequency of the time-domain respiration waveform.This was achieved by training digitally constructed sinusoid signals that could represent various breathing frequencies.Prior work [27] reported only simulation results of the detection of the frequency of digitally constructed sinusoidal signals.In contrast, the presented model is validated successfully by testing it using real measurement data.The model has one input, the time domain waveform and one output, the frequency of this waveform and is 95.3% accurate.
The advantage of using ANN is that once trained, the ANN model can determine the frequency of any new input with high accuracy and faster estimation compared to traditional analytical methods.Additionally, an ANN has the potential to detect any anomaly in the data and issue health warnings contributing to prognosis.

IV. PROPOSED IMPLEMENTATION
The overall flowchart of the proposed implementation is shown in Fig. 3.Each part will be explained in detail in the following sections.

A. Wi-Fi System Overview
A person is seated in front of a router breathing normally as depicted in Fig. 4 in a similar testing setup as in [26].The data is captured at approximately 100 Hz sampling rate.This sampling  frequency is an estimation because the received packets may not be evenly distributed in time because of interference from devices that are on the same Wi-Fi channel.Next, the sampled data is imported to Matlab for further signal processing, presented in Section II.
The Access Point (AP) used in these experiments was a ZTE ZXHN H298A wireless router operating at a 5 GHz Wi-Fi network on channel 36 with 80 MHz channel bandwidth and maximum transmitted power 24 dBm (250 mW) for the 5 GHz frequency, which comply with the Federal Communications Commission (FCC) standards [43].Another laptop was used to generate traffic by sending ping commands to the AP at 0.01 s intervals.This ensures a sampling frequency of approximately 100 Hz.The reply of the AP consists of pong packets.The RPi captured the CSI data of the pong packets as they are sent.The CSI data carries information about the RF and physical disruptions between the AP and the RPi.
The RPi used is the 4B model with 8 GB RAM and is configured with RaspiOS Buster and Kernel version 5.4.Nexmon is installed with filter options: Channel 36/80, Core 1, NSS mask 1, MAC address filter set for the AP.The data collection is achieved with a laptop on the 2.4 GHz network to reduce interference.The laptop is connected to Raspberry Pi over SSH.
The Nexmon parameters are setup on the RPi to enable collection on channel 36 with 80 MHz bandwidth on the first core for the first spatial stream.The RPi has one core and one antenna.A filter is then applied to capture packets originating from the MAC address of the wireless network at 5 GHz.The CSI is collected by listening on UDP socket 5500 using tcpdump which allows the user to capture and display packets being transmitted or received through the network.There is one UDP packet per configured core and spatial stream for each incoming frame matching the configured filter.
By default, there are approximately 10 packets per second which sets the sampling frequency to about 10 Hz.This is adequate to capture the breathing and heart rate frequency as they are between 0.2 -2 Hz.However, for processing purposes and to improve the quality of the received data, the sampling frequency is chosen to be larger, 100 Hz.This is achieved with a separate device to generate traffic, i.e., ping requests are sent to the AP which replies with pong packets.The RPi then captures the CSI of the pong packets.Information about the disturbances between the AP and RPi is embedded in the CSI data.The PC is connected to the 5 GHz network and sends a ping flood to the router.A ping flood is when packets are sent continuously without waiting for replies.
The duration of the measurement is defined by the number of collected packets.For example, for a 40 s measurement and a sampling frequency of about 100 Hz, approximately 4000 packets need to be collected.
The router protocol modes for the 5 GHz network are Mixed 802.11a/n/ac.These modes divide the channel into OFDM subcarriers, each of which has a bandwidth of 320 kHz.Each subcarrier is used to transmit data independently.The data bits are distributed among the subcarriers by OFDM.Therefore, CSI will be different for every subcarrier as they transmit different data streams.Some subcarriers are reserved and remain empty to reduce interference and measure the channel.These are called pilot carriers.
There are bandwidth × 3.2 OFDM subcarriers per channel and one CSI sample for every subcarrier.Therefore, the CSI data is a matrix m × n, where m is the number of packets, and n the number of subcarriers.In this case n = 80 • 3.2 = 256.
1) Environment: Due to Covid-19 lockdown, the experiments were carried out in a flat with a single subject.The layout of the flat can be seen in Fig. 5 and the picture of the measurement setup is shown in Fig. 6.There were two more 5 GHz wireless networks operating at the channels 52 and 36.For all the measurements the doors were kept open, and the furniture in the same position.The AP, the RPi and the laptop that generated traffic were placed in the living room for all experiments.They were placed on two tables 80 cm over the floor and the distance between them remained unchanged.The laptop to collect data was placed in bedroom 1, at a distance of about 6 m.
2) Data Representation: The amplitude of the CSI data is affected by the Automatic Gain Control (AGC) on the wireless chipset [26].The ADC controls the gain of the received signal, hence there is a variation in the CSI amplitude when there are no changes in the environment.This affects the measurement data, especially since the movement of the chest is so small.
The RSSI value can be used to cancel the AGC.Authors from [40] used the following factor: to rescale the data, where RSSI is the received signal strength in mW and CSI i is the extracted CSI in the ith subcarrier.Therefore, the extracted CSI can be multiplied by a factor s to yield the original amplitude.The new version of Nexmon firmware provides the RSSI value, therefore, was used along with (5) to rescale the data off-line.The effect of the AGC is shown in Fig. 7 below.Fig. 7(a) shows the raw unscaled data of one subcarrier during a measurement when a person is seated in front of the router breathing normally.It is observed that the signal looks like noise, and it seems hard to identify a specific pattern.The same signal after scaling, is depicted in Fig. 7(b), where after observation, even in raw data, a sinusoidal-like periodic changing pattern over time is visible.The envelope of the waveform is added to the plot to highlight this.This is caused by breathing.Further data processing is necessary to acquire a clear respiration waveform.
The collected CSI data is then imported to Matlab for further processing, which takes place off-line.Only the amplitude of Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.the CSI data is considered in this application.The CSI is stored in matrix of 4000 × 256 element matrix .
The Hampel filter is used to suppress the strong abnormal amplitudes and also removes the impacts of invalid CSI data samples caused by the sensing or data transmission.For the Hampel filter the number of neighbors is chosen as 10 and the number of standard deviations by which a sample must differ from its local median to be considered an outlier is the default value 3. The smoothening filter smoothens the CSI data by taking the median over a 70-element sliding window.An example of the signal processing used in a single subcarrier is shown in Fig. 8.
The amplitudes of different subcarriers have different sensitivity to the small chest movements caused by breathing.Different subcarriers have different central frequencies and, therefore, different wavelengths.When combining this with the effect of  multipath with different frequencies, CSI at different frequencies will have different amplitudes [13].One way to select a subcarrier that is sensitive enough to detect the BR would be to plot the variance of the CSI amplitude of the subcarriers, as shown in Fig. 9.The pilot and null subcarriers have been removed and can be identified as having a variance of 0 in the plot.
The variance shows how each data point of each subcarrier differs from the average value.A higher variance means that the data are more spread in relation to the average and, therefore, are more sensitive to the small movements of the chest.This way, only one subcarrier is used to provide the results.However, using only one subcarrier might suffer from unsuspected variations in the propagation channel or some sort of unpredictable interference.Therefore, it is more reliable to exploit as much subcarriers as possible.
To make use of all the data that are available from the 256 subcarriers, another alternative is to use principal component analysis (PCA) technique which is a latent space projection method [24].PCA method will calculate a new set of variables called principal components that will be constructed by linear combinations of the variables with the highest contribution.The number of principal components generated by PCA will be the same as the original variables, in this case 256.PCA achieves data reduction and noise suppression [24].The PCA method allows the use of the first principal component as it represents the best choice.PCA method was applied to the previous measurement, shown in Fig. 10.It can be seen that the breathing is clearly detected in the form of a time-domain waveform resulting from a person's respiration.Fast Fourier Transform (FFT) is used next to determine the respirations per minute.The frequency resolution was set to 0.0005 Hz.A peak at 0.235 Hz is observed in Fig. 11 which indicates that a BR of approximately 8.5 breath cycles per minute is shown in the respiration waveform of Fig. 10.
To determine whether this sinusoid like pattern obtained by the Wi-Fi system is indeed caused by the breathing, a commercially available ECG sensor MAX-ECG Monitor was strapped in the chest.This sensor logs the linear acceleration data of the surface it is mounted on.Fig. 12 depicts the comparison between the CSI data as selected by the PCA method and the acceleration data from the wearable sensor.There is a strong correlation between the obtained results from the two independent measurements methods.This is also demonstrated in Fig. 13 where the FFT of the two plots is shown, with the same peak for the respiration frequency.
Multiple measurements were carried out varying the distance between the router and the person being monitored.The same processing was applied to all these measurements.The results suggest that the system is able to detect BR with at least 2 m distance.

B. ANN Model Overview
1) Data Preparation: An ANN is developed next as an alternative to determine the respiration frequency.In this case, the input of the model is the waveform selected by PCA and its output the estimated BR frequency.
Matlab was used to generate the waves that were the ANN's training, validation and test dataset.Specifically, a cosine wave was chosen, which can be defined as: where A is the amplitude, t is time and ϕ is the phase.The frequency f of this cosine wave needed to be determined by the ANN.Although the actual respiration waveform may not be an exact sinusoidal signal, information about how deep a breath is, and if there is a very small (superficial) inhalation, may be lost, however, in this work, we are interested in the number of breaths taken per minute.The sampling frequency of the generated waveform is set to 10 Hz and the duration of the entire waveform is 40 s.This means each wave is constructed by 400 points.The amplitude is set as A = 1 and phase ϕ = 0°(the input waves are normalized).The BR values chosen for this dataset was the presentative frequency window defined by 0.1 Hz ≤ f ≤ 1 Hz with a step of 0.005 Hz, yielding 181 frequencies.This frequency range is chosen because a breathing frequency is likely to be within this range, as described in the introduction.This means that the input data is a matrix 181 × 400.The output data is one column, which represents the frequency of each wave.
To assess the efficiency of the ANN model, the output is compared to the FFT outcome.The comparison is performed by calculating the error given by (7).The BR frequency obtained by the ANN is f AN N , whereas f F F T is the ideal result in case of generated waveforms and the peak search on the FFT in case of measurements.
2) Training Information: A shallow ANN was implemented in Matlab using the fitnet function to generate the network.In Matlab, the initial weights and data division for training, validation and testing are random.Therefore, each time the model was trained, the results could be different.To get the same results each time, the random number generator was initialized to the same state before training.
Calculations were performed on an Intel Core i5-8365U at 1.6 GHz processor, 16 GB of RAM.To prepare the data and train the model, the computer required about 5 mins.The prediction of the frequency in unseen data took about 1 s.The simulations Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply. of number of neurons up to 200 took about 24 h on a server with 12 cores and 128 GB RAM.
The training set included 72%, the validation dataset 18% and the test dataset 10% of the data.Here the activation function was sigmoid.The epoch stopped value is 15 when the validation criterion was met, and the learning rate is the default number of 0.01.The training function Levenberg-Marquardt was used, and the performance was measured by mean squared error (MSE).
To select the optimum number of neurons in the hidden layer, the model was trained for several cases: from 1 and up to 200 neurons in the hidden layer.The performance of the model was evaluated by calculating the root MSE (RMSE) of the difference between the true output and the predicted output for the training set and the validation set.The equation used is: The percentage of RMSE of the trained model with different number of neurons in the hidden layer is shown in Fig. 14.It is observed that the model performs well with an error below 10% for the validation set when a small number of neurons, five in this case, is used.
Although the validation error for up to 5 neurons is very small, when tested in real data the results were inconclusive and the error was inconsistent.This could mean that the model is overfitted, hence it fits exactly on the training data and does not perform well on unseen data.
The option of having two hidden layers was explored.Multiple combinations of neurons in the two hidden layers were tested.It was found that for this application an ANN with two hidden layers with [30], [2] neurons in the first and second layer Fig. 15.ANN model schematic.The input is cosine waves with 400 samples each wave.Each sample is an input node to the ANN.The model has two hidden layers with 30, 2 neurons in the first and second layer respectively.The output is one node, the frequency of the wave.Fig. 16.Respiration measurement example.The denoted peak is higher than the previous peaks, this would give a wrong frequency estimation.
respectively works best.A schematic of the proposed network is described in Fig. 15.
It is important that for the model to give accurate results the measurement data are processed to match as much as possible the training data.The training data being a cosine wave, will always start from a peak value.However, in a real measurement, the first point could be anywhere between 0 and 1 (in a normalized plot).Therefore, the first peak should be selected as the starting point.A second observation during testing the model was that if a peak following the first peak is higher in amplitude that could cause the ANN to give a wrong result.An example is shown in Fig. 16.Additionally, many Wi-Fi system measurements exhibit a trend that make it difficult for the ANN to detect respiration rates accurately.For example, Fig. 17 demonstrates a downwards direction of the periodic movement caused by breathing over time.This trend makes the data very different than the waveform used to train the ANN and leads to a large error.As the important feature is the breaths taken over time, a low order polynomial was fit on the signal to detrend it.The results are shown in the figure below Fig. 18.The detrend in the data significantly reduced the ANN detection error in all the measurement data.
The measurement data is captured at different rates than the one used to implement the ANN.Therefore, downsampling is required to match the dataset sampling frequency.Upsampling would be necessary in case the sampling frequency was lower   than the one used for the ANN model.Additionally, normalization is applied to resemble the generated waves used to train, validate and test the model.

V. APPLYING THE ANN TO MEASUREMENT DATA
To test the ANN with unseen data, a measurement was used that was obtained with the Wi-Fi system from a distance of 1.5 m.The original measurement was sampled at 100 Hz.The proposed method is shown in Fig. 19.
The measurement results obtained after all the pre-processing steps (Fig. 19) are shown in Fig. 20.
The estimated BR obtained with the proposed ANN-based approach is 0.159 Hz.The FFT of this measurement is shown in Fig. 21.The BR rate obtained by the classical method of peak search performed on the FFT is 0.155 Hz.
The benefit of the pre-processing is demonstrated in Table III.The error is calculated using (7).Applying the preprocessing steps reduced the error significantly leading to successful breathing frequency estimation.This could have been achieved with increasing the degrees of freedom of the dummy training data.However, this is yet to be tested and requires careful selection of the degrees of freedom to be explored  as this approach naturally biases the operation of the neural network.In [27] the "dummy" training data included noise with helped with improving the performance of the proposed neural network.Similar approaches would be interesting to try in future work.
The model was validated with at least 20 different measurement data captured from different distances and various breathing frequencies.It successfully determined the breathing frequency with an average error of 4.7% when comparing the Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.output of the ANN to the FFT output.Table IV shows some indicative measurements for various distances between the person being monitored and the router.It is evident that the proposed simple neural network is simple and successful for most of these measurements.It seems that the distance does not play a role in the efficacy of both the Wi-Fi system and the ANN.This can be explained by the normalisation step in the pre-processing algorithm; the measurement of longer distances results in lower magnitude of the received signal due to propagation losses including multipath.Key advantages are that a very simple ANN can estimate the frequency accurately and very fast and with very low computational cost, something that is increasingly of concern in modern deep learning networks that require huge computational resources.Our model is suitable for mobile devices that have low computational power and where battery lifetime needs to be maximized.
Nonetheless, there were a few unsuccessful measurements.These cases consisted of more than one person present in the room and one of them is moving, as well as when only one person is present but not reasonable static.This limitation is inherent to all the wireless radar based breathing systems.Whether there is a way to train an ANN to consider those scenarios, is still currently an open question and perhaps the research subject of future work.The proposed method cancels out the contribution of the data embedded in the OFDM Wi-Fi signal, and more analysis is required to quantify when detection fails.Also, the Wi-Fi proposed technique was not tested for a distance beyond 2 m and more work needs to be done to estimate the accuracy for these longer distances.

VI. CONCLUSION
In this paper, a non-contact low-cost system using ambient Wi-Fi to detect respiration was demonstrated.The system operates with at least 2 m distance.For the first time, the Nexmon tool was installed in an RPi 4 for the purpose of detecting respiration of a person, and its installation is straightforward.The advantage of this tool is that compared to other existing tools, Nexmon supports the 80 MHz bandwidth and the newest Wi-Fi technologies such as 802.11ac that most routers use nowadays.A neural network was implemented to define the BR of the respiration waveform.181 waves from 0.1 to 1 Hz were digitally constructed for training, validating, and testing the model.The network architecture and the data pre-processing steps were described.The model was rapid and efficient in finding the frequency of unseen real measurement data with a low error of 4.7%.The same network can be generalized for other frequency ranges, for example to determine the heart rate frequency, using a frequency range 0.75 to 2.5 Hz.In future work, this ANN can be further developed to allow for identification of anomalies in the detected waveform, detection of diseases and can be extended to issue health warnings, a step towards assisted living.

Manuscript received 14
September 2022; revised 28 March 2023; accepted 18 November 2023.Date of publication 28 November 2023; date of current version 7 March 2024.This work was supported in part by the H2020 Marie Skłodowska-Curie Individual Fellowship (MSCA IF-RI) under Grant 840854 (VisionRF), in part by the UKRI EPSRC IAA 2022 under Grant 1109680 VisionRF, in part by the Scottish Enterprise High Growth Spin-Out Programme under Grant PS7305103C, and in part by the UKRI ICURe Explore Programme under Grant NXW-EX-MAR23-01-Heriot-Watt, Vision-RF.(Corresponding author: Panagiota Kontou.)

Fig. 4 .
Fig. 4. High level system diagram: The AP transmits ambient Wi-Fi signal in the room and detects variations through the CSI data.

Fig. 5 .
Fig. 5. Layout of the environment -the experiments were conducted during the Covid-19 lockdown in a flat with a single subject.

Fig. 6 .
Fig. 6.Measurement setup corresponding to diagram of Fig. 4 taking place in the environment depicted in Fig. 5.

Fig. 7 .
Fig.7.Effect of data calibration on raw data measurement of respiration, (a) before calibration the signal looks like noise and no pattern is observed, (b) after calibration, a ripple like pattern is noticeable, which is caused by breathing.

9 .
CSI variance of each of the 256 subcarriers.

Fig. 11 .
Fig. 11.Frequency representation of this measurement that shows a peak at 0.235 Hz, which is the BR of this measurement.

Fig. 12 .
Fig. 12.Comparison of the chest movement (acceleration data) and the CSI data.

Fig. 13 .
Fig.13.FFT results comparison of the two methods, where the same peak for the respiration frequency is observed.

Fig. 14 .
Fig. 14.RMSE of the model for the validation and training set as a function of the number of neurons in the hidden layer.

Fig. 17 .
Fig.17.Original measurement data with decreasing trend: a downwards direction over time is observed.This can lead to a wrong frequency estimation.

Fig. 19 .
Fig.19.Detailed flowchart that depicts all the steps for the proposed methodology.

Fig.
Fig. Pre-processing steps applied to measurement data.

Fig. 21 .
Fig. 21.FFT of the measurement showing a peak at 0.15 Hz which is the breathing frequency.

TABLE III FREQUENCY
ESTIMATION FROM ANN AND FFT ON THE ORIGINAL AND CALIBRATED DATA

TABLE IV FREQUENCY
ESTIMATION FROM ANN, FFT AND THE ERROR FOR VARIOUS DISTANCES