I use nrf52840 and max30003 and SD card that saves my ECG data. I've tried to make a lot of ECG and this one is the best. But I don't know why some ECG PEAKS are positive and some are negative :( why it happens and how to resolve it? 
I use nrf52840 and max30003 and SD card that saves my ECG data. I've tried to make a lot of ECG and this one is the best. But I don't know why some ECG PEAKS are positive and some are negative :( why it happens and how to resolve it? 
I'm not able to help significantly, but you might try increasing the sample rate. Either the patient is reversing the leads between heartbeats (highly improbable but it happens), the DC-restore circuitry is struggling to cope (improbable if the patient is still or resting) or you have a simple aliasing issue. Given a simple aliasing issue, try upping the sample rate to 250 samples per second and see if that changes the trace.
I should add that the aliasing can either be the MAX30003 sample rate or the transmission and display of the data should that happen to be at a lower sample rate (ie discarding ECG samples). The x-axis looks like insufficient readings which is concealed by using a smooth curve drawn between points.
Thanks for the reply.
How can I increase the sample rate?
Since the minimum sample rate on this part is 125 or 128 samples per second, I would instead focus on what happens to the samples and whether they are all actually being displayed; plotting points instead of smooth curve would show better how many points (samples) are on the graph, or just look at a raw data capture file of (say) 2 seconds and see how many samples are in that. That way it can be determined if the problem is at the front end or back end (the display). It would help for you to post a (small) data capture file.
Also try stuffing this data capture onto your display code; it should look like good ECG data.
int32_t SampleData[] = {
// 10 seconds at 250 samples/sec from ECG Simulator
415,421,420,450,481,468,468,473,496,506,506,475,472,460,418,365,334,290,238,191,156,136,88,67,63,68,49,23,20,21,38,23,-9,6,20,18,4,21,28,6,
9,21,37,24,9,17,32,16,11,18,18,11,4,-1,17,23,9,9,11,11,5,14,26,21,0,7,15,14,11,-1,16,30,22,8,12,31,9,2,1,18,
28,13,1,22,26,26,23,31,31,19,13,30,41,21,8,25,24,14,7,11,31,25,2,8,28,22,0,20,31,34,24,21,29,25,4,11,32,41,19,8,
19,28,22,7,21,33,26,4,16,29,14,8,30,33,32,20,16,31,38,26,25,34,43,28,22,45,101,141,187,231,265,275,281,303,315,299,278,251,209,154,
107,76,84,79,41,27,37,29,6,9,162,585,1128,1666,2201,2668,3053,3368,3649,3890,4041,4089,3993,3639,2946,2156,1583,1204,923,701,535,431,347,263,223,191,146,104,93,76,
73,58,45,58,56,33,26,39,43,26,18,24,54,51,38,38,71,95,88,100,128,146,151,161,199,231,241,248,273,312,313,311,336,364,389,383,391,418,434,427,
419,455,466,466,454,473,490,484,492,489,479,448,407,381,350,288,228,181,164,118,90,78,76,59,38,41,49,40,25,18,25,19,3,1,15,21,3,-4,17,18,
14,16,16,18,11,6,24,26,14,1,-1,24,19,4,9,24,26,9,5,22,26,21,3,21,35,22,0,12,19,19,19,15,31,22,-1,-15,22,21,14,14,
21,21,3,10,12,18,26,18,44,28,15,6,15,30,18,3,11,23,23,10,16,29,16,11,3,18,18,4,8,23,23,8,4,18,24,20,1,24,41,29,
19,36,25,11,14,27,38,23,2,11,27,34,6,11,36,29,9,19,31,43,24,6,34,66,95,135,193,242,262,254,288,298,302,299,291,252,203,156,119,104,
69,34,31,50,46,8,10,29,173,567,1099,1659,2179,2648,3029,3379,3671,3868,4018,4089,4001,3653,2957,2159,1603,1201,896,678,546,431,325,256,224,179,133,115,98,98,71,52,
49,47,45,19,25,36,28,12,26,34,31,23,44,69,77,79,97,121,132,127,144,184,210,219,219,246,284,296,304,334,354,354,352,383,409,408,405,429,437,448,
444,466,492,486,474,476,495,497,469,434,424,393,328,273,237,205,153,104,95,94,60,39,28,46,36,26,23,26,24,4,11,18,24,13,8,14,13,13,-1,4,
28,13,13,18,27,17,6,17,23,20,4,7,23,28,12,6,34,23,14,4,19,23,9,6,14,16,5,1,9,27,8,-4,9,30,26,19,24,31,19,4,
18,26,21,10,1,21,18,4,11,12,29,18,-2,28,36,15,4,17,24,19,19,26,28,17,11,8,26,14,4,16,30,39,12,19,29,33,23,9,19,26,
25,16,21,25,12,14,23,23,11,11,14,26,29,16,13,26,31,19,14,31,36,46,95,162,204,229,240,268,301,296,294,306,291,245,178,144,134,110,68,43,
51,38,24,15,22,36,154,561,1109,1671,2176,2616,3031,3392,3661,3870,4047,4114,4010,3635,2956,2185,1607,1196,916,703,562,418,316,264,217,175,131,113,111,80,73,67,63,55,
29,34,43,16,4,11,33,43,28,28,55,70,67,66,85,113,111,126,173,195,196,213,244,261,269,273,301,331,335,339,369,392,394,384,403,439,445,438,445,472,
483,478,469,496,496,479,456,440,413,366,313,271,249,188,124,110,93,66,49,50,46,36,27,32,33,33,7,-6,28,22,6,-1,19,31,10,1,3,15,23,8,
3,16,21,16,8,22,21,-1,-4,20,11,-4,8,24,22,11,10,31,41,17,11,20,28,14,3,14,31,13,-7,4,23,3,1,18,16,12,13,19,28,26,
17,16,6,8,2,3,24,29,8,13,30,32,26,11,11,46,34,7,-6,24,23,11,9,20,13,8,8,15,21,19,12,41,36,27,17,24,16,14,3,7,
12,11,9,16,35,25,1,27,43,25,9,12,31,25,15,3,19,26,8,34,88,153,186,206,229,268,272,273,293,316,289,234,199,159,106,74,71,69,51,30,
34,38,38,26,149,550,1096,1639,2147,2609,3036,3361,3624,3859,4042,4108,3996,3654,3004,2215,1607,1193,931,721,543,406,340,286,213,167,151,135,100,76,68,80,59,33,29,47,
42,33,32,33,26,14,23,43,57,48,51,80,103,107,130,149,166,193,204,236,254,251,264,290,318,328,333,361,381,378,386,406,437,443,431,438,466,473,469,473,
489,493,476,476,486,463,417,369,349,299,239,188,169,123,92,68,51,47,35,21,30,33,14,19,16,14,13,-8,-4,9,3,9,-3,4,23,12,6,14,23,28,
8,16,38,15,3,5,19,23,16,0,-4,3,3,-10,16,21,6,10,13,17,8,-2,25,36,29,10,24,26,13,1,13,29,8,-8,-8,12,16,0,-4,28,
17,-1,-1,13,24,13,8,16,26,9,5,37,41,28,6,-4,16,13,9,15,28,21,6,0,16,21,4,8,27,18,-1,4,29,37,28,9,7,36,39,21,
17,24,31,12,24,38,24,4,13,42,32,19,18,24,16,3,16,50,95,126,176,228,244,264,269,285,307,311,286,234,198,146,88,81,81,65,29,15,23,22,
7,14,152,563,1085,1634,2162,2624,3029,3363,3652,3894,4043,4086,3999,3672,2987,2178,1593,1197,917,696,525,421,343,258,213,192,166,108,87,85,88,71,54,37,48,43,21,24,
37,37,26,29,54,41,28,40,81,84,87,100,134,156,161,176,224,238,245,258,283,298,298,304,334,346,351,369,384,415,413,412,436,464,463,444,456,483,489,483,
487,481,483,445,406,373,328,282,223,178,159,118,91,79,64,35,29,29,29,28,7,7,26,16,4,4,8,15,3,6,23,23,7,-7,13,23,15,6,26,26,
4,-4,3,14,6,-7,7,19,19,12,-2,22,23,2,-1,11,20,4,-7,14,38,19,6,6,20,12,-1,11,27,18,6,11,14,15,8,3,20,33,13,-9,
13,19,3,-4,14,19,16,5,6,13,9,3,18,31,22,13,16,39,31,8,5,29,31,16,11,18,22,-1,-4,23,29,18,4,21,34,23,14,16,19,27,
18,18,28,13,16,14,19,24,12,3,33,29,5,13,39,54,86,131,183,226,236,241,268,289,284,283,276,251,191,130,113,101,79,38,18,37,29,10,19,36,
139,512,1044,1612,2151,2593,2984,3343,3631,3854,4007,4098,4028,3683,3019,2237,1648,1229,922,701,551,443,333,274,229,189,138,118,104,97,66,49,51,52,46,34,38,54,32,12,
23,26,28,21,29,59,56,55,89,121,130,133,151,186,201,214,229,261,285,285,300,329,349,346,349,378,401,419,398,408,429,444,446,454,467,474,463,487,499,493,
468,432,416,389,334,283,233,183,156,112,86,87,60,34,35,42,26,3,-9,9,14,-1,3,18,14,2,9,8,13,-6,-4,21,13,5,-9,8,31,19,12,3,
16,16,14,18,25,6,-14,-2,10,9,8,14,20,22,13,6,2,9,0,1,7,11,14,4,9,28,24,2,4,14,1,-4,3,14,19,5,6,19,21,10,
};
#define NUMBER_TEST_SAMPLES (sizeof(SampleData)/sizeof(SampleData[0]))Since the minimum sample rate on this part is 125 or 128 samples per second, I would instead focus on what happens to the samples and whether they are all actually being displayed; plotting points instead of smooth curve would show better how many points (samples) are on the graph, or just look at a raw data capture file of (say) 2 seconds and see how many samples are in that. That way it can be determined if the problem is at the front end or back end (the display). It would help for you to post a (small) data capture file.
Also try stuffing this data capture onto your display code; it should look like good ECG data.
int32_t SampleData[] = {
// 10 seconds at 250 samples/sec from ECG Simulator
415,421,420,450,481,468,468,473,496,506,506,475,472,460,418,365,334,290,238,191,156,136,88,67,63,68,49,23,20,21,38,23,-9,6,20,18,4,21,28,6,
9,21,37,24,9,17,32,16,11,18,18,11,4,-1,17,23,9,9,11,11,5,14,26,21,0,7,15,14,11,-1,16,30,22,8,12,31,9,2,1,18,
28,13,1,22,26,26,23,31,31,19,13,30,41,21,8,25,24,14,7,11,31,25,2,8,28,22,0,20,31,34,24,21,29,25,4,11,32,41,19,8,
19,28,22,7,21,33,26,4,16,29,14,8,30,33,32,20,16,31,38,26,25,34,43,28,22,45,101,141,187,231,265,275,281,303,315,299,278,251,209,154,
107,76,84,79,41,27,37,29,6,9,162,585,1128,1666,2201,2668,3053,3368,3649,3890,4041,4089,3993,3639,2946,2156,1583,1204,923,701,535,431,347,263,223,191,146,104,93,76,
73,58,45,58,56,33,26,39,43,26,18,24,54,51,38,38,71,95,88,100,128,146,151,161,199,231,241,248,273,312,313,311,336,364,389,383,391,418,434,427,
419,455,466,466,454,473,490,484,492,489,479,448,407,381,350,288,228,181,164,118,90,78,76,59,38,41,49,40,25,18,25,19,3,1,15,21,3,-4,17,18,
14,16,16,18,11,6,24,26,14,1,-1,24,19,4,9,24,26,9,5,22,26,21,3,21,35,22,0,12,19,19,19,15,31,22,-1,-15,22,21,14,14,
21,21,3,10,12,18,26,18,44,28,15,6,15,30,18,3,11,23,23,10,16,29,16,11,3,18,18,4,8,23,23,8,4,18,24,20,1,24,41,29,
19,36,25,11,14,27,38,23,2,11,27,34,6,11,36,29,9,19,31,43,24,6,34,66,95,135,193,242,262,254,288,298,302,299,291,252,203,156,119,104,
69,34,31,50,46,8,10,29,173,567,1099,1659,2179,2648,3029,3379,3671,3868,4018,4089,4001,3653,2957,2159,1603,1201,896,678,546,431,325,256,224,179,133,115,98,98,71,52,
49,47,45,19,25,36,28,12,26,34,31,23,44,69,77,79,97,121,132,127,144,184,210,219,219,246,284,296,304,334,354,354,352,383,409,408,405,429,437,448,
444,466,492,486,474,476,495,497,469,434,424,393,328,273,237,205,153,104,95,94,60,39,28,46,36,26,23,26,24,4,11,18,24,13,8,14,13,13,-1,4,
28,13,13,18,27,17,6,17,23,20,4,7,23,28,12,6,34,23,14,4,19,23,9,6,14,16,5,1,9,27,8,-4,9,30,26,19,24,31,19,4,
18,26,21,10,1,21,18,4,11,12,29,18,-2,28,36,15,4,17,24,19,19,26,28,17,11,8,26,14,4,16,30,39,12,19,29,33,23,9,19,26,
25,16,21,25,12,14,23,23,11,11,14,26,29,16,13,26,31,19,14,31,36,46,95,162,204,229,240,268,301,296,294,306,291,245,178,144,134,110,68,43,
51,38,24,15,22,36,154,561,1109,1671,2176,2616,3031,3392,3661,3870,4047,4114,4010,3635,2956,2185,1607,1196,916,703,562,418,316,264,217,175,131,113,111,80,73,67,63,55,
29,34,43,16,4,11,33,43,28,28,55,70,67,66,85,113,111,126,173,195,196,213,244,261,269,273,301,331,335,339,369,392,394,384,403,439,445,438,445,472,
483,478,469,496,496,479,456,440,413,366,313,271,249,188,124,110,93,66,49,50,46,36,27,32,33,33,7,-6,28,22,6,-1,19,31,10,1,3,15,23,8,
3,16,21,16,8,22,21,-1,-4,20,11,-4,8,24,22,11,10,31,41,17,11,20,28,14,3,14,31,13,-7,4,23,3,1,18,16,12,13,19,28,26,
17,16,6,8,2,3,24,29,8,13,30,32,26,11,11,46,34,7,-6,24,23,11,9,20,13,8,8,15,21,19,12,41,36,27,17,24,16,14,3,7,
12,11,9,16,35,25,1,27,43,25,9,12,31,25,15,3,19,26,8,34,88,153,186,206,229,268,272,273,293,316,289,234,199,159,106,74,71,69,51,30,
34,38,38,26,149,550,1096,1639,2147,2609,3036,3361,3624,3859,4042,4108,3996,3654,3004,2215,1607,1193,931,721,543,406,340,286,213,167,151,135,100,76,68,80,59,33,29,47,
42,33,32,33,26,14,23,43,57,48,51,80,103,107,130,149,166,193,204,236,254,251,264,290,318,328,333,361,381,378,386,406,437,443,431,438,466,473,469,473,
489,493,476,476,486,463,417,369,349,299,239,188,169,123,92,68,51,47,35,21,30,33,14,19,16,14,13,-8,-4,9,3,9,-3,4,23,12,6,14,23,28,
8,16,38,15,3,5,19,23,16,0,-4,3,3,-10,16,21,6,10,13,17,8,-2,25,36,29,10,24,26,13,1,13,29,8,-8,-8,12,16,0,-4,28,
17,-1,-1,13,24,13,8,16,26,9,5,37,41,28,6,-4,16,13,9,15,28,21,6,0,16,21,4,8,27,18,-1,4,29,37,28,9,7,36,39,21,
17,24,31,12,24,38,24,4,13,42,32,19,18,24,16,3,16,50,95,126,176,228,244,264,269,285,307,311,286,234,198,146,88,81,81,65,29,15,23,22,
7,14,152,563,1085,1634,2162,2624,3029,3363,3652,3894,4043,4086,3999,3672,2987,2178,1593,1197,917,696,525,421,343,258,213,192,166,108,87,85,88,71,54,37,48,43,21,24,
37,37,26,29,54,41,28,40,81,84,87,100,134,156,161,176,224,238,245,258,283,298,298,304,334,346,351,369,384,415,413,412,436,464,463,444,456,483,489,483,
487,481,483,445,406,373,328,282,223,178,159,118,91,79,64,35,29,29,29,28,7,7,26,16,4,4,8,15,3,6,23,23,7,-7,13,23,15,6,26,26,
4,-4,3,14,6,-7,7,19,19,12,-2,22,23,2,-1,11,20,4,-7,14,38,19,6,6,20,12,-1,11,27,18,6,11,14,15,8,3,20,33,13,-9,
13,19,3,-4,14,19,16,5,6,13,9,3,18,31,22,13,16,39,31,8,5,29,31,16,11,18,22,-1,-4,23,29,18,4,21,34,23,14,16,19,27,
18,18,28,13,16,14,19,24,12,3,33,29,5,13,39,54,86,131,183,226,236,241,268,289,284,283,276,251,191,130,113,101,79,38,18,37,29,10,19,36,
139,512,1044,1612,2151,2593,2984,3343,3631,3854,4007,4098,4028,3683,3019,2237,1648,1229,922,701,551,443,333,274,229,189,138,118,104,97,66,49,51,52,46,34,38,54,32,12,
23,26,28,21,29,59,56,55,89,121,130,133,151,186,201,214,229,261,285,285,300,329,349,346,349,378,401,419,398,408,429,444,446,454,467,474,463,487,499,493,
468,432,416,389,334,283,233,183,156,112,86,87,60,34,35,42,26,3,-9,9,14,-1,3,18,14,2,9,8,13,-6,-4,21,13,5,-9,8,31,19,12,3,
16,16,14,18,25,6,-14,-2,10,9,8,14,20,22,13,6,2,9,0,1,7,11,14,4,9,28,24,2,4,14,1,-4,3,14,19,5,6,19,21,10,
};
#define NUMBER_TEST_SAMPLES (sizeof(SampleData)/sizeof(SampleData[0]))