example_BPM/src/heartRate.h
//  Heart Rate Monitor functions takes a sample value and the sample number
//  Returns true if a beat is detected
//  A running average of four samples is recommended for display on the screen.
Heart Rate Monitor functions takes a sample value and the sample number
Returns true if a beat is detected
A running average of four samples is recommended for display on the screen.
Heart Rate Monitor functions takes a sample value and the sample number Returns true if a beat is detected A running average of four samples is recommended for display on the screen .
bool checkForBeat(int sample)
{
  bool beatDetected = false;
  IR_AC_Signal_Previous = IR_AC_Signal_Current;
  IR_Average_Estimated = averageDCEstimator(&ir_avg_reg, sample);
  IR_AC_Signal_Current = lowPassFIRFilter(sample - IR_Average_Estimated);
  if ((IR_AC_Signal_Previous < 0) & (IR_AC_Signal_Current >= 0))
  {
    IR_AC_Max = IR_AC_Signal_max; 
    IR_AC_Min = IR_AC_Signal_min;
    positiveEdge = 1;
    negativeEdge = 0;
    IR_AC_Signal_max = 0;
      ofLog()<<"(IR_AC_Max - IR_AC_Min) > 0"<<(IR_AC_Max - IR_AC_Min);
      ofLog()<<"(IR_AC_Max - IR_AC_Min) < 100 "<<(IR_AC_Max - IR_AC_Min);
    if ((IR_AC_Max - IR_AC_Min) > 20 & (IR_AC_Max - IR_AC_Min) < 1000)
    {
      beatDetected = true;
    }
  }
  if ((IR_AC_Signal_Previous > 0) & (IR_AC_Signal_Current <= 0))
  {
    positiveEdge = 0;
    negativeEdge = 1;
    IR_AC_Signal_min = 0;
  }
  if (positiveEdge & (IR_AC_Signal_Current > IR_AC_Signal_Previous))
  {
    IR_AC_Signal_max = IR_AC_Signal_Current;
  }
  if (negativeEdge & (IR_AC_Signal_Current < IR_AC_Signal_Previous))
  {
    IR_AC_Signal_min = IR_AC_Signal_Current;
  }
  return(beatDetected);
}
bool checkForBeat ( int sample ) { bool beatDetected = false ; IR_AC_Signal_Previous = IR_AC_Signal_Current ; IR_Average_Estimated = averageDCEstimator ( & ir_avg_reg , sample ) ; IR_AC_Signal_Current = lowPassFIRFilter ( sample - IR_Average_Estimated ) ; if ( ( IR_AC_Signal_Previous < 0 ) & ( IR_AC_Signal_Current >= 0 ) ) { IR_AC_Max = IR_AC_Signal_max ; IR_AC_Min = IR_AC_Signal_min ; positiveEdge = 1 ; negativeEdge = 0 ; IR_AC_Signal_max = 0 ; ofLog ( ) << " " << ( IR_AC_Max - IR_AC_Min ) ; ofLog ( ) << " " << ( IR_AC_Max - IR_AC_Min ) ; if ( ( IR_AC_Max - IR_AC_Min ) > 20 & ( IR_AC_Max - IR_AC_Min ) < 1000 ) { beatDetected = true ; } } if ( ( IR_AC_Signal_Previous > 0 ) & ( IR_AC_Signal_Current <= 0 ) ) { positiveEdge = 0 ; negativeEdge = 1 ; IR_AC_Signal_min = 0 ; } if ( positiveEdge & ( IR_AC_Signal_Current > IR_AC_Signal_Previous ) ) { IR_AC_Signal_max = IR_AC_Signal_Current ; } if ( negativeEdge & ( IR_AC_Signal_Current < IR_AC_Signal_Previous ) ) { IR_AC_Signal_min = IR_AC_Signal_Current ; } return ( beatDetected ) ; }
Heart Rate Monitor functions takes a sample value and the sample number
Returns true if a beat is detected
A running average of four samples is recommended for display on the screen.
Heart Rate Monitor functions takes a sample value and the sample number Returns true if a beat is detected A running average of four samples is recommended for display on the screen .
//  Save current state //This is good to view for debugging //Serial.print("Signal_Current: "); //Serial.println(IR_AC_Signal_Current); //  Process next data sample //  Detect positive zero crossing (rising edge) //Adjust our AC max and min //if ((IR_AC_Max - IR_AC_Min) > 100 & (IR_AC_Max - IR_AC_Min) < 1000) //Heart beat!!! //  Detect negative zero crossing (falling edge) //  Find Maximum value in positive cycle //  Find Minimum value in negative cycle