An Approach towards Motion-Tolerant PPG-Based Algorithm for Real-Time Heart Rate Monitoring of Moving Pigs

Animal welfare remains a very important issue in the livestock sector, but monitoring animal welfare in an objective and continuous way remains a serious challenge. Monitoring animal welfare, based upon physiological measurements instead of the audio–visual scoring of behaviour, would be a step forward. One of the obvious physiological signals related to welfare and stress is heart rate. The objective of this research was to measure heart rate (beat per minutes) in pigs with technology that soon will be affordable. Affordable heart rate monitoring is done today at large scale on humans using the Photo Plethysmography (PPG) technology. We used PPG sensors on a pig′s body to test whether it allows the retrieval of a reliable heart rate signal. A continuous wavelet transform (CWT)-based algorithm is developed to decouple the cardiac pulse waves from the pig. Three different wavelets, namely second, fourth and sixth order Derivative of Gaussian (DOG), are tested. We show the results of the developed PPG-based algorithm, against electrocardiograms (ECG) as a reference measure for heart rate, and this for an anaesthetised versus a non-anaesthetised animal. We tested three different anatomical body positions (ear, leg and tail) and give results for each body position of the sensor. In summary, it can be concluded that the agreement between the PPG-based heart rate technique and the reference sensor is between 91% and 95%. In this paper, we showed the potential of using the PPG-based technology to assess the pig′s heart rate.


Introduction
Animal welfare remains a very important issue in the livestock sector, but monitoring animal welfare in an objective and continuous way remains a serious challenge. The continuous monitoring of autonomic nervous system activity in farm animals is now gaining considerable attention worldwide. The vagal component of the autonomic nervous system in the farm animals plays a key role in regulating heart rate (HR) in response to external and internal stressors [1][2][3]. Variables derived from cardiac activity are becoming increasingly important in research into animal health and wellbeing.
implementation and reliability of real-time monitoring applications [9]. Motion artefacts in signals are considered as manifestations of the relationship between motion and noise. Voluntary and involuntary movements of the interface between the sensor and tissue [11] are the main cause of motion artefacts. Furthermore, anatomical and morphological regional variations in the skin constitute another reason for the varying PPG signal quality. Many studies have been done to improve the PPG physical sensing components so as to decrease motion artefacts, yet more analysis is needed to determine which sensor location is the best for monitoring heart rates in animals. Recently, many studies (e.g., [9,12,13]) have focused on determining the clinical reliability of the PPG measurements and the optimal signal quality index (SQI) in assessing the PPG signals, especially for mobile health and real-time applications.
The present paper presents a proof-of-concept study, with the main goal of testing the possibility of using the PPG-based technique to assess a pig s heart rate and to determine the optimal location on the pig s body that gives the best PPG signal quality. Additionally, we also sought to develop a real-time monitoring algorithm to extract a pig s heart rate from a PPG signal, and to minimise the effects of motion artefacts.

Experimental Setup and Measurements
Over the course of this study, all measurements were conducted on a female Göttinger Minipig (test pig) under both anaesthetised and non-anaesthetised conditions. The test pig was born on 28.04.2017, with a 0.99 m back length (nose to tail) and weighing 30.2 kg on the day of experiments. The experiments were conducted in the Institute for Laboratory Animal Science, Hannover Medical School, Hannover, Germany. The measurements were obtained as part of a medical experiment to investigate and optimise liver cell transplantation. The original study and all measurements were ethically approved by "Niedersächsisches Landesamt für Verbraucherschutz und Lebensmittelsicherheit" (LAVES) (Germany; 33.12-42502-04-16/2374). Due to predefined planning in the ethical committee document, only one test pig was assigned for this study, which is considered enough for a proof-of-concept and pilot study.
Test on anaesthetised pig During this part of the experiment, the pig was anaesthetised to measure the baseline maximum liver function capacity prior to liver resection (LiMAx measurement). The test pig underwent a total period of anaesthesia of one hour. These baseline measurements are always taken 5 days before the operation. To anaesthetise the pig, Zoletil (Tiletamin and Zolazepam, each mg.kg −1 i.m.) and Atropine (0.04-0.08 mg.kg −1 i.m.) were used. The timing of this part of the experiment was 60 min after the awakening procedures of the anaesthetised pig took place. This time course of 60 min was divided into three time slots, 20 min each. For each time slot, the PPG sensor probe was placed on three different anatomical sight/locations of the test pig (Figure 1), namely ear, upper tail and left back leg (below the knee). These locations of the pig s body were chosen because of their higher cutaneous perfusion, and being a place where body fat is low yet still suitable to place the sensor probe in practice.
Sensors 2020, 20, x FOR PEER REVIEW 3 of 15 main cause of motion artefacts. Furthermore, anatomical and morphological regional variations in the skin constitute another reason for the varying PPG signal quality. Many studies have been done to improve the PPG physical sensing components so as to decrease motion artefacts, yet more analysis is needed to determine which sensor location is the best for monitoring heart rates in animals.
Recently, many studies (e.g., [9,12,13]) have focused on determining the clinical reliability of the PPG measurements and the optimal signal quality index (SQI) in assessing the PPG signals, especially for mobile health and real-time applications. The present paper presents a proof-of-concept study, with the main goal of testing the possibility of using the PPG-based technique to assess a pig′s heart rate and to determine the optimal location on the pig′s body that gives the best PPG signal quality. Additionally, we also sought to develop a real-time monitoring algorithm to extract a pig′s heart rate from a PPG signal, and to minimise the effects of motion artefacts.

