Filtering heart rate sensor

edited July 2017 in Arduino

Hello! I'm working on project where I'm trying to make music from my real time heart beat I'm using ad8232 heart monitor and Arduino UNO Here is my bare bones code:

import processing.sound.*;
SoundFile file;

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;

void setup() {
  size(500, 500);
  file = new SoundFile(this, "KICK011F.wav");
  // Prints out the available serial ports.
  println(Arduino.list());

  arduino = new Arduino(this, Arduino.list()[1], 57600);
}

void draw() {
  background(0);

  if (arduino.analogRead(1)<600) {
    file.play();
  }

I would like to somehow filter the signal and only play one sound on each heart beat. For now it works fine, but sometimes there are multiple sounds for one heart beat. It should somehow see each beat and play the sound once. I'm guessing it could be done by setting a minimal distance between two sounds and choosing the highest value for each beat. I doesn't work if I just set a global theshold, because sometimes the highest value for one beat is lower then second highest in other.

Thanks!

Answers

  • Do you have a clean QRS curve? Are all those curve the same?

    In your code you have arduino.analogRead(1)<600. If you are looking at the peak, or above certain threshold, shouldn't you be looking at arduino.analogRead(1)<600?

    Without knowing much about the nature of the data, I can suggest the next modified version of draw() right below. Notice that if the data that is above the threshold is less that the length of the sound, then your code or the code below should give you the same result aka. no change.

    Kf

    boolean isHigh=false;
    
    void draw() {
      background(0);
    
      if (arduino.analogRead(1)> 600) {   //NOTICE change of inequality
    
        //ONLY play file once when above threshold
        if(isHigh==false){
          isHigh=true;
          file.play();
        }
      }
      else{
        isHigh=false;
      }
    }
    
Sign In or Register to comment.