Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
ecgg.cpp@22:ffa88619551d, 2017-06-23 (annotated)
- Committer:
- nikitateggi
- Date:
- Fri Jun 23 07:25:24 2017 +0000
- Revision:
- 22:ffa88619551d
- Parent:
- 20:7c64e6ecad76
- Child:
- 24:d992ee8369f4
Code with Battery monitoring(commented), glc modified, bt modified, pid modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikitateggi | 1:8316c23ec6b9 | 1 | /** ECG ADS1291 Test program. |
nikitateggi | 1:8316c23ec6b9 | 2 | ADS1291 is a single channel ECG chip |
nikitateggi | 1:8316c23ec6b9 | 3 | with a 24 bit Sigma-Delta ADC |
nikitateggi | 1:8316c23ec6b9 | 4 | */ |
nikitateggi | 1:8316c23ec6b9 | 5 | |
nikitateggi | 1:8316c23ec6b9 | 6 | #include "mbed.h" |
nikitateggi | 1:8316c23ec6b9 | 7 | #include <string.h> |
nikitateggi | 1:8316c23ec6b9 | 8 | #include <stdio.h> |
nikitateggi | 1:8316c23ec6b9 | 9 | #include "ds3231.h" |
nikitateggi | 1:8316c23ec6b9 | 10 | #include "SDFileSystem.h" |
nikitateggi | 1:8316c23ec6b9 | 11 | #include "ecg_dec.h" |
nikitateggi | 1:8316c23ec6b9 | 12 | #include "rtc.h" |
nikitateggi | 1:8316c23ec6b9 | 13 | #include "sdcard.h" |
nikitateggi | 3:9a06c2bed650 | 14 | #include "ec_bp.h" |
nidhinvarghese | 14:f5c62d30c6fc | 15 | |
nidhinvarghese | 14:f5c62d30c6fc | 16 | #include "struct.h" // Added on 31/5/17_Nidhin |
nikitateggi | 19:1650bbc923cc | 17 | //#include "test_type.h" //Added on 31/5/17_Nidhin |
nikitateggi | 3:9a06c2bed650 | 18 | Serial pc(USBTX,USBRX); |
nikitateggi | 1:8316c23ec6b9 | 19 | |
nikitateggi | 1:8316c23ec6b9 | 20 | |
nikitateggi | 22:ffa88619551d | 21 | uint16_t ecg(int32_t pid) |
nikitateggi | 22:ffa88619551d | 22 | //float ecg(int pid) |
nikitateggi | 3:9a06c2bed650 | 23 | { |
nikitateggi | 20:7c64e6ecad76 | 24 | |
nikitateggi | 20:7c64e6ecad76 | 25 | uint8_t lead_reg=0; // added on 14/06 to check lead -off |
nidhinvarghese | 14:f5c62d30c6fc | 26 | //----------------------- Structure for Bluetooth Added Nidhin 1/6/2017-------------------// |
nidhinvarghese | 14:f5c62d30c6fc | 27 | |
nidhinvarghese | 14:f5c62d30c6fc | 28 | //BLUETOOTH STRUCTURE |
nidhinvarghese | 14:f5c62d30c6fc | 29 | |
nidhinvarghese | 14:f5c62d30c6fc | 30 | BLEMsg_info *ptr_BLEMsg_info_ecg, BLEMsg_info_ecg; // A copy of master strcuture [ "BLEMsg_info" ] by name "BLEMsg_info_ecg" is created |
nidhinvarghese | 14:f5c62d30c6fc | 31 | ptr_BLEMsg_info_ecg = &BLEMsg_info_ecg; // *ptr_BLEMsg_info_bp is the pointer to local copy; |
nidhinvarghese | 14:f5c62d30c6fc | 32 | |
nidhinvarghese | 14:f5c62d30c6fc | 33 | // Declaration of Date Structure |
nidhinvarghese | 14:f5c62d30c6fc | 34 | DateTime_info *ptr_DateTime_info_ecg, DateTime_info_ecg; // A copy of Master Structure "DateTime_info" created, |
nidhinvarghese | 14:f5c62d30c6fc | 35 | ptr_DateTime_info_ecg = &DateTime_info_ecg; // Structure pointer points to that copy. |
nidhinvarghese | 14:f5c62d30c6fc | 36 | |
nidhinvarghese | 14:f5c62d30c6fc | 37 | |
nidhinvarghese | 14:f5c62d30c6fc | 38 | // RTC operations |
nidhinvarghese | 14:f5c62d30c6fc | 39 | time_t epoch_time_ecg; //A copy of time_t by name epoch_time_bp is created |
nidhinvarghese | 14:f5c62d30c6fc | 40 | epoch_time_ecg = rtc_read(); // time is got from get epoch function. |
nidhinvarghese | 14:f5c62d30c6fc | 41 | |
nidhinvarghese | 14:f5c62d30c6fc | 42 | struct tm * ptr_time_info_ecg, time_info_ecg; // Sturucture copy of tm is created |
nidhinvarghese | 14:f5c62d30c6fc | 43 | ptr_time_info_ecg = localtime(&epoch_time_ecg); // Structure accepts the time in local format from "time_t" type. |
nidhinvarghese | 14:f5c62d30c6fc | 44 | |
nidhinvarghese | 14:f5c62d30c6fc | 45 | //BELOW LINE IS TO CHECK Date and TIME |
nidhinvarghese | 15:208b146151ba | 46 | //pc.printf("Time is %d: %d: %d\n", (*ptr_time_info_ecg).tm_hour, (*ptr_time_info_ecg).tm_min, (*ptr_time_info_ecg).tm_sec); |
nidhinvarghese | 15:208b146151ba | 47 | //pc.printf("Date is %d:%d:%d\n", (*ptr_time_info_ecg).tm_mday, (*ptr_time_info_ecg).tm_mon+1, (*ptr_time_info_ecg).tm_year-100); |
nidhinvarghese | 14:f5c62d30c6fc | 48 | |
nidhinvarghese | 14:f5c62d30c6fc | 49 | //Copying from one structure to the other using variables |
nidhinvarghese | 14:f5c62d30c6fc | 50 | DateTime_info_ecg.hour = (uint8_t)(*ptr_time_info_ecg).tm_hour; |
nidhinvarghese | 14:f5c62d30c6fc | 51 | DateTime_info_ecg.mins = (uint8_t)(*ptr_time_info_ecg).tm_min; |
nidhinvarghese | 14:f5c62d30c6fc | 52 | DateTime_info_ecg.sec = (uint8_t)(*ptr_time_info_ecg).tm_sec; |
nidhinvarghese | 14:f5c62d30c6fc | 53 | |
nidhinvarghese | 14:f5c62d30c6fc | 54 | DateTime_info_ecg.date = (uint8_t) (*ptr_time_info_ecg).tm_mday; |
nidhinvarghese | 14:f5c62d30c6fc | 55 | DateTime_info_ecg.month =(uint8_t)(*ptr_time_info_ecg).tm_mon+1; |
nidhinvarghese | 14:f5c62d30c6fc | 56 | DateTime_info_ecg.year = (uint8_t)(*ptr_time_info_ecg).tm_year-100; |
nidhinvarghese | 14:f5c62d30c6fc | 57 | |
nidhinvarghese | 14:f5c62d30c6fc | 58 | // Copying Time to Main structure |
nidhinvarghese | 14:f5c62d30c6fc | 59 | BLEMsg_info_ecg.date_time.hour = DateTime_info_ecg.hour; |
nidhinvarghese | 14:f5c62d30c6fc | 60 | BLEMsg_info_ecg.date_time.mins = DateTime_info_ecg.mins; |
nidhinvarghese | 14:f5c62d30c6fc | 61 | BLEMsg_info_ecg.date_time.sec = DateTime_info_ecg.sec; |
nidhinvarghese | 14:f5c62d30c6fc | 62 | |
nidhinvarghese | 14:f5c62d30c6fc | 63 | BLEMsg_info_ecg.date_time.date = DateTime_info_ecg.date ; |
nidhinvarghese | 14:f5c62d30c6fc | 64 | BLEMsg_info_ecg.date_time.month = DateTime_info_ecg.month ; |
nidhinvarghese | 14:f5c62d30c6fc | 65 | BLEMsg_info_ecg.date_time.year = DateTime_info_ecg.year ; |
nidhinvarghese | 14:f5c62d30c6fc | 66 | |
nidhinvarghese | 14:f5c62d30c6fc | 67 | |
nidhinvarghese | 14:f5c62d30c6fc | 68 | //Checking if the structure has these values |
nidhinvarghese | 15:208b146151ba | 69 | //pc.printf("Time 2 is %d:%d:%d\n", DateTime_info_ecg.hour, DateTime_info_ecg.mins, DateTime_info_ecg.sec); |
nidhinvarghese | 15:208b146151ba | 70 | //pc.printf("\t Date is %d:%d:%d\n",DateTime_info_ecg.date, DateTime_info_ecg.month, DateTime_info_ecg.year); |
nidhinvarghese | 14:f5c62d30c6fc | 71 | |
nidhinvarghese | 14:f5c62d30c6fc | 72 | |
nidhinvarghese | 14:f5c62d30c6fc | 73 | //Loading values to of Test type |
nidhinvarghese | 14:f5c62d30c6fc | 74 | test_type_info test_type_info_ecg; // copy of " test_type_info" created |
nidhinvarghese | 14:f5c62d30c6fc | 75 | test_type_info_ecg = ECG_Test; // Loaded value 00 to the test type |
nidhinvarghese | 14:f5c62d30c6fc | 76 | |
nidhinvarghese | 14:f5c62d30c6fc | 77 | BLEMsg_info_ecg.test_type = test_type_info_ecg; |
nidhinvarghese | 14:f5c62d30c6fc | 78 | //Check if 00 is getting printed |
nidhinvarghese | 15:208b146151ba | 79 | //pc.printf("Test Type is : %d\n", test_type_info_ecg); |
nidhinvarghese | 14:f5c62d30c6fc | 80 | |
nidhinvarghese | 14:f5c62d30c6fc | 81 | |
nidhinvarghese | 14:f5c62d30c6fc | 82 | // Loading values of Length , PID, DID, sampling frequency, number of samples, calculated data. |
nidhinvarghese | 14:f5c62d30c6fc | 83 | BLEMsg_info_ecg.device_id = 01; // Device ID fixed |
nidhinvarghese | 14:f5c62d30c6fc | 84 | BLEMsg_info_ecg.patient_id = (uint32_t)pid; // Patient ID |
nidhinvarghese | 14:f5c62d30c6fc | 85 | BLEMsg_info_ecg.sampling_freq = 500; // sampling frrquency |
nikitateggi | 22:ffa88619551d | 86 | BLEMsg_info_ecg.length = 4022; //Total length of data in bytes 22 B+ 4000 data |
nidhinvarghese | 14:f5c62d30c6fc | 87 | |
nidhinvarghese | 14:f5c62d30c6fc | 88 | /* |
nidhinvarghese | 14:f5c62d30c6fc | 89 | //Loading number of samples |
nidhinvarghese | 14:f5c62d30c6fc | 90 | NumSamples_info NumSamples_info_bp; //Copy of structure NumSamples_info |
nidhinvarghese | 14:f5c62d30c6fc | 91 | NumSamples_info_bp.num_ppg_sample = 1664; // PPG & ECG Sample number loaded in structure copy |
nidhinvarghese | 14:f5c62d30c6fc | 92 | NumSamples_info_bp.num_ecg_sample = 1024; |
nidhinvarghese | 14:f5c62d30c6fc | 93 | */ |
nidhinvarghese | 14:f5c62d30c6fc | 94 | |
nidhinvarghese | 14:f5c62d30c6fc | 95 | BLEMsg_info_ecg.num_samples.num_sample_ppg_dummy = 0 ;// PPG number of samples copied to master struct |
nidhinvarghese | 14:f5c62d30c6fc | 96 | BLEMsg_info_ecg.num_samples.num_sample_ecg_OTtyp = 1000 ; // ECG number of samples copied to master struct |
nidhinvarghese | 14:f5c62d30c6fc | 97 | |
nidhinvarghese | 14:f5c62d30c6fc | 98 | //----------------------------------------END Structure for Bluetooth - Added Nidhin 1/6/2017------- |
nidhinvarghese | 14:f5c62d30c6fc | 99 | |
nidhinvarghese | 14:f5c62d30c6fc | 100 | |
nikitateggi | 1:8316c23ec6b9 | 101 | |
nidhinvarghese | 15:208b146151ba | 102 | int32_t concatenate_value2 = 0; // ORG. "int concatenate_value2 = 0;" Nidhin 1/6/17 |
nidhinvarghese | 15:208b146151ba | 103 | int32_t *ecg_ptr; // Added 1/6/2017 Nidhin |
nidhinvarghese | 14:f5c62d30c6fc | 104 | ecg_ptr = &concatenate_value2; // Pointer to pass for ECG write into SD card Nidhin 1/6/2017 |
nidhinvarghese | 14:f5c62d30c6fc | 105 | |
suhasini | 13:5d3b478ea9c7 | 106 | // int32_t sample_sum; // static int32_t avg[1500]; |
nikitateggi | 22:ffa88619551d | 107 | int32_t count = 0; |
nikitateggi | 22:ffa88619551d | 108 | //int32_t fs = 500; //COMMENTED NIDHIN 17/6/17 |
nikitateggi | 22:ffa88619551d | 109 | //uint32_t ecg_buf[N_ECG]; //COMMENTED NIDHIN 17/6/17 |
nikitateggi | 22:ffa88619551d | 110 | //Timer t; //COMMENTED NIDHIN 17/6/17 |
suhasini | 13:5d3b478ea9c7 | 111 | |
suhasini | 13:5d3b478ea9c7 | 112 | //------------------ Declaration for Peak value detection ------------------------------------ |
nikitateggi | 22:ffa88619551d | 113 | /* |
suhasini | 13:5d3b478ea9c7 | 114 | uint32_t hi_val;uint32_t pk_val[20];unsigned int pk_pos[20]={0};unsigned int a; //uint32_t pk=0; |
suhasini | 13:5d3b478ea9c7 | 115 | int hi_dif = 0;int j=0; // int count1 = N_ECG/fs, a_dif=0, fs1 = fs ,h=0; |
suhasini | 13:5d3b478ea9c7 | 116 | // ------------------------- Declaration for Heart Rate calculation -------------------------- |
suhasini | 13:5d3b478ea9c7 | 117 | int n=0; //int n=10; |
suhasini | 13:5d3b478ea9c7 | 118 | float pos_dif, HR[2], HR1,t_pos_dif;int t_sec = 60; float HR_sum = 0,HR_avg; |
nikitateggi | 22:ffa88619551d | 119 | */ //WHOLE SECTION COMMENTED NIDHIN 17/6/17 |
suhasini | 13:5d3b478ea9c7 | 120 | // ------------------------------------------------------------------------------------------- |
suhasini | 13:5d3b478ea9c7 | 121 | |
suhasini | 13:5d3b478ea9c7 | 122 | // unsigned char chk = 1; |
nikitateggi | 3:9a06c2bed650 | 123 | pc.baud(baud_rate); |
nikitateggi | 4:6bd81bb1790d | 124 | freqset(); // setting the frequency |
nikitateggi | 22:ffa88619551d | 125 | setupfunc(); |
nikitateggi | 22:ffa88619551d | 126 | //ecgtestsetupfunc(); // For test set up of 1Hz square wave signal |
nikitateggi | 22:ffa88619551d | 127 | lead_reg= ecgsetupfunc(); |
suhasini | 13:5d3b478ea9c7 | 128 | // chk = 1; |
nikitateggi | 22:ffa88619551d | 129 | |
nikitateggi | 22:ffa88619551d | 130 | |
nikitateggi | 22:ffa88619551d | 131 | //ORIGINAL sd_open_ECGfile(pid); // opening the ecg file COMMENTED Nidhin 1/6/2017 |
nikitateggi | 20:7c64e6ecad76 | 132 | if (lead_reg==0) // checking for proper lead contact// 14/06 |
nikitateggi | 22:ffa88619551d | 133 | { |
nidhinvarghese | 14:f5c62d30c6fc | 134 | sd_open_ECGfilee(pid); // REPLACED Nidhin 1/6/2017 Nidhin |
nidhinvarghese | 14:f5c62d30c6fc | 135 | |
suhasini | 13:5d3b478ea9c7 | 136 | pc.printf( "Raw data is = \n"); |
nikitateggi | 3:9a06c2bed650 | 137 | for(int i=0; i<N_ECG; i++) |
nikitateggi | 3:9a06c2bed650 | 138 | { |
nikitateggi | 3:9a06c2bed650 | 139 | concatenate_value2= readvalue(); |
nikitateggi | 22:ffa88619551d | 140 | pc.printf( "%d\n", concatenate_value2); //ADDED Nidhin 21/6/2017 |
nidhinvarghese | 14:f5c62d30c6fc | 141 | |
nidhinvarghese | 14:f5c62d30c6fc | 142 | //ORIGINAL sd_write(concatenate_value2); // writing into the sd card COMMENTED Nidhin 1/6/2017 |
nidhinvarghese | 14:f5c62d30c6fc | 143 | sd_ecgwrite(ecg_ptr); // REPLACED Nidhin 1/6/2017 |
nikitateggi | 22:ffa88619551d | 144 | //pc.printf( "%d\n", *ecg_ptr); |
nikitateggi | 22:ffa88619551d | 145 | //ecg_buf[i] = concatenate_value2; //COMMENTED Nidhin 10/6/2017 |
nikitateggi | 22:ffa88619551d | 146 | //pc.printf( "%d\n", concatenate_value2); //COMMENTED Nidhin 10/6/2017 |
nikitateggi | 3:9a06c2bed650 | 147 | } |
nidhinvarghese | 14:f5c62d30c6fc | 148 | |
nidhinvarghese | 14:f5c62d30c6fc | 149 | //sd_close(); // closing the file COMMENTED Nidhin 1/6/2017 |
nidhinvarghese | 14:f5c62d30c6fc | 150 | sd_close_ecg(); // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin |
nikitateggi | 22:ffa88619551d | 151 | |
nikitateggi | 22:ffa88619551d | 152 | |
suhasini | 13:5d3b478ea9c7 | 153 | /* |
suhasini | 13:5d3b478ea9c7 | 154 | // ---------- reading back SD data for processing -------------------- |
suhasini | 13:5d3b478ea9c7 | 155 | sd_read_file(15); |
suhasini | 13:5d3b478ea9c7 | 156 | printf("Reading back SD data\n"); |
suhasini | 13:5d3b478ea9c7 | 157 | for(int i=10;i<N_ECG;i++) |
suhasini | 13:5d3b478ea9c7 | 158 | { |
suhasini | 13:5d3b478ea9c7 | 159 | ecg_buf= sd_read(); |
suhasini | 13:5d3b478ea9c7 | 160 | //printf("%d\n",ecg_buf[i]); |
suhasini | 13:5d3b478ea9c7 | 161 | } |
suhasini | 13:5d3b478ea9c7 | 162 | |
suhasini | 13:5d3b478ea9c7 | 163 | sd_close(); */ |
suhasini | 13:5d3b478ea9c7 | 164 | |
suhasini | 13:5d3b478ea9c7 | 165 | //----------------------------- PEAK DETECTION AND HEART RATE CALCULATION --------------------------------------------------- |
suhasini | 13:5d3b478ea9c7 | 166 | // -------------------------------------- PEAK DETECTION ------------------------------------------------------------- |
suhasini | 13:5d3b478ea9c7 | 167 | |
suhasini | 13:5d3b478ea9c7 | 168 | // ------------------ Main loop --------------------------------- |
nikitateggi | 22:ffa88619551d | 169 | /* |
suhasini | 13:5d3b478ea9c7 | 170 | for(int i=0;i<N_ECG-10;i++){ |
suhasini | 13:5d3b478ea9c7 | 171 | if(ecg_buf[i]>ecg_buf[i+1]) |
suhasini | 13:5d3b478ea9c7 | 172 | { |
suhasini | 13:5d3b478ea9c7 | 173 | hi_val = ecg_buf[i]; //To find the high value |
suhasini | 13:5d3b478ea9c7 | 174 | //printf("high value= %d\n",hi_val); |
suhasini | 13:5d3b478ea9c7 | 175 | a = i; |
suhasini | 13:5d3b478ea9c7 | 176 | //printf("a= %d\n",a); |
suhasini | 13:5d3b478ea9c7 | 177 | hi_dif = hi_val-ecg_buf[a+10]; |
suhasini | 13:5d3b478ea9c7 | 178 | |
suhasini | 13:5d3b478ea9c7 | 179 | //a_dif = ecg_buf[a+2] - ecg_buf[a+1]; |
suhasini | 13:5d3b478ea9c7 | 180 | //printf("The difference between high and low value is = %d\n",hi_dif); |
suhasini | 13:5d3b478ea9c7 | 181 | |
suhasini | 13:5d3b478ea9c7 | 182 | // ---------------------------- If hi_val is greater than next ten input values, then compare the hi_val with the tenth input value. |
suhasini | 13:5d3b478ea9c7 | 183 | // If the diff is greater than 10000, then it is a valid peak (pls chk the below condition)-------------------------------------------------- |
suhasini | 13:5d3b478ea9c7 | 184 | // if((hi_dif > 10000) && ((a+10) < N_ECG)) |
suhasini | 13:5d3b478ea9c7 | 185 | if(hi_dif > 10000) |
suhasini | 13:5d3b478ea9c7 | 186 | { |
suhasini | 13:5d3b478ea9c7 | 187 | // if(a_dif <= 0) ------------------------ add this condition if needed ---------------------- |
suhasini | 13:5d3b478ea9c7 | 188 | // { |
suhasini | 13:5d3b478ea9c7 | 189 | pk_val[j] = hi_val; //if condition satisfied, put the "pk" value into "pk_val" buffer |
nikitateggi | 22:ffa88619551d | 190 | pc.printf("peak value= %d\n",pk_val[j]); |
suhasini | 13:5d3b478ea9c7 | 191 | pk_pos[j]=a; // also save the peak's position |
nikitateggi | 22:ffa88619551d | 192 | pc.printf("peak position is = %d\n",pk_pos[j]); |
suhasini | 13:5d3b478ea9c7 | 193 | i = a+120; // once confirmed that this is the necessary peak, skip the next 120 input values |
suhasini | 13:5d3b478ea9c7 | 194 | n = j; // where n is the number of peaks detected |
suhasini | 13:5d3b478ea9c7 | 195 | j = j+1; |
suhasini | 13:5d3b478ea9c7 | 196 | |
suhasini | 13:5d3b478ea9c7 | 197 | // printf("j after peak detection is= %d\n",j); |
suhasini | 13:5d3b478ea9c7 | 198 | // } |
suhasini | 13:5d3b478ea9c7 | 199 | } |
suhasini | 13:5d3b478ea9c7 | 200 | else |
suhasini | 13:5d3b478ea9c7 | 201 | { |
suhasini | 13:5d3b478ea9c7 | 202 | //h = a+1; |
suhasini | 13:5d3b478ea9c7 | 203 | i = a+1; |
suhasini | 13:5d3b478ea9c7 | 204 | // printf("i if peak not found is= %d\n",i); |
suhasini | 13:5d3b478ea9c7 | 205 | } |
suhasini | 13:5d3b478ea9c7 | 206 | // store the peak value position in "pk_pos" |
suhasini | 13:5d3b478ea9c7 | 207 | |
suhasini | 13:5d3b478ea9c7 | 208 | } |
suhasini | 13:5d3b478ea9c7 | 209 | } |
suhasini | 13:5d3b478ea9c7 | 210 | // ----------------- HEART RATE LOGIC --------------------------- |
nikitateggi | 3:9a06c2bed650 | 211 | |
suhasini | 13:5d3b478ea9c7 | 212 | for(int i = 0;i < n-1;i++) |
suhasini | 13:5d3b478ea9c7 | 213 | { |
suhasini | 13:5d3b478ea9c7 | 214 | pos_dif = pk_pos[i+1] - pk_pos[i]; // difference between two consequtive peaks |
suhasini | 13:5d3b478ea9c7 | 215 | pc.printf("peak position diff is = %f\n",pos_dif); |
suhasini | 13:5d3b478ea9c7 | 216 | //printf("peak position i value is = %d\n",i); |
suhasini | 13:5d3b478ea9c7 | 217 | t_pos_dif = pos_dif/fs; // sample difference between peak positions divided by sampling frequency gives the difference value in terms of actual time |
suhasini | 13:5d3b478ea9c7 | 218 | pc.printf("time in seconds is = %f\n",t_pos_dif); |
suhasini | 13:5d3b478ea9c7 | 219 | HR[i] = t_sec/t_pos_dif; //HR calculation |
suhasini | 13:5d3b478ea9c7 | 220 | pc.printf("Heart Rate is = %f\n",HR[i]); |
suhasini | 13:5d3b478ea9c7 | 221 | // n = i; |
suhasini | 13:5d3b478ea9c7 | 222 | HR1 = HR[0]; |
suhasini | 13:5d3b478ea9c7 | 223 | |
suhasini | 13:5d3b478ea9c7 | 224 | } |
suhasini | 13:5d3b478ea9c7 | 225 | // ---------------------- To average individual HRs for higher number of samples ----------------------- |
suhasini | 13:5d3b478ea9c7 | 226 | /* for(int i = 0;i < 5;i++) |
suhasini | 13:5d3b478ea9c7 | 227 | { |
suhasini | 13:5d3b478ea9c7 | 228 | HR_sum = HR[i]+HR_sum; |
suhasini | 13:5d3b478ea9c7 | 229 | } |
suhasini | 13:5d3b478ea9c7 | 230 | HR_avg = HR_sum/5; // To find average of all the individual HRs calculated |
suhasini | 13:5d3b478ea9c7 | 231 | printf("Heart Rate sum is = %f\n",HR_sum); |
suhasini | 13:5d3b478ea9c7 | 232 | printf("Denominator = %d\n",n); |
suhasini | 13:5d3b478ea9c7 | 233 | printf("Heart Rate = %f\n",HR_avg); |
suhasini | 13:5d3b478ea9c7 | 234 | */ |
nikitateggi | 22:ffa88619551d | 235 | //HR1 = 72; // Added Nidhin 10June17; |
nidhinvarghese | 14:f5c62d30c6fc | 236 | //ADDED Nidhin 1/6/2017 |
nidhinvarghese | 14:f5c62d30c6fc | 237 | |
nikitateggi | 22:ffa88619551d | 238 | uint16_t HR1; |
nidhinvarghese | 14:f5c62d30c6fc | 239 | |
nikitateggi | 22:ffa88619551d | 240 | //HR1 = 72; |
nikitateggi | 22:ffa88619551d | 241 | HR1 = heart_cal(pid); |
nikitateggi | 22:ffa88619551d | 242 | |
nikitateggi | 22:ffa88619551d | 243 | BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0; |
nikitateggi | 22:ffa88619551d | 244 | BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = HR1; //To be modified after HR code is added. |
nidhinvarghese | 14:f5c62d30c6fc | 245 | |
nikitateggi | 22:ffa88619551d | 246 | structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file //COMMENTED Nidhin 10/6/2017 |
nikitateggi | 22:ffa88619551d | 247 | ecgfile_mainfile(pid); // copy raw data to the main file and ECG file is cleared. //COMMENTED Nidhin 10/6/2017 |
nikitateggi | 22:ffa88619551d | 248 | |
nikitateggi | 22:ffa88619551d | 249 | pc.printf("Closed the main file\n"); |
nidhinvarghese | 14:f5c62d30c6fc | 250 | |
nidhinvarghese | 14:f5c62d30c6fc | 251 | |
nidhinvarghese | 14:f5c62d30c6fc | 252 | |
suhasini | 13:5d3b478ea9c7 | 253 | return HR1; |
suhasini | 13:5d3b478ea9c7 | 254 | // return HR_avg; |
nikitateggi | 20:7c64e6ecad76 | 255 | |
nikitateggi | 22:ffa88619551d | 256 | } |
nikitateggi | 20:7c64e6ecad76 | 257 | else |
nikitateggi | 20:7c64e6ecad76 | 258 | { |
nikitateggi | 20:7c64e6ecad76 | 259 | pc.printf("no - leadoff"); |
nikitateggi | 20:7c64e6ecad76 | 260 | return 0; |
nikitateggi | 20:7c64e6ecad76 | 261 | } |
suhasini | 13:5d3b478ea9c7 | 262 | |
nikitateggi | 22:ffa88619551d | 263 | } // End of main function |