Experimental Setup and Measurements
Over the course of this study, all measurements were conducted on a female Göttinger Minipig (test pig) under both anaesthetised and non-anaesthetised conditions. The test pig was born on 28.04.2017, with a 0.99 m back length (nose to tail) and weighing 30.2 kg on the day of experiments. The experiments were conducted in the Institute for Laboratory Animal Science, Hannover Medical School, Hannover, Germany. The measurements were obtained as part of a medical experiment to investigate and optimise liver cell transplantation. The original study and all measurements were ethically approved by "Niedersächsisches Landesamt für Verbraucherschutz und Lebensmittelsicherheit" (LAVES) (Germany; 33.12-42502-04-16/2374). Due to predefined planning in the ethical committee document, only one test pig was assigned for this study, which is considered enough for a proof-ofconcept and pilot study.
Test on anaesthetised pig During this part of the experiment, the pig was anaesthetised to measure the baseline maximum liver function capacity prior to liver resection (LiMAx measurement). The test pig underwent a total period of anaesthesia of one hour. These baseline measurements are always taken 5 days before the operation. To anaesthetise the pig, Zoletil (Tiletamin and Zolazepam, each mg.kg −1 i.m.) and Atropine (0.04-0.08 mg.kg −1 i.m.) were used. The timing of this part of the experiment was 60 min after the awakening procedures of the anaesthetised pig took place. This time course of 60 min was divided into three time slots, 20 min each. For each time slot, the PPG sensor probe was placed on three different anatomical sight/locations of the test pig ( Figure 1), namely ear, upper tail and left back leg (below the knee). These locations of the pig′s body were chosen because of their higher cutaneous perfusion, and being a place where body fat is low yet still suitable to place the sensor probe in practice. Test on non-anaesthetised pig (moving pig) Test on non-anaesthetised pig (moving pig) After about one hour (65 min) of applying the awakening procedure on the test pig, the PPG probe was placed on the left back leg (below the knee; Figure 2). Due to some practical difficulties we could not keeping a good contact between the PPG sensor and the skin of the pig s ear and tail because of the pig s movement. Then the test pig was allowed to move freely inside a test pen (Figure 2, right photo) with about 4.5 m 2 total surface area. The duration of the test was 60 min in total. During the whole period of the test, continuous medical and ethological observations were performed by the trained staff (Laboratory Animal Science, Hannover Medical School, Hannover). Throughout the test period, it was noticed that the pig was freely moving and playing, with no events of laying on the floor, drowsiness or stress. After about one hour (65 min) of applying the awakening procedure on the test pig, the PPG probe was placed on the left back leg (below the knee; Figure 2). Due to some practical difficulties we could not keeping a good contact between the PPG sensor and the skin of the pig′s ear and tail because of the pig′s movement. Then the test pig was allowed to move freely inside a test pen (Figure 2, right photo) with about 4.5 m 2 total surface area. The duration of the test was 60 min in total. During the whole period of the test, continuous medical and ethological observations were performed by the trained staff (Laboratory Animal Science, Hannover Medical School, Hannover). Throughout the test period, it was noticed that the pig was freely moving and playing, with no events of laying on the floor, drowsiness or stress. The PPG sensor is placed on the left back leg (below the knee) of the non-anaesthetised pig (left photo) and then the animal is allowed to move freely in a pen (right photo).

Measurements and Sensors
PPG signal A Shimmer Optical Pulse sensing probe (PPG sensor) together with Shimmer GSR+ module ( Figure 3a) were used to collect the PPG signal from the pig. The PPG signal is acquired at a sampling rate of 128 Hz. Gold standard (ECG signal) As a gold standard for heart rate measurements, continuous ECG measurements were performed. The ECG measurements were performed using a portable ECG recorder: BEAM ® ECG 3channels ( Figure 3b) Loop/Event recorder (IEM GmbH; Stolberg, Germany). It is an on-body portable ECG recorder, with three electrodes to stick on to the skin. The recorded ECG signal is automatically transferred from the BEAM ® via Bluetooth to a smartphone, and is forwarded from there to a secure database. The BEAM ® recorded the ECG data every 0.6 s.  After about one hour (65 min) of applying the awakening procedure on the test pig, the PPG probe was placed on the left back leg (below the knee; Figure 2). Due to some practical difficulties we could not keeping a good contact between the PPG sensor and the skin of the pig′s ear and tail because of the pig′s movement. Then the test pig was allowed to move freely inside a test pen (Figure 2, right photo) with about 4.5 m 2 total surface area. The duration of the test was 60 min in total. During the whole period of the test, continuous medical and ethological observations were performed by the trained staff (Laboratory Animal Science, Hannover Medical School, Hannover). Throughout the test period, it was noticed that the pig was freely moving and playing, with no events of laying on the floor, drowsiness or stress. The PPG sensor is placed on the left back leg (below the knee) of the non-anaesthetised pig (left photo) and then the animal is allowed to move freely in a pen (right photo).

