diff --git a/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c b/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c index 1a502a2..64bcb99 100755 --- a/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c +++ b/PULP/adaptive_Rpeak_detection/adaptiveRpeakDetection.c @@ -1,413 +1,529 @@ #include "rt/rt_api.h" #include "adaptiveRpeakDetection.h" #include "../defines.h" #include "../profiling/profile.h" #include "../profiling/profile_cl.h" #include "../profiling/defines.h" #include "../data/signal.h" #include "../Morph_filt/morpho_filtering.h" #include "../Morph_filt/defines_globals.h" #include "../error_detection/error_detection.h" #include "../kmeans_clustering/kmean/k_mean_functions.h" #define N_WINDOWS (int) (2*((ECG_VECTOR_SIZE-LONG_WINDOW)/DIM)+1)// Counting the worst case scenario when overlap is DIM RT_L2_DATA int16_t ecg_L2buff[(LONG_WINDOW+DIM)*(NLEADS+1)]; RT_L2_DATA rt_perf_t perf[NUM_CORES]; #ifdef MODULE_MF RT_L2_DATA int32_t *argMF[4]; RT_L2_DATA int32_t buffSize_windowMF; #endif #ifdef MODULE_RELEN RT_L2_DATA int32_t *argRelEn[4]; RT_L2_DATA int32_t start_RelEn = 1; RT_L2_DATA int32_t buffSize_windowRelEn; #endif #ifdef MODULE_RPEAK_REWARD RT_L2_DATA int32_t *argRW_Rpeak[3]; RT_L2_DATA int32_t indicesRpeaks[H_B+1]; #endif #ifdef MODULE_ERROR_DETECTION RT_L2_DATA int32_t *argErrDet[5]; RT_L2_DATA int32_t lastRpeak = 0; RT_L2_DATA int32_t lastRR = 0; RT_L2_DATA int32_t error_RWindow = 0; #endif #ifdef MODULE_CLUSTERING RT_L2_DATA int32_t rL2BufferIndex; RT_L2_DATA int32_t rL1BufferIndex = 0; +RT_L2_DATA int32_t sizeBufferTransferBytes = 2*DIM; //Transfering int16_t --> 2 bytes RT_L1_DATA int16_t ecg_L1buff[DIM*(NLEADS+1)]; RT_L2_DATA int32_t start_index_buff = 0; RT_L2_DATA int32_t end_main_loop; RT_L2_DATA int32_t flag_prev_error = 0; -RT_L2_DATA int32_t* argCL[8]; +RT_L2_DATA int32_t* argCL[9]; RT_L1_DATA int32_t overlapCL = 1; RT_L1_DATA int32_t* indicesRpeaksCL[H_B+1]; +RT_L1_DATA int32_t overlap_qrs_init = 0; RT_L2_DATA int32_t rpeaks_counter_cl; RT_L2_DATA rt_event_sched_t * psched = 0; RT_L2_DATA int32_t done = 0; #endif RT_L2_DATA int32_t overlap; RT_L2_DATA int32_t rWindow; void clearRelEn() { clearAndResetRelEn(); resetPeakDetection(); } #ifdef MODULE_CLUSTERING static void cluster_Rpeaks(int32_t *arg[]) { rt_team_fork(NUM_CORES, rpeaks, arg); } +static void prof_cluster_start(void *arg) +{ + rt_team_fork(NUM_CORES, profile_cl_start, arg); +} + +static void prof_cluster_stop(void *arg) +{ + rt_team_fork(NUM_CORES, profile_cl_stop, arg); +} + extern void end_of_call(void *arg) { done = 1; } static void fCore0_DmaTransfer_Window(void *arg) { rt_dma_copy_t dmaCp; // Copy data block window from L2 to shared L1 memory using the cluster DMA - rt_dma_memcpy((unsigned int)&ecg_L2buff[rL2BufferIndex], (unsigned int)&ecg_L1buff[rL1BufferIndex], 2*DIM, RT_DMA_DIR_EXT2LOC, 0, &dmaCp); + rt_dma_memcpy((unsigned int)&ecg_L2buff[rL2BufferIndex], (unsigned int)&ecg_L1buff[rL1BufferIndex], sizeBufferTransferBytes, RT_DMA_DIR_EXT2LOC, 0, &dmaCp); // Wait for dma to finish rt_dma_wait(&dmaCp); } #endif //#ifdef MODULE_CLUSTERING void adaptiveRpeakDetection(){ #ifdef MODULE_CLUSTERING rt_cluster_mount(MOUNT, 0, 0, NULL); #endif int32_t count_sample = 0; int32_t offset_window = 0; int32_t offset_ind = LONG_WINDOW/2+1; int32_t tot_overlap = 0; overlap = 0; #ifdef MODULE_MF int32_t flagMF = 0; int32_t i_lead = 0; buffSize_windowMF = LONG_WINDOW+DIM; argMF[0] = (int32_t*) ecg_L2buff; argMF[1] = &flagMF; argMF[2] = &i_lead; argMF[3] = &buffSize_windowMF; init_filtering(); #endif #ifdef MODULE_RELEN buffSize_windowRelEn = LONG_WINDOW+DIM; argRelEn[0] = (int32_t*) ecg_L2buff; argRelEn[1] = (int32_t*) &ecg_L2buff[(LONG_WINDOW+DIM)*NLEADS]; argRelEn[2] = &start_RelEn; argRelEn[3] = &buffSize_windowRelEn; clearRelEn(); #endif #ifdef MODULE_RPEAK_REWARD int32_t rpeaks_counter = 0; argRW_Rpeak[0] = (int32_t*) &ecg_L2buff[LONG_WINDOW+(LONG_WINDOW + DIM)*NLEADS]; argRW_Rpeak[1] = indicesRpeaks; argRW_Rpeak[2] = &offset_ind; #endif #ifdef MODULE_CLUSTERING rL2BufferIndex = 0; // Allocate event on the default scheduler if (rt_event_alloc(NULL, 1)) return -1; rt_event_t *event; #endif for(rWindow=0; rWindow= ECG_VECTOR_SIZE){ return; } if(rWindow > 0){ offset_window = LONG_WINDOW; } else{ offset_window = 0; } if (rWindow > 0) { for(int32_t i=0; i 0) start_RelEn = 0; argRelEn[0] = (int32_t*) &ecg_L2buff[offset_window + overlap]; argRelEn[1] = (int32_t*) &ecg_L2buff[offset_window + (LONG_WINDOW + DIM)*NLEADS+overlap]; buffSize_windowRelEn = LONG_WINDOW - offset_window + DIM-overlap; #endif relEn_w(argRelEn); #ifdef HWPERF_MODULES profile_stop(perf); #endif #ifdef PRINT_RELEN for(int32_t sample = offset_window + (LONG_WINDOW + DIM)*NLEADS; sample< (LONG_WINDOW + DIM)*(NLEADS+1); sample++) { printf("%d\n", ecg_L2buff[sample]); } #endif #endif #ifdef MODULE_RPEAK_REWARD #ifdef HWPERF_MODULE_RPEAK_REWARD || HWPERF_MODULES profile_start(perf); #endif getPeaks_w(argRW_Rpeak); rpeaks_counter = 0; while(indicesRpeaks[rpeaks_counter]!=0) { rpeaks_counter++; } #ifdef HWPERF_MODULE_RPEAK_REWARD || HWPERF_MODULES profile_stop(perf); #endif #ifdef PRINT_RPEAKS for(int32_t indR=0; indR1){ start_index_buff = DIM; } #endif argErrDet[0] = &rpeaks_counter; argErrDet[1] = &rWindow; argErrDet[2] = &lastRR; argErrDet[3] = indicesRpeaks; argErrDet[4] = &lastRpeak; error_RWindow = errorDetection(argErrDet); #ifdef PRINT_ERROR_RPEAKS - printf("%d\n", error_RWindow); + printf("Err: %d\n", error_RWindow); #endif #endif #ifdef MODULE_CLUSTERING rL2BufferIndex = LONG_WINDOW+(LONG_WINDOW + DIM)*NLEADS; end_main_loop = DIM*(NLEADS+1); #ifdef MODULE_ERROR_DETECTION if(error_RWindow == 0 || rWindow == 0){ //Previous window or first window + + // ======= Find the r peaks at the border of CL if it was run in the previous window (err=1) and the peak was not finished ======= // + if(flag_prev_error==1 && overlap_qrs_init!=0){ + rL1BufferIndex = DIM; + sizeBufferTransferBytes = 2*(MAX_QRS_DUR + 2 - overlap_qrs_init); + // --------------- Copy the few samples to finish the peak from the previous window from L2 to L1 memory if error was 1 ----------------- // + // Initialize event + event = rt_event_get_blocking(NULL); + + // Run function on Core 0 of the cluster + rt_cluster_call(NULL, 0, fCore0_DmaTransfer_Window, NULL, NULL, STACK_SIZE, STACK_SIZE, 1, event); + + // Wait for event + rt_event_wait(event); + // ------------------------------------------------------------------------------------------------------------------------------------- // + + start_index_buff = DIM; + end_main_loop = DIM + (MAX_QRS_DUR + 2 - overlap_qrs_init); + + argCL[0] = (int32_t*) ecg_L1buff; //The start index is the one in argCL[1] + argCL[1] = &rWindow; + argCL[2] = &start_index_buff; + argCL[3] = &end_main_loop; + argCL[4] = &offset_ind; + argCL[5] = &flag_prev_error; + argCL[6] = indicesRpeaksCL; + argCL[7] = &overlapCL; + argCL[8] = &overlap_qrs_init; + +#ifdef HWPERF_FULL + profile_stop(perf); +#endif + + #ifdef HWPERF_CLUSTER + rt_cluster_call(NULL, CID, prof_cluster_start, perf, NULL, STACK_SIZE, 0, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); + while(!done) + rt_event_execute(psched, 1); + done = 0; + #endif + + rt_cluster_call(NULL, CID, cluster_Rpeaks, argCL, NULL, STACK_SIZE, STACK_SIZE, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); + while(!done) + rt_event_execute(psched, 1); + done = 0; + + #ifdef HWPERF_CLUSTER + rt_cluster_call(NULL, CID, prof_cluster_stop, perf, NULL, STACK_SIZE, 0, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); + while(!done) + rt_event_execute(psched, 1); + done = 0; + #endif + +#ifdef HWPERF_FULL + profile_start(perf); +#endif + #ifdef PRINT_RPEAKS_CL + rpeaks_counter_cl = 0; + + while(indicesRpeaksCL[rpeaks_counter_cl]!=0) { + rpeaks_counter_cl++; + } + + for(int ix_rr=0; ix_rr 0 && error_RWindow == 1){ #else if(rWindow == 0){ rL1BufferIndex = 0; start_index_buff = 0; // -------------------------------- Copy first window ecg buffer from L2 to L1 memory ------------------------------------------ // // Initialize event event = rt_event_get_blocking(NULL); // Run function on Core 0 of the cluster rt_cluster_call(NULL, 0, fCore0_DmaTransfer_Window, NULL, NULL, STACK_SIZE, STACK_SIZE, 1, event); // Wait for event rt_event_wait(event); // ------------------------------------------------------------------------------------------------------------------------------// }else{ rL1BufferIndex = DIM; if(rWindow == 1) start_index_buff = 0; else start_index_buff = DIM; #endif // ----------------Copy current window ecg buffer from L2 to L1 memory if error was 1 or after first window--------------------- // // Initialize event event = rt_event_get_blocking(NULL); // Run function on Core 0 of the cluster rt_cluster_call(NULL, 0, fCore0_DmaTransfer_Window, NULL, NULL, STACK_SIZE, STACK_SIZE, 1, event); // Wait for event rt_event_wait(event); // ------------------------------------------------------------------------------------------------------------------------------// argCL[0] = (int32_t*) ecg_L1buff; //The start index is the one in argCL[1] argCL[1] = &rWindow; argCL[2] = &start_index_buff; argCL[3] = &end_main_loop; argCL[4] = &offset_ind; argCL[5] = &flag_prev_error; argCL[6] = indicesRpeaksCL; argCL[7] = &overlapCL; + argCL[8] = &overlap_qrs_init; + +#ifdef HWPERF_FULL + profile_stop(perf); +#endif + + #ifdef HWPERF_CLUSTER + rt_cluster_call(NULL, CID, prof_cluster_start, perf, NULL, STACK_SIZE, 0, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); + while(!done) + rt_event_execute(psched, 1); + done = 0; + #endif + rt_cluster_call(NULL, CID, cluster_Rpeaks, argCL, NULL, STACK_SIZE, STACK_SIZE, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); while(!done) rt_event_execute(psched, 1); done = 0; + #ifdef HWPERF_CLUSTER + rt_cluster_call(NULL, CID, prof_cluster_stop, perf, NULL, STACK_SIZE, 0, NUM_CORES, rt_event_get(psched, end_of_call, (void *) CID)); + while(!done) + rt_event_execute(psched, 1); + done = 0; + #endif + +#ifdef HWPERF_FULL + profile_start(perf); +#endif // Move last sample to index DIM-1 of L1 buffer for the next window (this is necessary if the clustering module runs without error detection // or if the previous error was 1 and the clustering must keep running) // The clustering uses the approximated signal derivative (a diff function), so it needs the last sample of the previous window to not miss anything - for(int ix_ov = 0; ix_ov < overlapCL; ix_ov++) + for(int ix_ov = 0; ix_ov < overlapCL; ix_ov++){ ecg_L1buff[DIM-overlapCL+ix_ov] = ecg_L1buff[end_main_loop-overlapCL+ix_ov]; + } flag_prev_error = 1; #ifdef PRINT_RPEAKS_CL rpeaks_counter_cl = 0; while(indicesRpeaksCL[rpeaks_counter_cl]!=0) { rpeaks_counter_cl++; } for(int ix_rr=0; ix_rr #include "rt/rt_api.h" #include "../defines.h" -#define ECG_VECTOR_SIZE 5874 +#define ECG_VECTOR_SIZE 6262 -RT_L2_DATA int16_t ecg_1l[ECG_VECTOR_SIZE] = {-36,-62,-58,-73,-129,-151,-136,-142,-137,-55,86,246,388,564,820,943,717,198,-426,-932,-1223,-1348,-1232,-941,-637,-359,-190,-119,-52,51,170,273,240,225,393,608,650,670,793,866,864,831,817,816,838,867,911,934,945,937,914,905,897,894,883,806,717,643,562,511,488,373,198,115,90,101,150,244,248,164,104,53,44,44,-32,-34,-35,-117,-185,-258,-370,-437,-475,-671,-897,-1043,-1091,-1109,-1129,-1093,-1050,-1065,-1091,-1128,-1123,-999,-777,-522,-266,25,289,258,-151,-683,-1154,-1512,-1691,-1668,-1522,-1277,-1018,-791,-655,-542,-423,-342,-313,-290,-239,-165,-118,-114,-118,-17,64,124,149,161,174,160,224,306,323,323,438,511,551,570,546,548,582,558,511,461,401,348,272,181,183,229,300,325,258,279,268,229,228,203,205,200,186,97,-21,-84,-122,-243,-314,-255,-173,-152,-164,-199,-238,-243,-211,-190,-149,-97,-66,32,186,332,564,756,905,975,744,256,-263,-670,-954,-1042,-919,-694,-464,-270,-152,-69,41,112,94,77,70,79,121,142,126,144,161,178,216,249,263,279,371,462,500,529,573,572,540,531,534,502,480,480,488,469,386,284,184,126,72,13,-7,19,73,94,131,180,187,144,120,140,189,203,170,109,21,-45,-46,-60,-115,-180,-209,-191,-160,-131,-123,-172,-234,-227,-108,-11,-12,-14,95,259,310,420,683,944,1040,851,365,-252,-800,-1130,-1183,-1063,-851,-651,-495,-401,-316,-268,-260,-314,-371,-338,-255,-295,-368,-377,-385,-377,-353,-323,-287,-250,-270,-237,-104,-22,31,66,55,57,100,95,54,147,225,214,175,134,108,67,11,8,3,0,23,53,58,82,78,54,67,65,4,-61,-84,-143,-255,-321,-342,-363,-407,-394,-353,-309,-276,-256,-274,-282,-250,-211,-157,-113,-106,-39,210,466,747,992,1063,848,408,-148,-602,-954,-1050,-853,-619,-459,-353,-244,-84,65,106,80,58,79,71,103,138,171,293,369,343,286,299,339,382,406,442,467,476,520,581,584,640,745,745,666,556,476,411,367,323,349,358,260,161,99,120,135,124,143,126,82,86,97,95,110,164,156,78,7,-110,-216,-248,-228,-174,-137,-98,-2,132,277,400,471,462,416,418,454,459,412,374,400,541,757,1027,1283,1374,1134,621,75,-359,-615,-622,-406,-146,16,91,81,41,75,126,144,134,173,174,113,82,106,108,95,75,59,90,147,141,113,164,195,215,243,272,358,381,757,700,464,375,345,219,80,-19,-189,-262,-275,-271,-292,-366,-414,-439,-408,-388,-396,-429,-477,-508,-555,-610,-625,-694,-783,-838,-850,-845,-826,-766,-741,-747,-735,-706,-696,-666,-642,-595,-583,-614,-552,-376,-131,142,416,652,745,503,-26,-620,-1100,-1378,-1400,-1215,-955,-724,-552,-460,-362,-245,-194,-138,-72,-54,-28,-12,-10,-1,34,118,206,251,219,220,272,316,345,359,325,350,410,401,332,310,270,213,131,51,-61,-144,-258,-380,-436,-451,-414,-291,-182,-143,-198,-262,-329,-309,-259,-247,-212,-199,-247,-273,-232,-246,-284,-237,-130,-118,-157,-217,-215,-156,-123,-123,-132,-136,-150,-151,-145,-34,235,551,833,1085,1255,1385,1409,1164,649,70,-408,-740,-883,-793,-583,-389,-188,36,163,178,118,68,67,96,127,185,235,250,235,221,259,299,306,306,279,283,342,405,444,476,480,500,578,654,707,712,673,599,504,415,367,337,305,249,179,98,49,69,126,165,133,21,-41,10,107,103,25,-83,-154,-224,-329,-400,-399,-399,-401,-366,-379,-383,-382,-427,-403,-319,-287,-345,-406,-486,-502,-348,-79,191,486,648,406,-320,-1107,-1702,-2078,-2191,-2088,-1882,-1632,-1396,-1200,-1032,-938,-886,-761,-641,-538,-472,-446,-419,-375,-314,-240,-182,-119,-82,-45,8,43,85,145,213,286,337,374,399,418,435,452,447,426,405,373,308,260,234,243,264,294,325,328,269,237,250,246,174,97,115,141,100,-26,-118,-156,-143,-91,-117,-222,-299,-235,-125,-85,-26,22,-7,-75,-126,-123,-138,-119,31,311,602,832,1048,1048,726,219,-308,-702,-944,-1006,-932,-696,-394,-256,-175,-17,98,155,155,147,140,135,182,262,311,300,321,389,401,344,311,290,332,411,481,539,557,619,711,748,661,556,549,575,555,516,407,267,156,50,29,80,122,145,181,176,108,60,58,74,64,56,64,40,-16,-49,-78,-122,-124,-128,-179,-254,-322,-322,-262,-201,-226,-288,-303,-284,-266,-256,-243,-274,-259,-124,66,343,693,953,1064,904,406,-223,-685,-1017,-1211,-1234,-1078,-869,-598,-268,-120,-214,-155,-47,-8,2,-4,-44,-50,-8,-2,16,38,76,102,92,79,79,92,102,103,173,217,241,302,300,248,244,297,336,344,316,239,164,107,56,37,37,48,74,104,110,105,84,67,45,12,-36,-115,-181,-253,-296,-345,-411,-433,-421,-399,-390,-406,-379,-343,-350,-334,-313,-266,-184,-110,-20,163,412,680,876,934,737,289,-210,-656,-960,-1135,-1094,-863,-594,-378,-238,-179,-71,71,115,64,-8,36,151,137,115,190,257,254,249,309,356,410,440,460,497,579,653,727,795,782,748,736,740,728,682,602,484,374,298,230,185,137,105,126,139,136,138,179,158,121,128,90,31,42,87,56,-61,-169,-236,-253,-241,-264,-312,-322,-314,-316,-323,-363,-383,-331,-297,-289,-306,-331,-334,-276,-138,66,302,538,806,941,718,189,-415,-855,-1108,-1153,-1029,-809,-571,-338,-143,-27,37,115,204,257,282,290,304,323,352,356,334,309,266,212,269,436,486,491,507,514,546,521,482,509,553,553,551,370,192,40,-77,-144,-247,-377,-388,-347,-334,-356,-381,-399,-451,-527,-452,-324,-275,-370,-511,-551,-543,-587,-607,-593,-599,-641,-702,-742,-759,-753,-729,-657,-571,-529,-539,-550,-525,-514,-493,-389,-149,146,464,761,820,502,-54,-619,-995,-1179,-1207,-1074,-857,-636,-432,-278,-164,-88,-31,26,28,29,53,98,126,155,210,245,272,265,330,398,416,450,539,587,604,587,621,672,705,722,683,609,558,515,525,561,603,625,537,450,441,386,291,331,447,504,419,269,166,135,141,150,161,182,198,199,189,207,313,408,361,282,252,268,257,225,267,332,323,251,210,233,330,543,682,756,977,1125,916,390,-265,-802,-1189,-1342,-1276,-1091,-842,-579,-430,-411,-417,-369,-281,-238,-228,-166,-88,-53,-109,-171,-158,21,216,293,376,516,639,703,730,760,782,778,765,800,847,879,873,794,700,653,581,491,405,337,273,211,187,230,226,191,148,67,-44,-116,-126,-144,-141,-174,-241,-330,-398,-428,-406,-405,-481,-558,-601,-633,-731,-731,-604,-528,-476,-491,-527,-578,-626,-749,-879,-902,-845,-731,-511,-226,-202,-509,-1022,-1508,-1904,-2101,-2083,-1891,-1595,-1313,-1087,-941,-832,-716,-635,-578,-549,-539,-496,-450,-437,-392,-313,-234,-182,-94,6,86,102,118,170,244,274,303,314,333,373,429,468,488,485,479,450,385,332,281,236,205,204,219,225,217,223,208,197,198,187,174,153,107,30,-47,-137,-210,-228,-227,-208,-202,-179,-121,-65,-39,-90,-168,-111,-21,142,343,516,604,631,617,734,1095,1337,1244,841,223,-287,-590,-749,-686,-488,-223,55,283,544,738,842,884,887,885,883,913,959,1033,1050,975,891,852,884,895,834,744,672,719,830,837,768,730,700,683,651,611,549,454,371,268,123,22,-38,-114,-161,-168,-124,-61,16,72,45,-4,-51,-100,-134,-190,-211,-202,-219,-346,-528,-626,-676,-677,-656,-629,-633,-668,-703,-693,-649,-618,-585,-566,-502,-455,-479,-483,-477,-477,-390,-200,49,284,272,-15,-461,-987,-1454,-1725,-1790,-1688,-1449,-1160,-979,-831,-600,-414,-331,-293,-296,-344,-354,-281,-188,-144,-222,-334,-299,105,1190,1059,626,217,-20,-89,-25,20,93,131,184,280,272,190,75,-7,-59,-103,-200,-306,-373,-406,-373,-288,-226,-230,-280,-286,-271,-233,-196,-198,-246,-279,-319,-360,-347,-336,-343,-330,-296,-283,-294,-305,-280,-219,-184,-175,-192,-188,-171,-145,-73,51,257,531,785,999,1080,847,360,-177,-596,-867,-966,-866,-638,-387,-177,-26,68,50,38,127,226,238,157,141,190,293,421,488,461,385,330,315,337,393,460,555,602,665,738,771,726,672,635,617,635,602,513,444,437,393,326,231,181,167,128,161,202,163,192,306,362,341,281,193,128,133,193,148,-1,-129,-161,-205,-272,-324,-300,-285,-305,-347,-402,-408,-356,-289,-251,-223,-189,-137,-10,233,553,855,1093,1329,1482,1349,866,275,-197,-528,-696,-633,-516,-412,-266,-135,-67,-25,25,26,-39,-73,-62,-44,-54,-95,-136,-121,-104,-95,-60,-32,-19,-15,-9,4,69,176,294,335,263,112,-27,-101,-91,-75,-114,-204,-262,-326,-370,-319,-278,-271,-304,-363,-467,-307,-82,-116,-198,-219,-188,-109,-138,-277,-373,-414,-435,-496,-567,-575,-533,-490,-480,-482,-486,-475,-447,-413,-406,-403,-344,-275,-210,-93,151,464,765,982,933,547,-21,-567,-975,-1161,-1099,-868,-593,-381,-229,-95,-4,36,74,121,129,122,128,130,150,196,242,280,271,294,310,298,344,406,424,482,636,740,722,669,662,672,643,552,485,446,373,345,286,242,259,285,283,254,232,250,295,335,372,367,309,261,252,201,75,-1,0,-23,-71,-120,-172,-185,-215,-204,-145,-154,-165,-152,-141,-160,-145,-86,-38,11,117,348,625,838,1066,1376,1465,1079,405,-231,-672,-880,-939,-896,-677,-403,-287,-179,-24,27,-9,-116,-146,-31,18,26,185,363,433,441,446,509,557,543,463,461,538,584,602,626,652,704,733,685,602,543,452,365,318,263,181,106,52,13,-7,-19,-15,-33,-81,-128,-143,-142,-138,-129,-147,-218,-298,-316,-300,-328,-507,-707,-881,-950,-885,-846,-866,-923,-905,-748,-689,-718,-709,-681,-616,-575,-602,-602,-390,-98,54,204,258,19,-508,-1015,-1388,-1705,-1887,-1799,-1549,-1275,-1055,-850,-730,-657,-596,-526,-479,-454,-444,-408,-337,-265,-242,-237,-215,-168,-104,-55,-16,35,105,182,242,275,314,397,455,508,545,539,545,528,479,430,389,357,331,280,233,204,185,185,178,222,269,287,256,224,270,231,139,77,-11,-99,-160,-179,-249,-241,-149,-133,-150,-171,-166,-156,-130,-90,-12,36,21,51,219,455,684,892,1167,1308,932,288,-321,-737,-955,-1013,-917,-629,-284,-22,128,201,186,192,205,248,331,427,423,359,308,288,296,332,389,387,330,352,422,483,491,489,537,567,569,575,599,593,540,496,443,370,235,55,-35,-49,14,77,90,142,232,274,316,373,449,473,411,287,198,148,97,8,-61,-68,-91,-199,-370,-477,-520,-534,-552,-572,-600,-629,-641,-619,-616,-640,-615,-574,-563,-508,-327,-58,210,481,665,513,59,-489,-951,-1230,-1329,-1245,-1129,-1006,-742,-445,-244,-166,-141,-71,-43,-146,-220,-145,-38,36,76,170,205,218,285,289,213,157,220,359,470,606,632,561,497,473,492,507,467,468,450,378,289,187,142,149,141,141,181,207,177,123,103,75,36,-3,-40,-81,-114,-155,-187,-219,-257,-289,-323,-329,-312,-283,-243,-197,-181,-184,-179,-167,-152,-151,-145,-4,188,450,679,867,920,718,288,-258,-730,-1028,-1119,-1023,-807,-540,-302,-100,8,25,24,72,123,136,92,80,114,142,165,191,272,354,347,315,336,336,336,312,335,391,431,456,511,550,572,604,592,577,548,449,370,339,274,162,49,-22,-41,-39,22,150,184,53,-22,9,38,70,75,61,13,-23,-56,-129,-242,-329,-367,-372,-323,-304,-347,-410,-453,-474,-480,-437,-354,-265,-232,-234,-203,-158,-52,98,271,462,700,800,520,-61,-654,-1065,-1272,-1276,-1149,-941,-715,-534,-458,-432,-377,-332,-298,-221,-172,-130,-55,-1,33,51,72,95,116,145,146,146,182,231,296,369,408,438,503,561,599,555,486,405,316,318,341,354,249,164,132,89,64,8,47,111,68,36,94,89,16,-55,-87,-126,-165,-168,-220,-253,-239,-268,-326,-293,-256,-255,-310,-385,-443,-442,-407,-413,-432,-372,-237,-17,260,508,738,836,626,141,-412,-809,-1031,-1105,-1025,-828,-625,-461,-329,-205,-89,-6,47,94,121,167,206,233,244,239,256,294,312,309,316,331,355,392,433,472,527,583,626,652,670,665,675,665,608,536,476,434,370,301,238,171,119,114,107,127,123,98,153,202,171,69,-31,-53,-77,-78,-73,-138,-235,-304,-331,-359,-353,-355,-417,-467,-425,-329,-162,-40,-26,-34,24,43,72,136,216,410,740,1079,1348,1422,1153,650,54,-500,-879,-1043,-980,-792,-654,-629,-578,-493,-425,-399,-379,-387,-428,-446,-398,-365,-317,-288,-285,-207,-96,-23,-7,-36,-68,-27,55,179,296,296,260,306,339,342,311,261,192,152,171,170,92,-14,-36,-14,-29,-56,-85,-88,-73,-37,-22,-62,-116,-141,-152,-173,-240,-328,-386,-435,-462,-463,-437,-410,-409,-392,-375,-359,-317,-271,-218,-180,-185,-210,-240,-169,18,256,499,774,963,767,266,-316,-821,-1151,-1227,-1043,-729,-551,-454,-296,-141,-44,16,75,87,138,215,181,125,81,30,92,201,262,285,297,305,324,351,382,406,424,437,478,544,575,571,563,524,464,389,331,298,254,225,224,205,176,146,137,173,226,275,300,297,271,227,197,185,149,92,13,-96,-208,-287,-363,-403,-448,-472,-479,-459,-417,-363,-303,-282,-288,-292,-269,-251,-239,-180,-61,109,307,540,829,995,759,210,-370,-838,-1199,-1326,-1206,-977,-758,-511,-296,-176,-146,-134,-118,126,109,91,205,343,458,582,651,616,454,376,417,473,486,544,604,663,713,697,682,640,585,495,526,551,436,293,201,164,150,103,0,-92,-63,-15,-28,-16,41,20,-70,-155,-217,-311,-375,-368,-349,-363,-419,-461,-470,-470,-496,-543,-560,-567,-527,-480,-533,-523,-458,-458,-490,-484,-373,-168,92,381,678,802,565,56,-515,-963,-1210,-1245,-1114,-883,-634,-456,-349,-278,-220,-184,-168,-163,-134,-78,-25,-22,3,39,34,-17,-92,-38,109,235,293,285,258,253,254,253,253,253,326,548,490,448,424,407,428,373,326,290,217,175,137,168,209,188,210,200,202,208,147,33,-31,-38,-67,-107,-119,-159,-255,-317,-365,-383,-378,-387,-397,-373,-380,-399,-421,-417,-367,-277,-166,-117,-90,-17,131,311,463,611,607,319,-242,-804,-1132,-1205,-1076,-858,-629,-439,-300,-212,-151,-108,-70,-19,22,64,96,119,149,158,156,173,195,215,247,301,348,395,477,534,495,427,384,385,444,475,404,252,166,143,117,44,35,58,29,-48,-87,-37,-24,3,90,131,120,134,184,158,117,92,13,-60,-102,-197,-284,-290,-302,-318,-341,-382,-355,-196,-68,-83,-146,-226,-290,-285,-270,-225,-146,-9,202,438,627,876,988,697,145,-368,-725,-998,-1105,-945,-741,-585,-388,-265,-119,39,66,11,35,120,168,199,234,262,251,253,241,208,205,246,282,258,256,300,342,367,385,414,454,472,441,371,317,296,285,268,239,193,133,122,129,122,105,126,142,139,132,105,88,86,80,33,-41,-121,-202,-268,-287,-277,-300,-323,-319,-321,-294,-309,-333,-341,-370,-350,-260,-170,-172,-185,-54,171,368,616,1403,2464,2220,1229,220,-466,-977,-1228,-1215,-1075,-930,-791,-628,-548,-525,-388,-265,-200,-200,-171,-178,-163,-73,-37,-96,-29,49,37,-9,10,82,126,140,195,251,333,426,462,482,466,446,361,229,113,46,13,-7,-43,-101,-146,-173,-160,-90,-24,3,16,30,23,-27,-51,-51,-78,-164,-263,-331,-376,-440,-468,-463,-425,-412,-489,-577,-594,-568,-568,-531,-436,-373,-421,-417,-322,-221,33,353,600,830,928,754,365,-202,-730,-1085,-1212,-1147,-920,-608,-340,-164,-121,-117,-84,52,146,165,165,152,151,188,190,161,206,300,372,353,327,414,520,520,534,629,733,787,799,750,699,706,696,709,695,656,617,524,424,358,327,320,336,322,308,332,346,321,246,174,144,99,-9,-48,-54,-87,-146,-223,-272,-284,-273,-265,-222,-192,-175,-180,-187,-178,-202,-216,-164,-170,-216,-155,40,322,577,816,940,746,288,-313,-864,-1229,-1307,-1171,-964,-777,-612,-441,-282,-151,-44,0,-14,-60,-58,-28,15,68,79,54,35,37,63,97,110,119,156,223,280,317,361,409,446,455,441,427,410,372,319,270,224,175,124,78,56,35,5,-6,6,35,22,-44,-106,-134,-143,-146,-160,-195,-237,-287,-356,-426,-446,-434,-419,-424,-441,-457,-458,-435,-400,-368,-346,-339,-336,-351,-372,-331,-194,-2,219,461,704,775,496,-41,-635,-1095,-1367,-1414,-1277,-1054,-822,-617,-468,-388,-348,-287,-207,-137,-98,-56,-24,-8,-9,-26,-12,37,83,122,168,227,285,344,403,455,512,573,592,580,568,603,665,643,564,494,375,210,115,158,243,209,163,159,124,51,3,22,56,49,-23,-114,-122,-148,-183,-210,-234,-285,-351,-358,-329,-304,-320,-351,-395,-392,-338,-275,-241,-255,-238,-153,50,320,587,828,946,764,292,-216,-595,-874,-1005,-929,-726,-555,-374,-183,-46,1,28,93,136,107,142,247,290,283,287,253,156,151,203,264,314,339,373,420,473,565,650,655,609,583,611,695,728,649,555,473,398,334,308,290,236,158,103,85,91,109,146,197,238,285,261,226,219,200,172,100,7,-56,-110,-156,-192,-228,-262,-260,-273,-308,-278,-241,-234,-232,-227,-231,-222,-195,-185,-192,-140,20,237,468,719,947,972,625,25,-558,-986,-1207,-1215,-1064,-853,-643,-478,-358,-270,-215,-177,-144,-117,-95,-67,-41,-23,5,27,44,47,42,57,104,147,174,202,256,310,347,378,405,424,431,421,400,372,324,273,220,175,127,74,49,43,29,20,22,36,49,61,63,44,20,-22,-66,-122,-184,-231,-266,-275,-292,-331,-355,-341,-331,-356,-385,-383,-358,-321,-258,-212,-224,-282,-291,-228,-65,153,359,566,732,674,427,-13,-528,-923,-1136,-1127,-961,-740,-545,-385,-252,-145,-83,-43,-27,-23,-11,35,76,105,117,120,120,141,162,178,181,193,229,280,331,385,439,477,514,543,541,514,475,436,401,349,280,204,105,35,10,-29,-73,-78,-68,-41,8,52,41,-24,-94,-151,-167,-149,-159,-220,-305,-368,-409,-439,-444,-441,-437,-423,-397,-373,-356,-336,-317,-309,-298,-275,-263,-255,-199,-70,137,381,632,867,919,647,118,-439,-867,-1130,-1190,-1044,-767,-519,-358,-251,-139,-51,-28,5,41,47,68,110,162,203,235,237,225,257,315,353,378,380,424,495,484,471,490,568,611,560,529,546,510,441,382,287,211,168,103,28,1,2,-19,-46,-26,66,109,70,39,12,3,-17,-70,-132,-197,-268,-348,-436,-517,-575,-579,-533,-489,-465,-456,-456,-448,-418,-377,-358,-370,-387,-331,-248,-143,70,328,573,814,882,578,38,-491,-892,-1130,-1188,-1061,-813,-579,-387,-219,-134,-99,-52,17,66,65,40,42,73,83,92,109,122,161,235,301,346,378,405,453,492,538,563,580,627,687,687,577,468,422,406,380,287,208,185,164,137,114,108,144,146,114,78,68,58,37,7,-49,-142,-221,-268,-294,-287,-282,-342,-397,-387,-341,-303,-307,-294,-263,-227,-229,-277,-302,-264,-190,-86,111,370,642,820,696,266,-299,-794,-1114,-1217,-1118,-877,-605,-418,-316,-252,-200,-158,-119,-78,-46,-9,20,39,54,94,136,146,142,146,169,218,274,337,405,466,511,548,561,568,582,583,562,536,499,443,367,302,232,151,85,57,49,58,63,78,95,105,114,121,117,137,146,119,90,75,35,-25,-103,-194,-293,-349,-332,-313,-338,-338,-308,-285,-268,-278,-270,-238,-185,-193,-174,-119,-56,101,327,583,880,1074,982,545,-71,-651,-1065,-1232,-1162,-978,-723,-475,-326,-262,-201,-133,-65,-4,61,81,71,125,164,155,121,117,120,91,151,269,324,312,307,340,383,393,410,442,463,455,446,411,323,232,139,60,24,-12,-58,-88,-90,-60,-26,-8,8,34,51,41,16,-13,-41,-56,-76,-112,-172,-240,-303,-347,-373,-414,-444,-453,-436,-410,-385,-348,-315,-301,-282,-249,-233,-251,-256,-198,-50,173,419,677,876,830,433,-156,-684,-1037,-1201,-1169,-992,-760,-545,-364,-228,-153,-126,-87,-51,-22,13,29,37,49,69,88,101,126,165,213,252,286,336,396,448,491,534,563,577,578,578,569,550,530,489,425,354,281,211,166,148,131,116,96,82,73,82,73,49,29,-4,-60,-122,-194,-252,-303,-348,-374,-399,-413,-409,-400,-387,-364,-327,-296,-274,-267,-258,-251,-258,-240,-146,38,292,549,782,868,813,814,813,814,-1128,-1193,-1040,-776,-537,-366,-246,-154,-86,-34,9,50,72,85,85,86,173,217,229,226,232,255,287,325,377,428,491,550,605,643,655,632,611,609,594,537,447,339,232,165,136,86,31,29,40,67,98,99,81,84,111,128,104,73,56,43,11,-31,-94,-152,-188,-220,-233,-261,-287,-316,-321,-306,-280,-255,-220,-167,-146,-155,-175,-197,-164,-95,58,289,542,776,978,1011,636,14,-583,-970,-1152,-1143,-986,-751,-521,-358,-252,-215,-186,-108,4,39,8,4,8,15,55,91,98,96,105,132,166,219,285,352,398,436,461,471,482,490,487,466,431,375,303,224,143,76,40,9,-19,-32,-14,16,32,39,60,96,139,126,63,23,-18,-105,-191,-231,-269,-334,-384,-403,-408,-409,-409,-414,-421,-427,-403,-359,-318,-295,-308,-306,-295,-274,-227,-120,83,300,456,697,860,732,275,-336,-852,-1145,-1199,-1084,-879,-667,-466,-307,-208,-145,-104,-71,-16,31,37,34,43,61,94,137,164,161,173,224,296,362,411,444,463,509,574,604,573,516,482,478,446,384,321,250,193,150,112,82,30,-15,-20,23,53,54,41,9,-23,-51,-81,-133,-192,-239,-292,-327,-370,-402,-414,-416,-421,-410,-392,-379,-365,-361,-351,-358,-330,-289,-300,-324,-254,-77,159,401,642,798,691,287,-268,-773,-1111,-1247,-1167,-946,-676,-452,-310,-204,-127,-96,-70,-23,19,69,95,82,69,98,125,134,150,206,270,320,364,398,437,483,536,586,591,572,575,580,565,535,498,462,400,332,243,144,91,87,98,80,50,37,62,86,100,137,151,148,139,130,105,54,-45,-125,-173,-200,-231,-262,-300,-295,-307,-312,-325,-335,-318,-311,-331,-321,-238,-160,-166,-205,-168,-36,145,371,633,876,922,586,-11,-576,-971,-1180,-1196,-1049,-805,-565,-399,-322,-271,-208,-144,-99,-70,-40,-1,35,51,51,61,70,93,121,152,198,264,328,379,446,513,514,474,453,470,490,495,469,417,359,265,164,88,20,-27,-48,-38,-8,18,23,33,74,108,100,65,21,-25,-74,-120,-164,-206,-247,-284,-319,-347,-368,-373,-375,-362,-334,-324,-321,-294,-275,-275,-275,-186,-243,-310,-289,-150,73,339,589,831,921,672,160,-408,-826,-1056,-1131,-1050,-836,-576,-391,-293,-208,-128,-91,-74,-11,71,97,91,94,108,130,152,174,229,283,298,318,344,372,426,491,547,579,610,606,579,577,575,544,473,399,334,262,201,167,115,68,60,83,126,184,173,95,58,46,24,17,7,-31,-74,-121,-180,-253,-306,-334,-348,-336,-331,-337,-333,-316,-294,-250,-209,-195,-204,-212,-217,-206,-179,-96,79,323,600,878,1040,894,397,-257,-789,-1103,-1203,-1122,-915,-666,-460,-304,-200,-105,-19,35,40,26,55,119,177,200,185,186,215,252,304,367,420,444,452,478,505,527,546,551,591,621,609,569,521,455,378,300,229,168,121,89,55,29,20,20,45,86,128,152,156,118,58,22,40,45,-42,-171,-240,-324,-408,-452,-475,-478,-462,-455,-450,-441,-424,-384,-355,-358,-370,-366,-360,-372,-355,-264,-98,142,418,696,850,711,261,-304,-795,-1156,-1291,-1224,-1028,-810,-622,-468,-300,-191,-140,-112,-89,-51,-24,-23,-27,-8,24,43,50,65,94,143,215,299,355,379,429,484,508,500,485,490,487,450,411,359,313,267,204,138,79,47,37,47,75,95,112,116,71,17,-16,-25,-44,-83,-151,-221,-271,-319,-368,-374,-398,-413,-434,-425,-362,-293,-245,-256,-281,-300,-300,-292,-325,-338,-258,-75,175,424,665,862,815,440,-134,-673,-1039,-1204,-1154,-947,-697,-471,-304,-225,-168,-103,-49,-11,-19,-5,73,133,135,112,108,122,157,201,241,271,303,348,407,462,536,600,591,585,599,597,564,526,466,392,314,245,178,134,49,-36,-60,-70,-57,-13,-1,9,52,107,134,108,81,58,41,32,18,-21,-88,-159,-223,-277,-338,-380,-385,-374,-362,-353,-348,-322,-274,-239,-223,-208,-197,-193,-180,-142,-20,184,407,630,904,1003,725,125,-522,-1013,-1284,-1327,-1190,-938,-662,-429,-278,-201,-130,-64,-60,-56,-12,31,8,-42,-52,-22,32,87,126,162,214,273,318,356,394,437,474,506,532,549,552,527,490,433,353,277,202,126,65,26,0,-14,-14,-13,-5,14,51,105,126,84,23,-7,-6,2,-35,-119,-186,-208,-266,-372,-460,-493,-486,-459,-420,-374,-339,-322,-313,-299,-266,-242,-248,-282,-283,-207,-40,206,481,759,963,888,491,-92,-641,-1026,-1179,-1110,-916,-680,-463,-309,-219,-158,-102,-50,-5,29,66,99,125,149,166,169,176,209,253,311,334,331,352,402,471,536,601,613,572,556,558,550,502,450,395,327,263,217,175,159,155,156,143,134,137,131,128,114,100,74,29,2,-20,-59,-114,-195,-277,-329,-349,-366,-394,-406,-413,-403,-353,-305,-295,-304,-302,-304,-307,-307,-299,-260,-169,12,255,506,735,876,762,364,-194,-727,-1096,-1259,-1205,-986,-691,-423,-229,-121,-66,-29,9,48,72,74,90,119,134,156,182,224,263,299,333,362,374,403,464,525,575,642,726,758,734,703,651,525,424,363,295,216,134,105,92,79,108,181,131,41,56,73,83,106,91,43,-23,-28,-10,-18,-116,-252,-346,-395,-389,-391,-434,-486,-511,-465,-404,-364,-374,-403,-415,-398,-360,-357,-366,-357,-302,-171,29,268,530,786,882,606,32,-567,-1008,-1247,-1256,-1099,-878,-665,-495,-365,-251,-173,-138,-118,-106,-78,-50,-33,0,40,59,79,101,138,204,276,335,380,426,457,483,506,508,542,554,525,481,439,401,353,294,229,184,163,127,110,117,118,120,107,104,113,154,155,124,97,64,18,-23,-71,-135,-191,-223,-230,-258,-318,-336,-314,-285,-251,-210,-175,-158,-139,-164,-208,-224,-255,-269,-200,-16,263,541,809,1024,1005,644,56,-510,-919,-1093,-1032,-840,-596,-411,-293,-180,-94,-40,9,22,24,47,74,97,133,153,190,222,247,273,307,346,382,425,498,571,565,549,555,565,576,596,583,519,439,388,316,214,147,100,70,45,20,23,46,38,15,18,32,32,34,21,-20,-49,-69,-102,-143,-189,-240,-307,-359,-372,-404,-438,-459,-454,-430,-374,-337,-342,-378,-392,-374,-343,-313,-301,-263,-152,27,259,515,804,1009,898,434,-195,-761,-1149,-1348,-1313,-1077,-778,-561,-437,-309,-184,-115,-79,-55,-19,23,57,68,69,61,81,110,152,225,271,274,332,396,466,552,608,596,568,531,488,460,423,401,395,366,312,224,126,41,-23,-49,-41,-24,-27,3,20,44,84,80,31,-23,-71,-90,-99,-138,-225,-307,-363,-386,-420,-423,-413,-458,-492,-477,-471,-452,-452,-470,-484,-447,-375,-323,-321,-298,-209,-49,175,420,668,868,863,482,-137,-690,-1050,-1209,-1189,-1042,-822,-609,-432,-287,-199,-155,-122,-79,-16,35,69,91,99,95,94,117,166,221,271,310,342,387,445,490,515,533,558,600,637,620,557,496,442,393,342,284,224,167,119,96,90,110,147,168,159,143,124,99,70,50,17,-26,-65,-97,-162,-256,-328,-353,-318,-273,-256,-269,-291,-307,-291,-248,-214,-228,-247,-271,-291,-277,-197,-38,195,451,712,922,895,542,-31,-580,-951,-1130,-1107,-940,-705,-491,-328,-196,-118,-57,-14,2,27,79,107,105,112,108,94,123,196,244,258,275,300,339,387,439,511,562,575,587,598,564,498,444,387,320,252,193,142,71,26,29,28,19,19,31,53,70,65,65,81,78,65,56,39,-11,-54,-86,-147,-225,-283,-308,-323,-343,-399,-431,-425,-412,-392,-346,-292,-275,-264,-234,-208,-207,-201,-125,28,218,436,641,840,972,840,415,-203,-754,-1103,-1238,-1173,-973,-690,-449,-276,-163,-88,-51,-40,12,57,43,4,-1,30,98,153,159,175,203,242,255,285,348,401,451,482,503,549,573,550,511,458,419,362,273,200,157,119,69,15,-28,-42,-27,-8,9,24,49,60,45,14,-11,-14,-3,-40,-122,-198,-269,-342,-400,-432,-446,-434,-415,-393,-378,-395,-425,-431,-422,-373,-314,-287,-296,-318,-308,-259,-136,79,339,612,865,934,654,102,-482,-919,-1142,-1150,-1012,-804,-580,-367,-217,-164,-141,-97,-30,43,93,90,78,80,89,125,153,167,198,262,339,393,439,486,536,592,648,681,662,661,678,611,506,456,433,379,312,264,214,189,160,126,98,111,128,142,137,141,130,104,54,-6,-65,-110,-147,-169,-206,-258,-311,-364,-377,-366,-347,-346,-342,-311,-267,-245,-218,-184,-170,-201,-230,-202,-101,121,376,607,786,771,450,-114,-663,-1025,-1192,-1174,-978,-723,-529,-369,-246,-129,-59,-70,-64,-21,19,32,30,50,112,158,180,181,193,220,257,302,358,428,494,556,607,638,644,614,564,544,526,459,368,293,239,147,57,-9,-40,-48,-51,-45,-20,13,57,80,69,72,100,143,120,38,-6,-14,-21,-63,-122,-201,-265,-310,-331,-320,-316,-337,-359,-375,-359,-329,-342,-374,-379,-341,-287,-271,-282,-239,-142,9,237,501,759,933,891,518,-103,-696,-1102,-1286,-1261,-1077,-831,-610,-426,-295,-221,-179,-148,-120,-79,-38,1,33,55,61,61,84,122,164,199,244,325,407,413,418,477,521,489,445,438,460,468,434,365,296,241,164,81,39,9,-28,-38,-39,-41,-22,4,25,65,73,71,60,34,4,-39,-93,-129,-143,-197,-279,-337,-362,-373,-371,-356,-343,-318,-310,-281,-249,-250,-261,-254,-227,-202,-202,-162,-29,184,426,678,896,870,523,-28,-571,-959,-1150,-1127,-948,-696,-455,-279,-197,-157,-119,-66,-26,-5,23,78,136,154,143,141,171,208,238,289,363,397,426,487,560,610,628,634,629,628,631,611,542,453,374,306,230,154,101,65,27,-8,-33,-25,8,47,82,127,173,184,56,-24,-51,-56,}; +RT_L2_DATA int16_t ecg_1l[ECG_VECTOR_SIZE] = {112,146,86,-43,-177,-247,-303,-335,-271,-160,-82,-61,-78,-116,-126,-69,27,155,372,600,694,660,423,69,-266,-478,-542,-520,-462,-366,-275,-200,-172,-169,-208,-191,-121,-83,-45,23,41,12,-1,-8,-31,8,93,185,185,152,120,140,168,135,95,96,106,98,100,67,6,-61,-94,-77,-83,-83,-46,-35,-70,-91,-122,-138,-149,-177,-139,-55,39,73,73,55,47,48,65,63,-1,-82,-143,-176,-192,-208,-202,-206,-215,-181,-173,-169,-105,7,92,104,172,419,710,848,779,433,52,-251,-462,-524,-483,-389,-296,-226,-187,-132,-50,-25,-33,-58,-72,-63,0,69,132,172,191,219,262,314,334,336,359,436,481,494,501,469,434,368,287,237,222,229,199,136,85,63,51,67,91,107,121,111,74,40,46,81,104,76,34,20,31,49,27,-10,-20,-43,-81,-71,-117,-136,-136,-336,-393,-461,-490,-489,-486,-467,-437,-363,-246,-96,-29,-75,-225,-511,-724,-801,-791,-749,-679,-552,-434,-310,-209,-119,-63,-11,41,69,99,139,174,181,148,116,93,122,161,220,282,314,372,415,445,462,468,445,398,351,278,213,197,169,137,126,139,142,103,38,24,57,103,123,139,165,177,161,170,212,223,166,58,-33,-15,91,115,42,-66,-207,-315,-296,-198,-121,-130,-240,-317,-416,-582,-684,-695,-653,-532,-356,-98,200,427,558,387,84,-225,-543,-746,-829,-840,-766,-674,-589,-541,-511,-480,-439,-440,-435,-408,-390,-339,-280,-240,-171,-94,-69,-90,-55,11,81,122,187,266,300,316,296,229,193,160,94,56,41,-5,-59,-52,-48,-32,0,-1,32,61,84,49,-15,-6,94,184,229,276,312,271,245,251,323,345,235,96,33,47,22,-29,-28,4,6,-30,-23,-19,-44,-43,83,292,497,667,833,943,831,525,219,-49,-229,-327,-334,-225,-83,2,-25,-70,-119,-111,-24,60,97,147,192,166,56,-77,-70,53,152,278,401,464,455,381,313,313,355,396,403,389,348,307,305,281,239,192,149,94,50,62,73,94,120,123,74,1,-11,18,62,130,156,139,97,55,-21,-69,-84,-101,-112,-124,-200,-293,-307,-265,-246,-245,-251,-254,-282,-296,-268,-223,-108,55,128,119,15,-234,-466,-655,-739,-727,-643,-543,-415,-329,-286,-235,-206,-171,-130,-114,-85,-41,12,66,91,137,191,207,223,219,208,235,239,250,275,330,383,352,311,274,252,227,209,189,101,-2,-45,-58,-46,-42,-36,5,18,20,14,3,20,49,84,112,133,104,101,110,116,114,48,-23,-104,-136,-137,-160,-156,-121,-114,-147,-145,-135,-193,-237,-224,-220,-165,-14,230,565,811,845,562,157,-211,-452,-534,-524,-488,-439,-391,-386,-405,-408,-369,-267,-172,-158,-174,-134,-65,2,0,-19,-22,-42,-24,42,96,110,120,155,204,250,291,274,174,47,-20,-24,6,69,53,1,-35,-23,13,98,130,111,83,58,77,79,99,118,107,119,96,105,133,122,88,30,-46,-110,-205,-307,-366,-303,-370,-417,-429,-421,-374,-313,-268,-234,-256,-217,-66,124,255,272,227,61,-190,-429,-573,-596,-509,-438,-388,-269,-109,-17,-23,-100,-172,-153,-14,82,117,149,173,166,177,214,285,332,339,407,503,556,561,500,433,393,385,440,472,421,324,237,169,75,-13,-39,-60,-91,-123,-165,-168,-163,-226,-251,-234,-171,-119,-76,-47,-46,-24,3,-13,-41,-51,-81,-146,-205,-270,-286,-337,-376,-382,-388,-403,-350,-289,-263,-235,-181,-42,161,391,544,611,580,317,29,-213,-356,-423,-380,-318,-287,-227,-129,-48,-37,-47,18,118,178,178,134,136,138,92,73,107,65,31,57,38,61,130,133,140,155,188,200,171,88,39,-4,-6,-19,13,40,-36,-77,-72,-23,1,-20,-42,-65,-62,-20,23,84,88,118,129,111,83,58,51,30,21,-61,-153,-226,-242,-238,-255,-250,-258,-263,-242,-251,-292,-329,-307,-175,64,410,693,824,733,414,69,-237,-536,-683,-673,-573,-499,-464,-377,-300,-275,-237,-169,-78,-64,-94,-145,-140,-53,31,40,-39,-103,-77,86,199,250,310,347,390,413,427,402,280,171,123,109,99,80,-34,-139,-184,-228,-232,-229,-232,-219,-237,-271,-247,-189,-204,-188,-128,-83,-64,-48,-76,-104,-128,-143,-148,-178,-231,-266,-300,-302,-239,-248,-267,-228,-198,-203,-208,-172,-98,2,147,321,362,311,176,-58,-252,-354,-399,-397,-380,-317,-218,-114,-61,-1,40,49,55,84,125,141,171,141,38,-430,-1737,-2735,-2427,-1172,-183,426,789,977,1052,1072,1068,1043,1014,993,954,904,802,680,614,621,629,620,585,508,451,470,495,490,490,492,506,531,518,485,465,472,452,446,414,325,266,209,147,115,53,0,-92,-140,-153,-174,-185,-184,-198,-208,-208,-226,-180,-76,149,478,738,850,659,278,-122,-416,-583,-630,-627,-597,-558,-491,-389,-306,-266,-224,-186,-178,-180,-180,-168,-127,-67,-12,2,-29,-45,-60,-46,-8,36,90,157,178,164,110,64,60,52,-30,-79,-90,-112,-121,-118,-123,-160,-170,-152,-103,-86,-57,-12,-3,-42,-107,-103,-50,57,111,131,126,78,-22,-75,-89,-117,-159,-221,-262,-321,-323,-315,-273,-239,-258,-308,-369,-398,-335,-116,150,383,498,509,308,26,-190,-362,-439,-424,-385,-309,-208,-147,-129,-117,-59,-40,-21,13,-35,-49,-48,2,48,89,117,157,202,212,222,281,332,383,401,354,306,296,275,282,279,250,197,75,-67,-167,-147,-92,-54,-25,26,79,71,57,45,40,28,-9,-68,-67,-45,-29,-30,-35,-47,-47,-94,-144,-188,-242,-297,-298,-276,-281,-284,-263,-273,-291,-309,-298,-258,-208,-88,105,260,279,243,62,-155,-330,-436,-451,-422,-335,-240,-144,-63,3,37,87,124,154,195,200,191,175,198,239,267,287,301,362,409,452,478,493,502,487,453,447,483,462,398,331,269,254,239,162,74,44,49,70,38,-16,-105,-777,-820,-457,-177,-2,143,242,288,289,317,307,261,217,172,112,72,27,-23,-79,-124,-161,-200,-240,-241,-242,-254,-299,-315,-316,-289,-168,103,472,744,848,676,236,-207,-526,-726,-835,-797,-668,-533,-448,-373,-329,-283,-236,-249,-274,-265,-230,-230,-237,-199,-165,-102,-23,29,56,43,38,81,159,231,276,282,255,217,148,80,61,54,51,37,-2,-26,-11,28,17,-35,-49,35,91,108,108,89,90,59,31,71,122,140,151,132,71,18,-24,-90,-157,-260,-372,-365,-260,-219,-252,-296,-311,-342,-365,-339,-224,-104,57,203,185,83,-148,-423,-542,-562,-559,-511,-412,-269,-119,-33,-32,-24,-30,-73,-81,-80,-81,-43,4,40,40,69,72,78,140,219,300,307,332,358,352,361,359,373,388,349,318,264,260,224,197,166,108,78,82,97,118,147,171,150,150,171,187,213,272,293,294,306,278,230,168,122,60,-9,-50,-73,-123,-162,-217,-226,-219,-208,-194,-195,-206,-223,-244,-256,-193,11,317,588,730,663,370,39,-249,-459,-541,-526,-489,-403,-312,-304,-308,-331,-275,-196,-141,-129,-122,-97,-78,-79,-103,-89,-25,52,99,105,117,147,204,225,155,147,215,262,260,207,101,19,5,6,-22,-80,-81,-39,3,27,10,-41,-86,-72,-45,-10,67,137,165,173,178,167,165,166,166,166,166,-140,-215,-353,-455,-475,-412,-302,-235,-218,-223,-254,-251,-204,-91,77,327,583,683,718,535,156,-199,-406,-479,-453,-364,-271,-199,-99,-57,-106,-143,-133,-40,34,61,99,84,86,145,230,279,270,224,183,233,289,337,426,423,318,232,280,370,370,331,303,265,173,105,39,-54,-103,-91,-95,-100,-2,83,54,4,-20,-50,-65,-97,-136,-108,13,115,129,76,14,-60,-103,-129,-177,-232,-334,-444,-490,-424,-333,-276,-268,-286,-314,-334,-331,-322,96,228,242,124,-171,-438,-607,-668,-651,-584,-499,-439,-388,-375,-373,-304,-204,-159,-154,-133,-96,-54,3,5,-7,30,71,134,198,284,375,445,513,570,604,606,563,529,490,441,334,257,181,111,24,-37,-47,-60,-66,-64,-63,-34,13,49,72,107,157,194,180,140,60,23,25,45,55,61,25,-44,-95,-148,-207,-247,-258,-236,-203,-212,-247,-216,-174,-156,-171,-184,-99,150,489,753,861,746,393,0,-293,-469,-596,-661,-641,-544,-461,-414,-336,-248,-169,-100,-73,-101,-166,-198,-147,-38,82,94,31,-12,33,156,277,298,289,269,251,211,227,258,241,187,88,37,50,61,41,-18,-56,-16,-10,-77,-167,-297,-322,-193,-28,85,115,162,221,211,146,74,60,85,96,75,-254,-695,-539,-361,-310,-383,-236,-128,-212,-301,-230,-115,-17,15,33,118,299,510,625,660,547,232,-33,-213,-311,-316,-342,-320,-202,-79,-51,-72,-51,35,202,262,231,215,165,133,234,288,294,337,328,216,147,221,394,488,516,538,558,598,602,471,327,263,238,188,114,52,11,-59,-137,-177,-163,-145,-103,-52,5,27,21,11,-22,-46,-59,-84,-102,-134,-166,-207,-251,-296,-316,-329,-345,-385,-382,-340,-345,-389,-413,-427,-509,-581,-593,-529,-389,-200,-13,69,57,-94,-331,-474,-537,-546,-535,-471,-395,-325,-270,-224,-179,-171,-161,-146,-111,-93,-54,-5,85,148,189,289,386,449,499,589,683,764,802,782,712,612,525,461,389,334,311,278,239,177,123,118,83,50,47,37,39,60,50,37,29,52,91,130,163,164,136,106,120,145,63,7,-59,-139,-222,-301,-338,-384,-421,-374,-327,-368,-391,-445,-477,-448,-396,-267,-56,287,681,946,948,600,171,-180,-435,-615,-720,-730,-687,-631,-546,-452,-395,-380,-377,-367,-342,-301,-232,-175,-141,-126,-121,-68,37,105,129,130,145,193,258,304,285,243,209,189,183,157,94,76,85,99,102,78,47,53,85,81,79,47,45,82,68,47,78,147,210,208,165,130,105,106,73,47,35,8,-91,-195,-250,-792,-952,-640,-383,-221,-327,-318,-252,-197,-6,262,-301,-1744,-2050,-1251,-627,-180,100,201,204,235,278,296,285,299,313,342,376,408,419,388,350,321,358,450,453,403,443,481,471,474,491,542,638,721,750,738,680,569,455,347,262,181,113,79,60,9,-64,-135,-176,-169,-149,-152,-165,-114,-29,16,34,18,22,40,66,40,-30,-98,-125,-174,-229,-266,-316,-375,-409,-387,-350,-297,-247,-252,-290,-327,-333,-326,-311,-233,-67,136,265,294,242,-5,-234,-375,-441,-455,-422,-379,-370,-350,-307,-223,-156,-96,-9,68,116,139,133,121,149,158,190,250,297,284,246,216,256,333,377,392,401,354,341,325,237,153,90,66,21,47,57,33,-1,-20,-33,-69,-75,-48,-12,18,33,18,24,18,4,26,64,81,78,52,-20,-94,-163,-202,-256,-302,-346,-365,-385,-391,-359,-367,-400,-427,-455,-380,-223,1,326,665,904,895,555,184,-134,-356,-509,-615,-607,-500,-386,-346,-342,-303,-291,-240,-166,-116,-104,-133,-130,-81,8,76,83,64,101,186,258,292,245,207,285,381,439,461,427,318,152,46,35,44,57,103,112,94,44,-26,-63,-73,-108,-30,119,128,38,31,117,218,292,314,264,168,124,132,78,-45,-110,-115,-147,-202,-250,-265,-212,-200,-284,-373,-368,-368,-348,-929,-796,-255,-139,-883,-1078,-892,-698,-539,-443,-1138,-2221,-2406,-1860,-2264,-1932,-713,269,868,1061,1084,1070,1061,1030,1017,1016,999,937,877,853,841,845,853,849,843,846,816,774,764,718,629,543,437,309,228,213,177,170,163,108,48,41,54,70,79,56,51,59,65,85,93,79,62,71,67,38,9,-54,-119,-132,-126,-133,-140,-136,-155,-156,-163,-170,-164,-163,-153,-141,-151,-105,47,280,499,599,532,281,-38,-310,-509,-614,-625,-532,-391,-291,-208,-138,-97,-69,-58,-53,-58,-59,-25,1,25,32,32,55,69,113,127,142,203,215,239,300,363,350,315,289,240,178,133,112,111,75,23,-35,-83,-83,-85,-86,-80,-106,-126,-97,-25,23,41,53,34,9,16,27,33,-3,-64,-146,-194,-197,-206,-242,-283,-319,-331,-299,-245,-261,-322,-334,-346,-346,-257,-21,253,444,522,454,182,-153,-398,-455,-441,-385,-330,-312,-337,-347,-322,-264,-144,-38,8,-13,-36,-7,22,31,86,172,219,159,53,135,326,491,554,600,604,518,439,330,202,175,178,194,232,250,252,202,114,58,51,107,113,56,45,105,140,181,253,283,237,167,104,97,141,173,131,79,-31,-131,-161,-170,-178,-224,-257,-273,-256,-242,-224,-249,-252,-604,-1951,-2470,-1588,-1075,-1091,-580,-234,-231,-304,-295,-437,-862,-617,-295,-15,174,276,359,476,507,493,476,458,447,427,419,433,435,441,435,417,391,383,405,461,487,502,552,564,522,431,393,353,298,243,210,127,28,-32,-61,-101,-104,-81,-75,-101,-86,-26,14,20,-1,-18,-27,9,30,39,51,35,2,-19,-53,-95,-129,-187,-258,-320,-347,-372,-377,-356,-318,-295,-271,-234,-225,-160,-13,208,483,706,739,501,137,-220,-466,-585,-626,-605,-578,-514,-446,-363,-302,-241,-177,-146,-150,-118,-69,-12,55,50,37,40,37,48,81,110,94,92,142,180,188,180,204,193,209,224,193,158,106,74,58,61,11,-33,-29,-54,-101,-65,15,82,119,144,135,113,79,44,25,8,10,2,-23,-83,-149,-170,-161,-184,-206,-189,-160,-123,-92,-87,-97,-140,-183,-198,-149,15,231,434,569,542,296,15,-232,-422,-486,-443,-328,-200,-151,-92,-21,17,16,4,-56,-99,-17,114,259,374,367,313,235,160,198,270,253,264,382,408,382,439,487,424,358,342,359,334,213,102,61,80,133,102,69,73,92,102,72,33,17,25,43,50,46,78,110,89,52,46,-552,-2095,-2836,-1947,-1124,-1474,-1177,-679,-302,-122,-993,-1805,-1194,-438,-202,-198,100,374,541,659,769,772,692,443,209,58,-9,-17,33,87,166,233,251,253,262,258,270,284,300,315,334,351,361,363,364,380,404,416,422,415,422,450,487,512,509,490,435,379,325,309,324,270,170,68,-4,-26,-39,-25,-4,18,5,3,9,13,7,6,34,89,131,114,107,91,83,121,139,84,4,-67,-203,-322,-388,-437,-434,-402,-358,-358,-415,-421,-383,-365,-301,-125,193,559,817,845,562,154,-235,-493,-617,-671,-640,-509,-394,-354,-336,-324,-329,-316,-276,-242,-207,-185,-159,-108,-52,23,122,214,306,413,501,534,472,365,270,218,190,181,168,145,137,76,-22,-89,-105,-116,-115,-71,-58,-75,-84,-80,-82,-95,-119,-131,-136,-98,-13,107,194,169,111,64,-3,-88,-95,-16,53,47,-20,-77,-107,-148,-166,-175,-175,-165,-172,-183,-139,-47,76,216,229,136,5,-126,-335,-580,-597,-434,-288,-244,-186,-45,55,110,149,178,166,149,165,145,79,87,165,255,297,242,139,83,167,320,407,433,426,410,431,402,-60,-123,52,80,-329,-269,-113,-101,-353,-259,-130,-40,-298,-1711,-2375,-2467,-2241,-1325,-572,-82,224,414,518,601,699,706,675,658,603,543,439,388,327,242,157,117,100,83,43,10,-14,-29,-39,-71,-65,39,210,280,264,148,-81,-271,-423,-487,-480,-430,-313,-234,-188,-117,-24,40,63,69,92,124,153,159,185,214,255,272,269,282,294,329,372,412,436,436,410,397,390,402,386,327,227,140,65,-17,-68,-112,-134,-134,-139,-146,-129,-114,-114,-114,-104,-90,-37,-8,-7,17,35,40,41,15,-34,-94,-116,-136,-167,-219,-268,-297,-290,-259,-267,-299,-355,-425,-450,-428,-322,-125,156,485,732,883,809,507,156,-144,-328,-445,-496,-523,-498,-393,-309,-249,-204,-175,-153,-127,-99,-55,-15,8,5,-19,0,87,173,236,275,293,319,363,385,414,429,396,368,346,327,261,147,62,34,4,22,49,65,27,-26,-104,-134,-3,158,210,215,209,212,238,257,251,220,157,105,54,-33,-89,-104,-116,-172,-282,-365,-365,-370,-392,-434,-511,-547,-487,-365,-195,-44,58,64,63,-31,-258,-486,-625,-667,-659,-602,-514,-411,-297,-195,-117,-49,-5,40,66,45,43,49,38,16,1,-7,4,30,112,197,262,278,359,380,366,330,287,227,188,152,105,73,27,-40,-102,-146,-175,-173,-134,-105,-73,-34,8,30,51,42,40,-7,-34,-31,-12,-21,-19,14,23,19,-38,-75,-81,-81,-121,-141,-137,-112,-121,-134,-165,-235,-272,-278,-246,-150,61,245,361,430,285,20,-223,-403,-484,-473,-448,-448,-294,-198,-146,-107,-49,17,30,-19,-7,9,-2,-6,37,93,117,132,173,209,230,244,263,293,339,409,429,391,337,261,193,147,110,30,-47,-95,-104,-87,-41,-12,-28,-51,-65,-49,13,68,64,62,96,141,192,243,266,241,186,107,1,-99,-202,-280,-304,-278,-227,-217,-233,-241,-253,-270,-283,-282,-263,-163,-4,217,486,697,796,691,377,35,-262,-408,-448,-440,-394,-373,-368,-345,-275,-225,-190,-143,-129,-132,-93,-64,-68,0,117,205,239,220,227,248,239,200,176,233,323,339,334,353,356,312,283,263,202,117,74,76,66,51,8,0,39,83,115,115,78,49,63,88,105,124,142,124,73,30,-51,-172,-256,-294,-282,-285,-311,-331,-352,-363,-368,-397,-448,-492,-487,-451,-363,-219,-38,87,136,53,-187,-401,-530,-589,-596,-567,-497,-394,-294,-197,-120,-94,-106,-131,-124,-93,-58,-12,43,76,86,107,132,144,154,165,193,231,276,312,330,332,325,302,278,278,173,110,49,13,-33,-57,-34,-22,-27,-32,-46,-44,-29,-19,8,49,65,49,36,25,42,51,41,49,49,0,-48,-68,-112,-163,-199,-202,-175,-176,-180,-192,-224,-272,-287,-268,-209,-65,165,375,434,405,181,-106,-318,-416,-428,-385,-317,-227,-153,-92,-40,3,49,102,126,107,119,127,110,123,170,206,234,274,302,327,352,397,417,397,390,430,480,472,419,359,289,251,249,219,171,145,135,107,102,138,144,141,155,161,161,161,142,105,109,124,123,115,122,107,56,-50,-126,-155,-189,-238,-289,-352,-375,-384,-298,-282,-345,-356,-381,-399,-363,-287,-59,226,456,570,484,254,-14,-325,-568,-650,-607,-517,-459,-440,-399,-335,-202,-95,-71,-105,-104,-68,-17,15,-2,-19,-22,61,115,158,163,171,190,239,262,247,253,210,193,201,170,102,68,-3,-92,-120,-82,-34,-7,-4,-21,-35,-44,-48,-38,17,63,65,90,185,240,214,186,163,132,61,-36,-131,-202,-240,-276,-333,-348,-319,-294,-282,-327,-400,-450,-465,-422,-299,-58,275,540,689,710,484,134,-201,-431,-562,-602,-560,-492,-395,-289,-224,-197,-194,-182,-160,-102,-49,-36,-45,-38,15,81,121,124,105,110,158,212,247,275,303,314,314,300,271,244,249,261,246,204,163,125,87,73,84,112,144,163,168,187,229,239,234,232,244,271,278,244,215,204,177,118,43,-21,-76,-127,-169,-183,-188,-197,-200,-202,-231,-274,-275,-219,-144,-21,182,370,441,431,231,-41,-272,-406,-460,-470,-436,-372,-302,-258,-217,-165,-109,-61,-61,-71,-73,-68,-43,-7,10,33,66,89,121,152,192,232,249,255,274,308,334,349,358,332,278,221,178,154,139,122,112,110,91,60,58,56,59,48,12,-11,17,27,34,42,35,18,10,10,1,-24,-75,-127,-166,-201,-269,-324,-335,-310,-292,-293,-292,-304,-312,-324,-296,-187,17,237,312,284,103,-201,-423,-521,-555,-511,-399,-289,-188,-106,-58,-41,-24,-17,-5,3,11,18,11,3,7,20,47,54,78,124,181,239,287,334,365,373,366,348,336,308,296,280,246,202,148,71,33,30,15,-12,-25,-38,-38,-34,-37,-46,-38,-31,-29,-9,22,41,42,34,10,-41,-75,-122,-165,-179,-173,-161,-195,-234,-255,-249,-238,-242,-282,-328,-316,-238,-113,59,278,419,466,326,30,-196,-328,-375,-384,-346,-278,-209,-165,-143,-104,-61,-17,5,28,62,100,148,130,105,100,106,129,175,198,203,212,256,309,337,341,365,391,375,320,249,198,168,137,98,66,47,8,-34,-34,-26,-24,-11,-2,-6,-19,-34,-32,-26,-28,-24,-9,16,9,-26,-70,-125,-192,-228,-227,-238,-273,-292,-295,-302,-323,-333,-323,-323,-343,-355,-321,-245,-81,197,468,636,629,350,-27,-331,-511,-535,-496,-441,-389,-336,-287,-246,-211,-183,-160,-134,-84,-20,8,32,48,49,36,59,87,98,142,218,295,366,407,409,384,348,346,377,380,329,256,234,234,230,185,142,124,86,57,61,81,103,131,129,114,112,105,71,32,20,17,17,9,-24,-93,-163,-222,-202,-182,-198,-244,-292,-310,-324,-343,-368,-382,-323,-243,-123,47,191,285,257,-24,-327,-530,-601,-548,-467,-396,-329,-273,-210,-153,-109,-81,-76,-72,-54,-24,20,56,81,100,86,86,114,168,225,249,286,327,372,417,448,459,453,421,378,321,264,200,134,57,2,-32,-64,-98,-139,-173,-173,-129,-80,-90,-120,-139,-124,-114,-97,-86,-76,-65,-61,-63,-82,-100,-140,-204,-251,-287,-307,-329,-331,-304,-287,-295,-292,-292,-290,-285,-248,-164,-22,185,298,282,128,-128,-325,-419,-443,-418,-350,-269,-179,-106,-38,-9,3,14,33,76,103,124,134,146,159,191,207,225,266,309,355,376,400,412,432,448,444,433,389,340,299,255,211,165,122,73,52,52,54,56,51,23,-7,-11,-6,5,23,35,25,27,32,33,32,25,22,-10,-41,-66,-127,-184,-224,-258,-286,-304,-298,-277,-263,-253,-260,-302,-344,-355,-294,-126,134,421,617,666,456,137,-157,-372,-492,-525,-480,-412,-347,-307,-275,-229,-184,-145,-121,-102,-72,-45,-24,-13,-7,9,52,103,137,178,220,255,280,301,302,301,312,314,290,273,225,153,102,96,93,66,43,29,18,11,11,16,28,36,40,49,71,96,126,159,161,144,132,116,88,48,12,-40,-110,-164,-205,-222,-221,-202,-193,-202,-228,-277,-292,-288,-269,-190,-29,210,424,529,461,187,-89,-298,-402,-431,-376,-309,-243,-196,-177,-141,-103,-63,-42,-4,55,93,88,61,51,51,64,94,125,192,295,387,425,447,466,480,453,409,380,373,342,280,201,126,116,143,111,49,0,-24,-12,-12,-28,-49,-60,-30,5,18,20,37,61,72,63,5,-73,-125,-171,-208,-246,-278,-322,-350,-335,-323,-316,-347,-405,-437,-426,-369,-320,-256,-150,15,155,180,117,-129,-404,-568,-631,-635,-599,-526,-431,-346,-290,-240,-189,-137,-75,-18,10,2,-9,1,21,75,130,168,201,237,291,345,395,434,469,499,500,484,445,404,367,333,288,232,163,99,68,60,50,38,30,30,25,22,18,17,16,10,35,62,79,83,87,95,84,50,14,-38,-94,-118,-147,-201,-254,-286,-304,-299,-280,-265,-257,-283,-301,-330,-345,-281,-123,129,350,465,458,229,-76,-320,-462,-507,-483,-435,-382,-307,-234,-177,-145,-110,-68,-41,-29,-31,-23,-3,33,52,56,71,110,162,188,215,260,311,334,327,309,286,263,250,223,174,129,107,85,60,46,19,-14,-35,-43,-25,13,12,-11,-28,-28,-3,39,87,100,89,73,67,62,60,11,-33,-86,-134,-224,-279,-305,-319,-301,-285,-282,-285,-320,-365,-374,-326,-233,-72,192,481,669,708,519,179,-160,-394,-498,-507,-466,-433,-390,-334,-284,-217,-138,-99,-57,-4,51,88,110,113,92,76,60,75,164,251,269,254,265,316,365,361,358,342,345,347,343,306,272,225,197,151,97,61,40,58,107,141,136,111,114,148,175,164,134,116,116,140,145,126,122,113,56,-13,-72,-125,-149,-179,-223,-273,-270,-243,-250,-297,-330,-330,-290,-197,-35,174,312,220,-69,-326,-483,-539,-519,-451,-374,-295,-232,-173,-127,-96,-61,-38,-28,-13,12,50,71,58,47,52,75,110,163,217,269,318,368,408,406,389,364,335,278,224,171,122,83,65,41,-49,-114,-145,-141,-136,-136,-141,-146,-134,-121,-112,-106,-79,-85,-87,-73,-75,-60,-56,-84,-103,-105,-112,-159,-218,-257,-290,-290,-277,-274,-245,-247,-265,-293,-324,-312,-261,-162,1,203,344,394,293,14,-231,-388,-431,-422,-377,-323,-240,-154,-75,-22,4,16,15,20,42,88,150,158,167,202,230,228,221,263,359,408,420,429,419,404,374,353,341,316,270,222,145,102,90,82,55,-6,-62,-80,-70,-72,-39,-33,-22,-35,-50,-64,-63,-53,-25,2,47,47,3,-12,5,3,-7,-51,-120,-184,-205,-238,-272,-309,-326,-303,-303,-342,-379,-418,-445,-363,-148,162,474,692,722,492,172,-133,-353,-470,-486,-446,-400,-350,-299,-264,-250,-207,-133,-66,-18,26,42,40,53,82,123,153,179,186,178,193,233,284,321,369,386,349,280,217,181,194,205,193,143,74,43,27,9,5,10,-6,-28,-23,12,70,114,135,131,118,100,121,159,175,167,143,82,-8,-102,-129,-112,-119,-117,-139,-205,-246,-228,-229,-238,-294,-329,-289,-175,-14,185,350,454,417,174,-99,-307,-465,-516,-474,-365,-234,-155,-125,-90,-52,-7,-3,-5,-12,-27,11,95,115,101,103,130,181,246,299,320,338,350,350,334,350,381,378,352,336,300,246,172,109,87,82,50,4,-19,-10,11,22,14,-10,-22,-16,-27,-36,-37,-20,6,9,-3,-25,-40,-69,-132,-213,-293,-358,-406,-427,-438,-431,-430,-449,-466,-462,-456,-457,-424,-337,-172,13,71,30,-144,-395,-563,-632,-631,-578,-499,-413,-321,-240,-177,-114,-60,-23,-13,1,26,64,95,125,172,211,235,233,236,287,344,405,447,479,510,517,512,463,410,359,322,268,201,134,94,52,25,27,27,38,41,9,-9,-8,-4,-6,-8,18,27,10,1,39,64,80,90,74,28,-45,-123,-185,-217,-245,-273,-281,-281,-292,-300,-286,-258,-269,-302,-318,-298,-241,-89,153,387,563,567,315,9,-219,-359,-433,-474,-427,-354,-288,-218,-168,-135,-114,-91,-34,-15,-26,-36,0,25,29,90,168,237,242,225,240,264,284,309,331,333,301,254,222,207,208,159,100,31,-28,-53,-60,-58,-56,-45,-29,-23,12,46,56,54,66,109,133,147,157,157,138,124,89,46,-34,-114,-156,-168,-168,-183,-214,-237,-250,-249,-249,-256,-291,-324,-344,-349,-307,-176,94,419,667,776,597,235,-124,-378,-503,-551,-537,-455,-346,-277,-265,-220,-153,-103,-63,-25,19,43,52,80,98,80,78,130,192,240,246,249,283,349,401,429,422,413,406,366,314,249,190,131,81,43,60,95,115,106,81,70,95,116,123,125,131,121,104,99,118,126,87,23,-5,-13,-40,-61,-77,-111,-205,-282,-298,-279,-263,-235,-222,-255,-320,-345,-347,-287,-122,141,294,317,202,-78,-313,-451,-522,-540,-494,-421,-346,-258,-170,-120,-82,-64,-50,-38,-12,33,74,103,117,111,113,148,197,244,279,314,337,360,370,363,366,355,337,291,248,197,141,89,31,-27,-79,-125,-141,-127,-131,-146,-145,-137,-128,-108,-97,-91,-84,-83,-69,-49,-19,6,21,18,2,-44,-99,-147,-204,-243,-259,-247,-243,-254,-274,-285,-285,-273,-270,-280,-284,-243,-119,93,300,382,359,150,-100,-285,-390,-431,-401,-346,-288,-216,-167,-108,-54,-10,26,55,55,71,96,103,108,123,144,189,220,216,251,311,358,385,400,425,416,387,352,297,230,206,186,179,145,78,25,2,-31,-46,-46,-51,-68,-58,-47,-24,10,45,63,39,45,38,73,86,95,107,74,1,-85,-163,-224,-255,-272,-304,-337,-341,-338,-332,-323,-305,-310,-325,-331,-319,-256,-92,176,456,656,711,498,161,-147,-355,-457,-495,-491,-461,-406,-324,-250,-200,-159,-102,-39,-27,-58,-82,-72,-34,22,102,185,246,275,271,269,275,289,306,332,346,355,343,318,288,220,154,130,116,84,34,-26,-49,-10,33,51,35,26,54,67,50,15,-9,29,77,101,103,87,89,94,52,-15,-72,-137,-181,-187,-185,-185,-195,-237,-267,-263,-263,-284,-339,-380,-341,-228,-36,208,385,431,307,9,-244,-380,-429,-442,-412,-343,-267,-214,-176,-148,-87,-20,0,-6,5,43,51,52,92,155,193,224,250,267,293,327,356,381,405,424,424,453,468,446,408,349,259,153,78,37,-9,-51,-90,-120,-118,-100,-103,-97,-99,-100,-102,-124,-140,-135,-107,-64,-25,-24,-35,-55,-69,-91,-156,-250,-324,-341,-341,-346,-336,-318,-296,-303,-305,-290,-286,-282,-269,-226,-80,158,315,350,275,-12,-253,-395,-457,-468,-418,-321,-232,-143,-78,-34,1,3,9,29,52,93,130,140,127,134,181,262,310,323,318,358,385,407,433,433,396,372,309,248,216,194,161,126,115,94,88,79,21,-35,-69,-55,-14,31,52,62,43,16,-2,0,22,53,72,89,93,77,66,56,19,-33,-96,-153,-212,-250,-255,-265,-273,-273,-269,-258,-260,-275,-289,-291,-218,-31,248,540,736,761,495,135,-167,-376,-506,-560,-540,-463,-364,-286,-225,-186,-155,-113,-68,-26,8,34,28,18,36,68,107,154,188,209,235,285,338,358,375,383,369,349,332,293,223,165,112,69,43,17,15,8,-19,-22,-3,22,42,47,30,36,62,92,103,107,107,105,109,105,67,27,-16,-65,-119,-161,-198,-234,-258,-273,-280,-289,-315,-337,-363,-397,-437,-428,-321,-115,154,383,499,455,197,-106,-354,-499,-578,-587,-552,-466,-367,-306,-265,-221,-182,-140,-97,-82,-85,-60,7,76,130,155,172,194,209,233,251,274,321,339,341,351,360,359,344,325,285,218,138,76,40,37,33,16,-22,-41,-41,-23,7,8,12,56,97,100,98,81,59,68,80,71,57,20,-55,-126,-196,-274,-327,-322,-293,-266,-281,-287,-273,-282,-310,-349,-379,-381,-334,-227,-51,137,252,324,184,-89,-313,-455,-476,-418,-380,-347,-318,-256,-201,-155,-102,-43,4,10,24,59,62,33,25,70,149,203,269,332,364,413,415,386,407,457,480,476,436,383,363,368,353,320,268,185,101,11,-24,-8,23,28,8,-18,-19,-19,-11,-2,-13,-38,-35,15,63,69,31,-18,-66,-134,-181,-229,-294,-364,-394,-411,-422,-425,-415,-404,-399,-415,-439,-450,-437,-372,-236,-36,81,89,2,-219,-423,-536,-555,-524,-465,-378,-292,-217,-139,-60,1,22,50,84,121,120,125,143,160,187,228,251,291,347,384,425,479,511,531,557,554,514,471,430,391,344,275,215,147,94,62,32,11,1,-16,-31,-41,-36,-28,-33,-53,-59,-39,-6,20,43,65,73,85,88,51,-18,-79,-89,-139,-224,-265,-289,-278,-254,-237,-228,-236,-267,-294,-309,-307,-287,-201,-34,241,500,656,676,439,99,-208,-400,-500,-524,-498,-441,-370,-297,-224,-148,-91,-64,-48,-30,0,31,63,78,92,98,100,125,157,213,262,290,295,314,334,324,308,302,317,301,239,156,89,51,30,16,-10,-40,-55,-61,-77,-87,-65,-28,-11,-31,-24,0,8,22,25,22,18,6,11,-11,-52,-100,-143,-169,-215,-258,-284,-302,-325,-345,-327,-291,-259,-260,-284,-302,-286,-229,-100,147,412,556,484,187,-90,-274,-354,-382,-394,-380,-329,-226,-134,-93,-85,-85,-74,-23,53,115,156,163,147,134,162,195,212,226,256,296,352,397,439,486,513,514,491,432,356,292,238,185,133,96,84,64,42,26,4,-19,2,10,20,25,17,3,1,-8,-1,5,4,-18,-34,-53,-89,-137,-209,-280,-311,-340,-349,-360,-365,-360,-358,-354,-346,-367,-382,-410,-422,-365,-219,5,172,215,155,-69,-311,-457,-509,-479,-395,-300,-200,-119,-70,-51,-56,-33,9,48,96,139,175,176,174,191,225,274,283,311,347,391,435,439,444,455,477,471,445,401,369,338,287,262,229,154,85,16,-32,-81,-59,-1,25,-1,-38,-31,2,43,52,34,34,84,105,98,111,127,78,0,-36,-43,-57,-131,-236,-292,-300,-285,-269,-275,-301,-293,-271,-268,-272,-313,-290,-203,-28,246,519,693,702,448,100,-204,-404,-500,-503,-483,-439,-390,-340,-279,-221,-180,-156,-125,-85,-64,-53,-52,-34,-19,-7,30,79,111,143,182,228,279,321,357,365,332,291,265,226,171,120,77,42,11,-7,-24,-34,-32,-19,-9,12,45,66,48,27,15,6,17,32,37,50,84,109,128,123,84,4,-85,-145,-170,-201,-233,-246,-249,-234,-244,-241,-231,-247,-284,-309,-279,-190,-19,207,}; #endif // SIGNAL_H_ diff --git a/PULP/defines.h b/PULP/defines.h index 28b04de..a04f82b 100755 --- a/PULP/defines.h +++ b/PULP/defines.h @@ -1,97 +1,107 @@ #ifndef DEFINES_H_ #define DEFINES_H_ //========= DEFINE PRINT DEBUG =========// // #define PRINT_DEBUG_WINDOW // #define PRINT_SIG_INPUT_PEAKS // #define PRINT_THR // #define PRINT_RPEAKS_BEFORE_T_CHECK // #define PRINT_DEBUG_ERRDET // #define PRINT_INITIAL_HCENTR +// #define PRINT_INPUT_SIG_CL // #define PRINT_ABS_DIFF // #define PRINT_GAUSS // #define PRINT_GAUSS_MU_SD // #define PRINT_GENLOGFUN // #define PRINT_BAYFILT // #define PRINT_CENTROIDS // #define PRINT_OVERLAPS // #define PRINT_DEBUG_STD // #define PRINT_DEBUG_CL // #define PRINT_RPEAKS_DEBUG //=========== Sampling frequency ========== // #define ECG_SAMPLING_FREQUENCY 250 //=========== Number of leads/channels ============// #define NLEADS 1 //=========== Buffer size for R peak detection ========== // //The minumum distance between two ECG peaks based on physiological limits: 200 miliseconds * sampling frequency #define BUFFER_LENGTH_SECONDS (float) 1.75 //2.048 // #define BUFFER_SIZE (int16_t) (BUFFER_LENGTH_SECONDS*ECG_SAMPLING_FREQUENCY) //=========== Overlap for Rel-En ========== // //long window delay length (in samples): sampling frequency times long window length in seconds //Long window length = 0.95 seconds #define LONG_WINDOW (uint16_t) (0.95*ECG_SAMPLING_FREQUENCY+1) //=========== R PEAK DETECTION PARAMETERS ===========// // #define NEGATIVE_PEAK //For ISSUL-EPFL dataset, comment this line. For QTDB used for publication in EMBC 2019 and ESWEEK 2020, uncomment. #define N 1 #define H_B 30 #define DIM (int16_t) (BUFFER_SIZE * N) //((BUFFER_SIZE * N) + LONG_WINDOW) #if ECG_SAMPLING_FREQUENCY == 250 #define OFFSET_MF 150 #else #define OFFSET_MF 300 #endif //=========== CLUSTERING PARAMETERS ===========// #define type_f float #define type_i int #define SIZE_PERCENTILE_ARR DIM*2//1000 //======== DEFINE MODULES ==========// #define MODULE_MF #define MODULE_RELEN #define MODULE_RPEAK_REWARD #ifdef MODULE_RPEAK_REWARD #define MODULE_ERROR_DETECTION #endif #define MODULE_CLUSTERING +//======== DEFINE PERFORMANCE OUTPUT ========// +// #define ACCURACY +#define PROFILING + //========= DEFINE PRINT OUTPUT ========// // #define PRINT_SIG_MF // #define PRINT_RELEN -// #define PRINT_RPEAKS -// #define PRINT_ERROR_RPEAKS +#ifdef ACCURACY +#define PRINT_RPEAKS +#define PRINT_ERROR_RPEAKS #define PRINT_RPEAKS_CL +#endif //======== DEFINE WINDOW OVERLAP ==========// // Copy the MF or the RelEn signal in the overlapping window. The two defines are mutually exclusive (only one can be uncommented) // #define OVERLAP_MF // not yet validated for this implementation #define OVERLAP_RELEN //default and validated for this implementation //======== DEFINE WINDOWS (ONLY FOR DEBUG) ==========// // #define ONLY_FIRST_WINDOW //========= DEFINE PROFILING ================// +#ifdef PROFILING // #define HWPERF_MODULE_RPEAK_REWARD //start profiling module RPEAK // #define HWPERF_MODULES //start profiling separate modules -// #define HWPERF_FULL //start profiling full app (N.B. it will profile also some buffering) -// #define ACTIVE +#define HWPERF_FULL //start profiling full app (N.B. it will profile also some buffering) +#define HWPERF_CLUSTER +#define ACTIVE //#define EXTACC //# of loads and stores in EXT memory (L2) //#define INTACC //# of loads and stores in INT memory (L1) //#define STALL //# number of core stalls //#define INSTRUCTION //# number of instructions //#define TCDM //# of conflicts in TCDM (L1 memory) between cores +#endif #define PULP_L1_DATA RT_L2_DATA #define PULP_L2_DATA RT_L2_DATA #define MUL #define SCALE 100//6//64 #define CGRA_OFF #endif // DEFINES_H_ diff --git a/PULP/error_detection/error_detection.c b/PULP/error_detection/error_detection.c index 1645585..028e1d8 100644 --- a/PULP/error_detection/error_detection.c +++ b/PULP/error_detection/error_detection.c @@ -1,74 +1,92 @@ #include "./error_detection.h" +int32_t RR_intervals[H_B+2]; + int errorDetection(int32_t *arg[]){ int32_t *r_counter = arg[0]; int32_t *rWindow = arg[1]; int32_t *lastRRp = arg[2]; int32_t *indRpeaks = arg[3]; int32_t *lastPeak = arg[4]; - int32_t RR_intervals[H_B+2]; int32_t ratioConsecutiveRR = 0; int32_t offset_ind_rr = -1; int32_t rr_counter = 0; + int32_t prev_r_counter = *r_counter; - for(int32_t ix_rr = 0; ix_rr < H_B ; ix_rr++) { + for(int32_t ix_rr = 0; ix_rr < H_B+2; ix_rr++) { RR_intervals[ix_rr] = 0; } if(*r_counter>0){ #ifdef PRINT_DEBUG_ERRDET printf("rWindow: %d r_counter: %d\nR[i] (samples), RR[i] (ms)\n", *rWindow,*r_counter ); for(int32_t ix_r = 0; ix_r < *r_counter; ix_r++){ printf("R[%d]: %d\n", ix_r,indRpeaks[ix_r]); } #endif if(!(*rWindow == 0)){ if(*lastRRp == 0){ RR_intervals[0] = (FACTOR_MS*(indRpeaks[0] - *lastPeak))/ECG_SAMPLING_FREQUENCY; offset_ind_rr = 0; #ifdef PRINT_DEBUG_ERRDET printf("RR[0]: %d\n", RR_intervals[0]); #endif } else{ RR_intervals[0] = *lastRRp; RR_intervals[1] = (FACTOR_MS*(indRpeaks[0] - *lastPeak))/ECG_SAMPLING_FREQUENCY; offset_ind_rr = 1; #ifdef PRINT_DEBUG_ERRDET printf("RR[0]: %d\nRR[1]: %d\n", RR_intervals[0], RR_intervals[1]); #endif } } for(int32_t ix_rp = 1; ix_rp < *r_counter; ix_rp++) { RR_intervals[ix_rp+offset_ind_rr] = (FACTOR_MS*(indRpeaks[ix_rp]-indRpeaks[ix_rp-1]))/ECG_SAMPLING_FREQUENCY; #ifdef PRINT_DEBUG_ERRDET printf("RR[%d]: %d\n", ix_rp+offset_ind_rr,RR_intervals[ix_rp+offset_ind_rr]); #endif } if(*rWindow==0) rr_counter = *r_counter-1; else rr_counter = *r_counter+1; - *lastPeak = indRpeaks[*r_counter-1]; - *lastRRp = RR_intervals[rr_counter-1]; + if(*lastRRp == 0){ + rr_counter = rr_counter-1; + } + +#ifdef PRINT_DEBUG_ERRDET + printf("rr_counter: %d\n", rr_counter); +#endif + if(*r_counter>0){ + *lastPeak = indRpeaks[*r_counter-1]; + } + if(rr_counter>0){ + *lastRRp = RR_intervals[rr_counter-1]; + } + + if(*rWindow == 1 && *r_counter==1 && prev_r_counter == 1){ + return 1; + } + #ifdef PRINT_DEBUG_ERRDET printf("lastPeak: %d lastRR: %d\n",*lastPeak,*lastRRp ); #endif for(int32_t ix_rr = 1; ix_rr < rr_counter; ix_rr++){ ratioConsecutiveRR = (FACTOR_RATIO_RR*RR_intervals[ix_rr])/RR_intervals[ix_rr-1]; #ifdef PRINT_DEBUG_ERRDET printf("ratioConsecutiveRR: %d\n", ratioConsecutiveRR); #endif if(ratioConsecutiveRRPERCENTILE_LOO_HIGH) return 1; } }else{ return 1; } return 0; -} \ No newline at end of file +} diff --git a/PULP/error_detection/error_detection.h b/PULP/error_detection/error_detection.h index 6f9cda1..5fac633 100644 --- a/PULP/error_detection/error_detection.h +++ b/PULP/error_detection/error_detection.h @@ -1,16 +1,16 @@ #ifndef ERROR_DETECTION_H_ #define ERROR_DETECTION_H_ #include #include #include #include "../defines.h" #define FACTOR_MS 1000 #define FACTOR_RATIO_RR 1000 -#define PERCENTILE_LOO_LOW 640 //This is the 0.5th percentile of the RR distribution detected by the clustering using the leave-one-out approach for each subject (it is subject-specific) -#define PERCENTILE_LOO_HIGH 1491 //This is the 99.5th percentile of the RR distribution detected by the clustering using the leave-one-out approach for each subject (it is subject-specific) +#define PERCENTILE_LOO_LOW 736 //This is the 0.5th percentile of the RR distribution detected by the clustering using the leave-one-out approach for each subject (it is subject-specific) +#define PERCENTILE_LOO_HIGH 1279 //This is the 99.5th percentile of the RR distribution detected by the clustering using the leave-one-out approach for each subject (it is subject-specific) int errorDetection(int32_t *arg[]); -#endif // ERROR_DETECTION_H_ \ No newline at end of file +#endif // ERROR_DETECTION_H_ diff --git a/PULP/kmeans_clustering/kmean/k_mean_functions.c b/PULP/kmeans_clustering/kmean/k_mean_functions.c index c6fbb5b..ad16631 100644 --- a/PULP/kmeans_clustering/kmean/k_mean_functions.c +++ b/PULP/kmeans_clustering/kmean/k_mean_functions.c @@ -1,438 +1,458 @@ #include "k_mean_functions.h" #include #include "../search/search_functions.h" #include "rt/rt_api.h" type_f genlogfunc(type_f x, type_f k, type_f b, type_f nu, type_f m){ return (k/powf(1+expf(-b*(x-m)),(1/nu))); } type_f gaussian(type_f x, type_f mu, type_f sign){ return expf(-powf((x - mu), 2)/(2*powf(sign, 2))); } /* Function to sort an array using insertion sort*/ void insertionSort(type_f arr[], int n) { type_f key; int i, j; for (i = 1; i < n; i++) { key = arr[i]; j = i - 1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } } RT_L1_DATA type_f abs_s2_init[SIZE_PERCENTILE_ARR]; //it's the first 1000 samples of abs diff to sort and find the 99 percentile type_f percentile(int16_t *x, int end, int percToFind){ int indexPerc = (end-1)*percToFind/100; for(int i = 0; i 0 && i==1 && last_peak > start_index_w){ // last_peak = rpks[num_peaks-2]; // mu = rpks[num_peaks-2] - rpks[num_peaks-3]; // sd = std(rpks, num_peaks-2, num_peaks_total-2); // #ifdef PRINT_DEBUG_CL_STD // printf("last_peak: %d mu: %f sd: %f\n",last_peak, mu, sd); // #endif // if(sd < 10) // sd = 10; // if(sd > 50) // sd = 50; // num_peaks = num_peaks-1; // last_peak_w = last_peak; // } //====== Uncomment if you are using qrs_init for overlap ======// #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check) printf("last_peak: %d input_value_gauss: %d mu: %f sd: %f\n",last_peak, start_index_w + (i-1) - last_peak, mu, sd); #endif bf = gaussian(start_index_w + (i-1) - last_peak, mu, sd); // i - last_peak_w #ifdef PRINT_GAUSS // DEBUG GAUSSIAN printf("%f,", bf); #endif #ifdef PRINT_GAUSS_MU_SD printf("%f %f %f \n", bf,mu,sd); #endif param_log = logf((hcentr - lcentr)/2)/(2*lcentr); param_log2 = log2f(hcentr/lcentr); bt = genlogfunc(x , hcentr, param_log, 1/param_log2, lcentr); #ifdef PRINT_GENLOGFUN printf("%f,", bt); #endif new_val = (bt * bf); if(x > new_val){ partial_fit(&x, &hcentr, &lcentr, &h_el, &l_el, &label); #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check) printf("index_all: %d i: %d x: %f hcentr: %f lcentr: %f label: %d\n", start_index_w + (i-1), i, x, hcentr, lcentr, label); #endif #ifdef PRINT_BAYFILT // DEBUG BAYESIAN FILTERED SIGNAL printf("%f,", x); #endif } else{ partial_fit(&new_val, &hcentr, &lcentr, &h_el, &l_el, &label); #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check) printf("index_all: %d i: %d new_val: %f hcentr: %f lcentr: %f label: %d\n", start_index_w + (i-1), i, new_val, hcentr, lcentr, label); #endif #ifdef PRINT_BAYFILT // DEBUG BAYESIAN FILTERED SIGNAL printf("%f,", new_val); #endif } #ifdef PRINT_CENTROIDS // DEBUG CENTROIDS printf("%f %f\n", lcentr,hcentr); #endif if(in_qrs == 1){ if(label == 0){ zeroctr += 1; }else{ zeroctr = 0; } s2[index_st] = (type_f) (ecg_buff[i] - ecg_buff[i-1]); if(x > new_val){ st[index_st] = x; index_st++; }else{ st[index_st] = new_val; index_st++; } #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check) printf("qrs_init: %d zeroctr: %d qrs_init_total: %d\n", qrs_init, zeroctr, qrs_init_total); #endif // Once a QRS has been detected, we look for 120ms of 0 output (30 samples) or 200ms to consider that the QRS has finished. - if(zeroctr==30 || start_index_w + (i-1) - qrs_init_total > max_qrs_dur){ + if(zeroctr==30 || start_index_w + (i-1) - qrs_init_total > MAX_QRS_DUR){ #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check) printf("start interval: %d stop interval: %d ecg_buff[start_interval]: %f i: %d zeroctr: %d label: %d index_st: %d stop_interval_st: %d \n",qrs_init, (i-1) - zeroctr + 1,ecg_buff[qrs_init],i, zeroctr, label,index_st-1,(index_st-1)-zeroctr+1 ); #endif // Search for location of the new peak. Checking maximum and minimum slopes, and move towards the peak end_qrs = (index_st-1)-zeroctr+1; argMaxMinProductSignSearch(st, s2, 0, end_qrs,max_min_slope_productSign); int max_slope = max_min_slope_productSign[0]; int min_slope = max_min_slope_productSign[1]; int max_slope_s2 = 0; int min_slope_s2 = 0; if (max_slope < min_slope){ new_peak = qrs_init + max_slope + argMaxProductSignSearch(st, s2, max_slope, min_slope+1); }else if (max_slope > min_slope){ argMaxMinSearch(s2, 0, end_qrs, max_min_slope); max_slope_s2 = max_min_slope[0]; min_slope_s2 = max_min_slope[1]; if(max_slope_s2 < min_slope_s2){ // Q wave new_peak = qrs_init + max_slope_s2 + argMaxSearch(s2, max_slope_s2, min_slope_s2+1); }else{ // S wave new_peak = qrs_init + argMaxSearch(s2, 0, min_slope_s2+1); } }else{ new_peak = qrs_init + argMaxSearch(st, 0, end_qrs); } #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check){ printf("BEFORE CORRECTION new_peak: %d\n", new_peak); if (max_slope > min_slope){ printf("end_qrs: %d max_slope: %d min_slope: %d max_slope_s2: %d min_slope_s2: %d\n",end_qrs,max_slope,min_slope,max_slope_s2,min_slope_s2); }else{ printf("end_qrs: %d max_slope: %d min_slope: %d\n",end_qrs,max_slope,min_slope); } } #endif if(ecg_buff[new_peak+1] > ecg_buff[new_peak]){ while(ecg_buff[new_peak+1] > ecg_buff[new_peak]){ new_peak += 1; } } else{ while(ecg_buff[new_peak] < ecg_buff[new_peak-1]){ new_peak -= 1; } } #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check) printf("AFTER CORRECTION new_peak: %d\n", new_peak); #endif last_peak = new_peak + start_index_w; if(last_peak > last_peak_w){ if(last_peak!=rpks[num_peaks]){ indicesRpeaks[ind_peak] = last_peak; ind_peak++; #ifdef PRINT_RPEAKS_DEBUG printf("ecg_buff_peak: %d last_peak: %d\n", new_peak, last_peak); #endif } if(num_peaks == MAX_PEAKS_IN_WIND){ for(int ix=0; ix 1){ mu = rpks[num_peaks]-rpks[num_peaks-1]; sd = std(rpks, num_peaks, num_peaks_total); #ifdef PRINT_DEBUG_CL_STD if(number_of_window==num_wind_to_check) printf("mu: %f sd: %f\n", mu, sd); #endif if(sd < 10) sd = 10; if(sd > 50) sd = 50; } num_peaks++; } last_peak_w = last_peak; end_last_peak = i-1; centroids_state[0] = hcentr; centroids_state[1] = lcentr; centroids_state[2] = (type_f) h_el; centroids_state[3] = (type_f) l_el; zeroctr = 0; in_qrs = 0; index_st = 0; } }else{ - if(label==1 && start_index_w + (i-1) > last_peak + min_rr_dist){ + if(label==1 && start_index_w + (i-1) > last_peak + MIN_RR_DIST){ in_qrs = 1; qrs_init = i-1; qrs_init_total = start_index_w + (i-1); s2[index_st] = (type_f) (ecg_buff[i] - ecg_buff[i-1]); if(x > new_val){ st[index_st] = x; index_st++; }else{ st[index_st] = new_val; index_st++; } } } } #ifdef PRINT_DEBUG_CL if(number_of_window==num_wind_to_check-1) printf("END OF WINDOW qrs_init: %d qrs_init_total: %d last_peak: %d mu: %f std: %f index_st: %d new_peak: %d\n",qrs_init,qrs_init_total,last_peak,mu,sd, index_st-1,new_peak); #endif - *overlap = end_main_loop + *overlap - end_last_peak - 1; // - qrs_init; // Using qrs_init gives some problems if the peak is a little bit before than qrs_init. This logically shouln't happen but unfortunately it happens because the python code is not perfect (probably needing some tweeking in the variable representing the duration of the qrs) + + if(in_qrs == 1) + *overlap_qrs_init = end_main_loop + *overlap - qrs_init - 1; + else + *overlap_qrs_init = 0; + +#ifdef PRINT_DEBUG_CL + if(number_of_window==num_wind_to_check-1) + printf("end_main_loop: %d overlap: %d qrs_init: %d overlap_qrs_init: %d\n",end_main_loop,*overlap,qrs_init, *overlap_qrs_init); +#endif + if(last_peak < start_index_w){ if(in_qrs == 0) *overlap = 1; else - *overlap = end_main_loop + *overlap - (qrs_init - max_qrs_dur) - 1; + *overlap = end_main_loop + *overlap - (qrs_init - MAX_QRS_DUR) - 1; + }else{ + *overlap = end_main_loop + *overlap - end_last_peak - 1; // - qrs_init; // Using qrs_init gives some problems if the peak is a little bit before than qrs_init. This logically shouln't happen but unfortunately it happens because the python code is not perfect (probably needing some tweeking in the variable representing the duration of the qrs) } in_qrs = 0; zeroctr = 0; //if overlap = end_main_loop - end_last_peak - 1; qrs_init = 0; index_st = 0; } diff --git a/PULP/kmeans_clustering/kmean/k_mean_functions.h b/PULP/kmeans_clustering/kmean/k_mean_functions.h index 79c91fe..2835139 100644 --- a/PULP/kmeans_clustering/kmean/k_mean_functions.h +++ b/PULP/kmeans_clustering/kmean/k_mean_functions.h @@ -1,14 +1,16 @@ #include #include #include "../../defines.h" #define PEAKS_STD 5 #define MAX_PEAKS_IN_WIND (N*15 + PEAKS_STD) +#define MAX_QRS_DUR 35 //50, 35 +#define MIN_RR_DIST 60 //50, 60 type_f ganlogfunc(type_f x, type_f k, type_f b, type_f nu, type_f m); type_f gaussian(type_f x, type_f mu, type_f sign); type_f percentile(int16_t *x, int end, int percToFind); void partial_fit(type_f *x, type_f *hcentr, type_f *lcentr, int *h_el, int *l_el, int *label); type_f std(type_i *x, int num_peaks, int num_peaks_total); void rpeaks(int32_t* arg[]); diff --git a/PULP/profiling/profile.c b/PULP/profiling/profile.c index b91603c..7180f1f 100755 --- a/PULP/profiling/profile.c +++ b/PULP/profiling/profile.c @@ -1,68 +1,67 @@ #include "profile.h" #include "rt/rt_api.h" #include "../defines.h" void profile_start(rt_perf_t *perf){ int id = rt_core_id(); if(id==0){ - printf("\nstart profile\n"); + printf("\nstart profile FC\n"); } rt_perf_init(&perf[id]); #ifdef ACTIVE rt_perf_conf(&perf[id],(1<