Heart beat recognizing

Hi everybody! I need help to develop a real time plotter for my pulsimeter. The data flow comes from arduino and the processing script I use is the basic poor's man oscilloscope: https://gist.github.com/chrismeyersfsu/3270419. I need that the software recognize beats and more precisely every pulse vertex to make graphics manipulations on these points. I tried to make it comparing serial values and "y" values progression, thinking to select the curve inversion points using simple if statement(if(a<b&&b>c)), with no results. I tried also to show "y" values on the console and the IDE lock so I need to force exit. Please give me an idea for advance on my project.

Answers

  • I need that the software recognize beats and more precisely every pulse vertex

    This is certainly possible. You capture all the points above a threshold and do a centroid estimation. However, unable to present an example without accessing some of your data.

    I tried also to show "y" values on the console and the IDE lock so I need to force exit.

    Please show your modified version of your code.

    Kf

  • Thank you for the replies. Using a threshold in a pulsimeter graphic is difficult because is not a linear graphic as an oscilloscope output but it change in intensity according blood oxigen saturation or low frequencies variations. Infact my goal is to highline these variations in graphic to have clearer reading of these phenomenons. So I though to make the program read data flow or cartesian values to match the higter point in the curve. Anyway I don't know if it is possible having data in byte format. Here is the code

    import processing.serial.*;
    
    Serial port;  // Create object from Serial class
    int val;      // Data received from the serial port
    int[] values;
    float zoom;
    
    void setup() 
    {
      size(1280, 700);
      // Open the port that the board is connected to and use the same speed (9600 bps)
      port = new Serial(this, Serial.list()[0], 9600);
      values = new int[width];
      zoom = 1.0f;
      smooth();
    }
    
    int getY(int val) {
      return (int)(height - val / 1023.0f * (height - 1));
    }
    
    int getValue() {
      int value = -1;
      while (port.available() >= 3) {
        if (port.read() == 0xff) {
          value = (port.read() << 8) | (port.read());
        }
      }
      return value;
    }
    
    void pushValue(int value) {
      for (int i=0; i<width-1; i++)
        values[i] = values[i+1];
      values[width-1] = value;
    }
    
    void drawLines() {
      stroke(255);
    
      int displayWidth = (int) (width / zoom);
    
      int k = values.length - displayWidth;
    
      int x0 = 0;
      int y0 = getY(values[k]);
      for (int i=1; i<displayWidth; i++) {
        k++;
        int x1 = (int) (i * (width-1) / (displayWidth-1));
        int y1 = getY(values[k]);
        line(x0, y0, x1, y1);
        x0 = x1;
        y0 = y1;
      }
    }
    
    void drawGrid() {
      stroke(255, 0, 0);
      line(0, height/2, width, height/2);
    }
    
    void keyReleased() {
      switch (key) {
        case '+':
          zoom *= 2.0f;
          println(zoom);
          if ( (int) (width / zoom) <= 1 )
            zoom /= 2.0f;
          break;
        case '-':
          zoom /= 2.0f;
          if (zoom < 1.0f)
            zoom *= 2.0f;
          break;
      }
    }
    
    void draw()
    {
      background(0);
      drawGrid();
      val = getValue();
      if (val != -1) {
        pushValue(val);
      }
      drawLines();
    }
    

    I try to modifi the draw lines part in many ways like:

    void drawLines() {
      stroke(255);
    
      int displayWidth = (int) (width / zoom);
    
      int k = values.length - displayWidth;
    
    
      int x0 = 0;
      int y0 = getY(values[k]);
      for (int i=1; i<displayWidth; i++) {
        k++;
        int x1 = (int) (i * (width-1) / (displayWidth-1));
        int y1 = getY(values[k]);
    
        line(x0, y0, x1, y1);
        x0 = x1;
        y0 = y1;
          //    values[i] = values[i+1]; ? 
    if ((y1-1)<y1&&y1>(y1+1));
    vertex(y1,x1);
    }
    }
    
Sign In or Register to comment.