Measurements and Sensors
PPG signal A Shimmer Optical Pulse sensing probe (PPG sensor) together with Shimmer GSR+ module ( Figure 3a) were used to collect the PPG signal from the pig. The PPG signal is acquired at a sampling rate of 128 Hz. Gold standard (ECG signal) As a gold standard for heart rate measurements, continuous ECG measurements were performed. The ECG measurements were performed using a portable ECG recorder: BEAM ® ECG 3channels ( Figure 3b) Loop/Event recorder (IEM GmbH; Stolberg, Germany). It is an on-body portable ECG recorder, with three electrodes to stick on to the skin. The recorded ECG signal is automatically transferred from the BEAM ® via Bluetooth to a smartphone, and is forwarded from there to a secure database. The BEAM ® recorded the ECG data every 0.6 s. Gold Standard (ECG Signal) As a gold standard for heart rate measurements, continuous ECG measurements were performed. The ECG measurements were performed using a portable ECG recorder: BEAM ® ECG 3-channels ( Figure 3b) Loop/Event recorder (IEM GmbH; Stolberg, Germany). It is an on-body portable ECG recorder, with three electrodes to stick on to the skin. The recorded ECG signal is automatically Sensors 2020, 20, 4251 5 of 15 transferred from the BEAM ® via Bluetooth to a smartphone, and is forwarded from there to a secure database. The BEAM ® recorded the ECG data every 0.6 s. Figure 4 shows the main steps of (pre-) processing methodologies to extract the pig s heart rate from the acquired PPG signals. The proposed algorithm consists of four main processing blocks. Each block is explained in detail in the following sections.

Signal Processing and Heart Rate Extraction
Sensors 2020, 20, x FOR PEER REVIEW 5 of 15 Figure 4 shows the main steps of (pre-) processing methodologies to extract the pig′s heart rate from the acquired PPG signals. The proposed algorithm consists of four main processing blocks. Each block is explained in detail in the following sections.

Pre-Processing of PPG Signals
The PPG signals are mostly affected by different sources of noise, such as surrounding lights and motion artefacts (in the non-anaesthetised case). Therefore, firstly, the signals are normalised to zero mean and unit variance [14]. Then, the normalised signals are filtered using a second order zerophase Butterworth high pass filter (cut-off frequency of 0.5 Hz) and a first order zero-phase Butterworth low pass filter (cut-off frequency of 6 Hz). These cut-off frequencies were chosen based on the expected physiological heart rate range. The Butterworth filter provides a maximally flat passband together with the zero-phase implementation which is preserving the pig′s cardiac wave. The second derivative of the PPG signal, also called the acceleration plethysmogram (APG), shows more defined peaks than those of the PPG signal, and can therefore be used as a more accurate detector of heart rate [15].

Wavelet Analysis and Cardiogenic Signal Reconstruction
In the medical and biomedical engineering fields, wavelet transform (WT) is often preferred over Fast Fourier Transform (FFT) in signal processing and the detection of cardiac waves. This is due to the fact that the physiological signals are naturally non-stationary, which makes WT a viable and powerful technique for biological and medical application. The wavelet transform is a suitable technique for analysing time series that contain nonstationary power at many different frequencies [16,17]. Using WT, the signals in the time domain are mapped onto the frequency domain in order to preserve both the time and frequency information. WT is a spectral estimation technique that functions by breaking a general function into an infinite series of wavelets [14].

Continuous Wavelet Transform Method
Generally, in the continuous wavelet transform (CWT) method, a specific wavelet centred around a given frequency is computed from the mother wavelet by scaling and shifting it. In this manner, the length of the wavelet contains the same number of centre (also called peak) frequency cycles. For a scale parameter, 0, and a position parameter, , which defines a translation of the wavelet and indicates the time localisation, the CWT can be given by: The wavelet analysis is performed by convoluting a signal, ( ), with a certain mother wavelet, (t). The * ( ) is the complex conjugate of the analysing mother wavelet. The term √ is an energy normalised factor (the energy of the wavelet must be the same for different values of the scale). As the scale, , increases, the wavelet is compressed, its spectrum dilates, and the peak frequency shifts to a higher value. Conversely, when decreases, the wavelet dilates, its spectrum is compressed and the peak frequency shifts to a lower value. In practice, the CWT is computed over a discrete value of the scale ' ′ in the range of continuous values. Thus, to approximate the continuous wavelet transform, the Equation (1) should be calculated times for each scale, where is the number of points in the discrete signal ( ) [17]. In general, the classic CWT transform is time-consuming and it requires too much computing power to be applied in real-time. Hence, more efficient algorithms

