Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_3rd_nov_2017 by
Diff: ecgg.cpp
- Revision:
- 36:00d96aa14658
- Parent:
- 34:8f6b0dc124e8
- Child:
- 39:69b09bd87502
--- a/ecgg.cpp Sat Jul 29 10:38:05 2017 +0000
+++ b/ecgg.cpp Sat Jul 29 11:23:19 2017 +0000
@@ -108,12 +108,13 @@
Timer t;
//------------------ Declaration for Peak value detection ------------------------------------
- uint32_t ecg_samp1[1] ; uint32_t ecg_samp2[1]; uint32_t ecg_samp3[1]; // Buff 12 &3 Stores sample 1, 2 & 10th sample
+ uint32_t ecg_samp1[1] ;
+ uint32_t ecg_samp2[1];
+ uint32_t ecg_samp3[1]; // to Stores sample 1, 2 & 10th sample
uint32_t fppos; // Variable to hold pointer position
uint32_t hi_val;
uint32_t pk_val[20];
uint16_t pk_pos[20]={0};
- // unsigned int a; //uint32_t pk=0;
int32_t hi_dif = 0; //diff between high value and it's consecutive value
uint16_t j=0; // int count1 = N_ECG/fs, a_dif=0, fs1 = fs ,h=0;
int32_t m =0; // Variable to move the file pointer in fseek fun
@@ -126,15 +127,12 @@
uint8_t t_sec = 60;
float HR_sum = 0,HR_avg;
// -------------------------------------------------------------------------------------------
- // unsigned char chk = 1;
pc.baud(baud_rate);
freqset(); // setting the frequency
setupfunc();
//ecgtestsetupfunc(); // For test set up of 1Hz square wave signal
lead_reg= ecgsetupfunc();
- // chk = 1;
-
-
+
//ORIGINAL sd_open_ECGfile(pid); // opening the ecg file COMMENTED Nidhin 1/6/2017
if (lead_reg==0) // checking for proper lead contact// 14/06
{
@@ -151,23 +149,9 @@
}
- //sd_close(); // closing the file COMMENTED Nidhin 1/6/2017
- sd_close_ecg(); // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin
+ sd_close_ecg(); // closing the ECG file REPLACED Nidhin 1/6/2017 Nidhin
-/*
- // ---------- 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 -------------------------------------------------------------
@@ -184,24 +168,16 @@
fread(ecg_samp2, sizeof(uint32_t), 1, fpeecg1); // Read Sample 2
fseek(fpeecg1, samp_10, SEEK_CUR); // Moving to tenth sample
fread(ecg_samp3, sizeof(uint32_t), 1, fpeecg1); // Read 3rd sample
-//pc.printf("ecg_samp1 = %d , ecg_samp2 = %d, ecg_samp3 = %d\n",ecg_samp1[0],ecg_samp2[0],ecg_samp3[0] ); //Test Value held by buffer each round
-
if(ecg_samp1[0]>ecg_samp2[0])
{
hi_val = ecg_samp1[0]; //To find the high value
-//printf("high value= %d\n",hi_val);
-//a = i;
-//printf("a= %d\n",a);
hi_dif = hi_val-ecg_samp3[0];
// ---------------------------- 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]=i; // also save the peak's position
@@ -211,16 +187,13 @@
j = j+1;
m = m + 480; //similar reason to considering 28, but to skip 120 samples. this cond. is satisfied only when we hit a peak - suhasini_26thjune17
- // printf("j after peak detection is= %d\n",j);
- // }
- }
+ }
else
{
m = m+4; // this is when we do not hit a peak and have to continue searching thru, hence move to the next sample and not skip 120 samples- - suhasini_26thjune17
}
- // store the peak value position in "pk_pos"
-}
+ }
else
{
m = m+4;
@@ -236,12 +209,10 @@
{
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];
}
@@ -253,7 +224,6 @@
}
HR_avg = HR_sum/(n-1); // 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 avg is = %f\n",HR_avg);
fclose(fpeecg1);
@@ -261,33 +231,25 @@
if(HR_avg>100 || HR_avg<40)
{
-
return 1; // out of range condition returning 1 //nikita//10/7
-
}
else
{
BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0;
- BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = HR_avg; //To be modified after HR code is added. // changed nikita
+ BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = HR_avg; //To be modified after HR code is added.
structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file //COMMENTED Nidhin 10/6/2017
ecgfile_mainfile(pid); // copy raw data to the main file and ECG file is cleared. //COMMENTED Nidhin 10/6/2017
pc.printf("Closed the main file\n");
-
-
-
- //return HR1;
return HR_avg;
}
}
else
{
pc.printf("improper lead connection");
- return 0; // returning 0 for improper lead connection
+ return 0;
}
pc.printf("closing temporary file\n");
- // fclose(fpeecg1);
-// pc.printf("temporary file closed\n");
} // End of main function
\ No newline at end of file
