Time period between 2 peaks of 2 different graphs

Hello guys.. I need help for my project. Got the 2 graphs from ECG and pulse wave from 2 sensors. I got them to plot out both graphs together on the serial plotter.

  1. How can I open the serial plotter and serial monitor at the same time? It keeps giving me error right now. I need both the graphs and the values..

  2. How do I get the time period (horizontal-axis) between the 2 peaks of the 2 different graphs?

Help is greatly appreciated!!! Thanks!

You need to include a time stamp in the loop using the micros() function.

uint32_t timestamp = micros();

Serial.print( timestamp );
Serial.print( "  " );

Is this okay? but i cant get decent values and i dont know what went wrong..

double ecgvalues[50];
int ecgtimearray[50];
double pulsewavevalues[50];
int pulsewavetimearray[50];
double largestecgvalue = 0;
double largestpulsewavevalue = 0;
double wantedecgvalue = 0;
double wantedpulsewavevalue = 0;
int ecgtimecalc = 0;
int pulsewavetimecalc = 0;
double ecgcompare = 0;
double pulsewavecompare = 0;
int wantedpos1 = 0;
int i = 0;
int j = 0;
double ecgpeakvalue = 0;
double pulsewavepeakvalue = 0;
unsigned long ecgpeaktime = 0;
unsigned long pulsewavepeaktime = 0;
unsigned long time_between_pulses = 0;
unsigned long pulsestarttime = 0;
const double minutes_in_milliseconds = 60000;
unsigned long timer;

//When you have determined your threshold, declare your variable
//right below this line. This will change from person to person.
const double ecgthreshold = 0.33;
const double pulsewavethreshold = 0.33;

void setup() {
Serial.begin(115200);

//creates a timer variable to keep track of time
  timer = millis();
    
  //small delay to change our sampling rate
  //and stabilize our signal
  delay(25);  
}

void loop() {
  // put your main code here, to run repeatedly:

    float sensorValue = analogRead(A1);
    float ECG = analogRead(A0);
  
  Serial.print(ECG);
  Serial.print(" ");
  Serial.println(sensorValue);
  
  long ecgpeaktime = detectecgThreshold(ECG);
  long pulsewavepeaktime = detectpulsewaveThreshold(sensorValue);
  
  if (ecgpeaktime != 0)
  {
    ecgvalues[i] = ECG;
  ecgtimearray[i] = ecgpeaktime;
  i++;
  }
  else
  { 
   for(byte p = 0; p < 50; p++)
  {
    largestecgvalue = max(ecgvalues[p], ecgcompare);
  }
   
   int wantedecgvalue = largestecgvalue;
   int wantedpos1;
   for (int q=0; q<50; q++) 
   {
   if (wantedecgvalue == ecgvalues[q]) 
  {
    wantedpos1 = q;
  }
   }
   
    i = 0; 
  
  }

  if (pulsewavepeaktime != 0)
  {
    pulsewavevalues[j] = sensorValue;
  pulsewavetimearray[j] = pulsewavepeaktime;
  j++;
  }
  else
  { 
  for(byte m = 0; m < 50; m++)
  {
    largestpulsewavevalue = max(pulsewavevalues[m], pulsewavecompare);
  }
   
   int wantedpulsewavevalue = largestpulsewavevalue;
   int wantedpos2;
   for (int n=0; n<50; n++) 
   {
   if (wantedpulsewavevalue == pulsewavevalues[n]) 
  {
    wantedpos2 = n;
  }
   }
   
  if (ecgtimearray[wantedpos1] != 0)
  {
  time_between_pulses = pulsewavetimearray[wantedpos1] - ecgtimearray[wantedpos2];
  
  memset(ecgvalues,0,sizeof(ecgvalues));
  memset(ecgtimearray,0,sizeof(ecgtimearray));
  }
  
  
  memset(pulsewavevalues,0,sizeof(pulsewavevalues));
  memset(pulsewavetimearray,0,sizeof(pulsewavetimearray));
  
  Serial.print(time_between_pulses);
  j = 0; }
 
  delay(5);
}

//detectThreshold()
//This method detects whether the signal has passed our
//threshold and determines the time between subsequent peaks
long detectecgThreshold(double absorbance)
{

  if (absorbance >= ecgthreshold)
  {
      pulsestarttime = timer;
  }
  

  return pulsestarttime;
}

long detectpulsewaveThreshold(double absorbance)
{

  if (absorbance >= pulsewavethreshold)
  {
      pulsestarttime = timer;
  }
  

  return pulsestarttime;
}

The 'timer = millis();' statement in setup() only captures the CPU clock at that moment and does no good in the loop() part. Move it to loop() just before the two data analogRead().