CQ Publishing
/
tg_201410s6_Plethysmographs
トランジスタ技術2014年10月号第6章のソフトウェア
Embed:
(wiki syntax)
Show/hide line numbers
PulseRate.h
Go to the documentation of this file.
00001 /** 00002 * @file PulseRate.h 00003 * @brief Header file for PulseRate.cpp 00004 * @date 2014.08.08 00005 * @version 1.0.0 00006 */ 00007 #ifndef _INC_PulseRate 00008 #define _INC_PulseRate 00009 00010 #include "mbed.h" 00011 00012 #define LED_ON (0) 00013 #define LED_OFF (1) 00014 00015 #define BEEP_FREQ (1000.0) 00016 #define BEEP_LOUD (0.5) 00017 00018 #define SAMPLING_RATE (0.01) /* A/D sampling rate (10ms) */ 00019 #define SPL_NUM (100) /* Range of sampling number (0 - 99) */ 00020 00021 #define AD_OFFSET (21845) /* Offset value for VREF (about +1.1V) */ 00022 00023 #define COEF_BH (0x3FCCB062) /* High pass filter b0, -b1 coefficient 0.1Hz/100Hz Q30 format */ 00024 /* Use (0x3F02946A) when 0.5Hz/100Hz Q30 format */ 00025 #define COEF_AH (0x3F9960C5) /* High pass filter -a1 coefficient 0.1Hz/200Hz Q30 format */ 00026 /* Use (0x3E0528D5) when 0.5Hz/100Hz Q30 format */ 00027 00028 #define MV_LENGTH (5) /* Number of moving averaging for pulse detection */ 00029 #define TH_COEF (0.993) /* Coefficient for pulse threshold (exponential decline) */ 00030 #define PEAK_MIN (127) /* Ignore waveform as pulse under this value */ 00031 00032 #define PR_LENGTH (5) /* Number of average for pulse rate */ 00033 #define PR_1MIN_SPL (6000) /* Number of sampling for 1 minute (60*100) */ 00034 #define PR_INT_MAX (300) /* 20 bpm (60*100/20) */ 00035 #define PR_INT_MIN (20) /* 300 bpm (60*100/300) */ 00036 00037 /** Calculate pulse waveform and pulse rate 00038 */ 00039 class PulseRate { 00040 00041 public: 00042 PulseRate(PinName sensor, PinName sync_led, PinName beep); 00043 void start_sampling(); 00044 bool get_wave(uint32_t &num, int32_t &wave_val); 00045 bool get_pr_val(uint32_t &pr); 00046 00047 private: 00048 Ticker _sampling; /* Interval timer for data sampling */ 00049 00050 AnalogIn _sensor; /* A/D converter */ 00051 DigitalOut _sync_led; /* Synchronous LED */ 00052 PwmOut _beep; /* Piezo sounder */ 00053 00054 /* Pulse waveform */ 00055 int32_t _val; /* Pulse waveform value */ 00056 int32_t _prev_val; /* Previous value */ 00057 int32_t _reg_hpf; /* High pass filter memory value */ 00058 bool _wave_flag; /* Pulse waveform set flag */ 00059 00060 uint32_t _sampling_num; /* Sampling number */ 00061 00062 /* Moving averaging */ 00063 int32_t _mv_buf[MV_LENGTH]; /* Circular buffer */ 00064 int32_t _mv_idx; /* Buffer index */ 00065 00066 /* Threshold for detecting pulse */ 00067 int32_t _detect_val; /* Detection value */ 00068 int32_t _prev_dt_val; /* Previous data */ 00069 00070 int32_t _threshold_val; /* Threshold value */ 00071 int32_t _prev_th_val; /* Previous data */ 00072 00073 /* Pulse rate */ 00074 int32_t _pr_counter; /* Counter for pulse rate */ 00075 int32_t _pr_buf[PR_LENGTH]; /* Circular buffer */ 00076 int32_t _pr_idx; /* Buffer index */ 00077 00078 int32_t _pr; /* Pulse rate value */ 00079 bool _pr_flag; /* Pulse rate set flag */ 00080 00081 /* Member functions */ 00082 void interval_timer(); 00083 int32_t hpf(int32_t val); 00084 bool detect_peak(int32_t val); 00085 void calc_pr(); 00086 }; 00087 #endif /* INC_PulseRate */
Generated on Wed Jul 13 2022 19:52:00 by 1.7.2