## 3 Materials and Methods  
In connection with the acquisition of the EEG signal, both medical equipment or low-cost sensors can be used for recording. The former ones often use twelve electrodes over the chest and limbs. These recordings are very accurate, but their portability is limited, making these devices unsuitable for WSNs. This equipment is commonly used in hospitals, and the subject must be at rest. With regard to low-cost sensors, only two or three electrodes on the chest or wrists are needed to capture the ECG traces. The signal can be a little noisy, but portability and integration into wearable devices (e.g., smart-watches or t-shirts [35]) make these devices very appropriate for WSNs: the wearer may be performing activities of her or his daily life; in other words, there is no need for the subject to be at rest. In our particular case, as a proof-of-concept, a low-cost ECG sensor (BITalino board with an ECG sensor [36]) was used for the acquisition of the ECG records. For this, three electrodes can be placed at the chest, but also at the palms of the hands. The aim of our contribution, taking advantage of the fact that some sensors in WSNs have the ability to sense heart signals, is to extract random numbers, which can be used for security purposes, from the above aforementioned signals. Once the raw ECG signal is acquired, pre-processing and randomness extraction by wavelet decomposition can be computed at the sensor itself or at the central node of the WSN that has greater computational and memory capabilities. Figure 2 shows all the necessary hardware, and the source-code is available in the following link to facilitate the reproduction of all the results (source code is available at these two links: [[https://goo.gl/WmQiiC](https://goo.gl/WmQiiC)]([https://goo.gl/WmQiiC](https://goo.gl/WmQiiC)) and [[https://goo.gl/TpvSQq](https://goo.gl/TpvSQq)]([https://goo.gl/TpvSQq](https://goo.gl/TpvSQq))). The signal pre-processing and randomness extraction procedure are described below. In detail, the ECG records have been cleaned using the following procedure (pre-processing procedure in Algorithm 1). Once the DC component is eliminated, a bandpass filter is used to remove two main noise sources. The lower and upper cut-off frequencies are fixed to 0.67 (to eliminate the noise caused by the respiration) and 45 Hz (to eliminate the power line noise), respectively. ```
1:procedurePreprocessing(\(ECG^{raw}\))
2: DC elimination
3: Bandpass filter (\([0.67-45 Hz]\))
4:procedureWaveletdecomposition(\(ECG^{cleaned}\))
5: Split \(ECG^{cleaned}\) into \(ECG-\)_windows_ (one heart-beat per window)
6:foreach ECG-window(j) do
7: Discrete wavelet decomposition (set parameters \(L\) and \(wf\))
8:procedureEntropyextraction(Wavelet coefficients of each \(ECG\)-_window_ (\(\{c_{i}\}_{i=1}^{N}\)))
9:foreach \(c_{i}\)do
10: Fractional part extraction (\(z_{i}\))
11: Output the 8-LBS bits (\(ri\)) \begin{table}
\begin{tabular}{c c c} \hline \hline
**Approximately** & **IPI-Based Approach** & **Optimal Values** \\ \hline Entropy & 7.957724 & 8 \\ \hline Optimum compression & 0\% & 0\% \\ \hline Chi square & 493.49 & 256 \\  & (0.01\%) & ([5–95\%]) \\ \hline Arithmetic mean value & 123.0993 & 127.5 \\ \hline Monte Carlo \(\pi\) value & 3.158811 & 3.14159 \\ \hline Serial correlation coefficient & 0.031878 & 0 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: ENT results (10-MB file with 4-LSB Inter-Pulse-Interval (IPI) values). For squeezing random values from the clean ECG trace, the following procedure (wavelet decomposition procedure in Algorithm 1) is proposed. The ECG record is split into windows that contain an R-peak (one heart-beat); for each ECG record, the first and last fifty windows have been discarded to guarantee that the signal is properly registered. Secondly, the approximation coefficients of each EGG window are obtained by wavelet analysis. Note that the discrete wavelet transform of a signal (\(x[n]\)) is computed by passing it through a low-pass filter (\(g[n]\)) and and high-pass filter (\(h[n]\)).