WorldFamousElectronics / PulseSensor_Pulse_Transit_Time

measures the time between beats on two Pulse Sensors
MIT License
3 stars 0 forks source link

Signals oscillate in diferent Thresholds #1

Open VladiLuzJr opened 3 years ago

VladiLuzJr commented 3 years ago

Signals oscillate in diferent Thresholds

Recently I have been engaged in my Conclusion Project of an technician course in electronics...

When trying to use two pulse sensors at once, in order to find PTT. I have received high variance values, while using Processing...

The sensor in Analog pin0 is located in the beginning of my hand thumb and the sensor in Analog pin1 is located at the tip of the same thumb. Is it possible that the two IR LEDs nearby can add noise to the signal, therefore creating this difference in Threshold?

Using windows 10 , Arduino UNO and PulseSensor Playground 1.5.1. I emphasize that the pulse graphics are tiny, even if I try "goldilocks pressure" : (

Is it possible that once both sensors are being powerd by de Arduino built-in 5v supply, they are acting like a current divider?

I have reason to believe that this errors may happen due to Arduino Interupts malfunction... Do I need to install some especific version of the Arduino IDE to use this define?

Once both signals oscillate in different levels, I think the PTT software cannot use the same Threshold for the pulse sensors...

In the pictures , the correspondig Processing GUI and Serial Plotter prints:

SerialPlotter_with_Interupts=False: SerialPlotter_with_Interupts=False

SerialPlotter_with_Interupts=True: SerialPlotter_with_Interupts=True

ProcessingGUI_with_Interupts=False: ProcessingGUI_withInterrupt=false

ProcessingGUI_with_Interupts=True: ProcessingGUI_with_Interupts=True

The .ino code is written as follows:

/* Arduino Sketch to detect pulses from two PulseSensors and measures the time between! This can be used to derive Pulse Transit Time (PTT)

Here is a link to the PTT tutorial https://pulsesensor.com/pages/pulse-transit-time

Copyright World Famous Electronics LLC - see LICENSE Contributors: Joel Murphy, https://pulsesensor.com Yury Gitman, https://pulsesensor.com Bradford Needham, @bneedhamia, https://bluepapertech.com

Licensed under the MIT License, a copy of which should have been included with this software.

This software is not intended for medical use. */

/* Every Sketch that uses the PulseSensor Playground must define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h. Here, #define USE_ARDUINO_INTERRUPTS false tells the library to not use interrupts to read data from the PulseSensor.

If you want to use interrupts, simply change the line below to read:

define USE_ARDUINO_INTERRUPTS true

Set US_PS_INTERRUPTS to false if either 1) Your Arduino platform's interrupts aren't yet supported by PulseSensor Playground, or 2) You don't wish to use interrupts because of the side effects.

NOTE: if US_PS_INTERRUPTS is false, your Sketch must call pulse.sawNewSample() at least once every 2 milliseconds to accurately read the PulseSensor signal. */

define USE_ARDUINO_INTERRUPTS true

include

/* The format of our output.

Set this to PROCESSING_VISUALIZER if you're going to run the multi-sensor Processing Visualizer Sketch. See https://github.com/WorldFamousElectronics/PulseSensorAmped_2_Sensors

Set this to SERIAL_PLOTTER if you're going to run the Arduino IDE's Serial Plotter. */ const int OUTPUT_TYPE = PROCESSING_VISUALIZER;

/ Number of PulseSensor devices we're reading from. / const int PULSE_SENSOR_COUNT = 2;

/* PULSE_POWERx = the output pin that the red (power) pin of the first PulseSensor will be connected to. PulseSensor only draws about 4mA, so almost any micro can power it from a GPIO. If you don't want to use pins to power the PulseSensors, you can remove the code dealing with PULSE_POWER0 and PULSE_POWER1. PULSE_INPUTx = Analog Input. Connected to the pulse sensor purple (signal) wire. PULSE_BLINKx = digital Output. Connected to an LED (must have at least 470 ohm resistor) that will flash on each detected pulse. PULSE_FADEx = digital Output. PWM pin onnected to an LED (must have at least 470 ohm resistor) that will smoothly fade with each pulse.

 NOTE: PULSE_FADEx must be pins that support PWM.
   If USE_INTERRUPTS is true, Do not use pin 9 or 10 for PULSE_FADEx
   because those pins' PWM interferes with the sample timer.

*/ const int PULSE_INPUT0 = A0; const int PULSE_BLINK0 = 13; // Pin 13 is the on-board LED const int PULSE_FADE0 = 5;

const int PULSE_INPUT1 = A1; const int PULSE_BLINK1 = 12; const int PULSE_FADE1 = 11;

const int THRESHOLD = 550; // Adjust this number to avoid noise when idle

/ All the PulseSensor Playground functions. We tell it how many PulseSensors we're using. / PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);

/ Variables used to determine PTT. NOTE: This code assumes the Pulse Sensor on analog pin 0 is closer to he heart. / unsigned long lastBeatSampleNumber[PULSE_SENSOR_COUNT]; int PTT;

void setup() { /* Use 250000 baud because that's what the Processing Sketch expects to read, and because that speed provides about 25 bytes per millisecond, or 50 characters per PulseSensor sample period of 2 milliseconds.

 If we used a slower baud rate, we'd likely write bytes faster than
 they can be transmitted, which would mess up the timing
 of readSensor() calls, which would make the pulse measurement
 not work properly.

*/ Serial.begin(250000);

/ Configure the PulseSensor manager, telling it which PulseSensor (0 or 1) we're configuring. /

pulseSensor.analogInput(PULSE_INPUT0, 0); pulseSensor.blinkOnPulse(PULSE_BLINK0, 0); pulseSensor.fadeOnPulse(PULSE_FADE0, 0);

pulseSensor.analogInput(PULSE_INPUT1, 1); pulseSensor.blinkOnPulse(PULSE_BLINK1, 1); pulseSensor.fadeOnPulse(PULSE_FADE1, 1);

pulseSensor.setSerial(Serial); pulseSensor.setOutputType(OUTPUT_TYPE); pulseSensor.setThreshold(THRESHOLD);

// Now that everything is ready, start reading the PulseSensor signal. if (!pulseSensor.begin()) { /* PulseSensor initialization failed, likely because our Arduino platform interrupts aren't supported yet.

   If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
*/
for (;;) {
  // Flash the led to show things didn't work.
  digitalWrite(PULSE_BLINK0, LOW);
  delay(50);
  digitalWrite(PULSE_BLINK0, HIGH);
  delay(50);
}

} }

