Kartik Sastry / Mbed 2 deprecated 4180Final

Dependencies:   4DGL-uLCD-SE LSM9DS1_Library-KVS MBed_Adafruit-GPS-Library PinDetect X_NUCLEO_53L0A1 mbed-rtos mbed

Committer:
ksastry3
Date:
Thu Dec 14 07:21:52 2017 +0000
Revision:
1:abc522e41d63
Final Version 12/14/2017 by Kartik V. Sastry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ksastry3 1:abc522e41d63 1 /** \file algorithm.h ******************************************************
ksastry3 1:abc522e41d63 2 *
ksastry3 1:abc522e41d63 3 * Project: MAXREFDES117#
ksastry3 1:abc522e41d63 4 * Filename: algorithm.h
ksastry3 1:abc522e41d63 5 * Description: This module is the heart rate/SpO2 calculation algorithm header file
ksastry3 1:abc522e41d63 6 *
ksastry3 1:abc522e41d63 7 * Revision History:
ksastry3 1:abc522e41d63 8 *\n 1-18-2016 Rev 01.00 SK Initial release.
ksastry3 1:abc522e41d63 9 *\n
ksastry3 1:abc522e41d63 10 *
ksastry3 1:abc522e41d63 11 * --------------------------------------------------------------------
ksastry3 1:abc522e41d63 12 *
ksastry3 1:abc522e41d63 13 * This code follows the following naming conventions:
ksastry3 1:abc522e41d63 14 *
ksastry3 1:abc522e41d63 15 *\n char ch_pmod_value
ksastry3 1:abc522e41d63 16 *\n char (array) s_pmod_s_string[16]
ksastry3 1:abc522e41d63 17 *\n float f_pmod_value
ksastry3 1:abc522e41d63 18 *\n int32_t n_pmod_value
ksastry3 1:abc522e41d63 19 *\n int32_t (array) an_pmod_value[16]
ksastry3 1:abc522e41d63 20 *\n int16_t w_pmod_value
ksastry3 1:abc522e41d63 21 *\n int16_t (array) aw_pmod_value[16]
ksastry3 1:abc522e41d63 22 *\n uint16_t uw_pmod_value
ksastry3 1:abc522e41d63 23 *\n uint16_t (array) auw_pmod_value[16]
ksastry3 1:abc522e41d63 24 *\n uint8_t uch_pmod_value
ksastry3 1:abc522e41d63 25 *\n uint8_t (array) auch_pmod_buffer[16]
ksastry3 1:abc522e41d63 26 *\n uint32_t un_pmod_value
ksastry3 1:abc522e41d63 27 *\n int32_t * pn_pmod_value
ksastry3 1:abc522e41d63 28 *
ksastry3 1:abc522e41d63 29 * ------------------------------------------------------------------------- */
ksastry3 1:abc522e41d63 30 /*******************************************************************************
ksastry3 1:abc522e41d63 31 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
ksastry3 1:abc522e41d63 32 *
ksastry3 1:abc522e41d63 33 * Permission is hereby granted, free of charge, to any person obtaining a
ksastry3 1:abc522e41d63 34 * copy of this software and associated documentation files (the "Software"),
ksastry3 1:abc522e41d63 35 * to deal in the Software without restriction, including without limitation
ksastry3 1:abc522e41d63 36 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
ksastry3 1:abc522e41d63 37 * and/or sell copies of the Software, and to permit persons to whom the
ksastry3 1:abc522e41d63 38 * Software is furnished to do so, subject to the following conditions:
ksastry3 1:abc522e41d63 39 *
ksastry3 1:abc522e41d63 40 * The above copyright notice and this permission notice shall be included
ksastry3 1:abc522e41d63 41 * in all copies or substantial portions of the Software.
ksastry3 1:abc522e41d63 42 *
ksastry3 1:abc522e41d63 43 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
ksastry3 1:abc522e41d63 44 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
ksastry3 1:abc522e41d63 45 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
ksastry3 1:abc522e41d63 46 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
ksastry3 1:abc522e41d63 47 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ksastry3 1:abc522e41d63 48 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
ksastry3 1:abc522e41d63 49 * OTHER DEALINGS IN THE SOFTWARE.
ksastry3 1:abc522e41d63 50 *
ksastry3 1:abc522e41d63 51 * Except as contained in this notice, the name of Maxim Integrated
ksastry3 1:abc522e41d63 52 * Products, Inc. shall not be used except as stated in the Maxim Integrated
ksastry3 1:abc522e41d63 53 * Products, Inc. Branding Policy.
ksastry3 1:abc522e41d63 54 *
ksastry3 1:abc522e41d63 55 * The mere transfer of this software does not imply any licenses
ksastry3 1:abc522e41d63 56 * of trade secrets, proprietary technology, copyrights, patents,
ksastry3 1:abc522e41d63 57 * trademarks, maskwork rights, or any other form of intellectual
ksastry3 1:abc522e41d63 58 * property whatsoever. Maxim Integrated Products, Inc. retains all
ksastry3 1:abc522e41d63 59 * ownership rights.
ksastry3 1:abc522e41d63 60 *******************************************************************************
ksastry3 1:abc522e41d63 61 */
ksastry3 1:abc522e41d63 62 #ifndef ALGORITHM_H_
ksastry3 1:abc522e41d63 63 #define ALGORITHM_H_
ksastry3 1:abc522e41d63 64
ksastry3 1:abc522e41d63 65 #include "mbed.h"
ksastry3 1:abc522e41d63 66
ksastry3 1:abc522e41d63 67 #define true 1
ksastry3 1:abc522e41d63 68 #define false 0
ksastry3 1:abc522e41d63 69 #define FS 100
ksastry3 1:abc522e41d63 70 #define BUFFER_SIZE (FS* 5)
ksastry3 1:abc522e41d63 71 #define HR_FIFO_SIZE 7
ksastry3 1:abc522e41d63 72 #define MA4_SIZE 4 // DO NOT CHANGE
ksastry3 1:abc522e41d63 73 #define HAMMING_SIZE 5// DO NOT CHANGE
ksastry3 1:abc522e41d63 74 #define min(x,y) ((x) < (y) ? (x) : (y))
ksastry3 1:abc522e41d63 75
ksastry3 1:abc522e41d63 76 const uint16_t auw_hamm[31]={ 41, 276, 512, 276, 41 }; //Hamm= long16(512* hamming(5)');
ksastry3 1:abc522e41d63 77 //uch_spo2_table is computed as -45.060*ratioAverage* ratioAverage + 30.354 *ratioAverage + 94.845 ;
ksastry3 1:abc522e41d63 78 const uint8_t uch_spo2_table[184]={ 95, 95, 95, 96, 96, 96, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 99, 99, 99, 99,
ksastry3 1:abc522e41d63 79 99, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
ksastry3 1:abc522e41d63 80 100, 100, 100, 100, 99, 99, 99, 99, 99, 99, 99, 99, 98, 98, 98, 98, 98, 98, 97, 97,
ksastry3 1:abc522e41d63 81 97, 97, 96, 96, 96, 96, 95, 95, 95, 94, 94, 94, 93, 93, 93, 92, 92, 92, 91, 91,
ksastry3 1:abc522e41d63 82 90, 90, 89, 89, 89, 88, 88, 87, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81, 81,
ksastry3 1:abc522e41d63 83 80, 80, 79, 78, 78, 77, 76, 76, 75, 74, 74, 73, 72, 72, 71, 70, 69, 69, 68, 67,
ksastry3 1:abc522e41d63 84 66, 66, 65, 64, 63, 62, 62, 61, 60, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50,
ksastry3 1:abc522e41d63 85 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 31, 30, 29,
ksastry3 1:abc522e41d63 86 28, 27, 26, 25, 23, 22, 21, 20, 19, 17, 16, 15, 14, 12, 11, 10, 9, 7, 6, 5,
ksastry3 1:abc522e41d63 87 3, 2, 1 } ;
ksastry3 1:abc522e41d63 88 static int32_t an_dx[ BUFFER_SIZE-MA4_SIZE]; // delta
ksastry3 1:abc522e41d63 89 static int32_t an_x[ BUFFER_SIZE]; //ir
ksastry3 1:abc522e41d63 90 static int32_t an_y[ BUFFER_SIZE]; //red
ksastry3 1:abc522e41d63 91
ksastry3 1:abc522e41d63 92
ksastry3 1:abc522e41d63 93 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);
ksastry3 1:abc522e41d63 94 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 );
ksastry3 1:abc522e41d63 95 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 );
ksastry3 1:abc522e41d63 96 void maxim_remove_close_peaks( int32_t *pn_locs, int32_t *pn_npks, int32_t *pn_x, int32_t n_min_distance );
ksastry3 1:abc522e41d63 97 void maxim_sort_ascend( int32_t *pn_x, int32_t n_size );
ksastry3 1:abc522e41d63 98 void maxim_sort_indices_descend( int32_t *pn_x, int32_t *pn_indx, int32_t n_size);
ksastry3 1:abc522e41d63 99
ksastry3 1:abc522e41d63 100 #endif /* ALGORITHM_H_ */