## 2 Materials and Methods
### System Description
#### 2.2.1 IEEE Agent
They are processed to obtain the relevant information (plethysmographic waveform, SpO2 value, ECG waveform, and HR). Then, data are encapsulated following the corresponding IEEE device specialization standard. The most relevant algorithms and new characteristics included in our system are described in the following subsections. _SpO2 Data Processing._ To acquire the SpO2 data, the DSP reads alternatively the R and IR values from SPI every 1 ms.  
A first-order IIR filter is used to remove the DC component. Then, a Hamming windowed 51 st order low-pass FIR filter removes unwanted frequencies above 10 Hz. The SpO2 percentage value is obtained from the ratio of the Root Mean Square (RMS) of the R and IR signals using a look-up table (LUT) every three heart beats. The pulse rate is detected using the filtered IR signal. The values of samples from the plethysmographic  
Figure 4: Example of connection establishment sequence between a manager and a SpO2 IEEE agent implemented in the iWRAP firmware. This figure shows the syntax and the order of the commands exchanged. waveform are calculated through a square root algorithm which provides a proportional value of the peak-to-peak signal. To provide a timestamp for the measure, we used the CSL to implement the RTC. Further details regarding the actual ECG implementation can be found in the TI Application Report SPRAB37A--June 2010 [24]. Once the SpO2 percentage value is calculated and its timestamp is obtained, the SpO2 value is compared with the threshold. Hence, if the mean SpO2 value is lower than 95%, the system generates an alarm. To avoid false alarms, we calculated the mean of the last 10 values of the SpO2 percentage. Moreover, the first four SpO2 values for each monitoring session were discarded to allow the signal to become steady. In that moment, and if the connection between the agent and the manager is already established, the system sends the last value of SpO2 and the timestamp through the UART peripheral to the Bluetooth, following the iWRAP syntax (Table 1). The UART peripheral is configured to work to 115,200 bauds, 8 data bits, no parity, and one stop bit. When the alarm has been sent, the system waits for the ACK from the manager. Previously, to send an alarm, the agent and manager had to establish the connection following the state machine defined in IEEE 11073-20601. The state machine defines the states and substates an agent and manager pair pass through. The agent implementation in the iWRAP 5.0, corresponding to the standard SpO2, manages it. A successful IEEE association is indicated to the DSP by an event message from the Bluetooth chip, and the agent will pass to the operating state. The message contains the channel and configuration identifiers of the IEEE configuration that the manager accepted. Then, the agent is ready to send data to the manager. If this state is not reached, the association with the manager has failed and the agent will pass to the unassociated state. ECG Data ProcessingAn interruption is generated every 2 ms in order to read ECG data from the SPI bus. The DSP digitizes nine channels with 24 bits of resolution. The first channel is the lead-off status. The eight remaining channels are passed through the same IIR filter as the SpO2 signal, to remove the DC component. Removing unwanted frequencies is achieved using a multi-band-pass filter, which consists of a FIR filter and notch filter at 50/60 Hz. Once the data is filtered, the DSP computes the remaining four leads. Then, a QRS detection algorithm is used to detect the R-peak and compute the HR. The QRS algorithm is applied over the lead II and consists of a variable threshold method [25]. The HR is calculated when five R-peaks have been detected. Further details regarding the actual ECG implementation can be found in the TI Application Report SPRAB36A--July 2009 [26]. To accomplish the medical requirements, data from the previous five minutes are stored in an external memory to assess for potential current events.