void loop() {

/ Wait a bit. We don't output every sample, because our baud rate won't support that much I/O. / delay(20);

// write the latest sample to Serial. pulseSensor.outputSample();

/ If a beat has happened on a given PulseSensor since we last checked, write the per-beat information about that PulseSensor to Serial. / for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) { if (pulseSensor.sawStartOfBeat(i)) { pulseSensor.outputBeat(i);

  lastBeatSampleNumber[i] = pulseSensor.getLastBeatTime(i);
  if(i == 1){
    PTT = lastBeatSampleNumber[1] - lastBeatSampleNumber[0];
    pulseSensor.outputToSerial('|',PTT);
  }
}

}

}

I would really appreciate any collaboration and will be forever in debt! I apologize the bad English, my native country is Brazil. If there is any doubt, I am happy to help!

Thank you in advance, Looking forward for answers...

biomurph commented 3 years ago

@VladiLuzJr Thanks for using Pulse Sensor! Your signal does look small. I don't think you will have signal problems because of the sensors being too close. If you are using Arduino Uno, you should definitely use the interrupts. They make the result very accurate. I have not used this code base in a little while. I will try to replicate your problem and see if I can make it work.

Also, can you verify your hardware? Send a picture of your setup?

VladiLuzJr commented 3 years ago