Pre-Processing of PPG Signals
The PPG signals are mostly affected by different sources of noise, such as surrounding lights and motion artefacts (in the non-anaesthetised case). Therefore, firstly, the signals are normalised to zero mean and unit variance [14]. Then, the normalised signals are filtered using a second order zero-phase Butterworth high pass filter (cut-off frequency of 0.5 Hz) and a first order zero-phase Butterworth low pass filter (cut-off frequency of 6 Hz). These cut-off frequencies were chosen based on the expected physiological heart rate range. The Butterworth filter provides a maximally flat passband together with the zero-phase implementation which is preserving the pig s cardiac wave. The second derivative of the PPG signal, also called the acceleration plethysmogram (APG), shows more defined peaks than those of the PPG signal, and can therefore be used as a more accurate detector of heart rate [15].

Wavelet Analysis and Cardiogenic Signal Reconstruction
In the medical and biomedical engineering fields, wavelet transform (WT) is often preferred over Fast Fourier Transform (FFT) in signal processing and the detection of cardiac waves. This is due to the fact that the physiological signals are naturally non-stationary, which makes WT a viable and powerful technique for biological and medical application. The wavelet transform is a suitable technique for analysing time series that contain nonstationary power at many different frequencies [16,17]. Using WT, the signals in the time domain are mapped onto the frequency domain in order to preserve both the time and frequency information. WT is a spectral estimation technique that functions by breaking a general function into an infinite series of wavelets [14].

Continuous Wavelet Transform Method
Generally, in the continuous wavelet transform (CWT) method, a specific wavelet centred around a given frequency is computed from the mother wavelet by scaling and shifting it. In this manner, the length of the wavelet contains the same number of centre (also called peak) frequency cycles. For a scale parameter, s > 0, and a position parameter, b, which defines a translation of the wavelet and indicates the time localisation, the CWT can be given by: The wavelet analysis is performed by convoluting a signal, x(t), with a certain mother wavelet, ψ(t). The ψ * (t) is the complex conjugate of the analysing mother wavelet. The term 1 √ s is an energy normalised factor (the energy of the wavelet must be the same for different s values of the scale). As the scale, s, increases, the wavelet is compressed, its spectrum dilates, and the peak frequency shifts to a higher value. Conversely, when s decreases, the wavelet dilates, its spectrum is compressed and the peak frequency shifts to a lower value. In practice, the CWT is computed over a discrete value of the  (1) should be calculated N times for each scale, where N is the number of points in the discrete signal x(t) [17]. In general, the classic CWT transform is time-consuming and it requires too much computing power to be applied in real-time. Hence, more efficient algorithms have been developed to reduce the required computational power and the time of CWT calculation (e.g., [18][19][20]).
In this paper, the CWT is calculated using fast Fourier transform (CWFT) [20], which allows us to compute the N convolutions simultaneously, which is more suitable for real-time applications. The CWFT algorithm implements the following steps: i.
Compute the discrete Fourier transform (DFT) of the analysed signal x(n), which includes N samples, using Fast Fourier Transform (FFT) as follows: where k is an index of frequency. ii.
Obtain the DFT (ψ) of the analysing wavelet (ψ) at the appropriate angular frequencies as follows: iii.
Obtain the DFT of the analysing wavelet ψ(n) at different scales.
To maintain a unit of energy for each scale s, the wavelet function is normalised by the following formula:ψ where ∆t = 1/ f s is the sampling period, with f s as the sampling frequency and ω k = 2πk N∆t . Compute the product of the signal DFT and the wavelet DFT over all the defined scales. Invert the DFT to obtain the CWT coefficients as follows: During the initial phase of processing, the aforementioned CWTFT algorithm is applied to decouple the cardiogenic pulsatile signals from the measured PPG signals based on various wavelets, namely non-analytical Mortlet, m-th order Derivative of Gaussian (DOG) Bump and Paul. Based on the initial signal processing of the acquired PPG signals from the pig, the m-th order Derivative of Gaussian (DOG) wavelets were chosen for the presented work because, in general, the obtained scalograms (scales "s" vs. positions "b") using these wavelets showed clear frequency contents within the expected pulse rate ranges of the different strains of pigs [7].
The Gaussian function is perfectly local in the time and frequency domains, and a derivative of any order (m) of the Gaussian function may be a wavelet transform (WT) since it is indefinitely derivable. A typical cardiac pulse event in the PPG signal consists of two modulus maxima with different signs of W s (s, b) (i.e., maxima and minima) [21]. Sahambi et al. [21] used a first order (m = 1) odd function ( Figure 5) to detect the QRS complex in the ECG signal. However, in our case here, the minima of the cardiac event in the measured PPG is found to be distorted in most of the cases. Therefore, only the maxima are used to compute the pig s heart rate (HR) from the measured PPG. Hence, in this paper, an even order (with order m = {2z : z ∈ Z}) derivative Gaussian (DOG) wavelet is used to decouple the cardiogenic (pulsatile) PPG signal using the CWTFT algorithm.
Three orders of the DOG wavelet, namely, m = 2, 4 and 6, were tested to investigate the most suitable one for computing the HR from the acquired PPG signals. The processing and analysis of the signals is done using custom script written in MATLAB (The Math Works, Inc., Natick, Massachusetts, USA) based on the Signal Processing and Wavelet Analyser toolboxes.

