## 2 Materials and Methods
### Chest Band's Firmware for Measuring the Breathing Parameters  
In this section, the operational modalities of developed firmware are discussed; these modalities are managed by the SAMD21G18A microcontroller board, the core section of the designed wearable system. Figure 5 shows the flowchart of the algorithm developed to extract the breathing parameters. The first step consists in declaring all variables and initializing the various communication interfaces (UARTs, I\({}^{2}\)C interfaces). A variable called startTime, initialized with current_time, is used to store the time the wearable device is activated. The _peakGood_ value indicates whether the peak detected by the piezoresistive sensor is due to respiration (set to 1 in this case) or other movements; T\({}_{\mathrm{w}}\) is the time window for RR estimation, set to 30 s. _peakCounter_ is the variable used to count the number of negative peaks in the time window, and is initially set to 0. At this point, the program enters an infinite loop to acquire the raw data; if less than 30 s have passed since the cycle start, the analog voltage is acquired from the piezoresistive sensor and digitally filtered by a second-order Butterworth filter with a 0.5 Hz cut-off frequency. Afterwards, the peak detector function analyzes the acquired signal and assigns them a value (\(-1\), 0, 1) depending on the signal value deviating from the moving average of more than a given z-score. If peak = \(-1\), _current_time_ is marked with t\({}_{1}\). The firmware flow enters into a cycle until the peak value is \(-1\), during which the data are acquired from the MPU-605Q IMU. In particular, we assumed that a relatively high acceleration value characterizes peaks attributable to body movements extraneous to breathing. Thus, the peaks provided by the peak detector algorithm are classified according to simultaneous acceleration values. Peaks recorded by the acceleration module (\(|a|\)) higher than a threshold are discarded from the counting of the inhalations. If \(|a|>a_{T}\), the peakGood flag is set false, where \(a_{T}\) is the threshold on the acceleration module, which attributes the peak to extraneous body movements and not to breathing. Figure 4: Front (**a**) and back (**b**) views of the developed piezoresistive band. Electronic sensing and conditioning with highlighting of the main components and modules (**c**). Figure 5: Flowchart of the breathing rate sensor’s firmware. Then, peak_time is stored and compared with peak_time_prev (previous peak time). If the following condition is met:  
\[peak\_time-peak\_time\_prev>\Delta\mathrm{T}_{\mathrm{threshold}} \tag{2}\]  
Then it means that peakGood is verified, and if true, the peakCounter is increased; this check is added to discard double negative peaks that may be detected in the breathing signal due to extraneous body movements. The above-mentioned time threshold was set to 1.6 s (empirically established value). The mean inhalation (TI\({}_{\mathrm{med}}\)) and exhalation (TE\({}_{\mathrm{med}}\)) times over the 30 s time window are calculated by measuring inhalation (TI) and exhalation (TE) times breath-by-breath. Particularly, these latter are evaluated by marking the starting instants of inspiration (t\({}_{\mathrm{1}}\)) and expiration (t\({}_{\mathrm{2}}\)), signaled with negative (\(-\)1) and positive (\(+\)1) peaks at the output of the peak detector algorithm and calculating the corresponding time difference. The inhalation time is calculated as the difference between the starting instants of inhalation (t\({}_{\mathrm{1}}\)) and exhalation (t\({}_{\mathrm{2}}\)): on the contrary, the difference between the starting instants of exhalation (t\({}_{\mathrm{2}}\)) and inhalation (t\({}_{\mathrm{1}}\)) gives the exhalation time. If peak = 1, _current_time_ is marked with t\({}_{\mathrm{2}}\); then, the firmware verifies that t\({}_{\mathrm{1}}\) and t\({}_{\mathrm{2}}\) have been updated (compares them with _t1_prev_ and _t2_prev_ values to avoid acquiring the same peak twice).