WorldFamousElectronics / PulseSensor_Amped_Processing_Visualizer

Processing code for pulse wave visualization
MIT License
90 stars 102 forks source link

Not displaying BPM and IBI #27

Open VeiTheOne opened 1 year ago

VeiTheOne commented 1 year ago

It says in the code that it's TODO for next project. Has anyone done this second project?

Plus, how can I have it show the BPM and IBI? I am using the Phidget VINT hub if that's a factor.

biomurph commented 1 year ago

@VeiTheOne Please provide more information to help troubleshoot your question. What exactly in the code is not functioning as expected? What other code are you using with the code in this repo? What hardware board are you using? Etc.?

VeiTheOne commented 1 year ago

I am using Phidget's VINT Hub as the board. The Graph visualizer works fine, and I have been trying to get it to display the BPM. The code works, there's just nothing to get the BPM. And I'm using the code listed here.

Here's my current code, which is unchanged.

import com.phidget22.*;

VoltageRatioInput heartSensor;
Scrollbar scaleBar;

PFont font;
PFont portsFont;

//Holds heartbeat data
float [] pulses;      
float [] scaledPulses;   

float zoom;
color eggshell = color(255, 253, 248);

//Sizing of windows
int PulseWindowWidth = 490;
int PulseWindowHeight = 512;
int BPMWindowWidth = 180;
int BPMWindowHeight = 340;

void setup() {
  size(700, 600);
  frameRate(100);
  font = loadFont("Arial-BoldMT-24.vlw");
  textFont(font);
  textAlign(CENTER);
  rectMode(CENTER);
  ellipseMode(CENTER);

  //Create scroll bar for zooming
  scaleBar = new Scrollbar (400, 575, 180, 12, 0.0, 1.0);

  pulses = new float[PulseWindowWidth];
  scaledPulses = new float[PulseWindowWidth];

  //Default zoom
  zoom = 0.75;                               

  //Drawing
  resetDataTraces();
  background(0);
  drawDataWindows();
  drawHeart();
  fill(eggshell);

  //Phidgets initialize 
  try {
    //Create
    heartSensor = new VoltageRatioInput();
    //Address
    heartSensor.setHubPort(0);
    heartSensor.setIsHubPortDevice(true);
    //Open
    heartSensor.open(1000);
    //Set data interval to minimum | This will increase the data rate from the sensor, and make your graph more responsive
    heartSensor.setDataInterval(heartSensor.getMinDataInterval());
  }
  catch(Exception e) {
    e.printStackTrace();
  }
}

void drawDataWindows() {
  noStroke();
  fill(eggshell);
  rect(255, height/2, PulseWindowWidth, PulseWindowHeight);
  rect(600, 385, BPMWindowWidth, BPMWindowHeight);  
}

void drawHeart() {
  fill(250, 0, 0);
  stroke(250, 0, 0);
  smooth();
  bezier(width-100, 50, width-20, -20, width, 140, width-100, 150);
  bezier(width-100, 50, width-190, -20, width-200, 140, width-100, 150);
  strokeWeight(1);
}

void drawPulseWaveform() {
  float pulseVal = 0;
  try {
    pulseVal = (float)heartSensor.getVoltageRatio();
  }
  catch(Exception e) {
    e.printStackTrace();
  }

  pulses[pulses.length-1] = ((pulseVal - 0.5)* 512);   //pulseVal is between 0 and 1. Center and scale up to fit window.
  zoom = scaleBar.getPos();  
  for (int i = 0; i < pulses.length-1; i++) {
      pulses[i] = pulses[i+1];                         // shifting all raw datapoints one pixel left
      scaledPulses[i] = pulses[i] * -zoom + height/2;  // adjust the raw data to the selected scale
  }
  stroke(250, 0, 0);                               
  noFill();
  beginShape();                                  
  for (int x = 1; x < scaledPulses.length-1; x++) {
    vertex(x+10, scaledPulses[x]);                    //draw a line connecting the data points
  }
  endShape();
}

void draw() {
  background(0);
  noStroke();
  drawDataWindows();
  drawPulseWaveform();
  drawHeart();

  fill(eggshell);
  text("Pulse Sensor Amped Visualizer - Phidgets", 245, 30);
  text("IBI",600,585); // TODO for next project
  text("BPM",600,200); // TODO for next project
  text("Pulse Window Scale " + nf(zoom, 1, 2), 150, 585);

  //Manage scroll bar
  scaleBar.update (mouseX, mouseY);
  scaleBar.display();
}

void resetDataTraces() {
  for (int i=0; i<pulses.length; i++) {
    pulses[i] = height/2;
  }
}
biomurph commented 1 year ago

@VeiTheOne That is not the code that is in this repo. I don't have experience with Phidget.

You may need to ask the source of that code about your problems.

VeiTheOne commented 1 year ago
Well, I’m just trying to get a bpm calculation working for an upcoming competition. Thanks tho. Sent from Mail for Windows From: Joel MurphySent: Friday, March 24, 2023 2:50 PMTo: WorldFamousElectronics/PulseSensor_Amped_Processing_VisualizerCc: Vei The One; MentionSubject: Re: [WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer] Not displaying BPM and IBI (Issue ***@***.*** is not the code that is in this repo.I don't have experience with Phidget.You may need to ask the source of that code about your problems.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***> Virus-free.www.avast.com
VeiTheOne commented 1 year ago

Ok, Email looks like shit.

Well, I’m just trying to get a bpm calculation working for an upcoming competition. Thanks tho.

VeiTheOne commented 1 year ago

You may need to ask the source of that code about your problems.

And they don't have an issues page.

biomurph commented 1 year ago

You may need to ask the source of that code about your problems.

And they don't have an issues page.

Dang. Is there any community around it? A forum or anything?

Our PulseSensor Arduino library does all the work to find the heartbeat in the signal and derive BPM and IBI. What are you using for heartbeat detection? What hardware? Or are you simulating?

VeiTheOne commented 1 year ago

We got 3 pulse sensors from Phidgets. And I can't seem to find it. We were able to display the raw voltage, but none of us have yet to figure out how to get it to display the BPM. What's worse is that they said on the Phidgets page says "Stay tuned for part two." of the project. There has never been updates since, and that's where I'm stuck at, sadly.

I'm using a VINT HUB0001_0 from Phidgets as the "board".

biomurph commented 1 year ago

Interesting. Looks like a lot of engineering for some simple interfacing.

It would take some ramping up for us to make PulseSensor compatible with Phidgets. Give me a bit of time to investigate how their tech works.