Signal Quality Indices (SQIs)
The perfusion index ( ) is presented as the gold standard in many research works (e.g., [9], [22][23][24]) for assessing PPG signal quality. In their work [9], Elgendi et al. used a statistical approach to find out the optimal SQI for the quality assessment of PPG samples out of eight different SQIs, of which the "skewness" index ( ) was said to perform best. Additionally, Krishnan et al. [25] found out that the skewness can be associated with corrupted PPG signals. In many science and engineering applications, signal to noise ratio ( ) is a standard measure that compares the level of a desired signal to the level of background noise, which can be a good indicator of PPG signal quality. In this paper, we used the three aforementioned signal quality indices, namely, perfusion index ( ), skewness index ( ) and signal to noise ratio index ( ) to assess the quality of the PPG signal acquired from different body locations of the pig. The used SQIs are defined as follows: • Perfusion index ( ) is defined as the ratio of the pulsatile signal component to the non-pulsatile or static blood flow in the peripheral tissue. In other words, it is the difference in the amount of light absorbed by the pulse when light is transmitted through the finger [9], which can be defined as follows: where ̅ is the statistical mean of the x signal (raw PPG signal), and is the filtered PPG signal.
• Skewness index ( ) is a measure of the symmetry/asymmetry of a probability distribution of the signal about its mean, which is defined as: where ̂ and are the empirical estimate of the mean and standard deviation of , respectively, and N is the number of samples in the PPG signal [9].
• Signal to Noise ratio ( ) compares the level of a desired signal (pulsatile cardiogenic signal) to the level of background noise [9], and is given by where σ is the standard deviation of the absolute value of the PPG signal (x), and σ is the standard deviation of the noise.

