How to draw a dynamic ECG curve (aka machine that gowe Bing)

edited February 2014 in How To...

Hello everyone,

to visualize the data I gather from a mobile EMG/ EDA/ ECG device (like with a electro-cardiogramm/ heart monitor in Dr. House or Monty Python's Meaning of Life), a Bitalino device, I'd like to use Processing. In principle, I'm pretty sure I would find a way to render this. However, before trying to implement this all by myself, I'd like to ask if someone here knows of a library or an application that might be fit for visualizing these data, so I wouldn't have to build it all from scratch.

Thanks in advance, Marius

Answers

  • edited February 2014 Answer ✓
    int x = 0;
    float py = 0;
    
    void setup(){
      size(600,200);
      background(0);
    }
    
    void draw(){
      noStroke();
      fill(0,0,0,15);
      rect(0,0,width,height);
      translate(0,height/2);
      x++;
      x%=width;
      float fx = py + random(-20,20);
      stroke(100,255,100);
      noFill();
      line(x-1,py, x,fx);
      py = fx;
      if(py>height/2) py=height/2;
      if(py<-height/2) py=-height/2;
    }
    
  • That works like a charm, thanks!

  • Hi Marius,

    Could you please shortly describe how you connect bitalino with processing or even share your code?

    Pedro

  • Hi Pedro,

    I won't share my full code here as it's a bit messy and buggy, so I'm a bit ashamed. ;-) But I'll be glad to help.

    I have just used the JAVA API that is available at the Bitalino site. In the main loop of the tread generated by this class, the data is continuously read from the device once it has been connected. Essentially, you get objects of the type Frame there; Frame is defined in the Bitalino API.

    From this object, you can get the data you read/ want (the values from the sensors are raw values from 0 to 1023). I use a listener and just throw these data over to my Processing class holding the Canvas, to draw the values.

    If you like, just drop me a PM and I can mail you the code. But as I said, it was trial and error, there are too many threads and too few comments inside. ;-)

    All the best, Marius

  • @Marius Hi Marius. How do you import the bitalino api to the processing? Where should I put the api files and how should I configure it? I am kind of noob on this, thank you in advance! :)

  • edited May 2016

    What I did is that I downloaded the API_Java file from BITalino's website, and copied it to my libraries folder under my processing's working path. I renamed the subfiles and then I could see the BITalino library as a contributed library in processing. However, when I imported the BITalino library, it showed as follow:

    import com.intel.bluetooth.*;
    import com.intel.bluetooth.btspp.*;
    import com.intel.bluetooth.btl2cap.*;
    import com.intel.bluetooth.gcf.socket.*;
    import com.intel.bluetooth.btgoep.*;
    import com.intel.bluetooth.obex.*;
    import com.intel.bluetooth.tcpobex.*;
    import com.sun.cdc.io.j2me.btspp.*;
    import com.sun.cdc.io.j2me.btl2cap.*;
    import com.sun.cdc.io.j2me.btgoep.*;
    import com.sun.cdc.io.j2me.tcpobex.*;
    import com.ibm.oti.connection.btspp.*;
    import com.ibm.oti.connection.btl2cap.*;
    import com.ibm.oti.connection.btgoep.*;
    import com.ibm.oti.connection.tcpobex.*;
    import javax.bluetooth.*;
    import javax.obex.*;
    import javax.microedition.io.*;
    

    I don`t know how to deal with this problem, so I am now got stuck :(

  • edited February 2018

    @TfGuy44 Very nice! However, the faded-out lines leave a grayish trace, see here: http://tinybrain.de/1013743

    Any way to fix this?

    Here's the actual program: http://tinybrain.de/1013742

  • The fix for that is to draw everything properly. To do that you need to track all the data properly. Like this.

    int x = 0;
    float py;
    ArrayList<PVector> ar = new ArrayList();
    
    void setup(){
      size(600,200);
      py = height/2;
    }
    
    void draw(){
      background(0);
      x++;
      x%=width;
      float fx = py + random(-20,20);
      fx = constrain(fx,0,height);
      ar.add(new PVector(x,fx));
      if( ar.size() > 50 ) ar.remove(0);
      for( int i = 0; i<ar.size()-1; i++){
        stroke(100,255,100,map(i,0,ar.size()-1,0,255));
        if( ar.get(i).x < ar.get(i+1).x) 
        line(ar.get(i).x,ar.get(i).y, ar.get(i+1).x,ar.get(i+1).y);
      }
      py = fx;
    }
    
Sign In or Register to comment.