Greetings @biomurph!

Thanks for communicating with us and being available, we acknowledge your dedication... Firstly we would like to congratulate you for your hard work in the pulse sensor project, we are very happy to collaborate with you.

In the following link you can take a look in the video we have recorded, in order for you to understand the hardware configuration(I am sorry for the cable management....) https://drive.google.com/file/d/1gY98lt8Hd64yu2MZn41rZvPAbFaBdhiK/view?usp=sharing

This is how we test the software, for PTT acquisition: How_we_test_the_software

Here follows the Arduino an protoboard pinout: Pinout

Pulse Sensor 1(Analog pin0)

Pulse Sensor 1 Front: Pulse_sensor_1_front

Pulse Sensor 1 Back: Pulse_sensor_1_back

Pulse Sensor 2(Analog pin1)

Pulse Sensor 2 Front: Pulse_sensor_2_front

Pulse Sensor 2 Back: Pulse_sensor_2_back

If there is any doubt, please fell free to ask me... Sincerely, Vladimir

biomurph commented 3 years ago

@VladiLuzJr thank you for sending the pictures. They make everything very clear. First, you are not using the Pulse Sensors that we make. Those you have are knockoffs. I can't troubleshoot your hardware because I don't know what is on those boards. Please support the original makers of open source hardware and purchase legitimate products. You can guy on our site, www.pilsesenslor.com, or Adafruit, ot SparkFun, also Mouser and Digikey carry. Also, SparkFun bundles our PulseSensor in a kit they ship to brick-and-morter stores around the world. Check their 'distributors' page and call around if you have trouble ordering.

Regarding the PTT measurement, I would like to know if you have any study or white paper that you are following to put the two sensors so close together? They seem to be too close in proximity to get a valid or useful PTT. At the distance you have, it may require a rather high sample rate to gather anything useful. I usually see PTT placement in earlobe and fingertip, or other far away sites. This makes the difference easier to measure, as well as being able to tell when there are changes due to vasoconstriction. Much easier when further away.

VladiLuzJr commented 3 years ago

@biomurph , thanks for your attention!

Sorry I have bought those knockoffs... guess the COVID-19 crisis have effected the Brazilian currency, in a way two Pulse Sensor would cost R$500.00 with shipping in SparkFun.

Do you think I could by me some of these real IR LEDs and re-attach them as in thins link: https://makezine.com/2012/02/17/reel-crime-the-pulse-sensor-counterfeit-leds-story/

or should I manage to achieve some real ones for myself???

In regard to the Pulse Transit Distance, I will link in some paper in witch the distance of (Wrist - finger or even

closer) were used. We proposed ourselves(by using different microcontroller, such as a STM32 which has higher clock settings), if it was possible to built-in the "local-PWV" measurement in an oximeter device.

Happy to share our research with you... Furthermore through the end of the year I will link our published paper if I may!

28mm apart IR Rx for local PWV: Carotid_Single_Source_DuallPPG_PWV.pdf

Wrist_finger PPG: Wrist_FingerPPG_PWV.pdf

Wrist-finger for SPWV: nam2013.pdf

biomurph commented 3 years ago

I can't say what changes need to be made, as I have no idea what the parts they used to make their knockoff. Sorry.

As for the LED, we use a green LED because the sensor we use is most sensitive at that wavelength. IR would not be effective if it were our hardware.

Thanks for the links to the papers! They look very interesting indeed.

VladiLuzJr commented 3 years ago

I meant those brighter green LEDs as referred in the blog post, lol.

Although I understand it wouldn't be possible to know the components used... I have an Oscilloscope in hands, maybe I'll try to hard dig what is creating this difference in threshold. In the mean time I am looking forward to buy myself some real pulse sensors....

Thanks for being supportive! As soon as I have more news I will keep in touch

biomurph commented 3 years ago

Please do let me know what you discover. In our design, the raw PPG from the sensor can be found on the left side of the capacitor just above the green wire in your hardware photo.