Signal Quality Indices (SQIs)
The perfusion index (P SQI ) is presented as the gold standard in many research works (e.g., [9,[22][23][24]) for assessing PPG signal quality. In their work [9], Elgendi et al. used a statistical approach to find out the optimal SQI for the quality assessment of PPG samples out of eight different SQIs, of which the "skewness" index (S SQI ) was said to perform best. Additionally, Krishnan et al. [25] found out that the skewness can be associated with corrupted PPG signals. In many science and engineering applications, signal to noise ratio (NS SQI ) is a standard measure that compares the level of a desired signal to the level of background noise, which can be a good indicator of PPG signal quality. In this paper, we used the three aforementioned signal quality indices, namely, perfusion index (P SQI ), skewness index (S SQI ) and signal to noise ratio index (SN SQI ) to assess the quality of the PPG signal acquired from different body locations of the pig. The used SQIs are defined as follows: • Perfusion index (P SQI ) is defined as the ratio of the pulsatile signal component to the non-pulsatile or static blood flow in the peripheral tissue. In other words, it is the difference in the amount of light absorbed by the pulse when light is transmitted through the finger [9], which can be defined as follows: where x is the statistical mean of the x signal (raw PPG signal), and X is the filtered PPG signal. • Skewness index (S SQI ) is a measure of the symmetry/asymmetry of a probability distribution of the signal about its mean, which is defined as: whereμ x and σ are the empirical estimate of the mean and standard deviation of x i , respectively, and N is the number of samples in the PPG signal [9]. • Signal to Noise ratio (SN SQI ) compares the level of a desired signal (pulsatile cardiogenic signal) to the level of background noise [9], and is given by where σ x is the standard deviation of the absolute value of the PPG signal (x), and σ noise is the standard deviation of the noise.

Peak Detection and Heart Rate Calculation
In general, the heartbeat could be estimated by calculating the time between the peak intervals in the PPG signal. The peak is detected by calculating the local maxima of the decoupled cardiac pulse signal X(n) within a predefined interval (window) I, so that by finding n o ∈ I we fulfil that X(n o ) ≥ X(n), ∀n ∈ I The algorithm then repeats the procedure of the tallest peak and iterate until it runs out of considerable peaks.
The heart rate in bpm is calculated based on the number of detected peaks within a sliding time window or an epoch of one minute, with 30 s (50%) overlap ( Figure 6).

Peak Detection and Heart Rate Calculation
In general, the heartbeat could be estimated by calculating the time between the peak intervals in the PPG signal. The peak is detected by calculating the local maxima of the decoupled cardiac pulse signal ( ) within a predefined interval (window) I, so that by finding ∈ I we fulfil that ( ) ( ), ∀ ∈ I The algorithm then repeats the procedure of the tallest peak and iterate until it runs out of considerable peaks.
The heart rate in bpm is calculated based on the number of detected peaks within a sliding time window or an epoch of one minute, with 30 s (50%) overlap ( Figure 6).

Decoupling of the Pulse Wave in the Anaesthetised Pig
All the measured PPG signals obtained from the ear, leg and the tail of the anaesthetised pig are divided into segments of 60 s (i.e., 2560 data samples) to be processed individually. After the preprocessing step (see Section 2.2.1), the continuous wavelet transform of each segment is computed using the CWTFT algorithm. The most tricky steps in decoupling the cardiogenic pulse wave using CWT are, first, choosing the optimal suitable set of scales ( ), and second, choosing the suitable mother wavelet.

Scales Selection
The scale ( ) parameter is the set of real powers of 2, i.e., = 2 { ∈ ℤ}. The suitable set of scales should contain most of the energy of the cardiogenic pulse wave. We found that the energy of the cardiogenic pulse signals, in all the PPG segments, is dominated by the scales between 2 . and 2 . . Therefore, a set of five scales (s), namely 2 . 2 . 2 . 2 . 2 . , is chosen for the wavelet calculation. An example scalogram showing the distribution of the calculated CWT coefficients, using the fourth order DOG wavelet, over the chosen set of scales is depicted in Figure  7.

Decoupling of the Pulse Wave in the Anaesthetised Pig
All the measured PPG signals obtained from the ear, leg and the tail of the anaesthetised pig are divided into segments of 60 s (i.e., 2560 data samples) to be processed individually. After the preprocessing step (see Section 2.2.1), the continuous wavelet transform of each segment is computed using the CWTFT algorithm. The most tricky steps in decoupling the cardiogenic pulse wave using CWT are, first, choosing the optimal suitable set of scales (s), and second, choosing the suitable mother wavelet.

Scales Selection
The scale (s) parameter is the set of real powers of 2, i.e., s = 2 a where {a ∈ Z}. The suitable set of scales should contain most of the energy of the cardiogenic pulse wave. We found that the energy of the cardiogenic pulse signals, in all the PPG segments, is dominated by the scales between 2 0.16 and 2 0.50 . Therefore, a set of five scales (s), namely 2 0.16 2 0.21 2 0.28 2 0.38 2 0.50 , is chosen for the wavelet calculation. An example scalogram showing the distribution of the calculated CWT coefficients, using the fourth order DOG wavelet, over the chosen set of scales is depicted in Figure 7.

Mother Wavelet Selection
As explained earlier, even order (with order = {2 ∶ ∈ ℤ}) derivative Gaussian (DOG) wavelets are chosen to calculate the CWT of the PPG signals. In particular, three orders of the DOG wavelet, namely, = 2, 4 and 6, are tested. In the Fourier domain, the m-th order derivatives of Gaussian wavelets, DOG, are defined by: where Г denotes the gamma function. For each PPG data segment obtained from the ear, leg and the tail of the anaesthetised pig, the CWT are computed using the CWTFT algorithm, using DOG wavelets with the three selected orders. Figure 8 shows an example of the decoupled cardiac pulse waves using the CWTFT algorithm and the three DOG wavelets (second, fourth and sixth order DOG wavelets) from one segment of PPG signal obtained from the ear of the anaesthetised pig. Based on the decoupled cardiac pulse waves, resulted from the CWTFT algorithm, the pig′s heart rate (bpm) is computed using the peak detection algorithm. The estimated heart rate from the PPG signal is compared with the ground-truth heart rate (reference), which is calculated from the gold standard ECG signal. The performance of the developed algorithm is then evaluated in terms of the quality of the pulse rate estimation, which is assessed using the Mean Absolute Error (MAR) and the Root Mean Square Error (RMSE), which are given as follows: where is the total number of data points, and ( ) and ( ) are the estimated heart rate from the PPG signal and that calculated from the ECG, respectively, at time instant . RMSE is more sensitive to large estimation errors than MAE, so a small number of large errors results in high RMSE and low MAE. Table 1 shows a comparison of the estimated heart rate (HR) using three DOG wavelets (second, fourth and sixth order DOG wavelets) based on the MAR and RMSE values calculated for each PPG segment obtained from the anaesthetised pig. The results show that there are

Mother Wavelet Selection
As explained earlier, even order (with order m = {2z : z ∈ Z}) derivative Gaussian (DOG) wavelets are chosen to calculate the CWT of the PPG signals. In particular, three orders of the DOG wavelet, namely, m = 2, 4 and 6, are tested. In the Fourier domain, the m-th order derivatives of Gaussian wavelets, DOG, are defined by: where Г denotes the gamma function. For each PPG data segment obtained from the ear, leg and the tail of the anaesthetised pig, the CWT are computed using the CWTFT algorithm, using DOG wavelets with the three selected orders. Figure 8 shows an example of the decoupled cardiac pulse waves using the CWTFT algorithm and the three DOG wavelets (second, fourth and sixth order DOG wavelets) from one segment of PPG signal obtained from the ear of the anaesthetised pig. Based on the decoupled cardiac pulse waves, resulted from the CWTFT algorithm, the pig s heart rate (bpm) is computed using the peak detection algorithm. The estimated heart rate from the PPG signal is compared with the ground-truth heart rate (reference), which is calculated from the gold standard ECG signal. The performance of the developed algorithm is then evaluated in terms of the quality of the pulse rate estimation, which is assessed using the Mean Absolute Error (MAR) and the Root Mean Square Error (RMSE), which are given as follows: (HR PPG (n) − HR ECG (n)) 2 (11) where N is the total number of data points, and HR PPG (n) and HR ECG (n) are the estimated heart rate from the PPG signal and that calculated from the ECG, respectively, at time instant n. RMSE is more sensitive to large estimation errors than MAE, so a small number of large errors results in high RMSE and low MAE. Table 1 shows a comparison of the estimated heart rate (HR) using three DOG wavelets (second, fourth and sixth order DOG wavelets) based on the MAR and RMSE values calculated for each PPG segment obtained from the anaesthetised pig. The results show that there are significant (p < 0.05) differences in both the MAR and RMES values for all the estimated HR values using the second order DOG wavelet and those estimated using the fourth and sixth order DOG wavelets. The results did not show a significant difference between the fourth and sixth order DOG wavelets in either the MAR or RMES values. As such, the fourth order DOG wavelet is suggested to decouple the cardiac pulse signals from the measured PPG using the CWTFT algorithm.
decouple the cardiac pulse signals from the measured PPG using the CWTFT algorithm.

Assessment of PPG Signal Quality
To assess the signal quality of each segment of the measured PPG signals obtained from the ear, leg and the tail of the anaesthetised pig, the cardiac pulse waves were decoupled using the CWTFT algorithm based on the fourth order DOG wavelet. Then, specific SQIs, namely perfusion index ( ), skewness index ( ) and signal to noise ratio index ( ), were computed for each segment and compared. Table 2 shows the three calculated SQI values of the PPG signals obtained from different pig body positions (ear, leg and tail) under both anaesthesia and no-anaesthesia conditions.

Assessment of PPG Signal Quality
To assess the signal quality of each segment of the measured PPG signals obtained from the ear, leg and the tail of the anaesthetised pig, the cardiac pulse waves were decoupled using the CWTFT algorithm based on the fourth order DOG wavelet. Then, specific SQIs, namely perfusion index (P SQI ), skewness index (S SQI ) and signal to noise ratio index (SN SQI ), were computed for each segment and compared. Table 2 shows the three calculated SQI values of the PPG signals obtained from different pig body positions (ear, leg and tail) under both anaesthesia and no-anaesthesia conditions. The overall accuracy of the heart rate (HR) estimation algorithm is calculated for the PPG signal obtained from the ear, leg and the tail of the anaesthetised pig ( Figure 9). The developed HR estimation algorithm is able to detect the heart rate from the pig s ear, leg and tail with overall accuracies of 91%, 92.4% and 93.2%, respectively.  The overall accuracy of the heart rate (HR) estimation algorithm is calculated for the PPG signal obtained from the ear, leg and the tail of the anaesthetised pig ( Figure 9). The developed HR estimation algorithm is able to detect the heart rate from the pig′s ear, leg and tail with overall accuracies of 91%, 92.4% and 93.2%, respectively. Figure 9. Estimated heart rate from PPG signal vs. heart rate from the gold standard (ECG) measured from the anaesthetised pig′s ear (a), the leg (b) and the tail(c). Figure 9. Estimated heart rate from PPG signal vs. heart rate from the gold standard (ECG) measured from the anaesthetised pig s ear (a), the leg (b) and the tail(c).

Heart Rate Estimation Based on Measured PPG From the Non-Anaesthetised (Moving) Pig
Due to the practical difficulty, we could not keep a good contact between the pig s ear and the PPG sensor during the pig s motion. Furthermore, to avoid the problem of tail biting, one of the largest animal welfare problems in modern pig production [26,27], attaching the PPG sensor to the pig s tail is avoided. Hence, for the non-anaesthetised (moving) pig, PPG measurements are only obtained from the pig s leg. The cardiac pulse waves from the moving pig are decoupled from the PPG signal using the CWTFT algorithm based on the fourth order DOG and the selected scales. The raw PPG signal showed more baseline wander and noises, which can be attributed to motion artefacts. However, the developed algorithm is successfully able to decouple the cardiac pulse waves (Figure 10). It is observed that most of the energy of the motion artefacts and baseline drifts increases for scales s > 2 0.55 , corresponding to frequencies <0.78 Hz.

Heart Rate Estimation Based on Measured PPG From the Non-Anaesthetised (Moving) Pig
Due to the practical difficulty, we could not keep a good contact between the pig′s ear and the PPG sensor during the pig′s motion. Furthermore, to avoid the problem of tail biting, one of the largest animal welfare problems in modern pig production [26,27], attaching the PPG sensor to the pig′s tail is avoided. Hence, for the non-anaesthetised (moving) pig, PPG measurements are only obtained from the pig′s leg. The cardiac pulse waves from the moving pig are decoupled from the PPG signal using the CWTFT algorithm based on the fourth order DOG and the selected scales. The raw PPG signal showed more baseline wander and noises, which can be attributed to motion artefacts. However, the developed algorithm is successfully able to decouple the cardiac pulse waves ( Figure 10). It is observed that most of the energy of the motion artefacts and baseline drifts increases for scales 2 . , corresponding to frequencies <0.78 Hz. The heart rate (HR) of the moving pig is estimated using the peak detecting algorithm based on the decoupled cardiac pulse waves. Figure 11 shows the estimated HR based on the CWTFT algorithm for the whole measurement period, and highlights the evolution of the heart rate through the awakening period after the anaesthetised period. Then, the estimated heart rate from the PPG signal is compared with the ground-truth heart rate (reference) from the gold standard ECG signal. Figure 11. The estimated HR of the non-anaesthetised (moving) pig using the developed CWTFTbased algorithm along the whole measurement period, including the awakening period. The heart rate (HR) of the moving pig is estimated using the peak detecting algorithm based on the decoupled cardiac pulse waves. Figure 11 shows the estimated HR based on the CWTFT algorithm for the whole measurement period, and highlights the evolution of the heart rate through the awakening period after the anaesthetised period. Then, the estimated heart rate from the PPG signal is compared with the ground-truth heart rate (reference) from the gold standard ECG signal.
The calculated Mean Absolute Error (MAE) and Root Mean Square Error (RMSE) of the estimated heart rate of the moving pig are 1.6(±0.8) bpm and 2.5 (±1.9) bpm, respectively. The algorithm successfully estimated the heart rate of the moving pig with an overall accuracy of 91%. This work illustrates the capacity of the developed PPG-based algorithm, as a proof-of-concept, and the possibility of using it to continuously monitor the pig s heart rate in the field. Although the developed algorithm successfully estimated the heart rate, with high accuracy, of both an anaesthetised and a moving pig, the algorithm is still to be tested on a large population of pigs, considering the age, sex, weight and strain. However, the algorithm is a potential technique for real-time application in monitoring pig heart rates. In addition to pigs heart rates, the developed PPG-based algorithm can also be upgraded to calculate other vital health and welfare signs, such as animal heart rate variability (HRV) and respiration rate in the field. That said, most HRV studies in pigs are based on the pigs as models in biomedical research for human diseases, however some studies have considered its potential role in stress and welfare monitoring [8]. Hence, we are planning in future work to test the possibility of including the HRV and respiration rate in the proposed algorithm. In the last 10 years, the PPG-based sensors have been successfully applied in human-related applications that, because they are low cost and simple, can be developed with ultra-low power technology and be non-invasive. Therefore, the transfer of PPG-based techniques to livestock applications is promising. Nie et al. [7] pointed out one important consideration concerning whether the PPG theory based on skin blood perfusion is applicable for animals, which is an issue related to the similarities in skin characteristics between humans and animals. In the current work, we can conclude that the PPG theory is applicable to heart rate assessment for pigs. This can be attributed to the several documented [7] anatomical and physiological similarities between pig skin and human skin. However, it should be stated here that some technical and practical factors are to be considered, such as the contact pressure between the sensor and the animal skin, power consumption, weight/size, and last but not least, the cost. A detailed assessment of such challenging factors can be found in the intensive review work concerning the continuous heart rate monitoring of livestock by Nie et al. [7]. Figure 11. The estimated HR of the non-anaesthetised (moving) pig using the developed CWTFT-based algorithm along the whole measurement period, including the awakening period.

Conclusions
In this paper, a PPG sensor system is used to measure the heart rate (HR) of a Göttinger Minipig under anaesthetised and free-moving (non-anaesthetised) conditions. The PPG probe is placed on three different anatomical body positions, namely ear, leg and tail. The pulsatile cardiogenic signals are decoupled using a continuous wavelet transform (CWT). Three different wavelets, namely second, fourth and sixth order DOG, are tested. The 4th order DOG wavelet is found to be the most suitable mother wavelet for decoupling the cardiac pulse waves from both the anaesthetised and the free-moving pig. The peaks of the pulsatile cardiogenic signal are detected and pulse rates (bpm) are estimated from the PPG signals, using the developed algorithm. The results showed that the PPG signals obtained from the ear contained the highest SNR (3.85 ± 0.4 dB), while the PPG obtained from the tail contained the lowest SNR (3.51 ± 0.43 dB). The estimated HR of the free-moving pig (PPG probe placed on the leg) has shown RMSE and MAE values of 2.5 ± 0.4 bpm and 1.6 ± 0.8 bpm, respectively. In general, the developed CWTFT-based algorithm is able to decouple the pulsatile cardiogenic signals and estimate the pulse rate of the pigs from PPG signals obtained from the three different body positions, with accuracy levels between 91% and 95%. In this paper, we showed that the PPG theory is applicable to heart rate assessment for pigs. The developed algorithm represents a proof-of-concept for the real-time monitoring of a pig s heart rate in the field using PPG-based technology. However, further investigations are needed to test the developed PPG-based algorithm on different and larger population, with consideration being paid to the animal age, sex, weight and strain.