MAXREFDES117# Code Documentation  V01.00
Heart Rate / SpO2 Monitor
 All Files Functions Variables Macros Pages
algorithm.h File Reference
#include "mbed.h"

Go to the source code of this file.

Macros

#define true   1
 
#define false   0
 
#define FS   100
 
#define BUFFER_SIZE   (FS* 5)
 
#define HR_FIFO_SIZE   7
 
#define MA4_SIZE   4
 
#define HAMMING_SIZE   5
 
#define min(x, y)   ((x) < (y) ? (x) : (y))
 

Functions

void maxim_heart_rate_and_oxygen_saturation (uint32_t *pun_ir_buffer, int32_t n_ir_buffer_length, uint32_t *pun_red_buffer, int32_t *pn_spo2, int8_t *pch_spo2_valid, int32_t *pn_heart_rate, int8_t *pch_hr_valid)
 Calculate the heart rate and SpO2 level.
 
void maxim_find_peaks (int32_t *pn_locs, int32_t *pn_npks, int32_t *pn_x, int32_t n_size, int32_t n_min_height, int32_t n_min_distance, int32_t n_max_num)
 Find peaks.
 
void maxim_peaks_above_min_height (int32_t *pn_locs, int32_t *pn_npks, int32_t *pn_x, int32_t n_size, int32_t n_min_height)
 Find peaks above n_min_height.
 
void maxim_remove_close_peaks (int32_t *pn_locs, int32_t *pn_npks, int32_t *pn_x, int32_t n_min_distance)
 Remove peaks.
 
void maxim_sort_ascend (int32_t *pn_x, int32_t n_size)
 Sort array.
 
void maxim_sort_indices_descend (int32_t *pn_x, int32_t *pn_indx, int32_t n_size)
 Sort indices.
 

Variables

const uint16_t auw_hamm [31] ={ 41, 276, 512, 276, 41 }
 
const uint8_t uch_spo2_table [184]
 

Detailed Description

******************************************************

Project: MAXREFDES117# Filename: algorithm.h Description: This module is the heart rate/SpO2 calculation algorithm header file

Revision History:
1-18-2016 Rev 01.00 SK Initial release.


This code follows the following naming conventions:


char ch_pmod_value
char (array) s_pmod_s_string[16]
float f_pmod_value
int32_t n_pmod_value
int32_t (array) an_pmod_value[16]
int16_t w_pmod_value
int16_t (array) aw_pmod_value[16]
uint16_t uw_pmod_value
uint16_t (array) auw_pmod_value[16]
uint8_t uch_pmod_value
uint8_t (array) auch_pmod_buffer[16]
uint32_t un_pmod_value
int32_t * pn_pmod_value


Definition in file algorithm.h.

Macro Definition Documentation

#define BUFFER_SIZE   (FS* 5)

Definition at line 70 of file algorithm.h.

#define false   0

Definition at line 68 of file algorithm.h.

#define FS   100

Definition at line 69 of file algorithm.h.

#define HAMMING_SIZE   5

Definition at line 73 of file algorithm.h.

#define HR_FIFO_SIZE   7

Definition at line 71 of file algorithm.h.

#define MA4_SIZE   4

Definition at line 72 of file algorithm.h.

#define min (   x,
 
)    ((x) < (y) ? (x) : (y))

Definition at line 74 of file algorithm.h.

#define true   1

Definition at line 67 of file algorithm.h.

Function Documentation

void maxim_find_peaks ( int32_t *  pn_locs,
int32_t *  pn_npks,
int32_t *  pn_x,
int32_t  n_size,
int32_t  n_min_height,
int32_t  n_min_distance,
int32_t  n_max_num 
)

Find peaks.

Details
Find at most MAX_NUM peaks above MIN_HEIGHT separated by at least MIN_DISTANCE
Return values
None

Definition at line 254 of file algorithm.cpp.

void maxim_heart_rate_and_oxygen_saturation ( uint32_t *  pun_ir_buffer,
int32_t  n_ir_buffer_length,
uint32_t *  pun_red_buffer,
int32_t *  pn_spo2,
int8_t *  pch_spo2_valid,
int32_t *  pn_heart_rate,
int8_t *  pch_hr_valid 
)

Calculate the heart rate and SpO2 level.

Details
By detecting peaks of PPG cycle and corresponding AC/DC of red/infra-red signal, the ratio for the SPO2 is computed. Since this algorithm is aiming for Arm M0/M3. formaula for SPO2 did not achieve the accuracy due to register overflow. Thus, accurate SPO2 is precalculated and save longo uch_spo2_table[] per each ratio.
Parameters
[in]*pun_ir_buffer- IR sensor data buffer
[in]n_ir_buffer_length- IR sensor data buffer length
[in]*pun_red_buffer- Red sensor data buffer
[out]*pn_spo2- Calculated SpO2 value
[out]*pch_spo2_valid- 1 if the calculated SpO2 value is valid
[out]*pn_heart_rate- Calculated heart rate value
[out]*pch_hr_valid- 1 if the calculated heart rate value is valid
Return values
None

Definition at line 62 of file algorithm.cpp.

void maxim_peaks_above_min_height ( int32_t *  pn_locs,
int32_t *  pn_npks,
int32_t *  pn_x,
int32_t  n_size,
int32_t  n_min_height 
)

Find peaks above n_min_height.

Details
Find all peaks above MIN_HEIGHT
Return values
None

Definition at line 268 of file algorithm.cpp.

void maxim_remove_close_peaks ( int32_t *  pn_locs,
int32_t *  pn_npks,
int32_t *  pn_x,
int32_t  n_min_distance 
)

Remove peaks.

Details
Remove peaks separated by less than MIN_DISTANCE
Return values
None

Definition at line 299 of file algorithm.cpp.

void maxim_sort_ascend ( int32_t *  pn_x,
int32_t  n_size 
)

Sort array.

Details
Sort array in ascending order (insertion sort algorithm)
Return values
None

Definition at line 328 of file algorithm.cpp.

void maxim_sort_indices_descend ( int32_t *  pn_x,
int32_t *  pn_indx,
int32_t  n_size 
)

Sort indices.

Details
Sort indices according to descending order (insertion sort algorithm)
Return values
None

Definition at line 346 of file algorithm.cpp.

Variable Documentation

const uint16_t auw_hamm[31] ={ 41, 276, 512, 276, 41 }

Definition at line 76 of file algorithm.h.

const uint8_t uch_spo2_table[184]
Initial value:
={ 95, 95, 95, 96, 96, 96, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 99, 99, 99, 99,
99, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 99, 99, 99, 99, 99, 99, 99, 99, 98, 98, 98, 98, 98, 98, 97, 97,
97, 97, 96, 96, 96, 96, 95, 95, 95, 94, 94, 94, 93, 93, 93, 92, 92, 92, 91, 91,
90, 90, 89, 89, 89, 88, 88, 87, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81, 81,
80, 80, 79, 78, 78, 77, 76, 76, 75, 74, 74, 73, 72, 72, 71, 70, 69, 69, 68, 67,
66, 66, 65, 64, 63, 62, 62, 61, 60, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50,
49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 31, 30, 29,
28, 27, 26, 25, 23, 22, 21, 20, 19, 17, 16, 15, 14, 12, 11, 10, 9, 7, 6, 5,
3, 2, 1 }

Definition at line 78 of file algorithm.h.