WorldFamousElectronics / PulseSensor_Heart-Rate-Variabilty

Processing Sketches for exploring Heart Rate Variability (HRV)
34 stars 15 forks source link

Added Biofeedback Sketch #8

Closed biomurph closed 6 years ago

biomurph commented 6 years ago

Building off the Frequency Domain sketch. This HRV Biofeedback sketch provides a breathing prompt, graph of BPM over time, and graph of HRV, the difference in the highest and lowest BPM.

georod99 commented 6 years ago

Here is a comparison: Figure 1 is for a 74 year old male. HRV is very low. Figure 2 is for a 20 year old male, breathing normally. Figure 3 is the same guy breathing at 6 breaths per minute. Note how HRV goes up, from 4 to 22. hrv-1 hrv-2 hrv-3

biomurph commented 6 years ago

Hey @georod99 that's really cool! Something is wacky with the font sizes on your screenshots. Did you change that in the sketch?

georod99 commented 6 years ago

No, since the beginning I was wondering exactly that, how you did not use a smaller font.

On Mon, Jul 16, 2018 at 3:14 PM, Joel Murphy notifications@github.com wrote:

Hey @georod99 https://github.com/georod99 that's really cool! Something is wacky with the font sizes on your screenshots. Did you change that in the sketch?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405350367, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vqjwCv4vnxfnG6ey-xrFAHqS_mg2yks5uHOX5gaJpZM4Uoc2D .

-- George Rod 954-294-0700

biomurph commented 6 years ago

LOL Well, I do use a smaller font! I will have to check and see what the issue is in the code/data...

georod99 commented 6 years ago

Thanks.

On Mon, Jul 16, 2018 at 3:44 PM, Joel Murphy notifications@github.com wrote:

LOL Well, I do use a smaller font! I will have to check and see what the issue is in the code/data...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405358794, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vqrlmn0SQvFUbu6d-MbMDeirfE_qLks5uHO0FgaJpZM4Uoc2D .

-- George Rod 954-294-0700

georod99 commented 6 years ago

You have been very kind to me, but if you could take a few minutes and explain to me what the parameters (or variables) mean in the lines: 23 and 24: how can I change the font size. 92 font = loadFont("Arial-BoldMT-18.vlw"); 93 textFont(font); 196 text("BPM: "+int(BPM), pulseX,50); 265 text(i, 40,map(i,30,150,615,75)); 272 ine(75,map(i,30,150,614,74),85,map(i,30,150,614,74)); and in general, the lines that contain "text", so I can customize the graphic. Thanks.

On Mon, Jul 16, 2018 at 5:49 PM, George Rod georod99@gmail.com wrote:

Thanks.

On Mon, Jul 16, 2018 at 3:44 PM, Joel Murphy notifications@github.com wrote:

LOL Well, I do use a smaller font! I will have to check and see what the issue is in the code/data...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405358794, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vqrlmn0SQvFUbu6d-MbMDeirfE_qLks5uHO0FgaJpZM4Uoc2D .

-- George Rod 954-294-0700

-- George Rod 954-294-0700

biomurph commented 6 years ago

Hi George,

I'm just running the code on my machine, and I get the font size shown below. In the github, the font that is loaded into the data file is Arial-BoldMT-36.vlw

If you want to change the font, in Processing, go to Tools > Create Font... to pick a different size. This process will load the font into the data folder so the sketch can use it. I'm going to download the latest Processing to see if that makes any difference at all.

Also, in the sketch, you can change the font size with the line

textFont(font,12);

where the second parameter is the font size you want to use. It's always better to load a larger font and then adjust to smaller font when you want, and not the other way around.

Try re-downloading the code?

Joel


Making the world safe for robots
www.pulsesensor.com
www.openbci.com

On Tue, Jul 17, 2018 at 8:50 AM, George Rod <notifications@github.com>
wrote:

