
Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Revision 13:5d3b478ea9c7, committed 2017-05-27
- Comitter:
- suhasini
- Date:
- Sat May 27 05:47:55 2017 +0000
- Parent:
- 12:ab85607bb10a
- Child:
- 14:f5c62d30c6fc
- Commit message:
- This code has ECG functionality with HRD calculation, BP, BG, new display
Changed in this revision
--- a/display_modules.cpp Mon May 08 05:19:22 2017 +0000 +++ b/display_modules.cpp Sat May 27 05:47:55 2017 +0000 @@ -154,20 +154,21 @@ - void screen_ecg_2() // ECG screen 2 + void screen_ecg_2(float heart_rate) // ECG screen 2 { + char buf[5]; backlight = 0 ; TFT.BusEnable(true) ; TFT.background(White) ; TFT.foreground(Green) ; - + sprintf (buf, "%.0f bpm",heart_rate); TFT.fillrect(5,90,230,150,White); TFT.locate(3,100) ; TFT.printf(" Tst is Done ") ; TFT.locate(3,150) ; TFT.printf(" HeartRate ") ; - TFT.locate(3,180); - TFT.printf(" 72 bpm") ; + TFT.locate(30,180); + TFT.printf(buf) ; TFT.background(Green) ; TFT.fillrect(10,215,230,290,White); TFT.fillrect(60,230,180,300,Green);
--- a/display_modules.h Mon May 08 05:19:22 2017 +0000 +++ b/display_modules.h Sat May 27 05:47:55 2017 +0000 @@ -10,7 +10,7 @@ void screen_bp(); void screen_glc(); void init_screen(); -void screen_ecg_2(); +void screen_ecg_2(float heart_rate); void ecg_countdown(); void bp_countdown(); void glc_1();
--- a/ecg_dec.h Mon May 08 05:19:22 2017 +0000 +++ b/ecg_dec.h Sat May 27 05:47:55 2017 +0000 @@ -84,5 +84,5 @@ #define MAX_BRIGHTNESS 255 // BP ADD int ecg(int pid); */ -int ecg(int pid); +float ecg(int pid); #endif \ No newline at end of file
--- a/ecgg.cpp Mon May 08 05:19:22 2017 +0000 +++ b/ecgg.cpp Sat May 27 05:47:55 2017 +0000 @@ -16,30 +16,125 @@ -int ecg(int pid) +float ecg(int pid) { int concatenate_value2 = 0; - int32_t sample_sum; // static int32_t avg[1500]; - int32_t count = 0; int32_t fs = 500; int32_t w=0,w1=0; + // int32_t sample_sum; // static int32_t avg[1500]; + int32_t count = 0; int32_t fs = 500; + uint32_t ecg_buf[N_ECG]; Timer t; - unsigned char chk = 1; + + //------------------ Declaration for Peak value detection ------------------------------------ + + uint32_t hi_val;uint32_t pk_val[20];unsigned int pk_pos[20]={0};unsigned int a; //uint32_t pk=0; + int hi_dif = 0;int j=0; // int count1 = N_ECG/fs, a_dif=0, fs1 = fs ,h=0; + // ------------------------- Declaration for Heart Rate calculation -------------------------- + int n=0; //int n=10; + float pos_dif, HR[2], HR1,t_pos_dif;int t_sec = 60; float HR_sum = 0,HR_avg; + // ------------------------------------------------------------------------------------------- + + // unsigned char chk = 1; pc.baud(baud_rate); freqset(); // setting the frequency setupfunc(); ecgsetupfunc(); - chk = 1; + // chk = 1; sd_open_ECGfile(pid); // opening the ecg file - + pc.printf( "Raw data is = \n"); for(int i=0; i<N_ECG; i++) { concatenate_value2= readvalue(); sd_write(concatenate_value2); // writing into the sd card + ecg_buf[i] = concatenate_value2; pc.printf( "%d\n", concatenate_value2); } sd_close(); // closing the file - +/* + // ---------- reading back SD data for processing -------------------- + sd_read_file(15); + printf("Reading back SD data\n"); + for(int i=10;i<N_ECG;i++) + { + ecg_buf= sd_read(); + //printf("%d\n",ecg_buf[i]); + } + + sd_close(); */ + + //----------------------------- PEAK DETECTION AND HEART RATE CALCULATION --------------------------------------------------- + // -------------------------------------- PEAK DETECTION ------------------------------------------------------------- + + // ------------------ Main loop --------------------------------- +for(int i=0;i<N_ECG-10;i++){ +if(ecg_buf[i]>ecg_buf[i+1]) +{ +hi_val = ecg_buf[i]; //To find the high value +//printf("high value= %d\n",hi_val); +a = i; +//printf("a= %d\n",a); +hi_dif = hi_val-ecg_buf[a+10]; + +//a_dif = ecg_buf[a+2] - ecg_buf[a+1]; +//printf("The difference between high and low value is = %d\n",hi_dif); + + // ---------------------------- If hi_val is greater than next ten input values, then compare the hi_val with the tenth input value. + // If the diff is greater than 10000, then it is a valid peak (pls chk the below condition)-------------------------------------------------- + // if((hi_dif > 10000) && ((a+10) < N_ECG)) + if(hi_dif > 10000) + { + // if(a_dif <= 0) ------------------------ add this condition if needed ---------------------- + // { + pk_val[j] = hi_val; //if condition satisfied, put the "pk" value into "pk_val" buffer + pc.printf("peak value= %d\n",pk_val[j]); + pk_pos[j]=a; // also save the peak's position + pc.printf("peak position is = %d\n",pk_pos[j]); + i = a+120; // once confirmed that this is the necessary peak, skip the next 120 input values + n = j; // where n is the number of peaks detected + j = j+1; + + // printf("j after peak detection is= %d\n",j); + // } + } + else + { + //h = a+1; + i = a+1; + // printf("i if peak not found is= %d\n",i); + } + // store the peak value position in "pk_pos" + +} +} + // ----------------- HEART RATE LOGIC --------------------------- - } // End of main function + for(int i = 0;i < n-1;i++) + { + pos_dif = pk_pos[i+1] - pk_pos[i]; // difference between two consequtive peaks + pc.printf("peak position diff is = %f\n",pos_dif); + //printf("peak position i value is = %d\n",i); + t_pos_dif = pos_dif/fs; // sample difference between peak positions divided by sampling frequency gives the difference value in terms of actual time + pc.printf("time in seconds is = %f\n",t_pos_dif); + HR[i] = t_sec/t_pos_dif; //HR calculation + pc.printf("Heart Rate is = %f\n",HR[i]); + // n = i; + HR1 = HR[0]; + + } + // ---------------------- To average individual HRs for higher number of samples ----------------------- + /* for(int i = 0;i < 5;i++) + { + HR_sum = HR[i]+HR_sum; + } + HR_avg = HR_sum/5; // To find average of all the individual HRs calculated + printf("Heart Rate sum is = %f\n",HR_sum); + printf("Denominator = %d\n",n); + printf("Heart Rate = %f\n",HR_avg); + */ + return HR1; + // return HR_avg; + +} // End of main function +
--- a/main.cpp Mon May 08 05:19:22 2017 +0000 +++ b/main.cpp Sat May 27 05:47:55 2017 +0000 @@ -29,7 +29,7 @@ unsigned char flag=0; unsigned char ecg_flag=0; unsigned char glc_flag=0; - +float heart_rate=0; DisableTouch(); gc.baud(115200); @@ -240,9 +240,9 @@ case 8: DisableTouch(); ecg_countdown(); // countdown before ecg capture - ecg(pid); // capturing ecg + heart_rate=ecg(pid); // capturing ecg state1=0; - screen_ecg_2(); + screen_ecg_2(heart_rate); state=6; nstate=state; ecg_flag=1;