PPG analysis beyond HR at rest

Posted on
of 3
First Prev
/ 3
  • I don't think a simple 2 line display that was updated on sending a record would be too heavy on the Cpu

    HRM 66
    COUNT 255

    The count does have to be an exact record count but just something that shows the recording is progressing and data is being sent. Printing HRM value allows observations to be made about the recording to be made while running etc. Eg I know my heart was 145 but it showed 89 etc.

  • The following is a compressed summery of what I found out so far (No code from me so far. Credit goes to gordon, helmrich, myownself and others)
    Please correct me where I am wrong or point me to good information I did't find so far.

    Where is the problem?

    • As all smartwatches, bangle usese optical sensing ("PPL" = "Photoplethysmography") not electrical as chestbelts do in order to measure heart related information.
    • This type of sensor signal is much more vulnerable to disturbance, especially by movement, and therefore considerably more difficult to interpret.
    • On the other hand it contains additional information that eg. could enables estimation of oxygen saturation (SpO2) and more.
    • There is a proprietory interpretation software blob from the chip manufacturer, but we try to stay open source if possible.
    • Here is some literature on how such algorithms work:

    What is the current state?

    How can I have a quick look or start experimenting?

    • For a quick start, you may want to just paste this code into left side of WebIDE
      Yellow is the raw input signal, red the improved filtered one and after a while you can see all recognised peaks marked in purple over the red graph.
      You can see how good the current algorithm works for you (and see that there is even low hanging fruit for improvement still)
    • The "HRM Accelerometer event recorder" App allows a more detailed analyses by recording this data and more on a computer/phone into a csv file.
      With this csv you can start analysing and testing in whatever tool/language you prefer.
      As the name suggests also acceleration data is recorded, which so far is not used at all in espruino HRM. Including it should really make a difference.
      This app is also a good example to learn how to get all the relevant sensor readings.

    What is the plan?

    • Set up a test harness where a potential algorithm can be optimized and reproducably evaluated on a train/validation/test set of recordings.
    • Collect a good (increasing level of difficulty; from different persons) set of recordings of bangle PPL and Acc sensor data toghether with refernce data from a good external sensor via BLE
    • Try differnt algorithms starting with basic ones as eg.
      • just ignore all PPL readings above a certain threshold of movement measured by Accelerometer
      • Improve peak finding (as with the eye one sees very clear peaks that are not found)

    What can I do right now?
    (until me/you/somebody finds the time to improve the algorithm)

    • Use a BT chest belt. Bangle can recieve, show, store heartrate via bluetooth.
  • Actually wrote that summery some time ago already, but wanted to post it only after having some code ready - then some unexpected urgent tasks came into the way preventing any work on bangle unfortunatly. Plan to spent some time this weekend though finally.

  • Awsome summary! Please don't credit me, I haven't contributed to any of the code, just messed around a bit. I've also not had chance to do anything a while. Iwas ill in Feb and been playing catch up since then.

  • Hi all,

    linking to this other thread, I had setup a repo for testing algorithms on Bangle JS. We currently have algos for step counting but it would make sense to add HR as well.

    I have some student working on HR from PPG on mobile phones, but, if time allows, would like also to contribute to BangleJS.

    The first thing to do would be to collect raw PPG data, as it comes to the algorithm, with a reference HR from another, trusted, sensor.

    Once we are happy with the HR, it would be also cool to see if we can extract other parameters, such as respiration rate, but that would probably come later...

  • Yes.

    I am hesitant to ask for recordings though before having done a whole iteration.
    Typically then one finds some improvements or missing parts (eg in the file format or naming convention or ...) that are easyly corrected before building the recording library but difficult thereafter.

    The first thing to do would be to collect raw PPG data, as it comes to the algorithm, with a reference HR from another, trusted, sensor.

    So to me that would be the second thing after having implemented testing harness and at least one algorithm to be parametrized and done that with two or three short recordings of myself.

  • The original step counting test repo is at https://github.com/gfwilliams/step-count­ too - that's what we've been using to tune step counting so far.

    But definitely the only way to make real improvements (IMO) is to get the data. Personally I think HR data without a trusted HR source to compare to isn't that useful at all.

    I believe @halemmerich has actually done all the work there already - he has an app that'll connect to an external BLE sensor and will log the Bangle's HRM data and the trusted data to a file on your PC, so it seems like that'd be a great start.

    But yes, if it's just a matter of setting up a repo and test harness and getting some code running then I guess pretty much any data should do it - although if you're doing file parsing it seems it's be worth getting it parsing @halemmerich's files as a first try

  • Mentioned app is at https://banglejs.com/apps/?id=hrmacceven­ts .
    The format is simple csv. Recording of a reference HRM via bluetooth requires https://banglejs.com/apps/?id=bthrm to be installed.

  • For developing a good algorithm we would need the following:

    1. raw PPG signal (as it comes from the driver)
    2. acceleration signal (useful for trying out motion artefacts cancellation)
    3. reference HR

    looks like we can get all of them with the apps we have?

  • Yes - I think hrmaccevents does that all for you in one go

  • I had a look at this app and I think if we want to get people to use it and submit logs it needs to be documented with a README file and a few UI changes are needed.

    The current way it works is a bit odd, in that you get a blank screen. I would have tried to capture some logs but there is no way I am walking or running with my watch showing a blank screen as I have no way of knowing if the thing is working or not. Plus you have to carry a phone etc with you. I think it would be better to make this app work like the accellog app - where the data is stored in Flash and then downloaded later. A 20 minute trace is probably more than adequate and that should fit into the Flash storage on a Bangle 2.

    The README needs to cover:

    1. what the app is for
    2. how to use it
    3. pre-requisties - eg you need you install a reference HRM
  • I think it would be better to make this app work like the accellog app - where the data is stored in Flash and then downloaded later

    There were discussions about this and I think @halemmerich had some troubles getting the relatively big file off the watch afterwards which is why he went direct.

    Honestly, for the few HRM traces we need to get started, I think it's probably not the end of the world to have a phone in your pocket. It's not perfect I know, but it's not a reason not to use an app that does exactly what we need right now.

    But yes, screen & readme could be added and I'm sure PRs for those would be appreciated - but again, I think there are probably only a handful of people that are going to actually do this with an external HRM, and for them a simple forum post with a few steps would work just fine

  • Ok, I've just created a repo for the test harness, with some sample data in there. Info at http://forum.espruino.com/conversations/­373033/#comment16554946

  • Hmm, I have recorded about 2.5 hours worth of data (including a "gold standard" reference from Garmin watch), but I am not able to download the log.csv file from the web IDE - it says "downloading ...", and after maybe 10 minutes it prints many rows of what looks like base64 data to the left panel, but no file gets downloaded. Is it too large?

  • @user145221 Yeah, your log.csv file is probably too big.

    By 'gold standard', do you mean another PPG sensor? ECG/EKG chest straps are the ideal reference and would be your gold standard here. Another PPG sensor might have the same issues (i.e. movement artifacts).

  • You can try to make a backup with the app loader and get the file from the resulting zip. That worked for me when I had your problem.

  • @halemmerich: yes, this worked for me. Will upload CSV soon.

    Should I fill a bug report against the web IDE not being to download large files?

  • I take the above back. Downloading the backup did not fail, but the ZIP file has storage-files/log.csv, which covers only about 45 minutes worth of data, instead of 2+ hours, if I interpret the Time column as miliseconds since Epoch - it starts at 1655828999759.82763671875 and ends at "165583160794" (the last line seems to be truncated).

  • Should I fill a bug report against the web IDE not being to download large files?

    I think there is already an issue about this.

    Honestly, I think right now, for the heart rate analysis, maybe we can just keep the data files to a lower length, like a half hour maximum? Given how we're plotting graphs right now we don't really have the tools to view useful information out of files larger than a few minutes - so while they could be run through the test harness, if they didn't work out well it'd be pretty hard to figure out why.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

PPG analysis beyond HR at rest

Posted by Avatar for Mi @Mi