> You have been very kind to me, but if you could take a few minutes and
> explain to me what the parameters (or variables) mean in the lines:
> 23 and 24: how can I change the font size.
> 92 font = loadFont("Arial-BoldMT-18.vlw");
> 93 textFont(font);
> 196 text("BPM: "+int(BPM), pulseX,50);
> 265 text(i, 40,map(i,30,150,615,75));
> 272 ine(75,map(i,30,150,614,74),85,map(i,30,150,614,74));
> and in general, the lines that contain "text", so I can customize the
> graphic.
> Thanks.
>
>
>
>
> On Mon, Jul 16, 2018 at 5:49 PM, George Rod <georod99@gmail.com> wrote:
>
> > Thanks.
> >
> > On Mon, Jul 16, 2018 at 3:44 PM, Joel Murphy <notifications@github.com>
> > wrote:
> >
> >> LOL
> >> Well, I do use a smaller font! I will have to check and see what the
> >> issue is in the code/data...
> >>
> >> —
> >> You are receiving this because you were mentioned.
> >> Reply to this email directly, view it on GitHub
> >> <https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-
> Variabilty/pull/8#issuecomment-405358794>,
> >> or mute the thread
> >> <https://github.com/notifications/unsubscribe-auth/Aj2vqrlmn0SQvFUbu6d-
> MbMDeirfE_qLks5uHO0FgaJpZM4Uoc2D>
> >> .
> >>
> >
> >
> >
> > --
> > George Rod
> > 954-294-0700
> >
>
>
>
> --
> George Rod
> 954-294-0700
>
> —
> You are receiving this because you modified the open/close state.
> Reply to this email directly, view it on GitHub
> <https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405570274>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AF_jGUnhJxuIBi48HXubz-1Ut8hihz76ks5uHd19gaJpZM4Uoc2D>
> .
>
biomurph commented 6 years ago

OK, I ran the sketch from Processing 3.3.7 and I don't see any font size issues. I'm on a Macbook Pro. What system are you using? What version of Processing are you using?

Best,

Joel


Making the world safe for robots
www.pulsesensor.com
www.openbci.com

On Tue, Jul 17, 2018 at 10:08 AM, Joel Murphy <biomurph@gmail.com> wrote:

> Hi George,
>
> I'm just running the code on my machine, and I get the font size shown
> below.
> In the github, the font that is loaded into the data file is
> Arial-BoldMT-36.vlw
>
> If you want to change the font, in Processing, go to Tools > Create
> Font... to pick a different size. This process will load the font into the
> data folder so the sketch can use it. I'm going to download the latest
> Processing to see if that makes any difference at all.
>
> Also, in the sketch, you can change the font size with the line
>
> textFont(font,12);
>
>
> where the second parameter is the font size you want to use. It's always
> better to load a larger font and then adjust to smaller font when you want,
> and not the other way around.
>
> Try re-downloading the code?
>
> Joel
> ~~~
> Making the world safe for robots
> www.pulsesensor.com
> www.openbci.com
>
> On Tue, Jul 17, 2018 at 8:50 AM, George Rod <notifications@github.com>
> wrote:
>
>> You have been very kind to me, but if you could take a few minutes and
>> explain to me what the parameters (or variables) mean in the lines:
>> 23 and 24: how can I change the font size.
>> 92 font = loadFont("Arial-BoldMT-18.vlw");
>> 93 textFont(font);
>> 196 text("BPM: "+int(BPM), pulseX,50);
>> 265 text(i, 40,map(i,30,150,615,75));
>> 272 ine(75,map(i,30,150,614,74),85,map(i,30,150,614,74));
>> and in general, the lines that contain "text", so I can customize the
>> graphic.
>> Thanks.
>>
>>
>>
>>
>> On Mon, Jul 16, 2018 at 5:49 PM, George Rod <georod99@gmail.com> wrote:
>>
>> > Thanks.
>> >
>> > On Mon, Jul 16, 2018 at 3:44 PM, Joel Murphy <notifications@github.com>
>> > wrote:
>> >
>> >> LOL
>> >> Well, I do use a smaller font! I will have to check and see what the
>> >> issue is in the code/data...
>> >>
>> >> —
>> >> You are receiving this because you were mentioned.
>> >> Reply to this email directly, view it on GitHub
>> >> <https://github.com/WorldFamousElectronics/PulseSensor_
>> Heart-Rate-Variabilty/pull/8#issuecomment-405358794>,
>> >> or mute the thread
>> >> <https://github.com/notifications/unsubscribe-auth/
>> Aj2vqrlmn0SQvFUbu6d-MbMDeirfE_qLks5uHO0FgaJpZM4Uoc2D>
>> >> .
>> >>
>> >
>> >
>> >
>> > --
>> > George Rod
>> > 954-294-0700
>> >
>>
>>
>>
>> --
>> George Rod
>> 954-294-0700
>>
>> —
>> You are receiving this because you modified the open/close state.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405570274>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AF_jGUnhJxuIBi48HXubz-1Ut8hihz76ks5uHd19gaJpZM4Uoc2D>
>> .
>>
>
>
georod99 commented 6 years ago

Version 3.3.7, Windows. I have made several changes and the size of the font does not change.

On Tue, Jul 17, 2018 at 10:15 AM, Joel Murphy notifications@github.com wrote:

OK, I ran the sketch from Processing 3.3.7 and I don't see any font size issues. I'm on a Macbook Pro. What system are you using? What version of Processing are you using?

Best,

Joel


Making the world safe for robots
www.pulsesensor.com
www.openbci.com

On Tue, Jul 17, 2018 at 10:08 AM, Joel Murphy <biomurph@gmail.com> wrote:

> Hi George,
>
> I'm just running the code on my machine, and I get the font size shown
> below.
> In the github, the font that is loaded into the data file is
> Arial-BoldMT-36.vlw
>
> If you want to change the font, in Processing, go to Tools > Create
> Font... to pick a different size. This process will load the font into
the
> data folder so the sketch can use it. I'm going to download the latest
> Processing to see if that makes any difference at all.
>
> Also, in the sketch, you can change the font size with the line
>
> textFont(font,12);
>
>
> where the second parameter is the font size you want to use. It's always
> better to load a larger font and then adjust to smaller font when you
want,
> and not the other way around.
>
> Try re-downloading the code?
>
> Joel
> ~~~
> Making the world safe for robots
> www.pulsesensor.com
> www.openbci.com
>
> On Tue, Jul 17, 2018 at 8:50 AM, George Rod <notifications@github.com>
> wrote:
>
>> You have been very kind to me, but if you could take a few minutes and
>> explain to me what the parameters (or variables) mean in the lines:
>> 23 and 24: how can I change the font size.
>> 92 font = loadFont("Arial-BoldMT-18.vlw");
>> 93 textFont(font);
>> 196 text("BPM: "+int(BPM), pulseX,50);
>> 265 text(i, 40,map(i,30,150,615,75));
>> 272 ine(75,map(i,30,150,614,74),85,map(i,30,150,614,74));
>> and in general, the lines that contain "text", so I can customize the
>> graphic.
>> Thanks.
>>
>>
>>
>>
>> On Mon, Jul 16, 2018 at 5:49 PM, George Rod <georod99@gmail.com> wrote:
>>
>> > Thanks.
>> >
>> > On Mon, Jul 16, 2018 at 3:44 PM, Joel Murphy <
notifications@github.com>
>> > wrote:
>> >
>> >> LOL
>> >> Well, I do use a smaller font! I will have to check and see what the
>> >> issue is in the code/data...
>> >>
>> >> —
>> >> You are receiving this because you were mentioned.
>> >> Reply to this email directly, view it on GitHub
>> >> <https://github.com/WorldFamousElectronics/PulseSensor_
>> Heart-Rate-Variabilty/pull/8#issuecomment-405358794>,
>> >> or mute the thread
>> >> <https://github.com/notifications/unsubscribe-auth/
>> Aj2vqrlmn0SQvFUbu6d-MbMDeirfE_qLks5uHO0FgaJpZM4Uoc2D>
>> >> .
>> >>
>> >
>> >
>> >
>> > --
>> > George Rod
>> > 954-294-0700
>> >
>>
>>
>>
>> --
>> George Rod
>> 954-294-0700
>>
>> —
>> You are receiving this because you modified the open/close state.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-
Variabilty/pull/8#issuecomment-405570274>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-
auth/AF_jGUnhJxuIBi48HXubz-1Ut8hihz76ks5uHd19gaJpZM4Uoc2D>
>> .
>>
>
>

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405597226>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Aj2vqjvaVwCG7jSs2SHW9VI0OP2MnGlzks5uHfFxgaJpZM4Uoc2D>
.

-- George Rod 954-294-0700

biomurph commented 6 years ago

What Windows version are you using?

I will do my best to replicate it. In the mean time, try loading a smaller font into the sketch and try that?

georod99 commented 6 years ago

Win 10 Pro. I have tried several options and have not been able to change the size. Do you mind if I ask for help in the forum? Maybe somebody with more time will help me

On Tue, Jul 17, 2018 at 10:36 AM, Joel Murphy notifications@github.com wrote:

What Windows OS are you using?

I will do my best to replicate it. In the mean time, try loading a smaller font into the sketch and try that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405604974, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vql1HPycvMHyajgPNOtWJ1pOMwuFjks5uHfZ9gaJpZM4Uoc2D .

-- George Rod 954-294-0700

georod99 commented 6 years ago

This is what I have achieved: (Pic 1 is your sketch. Pic 4 my modifications):

  1. Make shorter the titles.
  2. Lower the title HRV. Nothing else.

On Tue, Jul 17, 2018 at 11:34 AM, George Rod georod99@gmail.com wrote:

Win 10 Pro. I have tried several options and have not been able to change the size. Do you mind if I ask for help in the forum? Maybe somebody with more time will help me

On Tue, Jul 17, 2018 at 10:36 AM, Joel Murphy notifications@github.com wrote:

What Windows OS are you using?

I will do my best to replicate it. In the mean time, try loading a smaller font into the sketch and try that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405604974, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vql1HPycvMHyajgPNOtWJ1pOMwuFjks5uHfZ9gaJpZM4Uoc2D .

-- George Rod 954-294-0700

-- George Rod 954-294-0700

georod99 commented 6 years ago

Correction: line 165 says: //P is the trough Must say: //P is the peak.

On Tue, Jul 17, 2018 at 11:42 AM, George Rod georod99@gmail.com wrote:

This is what I have achieved: (Pic 1 is your sketch. Pic 4 my modifications):

  1. Make shorter the titles.
  2. Lower the title HRV. Nothing else.

On Tue, Jul 17, 2018 at 11:34 AM, George Rod georod99@gmail.com wrote:

Win 10 Pro. I have tried several options and have not been able to change the size. Do you mind if I ask for help in the forum? Maybe somebody with more time will help me

On Tue, Jul 17, 2018 at 10:36 AM, Joel Murphy notifications@github.com wrote:

What Windows OS are you using?

I will do my best to replicate it. In the mean time, try loading a smaller font into the sketch and try that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405604974, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vql1HPycvMHyajgPNOtWJ1pOMwuFjks5uHfZ9gaJpZM4Uoc2D .

-- George Rod 954-294-0700

-- George Rod 954-294-0700

-- George Rod 954-294-0700

georod99 commented 6 years ago

Now much better. I have learned a lot.

On Tue, Jul 17, 2018 at 1:42 PM, George Rod georod99@gmail.com wrote:

Correction: line 165 says: //P is the trough Must say: //P is the peak.

On Tue, Jul 17, 2018 at 11:42 AM, George Rod georod99@gmail.com wrote:

This is what I have achieved: (Pic 1 is your sketch. Pic 4 my modifications):

  1. Make shorter the titles.
  2. Lower the title HRV. Nothing else.

On Tue, Jul 17, 2018 at 11:34 AM, George Rod georod99@gmail.com wrote:

Win 10 Pro. I have tried several options and have not been able to change the size. Do you mind if I ask for help in the forum? Maybe somebody with more time will help me

On Tue, Jul 17, 2018 at 10:36 AM, Joel Murphy notifications@github.com wrote:

What Windows OS are you using?

I will do my best to replicate it. In the mean time, try loading a smaller font into the sketch and try that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405604974, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vql1HPycvMHyajgPNOtWJ1pOMwuFjks5uHfZ9gaJpZM4Uoc2D .

-- George Rod 954-294-0700

-- George Rod 954-294-0700

-- George Rod 954-294-0700

-- George Rod 954-294-0700

biomurph commented 6 years ago

Please send me the code you are working with. Either link here to yourrepo, or email me directly

georod99 commented 6 years ago

/* PulseSensor Amped HRV Biofeedback v1.1.0

This is an HRV visualizer code for Pulse Sensor. www.pulsesensor.com Use this with PulseSensor_BPM Arduino code and the Pulse Sensor Amped hardware. This code will track Heart Rate Variabilty by tracing the changes in BPM values The code looks for a change in the trend of BPM values, up or down, and calculates the HRV using the last peak or trough. HRV, measured in the difference in BPM is also graphed. There is also a breathing prompt that helps you breath at a specific breaths per minute.

key press commands included in this version: press 'S' to take a picture of the data window. (JPG image saved in Sketch folder) press 'C' to refresh the graph press 'W' to show or hide the IBI waveform (as seen in Time Domain example) Created by Joel Murphy, Spring 2018 Updated Summer 2013 for efficiency and readability This code released into the public domain without promises that it will work for your intended application. Or that it will work at all, for that matter. I hereby disclaim. */

import processing.serial.*; // serial library lets us talk to Arduino PFont font; PFont portsFont; Serial port;

// float freq; // used to hold derived HRV frequency float runningTotal = 1; // can't initialize as 0 because math float mean; // useful for VLF derivation........... int IBI; // length of time between heartbeats in milliseconds (sent from Arduino, updated in serialEvent) int P; // peak value of IBI waveform int T; // trough value of IBI waveform float HRV; float BPM; float lowBPM; float highBPM; int amp; // amplitude of IBI waveform int lastIBI; // value of the last IBI sent from Arduino int[] PPG; // array of raw Pulse Sensor datapoints int[] beatTime; // array of IBI values to graph on Y axis int windowWidth = 550; // width of IBI data window int windowHeight = 550; // height of IBI data window int pulseX = 715; // left edge of rectangle for pulse window int ibiX = 350; // left edge of rectangle for IBI window

int breathCenterX = 995; int breathCenterY; float breathXmax = 315.0; float breathXmin = 35.0; float breathYmax = 225.0; float breathYmin = 25.0; float breathX = breathXmin; float breathY = breathYmin; float breathXstep = (breathXmax-breathXmin)/180.0; float breathYstep = (breathYmax-breathYmin)/180.0; float blue = 17.0; float red = 180.0; //197; float fadeValue = blue; float breathCycle = 10.0;

float HRVdelta[]; boolean newDelta = false; int deltaGraphHeight = 256; int deltaGraphY;

// boolean fadeUp = true; float angle; float angleStep; int counter = 0;

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

String direction = "none"; // used in verbose feedback

// initializing flags boolean pulse = false; // made true in serialEvent when new IBI value sent from arduino boolean first = true; // try not to screw up if it's the first time boolean showWave = true; // show or not show the IBI waveform on screen boolean goingUp; // used to keep track of direction of IBI wave

// SERIAL PORT STUFF TO HELP YOU FIND THE CORRECT SERIAL PORT String serialPort; String[] serialPorts = new String[Serial.list().length]; boolean serialPortFound = false; Radio[] button = new Radio[Serial.list().length*2]; int numPorts = serialPorts.length; boolean refreshPorts = false;

void setup() { size(1300,650); // stage size frameRate(60); // frame rate font = loadFont("Arial-BoldMT-10.vlw"); textFont(font,10); //It was ...font). Changes nothing. <- <- <- textAlign(CENTER); rectMode(CENTER); ellipseMode(CENTER); breathCenterY = height/4 + height/16; deltaGraphY = (height/4)*3; beatTime = new int[windowWidth]; // the beatTime array holds IBI graph data PPG = new int[150]; // PPG array that that prints heartbeat waveform HRVdelta = new float[32]; for(int i=0; i<32; i++){ HRVdelta[i]= 1.0; } // set data traces to default resetDataTraces();

background(0); drawDataWindows();

// GO FIND THE ARDUINO fill(eggshell); text("Select Your Serial Port",350,50); listAvailablePorts();

// println(breathY);

} // END OF SETUP

void draw(){ if(serialPortFound){ // ONLY RUN THE VISUALIZER AFTER THE PORT IS CONNECTED background(0); // DRAW THE BACKGROUND ELEMENTS AND TEXT noStroke(); drawDataWindows(); writeLabels();

// UPDATE THE IBI ARRAY IF THERE HAS NEW DATA // when we get heartbeat data, try to find the latest HRV freq if it is available if (pulse == true){ // check for new data from arduino pulse = false; // drop the pulse flag, it gets set in serialEvent

if (IBI < lastIBI && goingUp == true){  // check for IBI wave peak
  goingUp = false;                 // now changing direction from up to

down direction = "down"; // used in verbose feedback runningTotal = 0; // reset this for next time amp = P-T; // measure the size of the IBI 1/2 wave that just happend mean = P-amp/2; // the average is useful for VLF derivation....... newDelta = true; T = lastIBI; // set the last IBI as the most recent trough cause we're going down lowBPM = 60000.0/T; HRV = highBPM - lowBPM; }

if (IBI > lastIBI && goingUp == false){  // check for IBI wave trough
  goingUp = true;                  // now changing direction from down

to up direction = "up"; // used in verbose feedback runningTotal = 0; // reset this for next time amp = P-T; // measure the size of the IBI 1/2 wave that just happend mean = P-amp/2; // the average is useful for VLF derivation....... newDelta = true; P = lastIBI; // set the last IBI as the most recent peak cause we're going up highBPM = 60000.0/P; HRV = highBPM - lowBPM; }

if (IBI < T){                        // T is the trough
  T = IBI;                           // keep track of lowest point in

pulse wave } if (IBI > P){ // P is the peak <- <- <- P = IBI; // keep track of highest point in pulse wave } lastIBI = IBI; // keep track to measure the trend runningTotal += IBI; // how long since IBI wave changed direction?

// UPDATE IBI ARRAY for (int i=0; i<beatTime.length-3; i+=3){ // shift the data in beatTime array 3 pixels left beatTime[i] = beatTime[i+3]; // shift the data points through the array } BPM = 60000.0/IBI; BPM = constrain(BPM,20,150); // don't let the new IBI value escape the data window! beatTime[beatTime.length-1] = int(BPM); // update the current IBI

}

// DRAW THE BPM PLOT if(showWave){ stroke(0,0,255); // IBI graph in blue noFill(); beginShape(); // use beginShape to draw the graph for (int i=0; i<=beatTime.length-1; i+=3){ // set a datapoint every three pixels float y = map(beatTime[i],30,150,615,65); // invert and scale data so it looks normal vertex(i+75,y); // set the vertex coordinates } endShape(); // connect the vertices noStroke(); fill(250,0,0); // draw the current data point as a red dot for fun float y = map(beatTime[beatTime.length-1],30,150,615,65); // invert and scale data so it looks normal ellipse(windowWidth+75,y,6,6); // draw latest data point as a red dot fill(255,253,248); // eggshell white text("B/M: "+int(BPM), pulseX,50); //It was BPM, 50 sets the vert pos // print latest IBI value above pulse wave window noFill();

// GRAPH THE PULSE SENSOR DATA stroke(250,0,0); // use red for the pulse wave beginShape(); // beginShape is a nice way to draw graphs! for (int i=1; i<PPG.length-1; i++){ // scroll through the PPG array float x = 640+i; //width-160+i; y = PPG[i]; vertex(x,y); // set the vertex coordinates } endShape(); }

// GRAPH THE HRV DELTA noStroke(); fill(128); if(newDelta){ for(int i=HRVdelta.length-1; i>0; i--){ HRVdelta[i] = HRVdelta[i-1]; } HRVdelta[0] = HRV; newDelta = false; } int deltaCounter = 0; for(int i=0; i<deltaGraphHeight; i+=8){ stroke(0);

rect(breathCenterX,(deltaGraphY+deltaGraphHeight/2)-i-4,HRVdelta[deltaCounter]*4,8); noStroke(); deltaCounter++; }

} else { // SCAN BUTTONS TO FIND THE SERIAL PORT

autoScanPorts();

if(refreshPorts){
  refreshPorts = false;
  drawDataWindows();
  listAvailablePorts();
}

for(int i=0; i<numPorts+1; i++){
  button[i].overRadio(mouseX,mouseY);
  button[i].displayRadio();
}

} // DRAW THE BREATH PROMPT angle = radians(((millis()/1000.0)/breathCycle)360); breathX = 35 + (sin(angle) breathXmax/2) + breathXmax/2; breathY = 25 + (sin(angle) breathYmax/2) + breathYmax/2; fadeValue = blue + (sin(angle) red/2) + red/2; noStroke(); fill(fadeValue,105,206); ellipse(breathCenterX,breathCenterY,breathX,breathY);

} //end of draw loop

void drawDataWindows(){ noStroke(); fill(eggshell); // eggshell white rect(ibiX,height/2+15,windowWidth,windowHeight); // draw IBI data window rect(pulseX,(height/2)+15,150,550); // draw the pulse waveform window // ellipse(breathCenterX,breathCenterY,breathXmax,breathYmax); //350,250); // breathing prompt rect(breathCenterX,deltaGraphY,380,deltaGraphHeight); // amplitiude graph

fill(200); // print scale values in grey for (int i=30; i<=150; i+=30){ // print Y axis scale values text(i, 40,map(i,30,150,615,75)); } for (int i=30; i<=180; i+=30){ // print X axis scale values text(i, map(i,180,0,75,windowWidth+75),height-10); } stroke(200,10,250); // draw Y gridlines in purple, for fun for (int i=30; i<=150; i+=30){ // draw Y axis lines with 100mS resolution line(75,map(i,30,150,614,74),85,map(i,30,150,614,74)); //grid the Y axis } for (int i=0; i<=180; i+=10){ // draw X axis lines with 10 beat resolution line(map(i,0,180,625,75),height-35,map(i,0,180,625,75),height-45); // grid the X axis } noStroke(); }

void writeLabels(){ fill(eggshell); text("PulSen Biofeedback",ibiX,40); // title <- <- <- // fill(200); textFont(font,24); //I added this line <- <- <- <- text("BpM", 35,150); //It was 40. Shifted a little to the left. // Y axis label <- // text("mS",40,230); text("Beats", 75+windowWidth-25, height-10); // X axis advances 3 pixels with every beat text("Breaths/Min " + 60/breathCycle, breathCenterX, 40); String hrv = nf(HRV,2,1); text(" HRV " + hrv, breathCenterX,height-10); //10 is the vertical position <- <- <- }

void listAvailablePorts(){ println(Serial.list()); // print a list of available serial ports to the console serialPorts = Serial.list(); fill(0); textFont(font,16); textAlign(LEFT); // set a counter to list the ports backwards int xPos = 150; int yPos = 0; for(int i=numPorts-1; i>=0; i--){ button[i] = new Radio(xPos, 130+(yPos20),12,color(180),color(80),color(255),i,button); text(serialPorts[i],xPos+15, 135+(yPos20)); yPos++; if(yPos > height-30){ yPos = 0; xPos+=100; } } int p = numPorts; fill(233,0,0); button[p] = new Radio(xPos, 130+(yPos20),12,color(180),color(80),color(255),p,button); text("Refresh Serial Ports List",xPos+15, 135+(yPos20));

textFont(font); textAlign(CENTER); }

void autoScanPorts(){ if(Serial.list().length != numPorts){ if(Serial.list().length > numPorts){ println("New Ports Opened!"); int diff = Serial.list().length - numPorts; // was serialPorts.length serialPorts = expand(serialPorts,diff); numPorts = Serial.list().length; }else if(Serial.list().length < numPorts){ println("Some Ports Closed!"); numPorts = Serial.list().length; } refreshPorts = true; return; } }

void resetDataTraces(){ // reset IBI trace for(int i=0; i<beatTime.length; i++){ beatTime[i] = 90; // initialize the BPM graph with data line at midpoint } // reset PPG trace for (int i=0; i<=PPG.length-1; i++){ PPG[i] = height/2+15; // initialize PPG widow with data line at midpoint } // reset HRV graph for(int i=0; i<HRVdelta.length-1; i++){ HRVdelta[i] = 1.0; } }

On Tue, Jul 17, 2018 at 2:36 PM, Joel Murphy notifications@github.com wrote:

Please send me the code you are working with. Either link here to yourrepo, or email me directly

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WorldFamousElectronics/PulseSensor_Heart-Rate-Variabilty/pull/8#issuecomment-405684475, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj2vql4qWPbSsbtFV9Ncdvtmh-Q9xvnAks5uHi69gaJpZM4Uoc2D .

-- George Rod 954-294-0700

georod99 commented 6 years ago

I'm new to Arduino and Processing. I have studied the parts that I need, but I will never study the whole language. If somebody wants to explain (comment) the following lines (in the former sketch): 23 and 24: how can I change the font size. 92 font = loadFont("Arial-BoldMT-18.vlw"); 93 textFont(font); 196 text("BPM: "+int(BPM), pulseX,50); 265 text(i, 40,map(i,30,150,615,75)); 272 ine(75,map(i,30,150,614,74),85,map(i,30,150,614,74)); and in general, the lines that contain "text", so I can customize the graphic. I will appreciate the help.