theironrobin / siglo

GTK app to sync InfiniTime watch with PinePhone
Mozilla Public License 2.0
153 stars 23 forks source link

Receive Heartrate raw data to build tensorflow model #33

Closed limoncelli closed 3 years ago

limoncelli commented 3 years ago

Just a thought on how it might be possible to improve heart rate accuracy.

If a lot of the community members collect raw sensor data, best if accompanied with some validated second heart rate sensor (eg infrared or red light measurement), we could train a tensorflow model to get better predictions. Siglo itself could display the heart rate, or send it to pinetime for display or tensorflow lite could run directly with the trained model on the pinetime.

Might be something on the future wishlisi,

Thanks for all the effort

pfeerick commented 3 years ago

lol... HR reading was the last thing on my 0.1 milestone for a cli script I'm working on for playing with some of the InfiniTime/pinetime bluetooth capabiliites... so I went ahead and added it... It's crude, and barely works... but it should help if HR monitoring is added... https://github.com/pfeerick/InfiniTimeToy/commit/d80528f2eaeb641c1b725d4661cb6ea15cdb991b

limoncelli commented 3 years ago

Great,

is this the measurement value part:

octet 1 - 3.88.2.1 

octet 2 - HR (uint8) 

octet 3 - HR (uint16)

and Octet 2 being the BPM? Is Octet 3 then the raw signal (wasp-OS had a video showing raw data)

How will one need to call the script from command line, once the device is paired. In the end I'm thknking of something of this type of style for the output:

Timestamp w millisec         BPM  raw 2021-05-03 15:21:02.0004   75     81 2021-05-03 15:21:02.0005   75     80 2021-05-03 15:21:02.0006   75     63 2021-05-03 15:21:02.0006   75     67 2021-05-03 15:21:02.0007   75     75 2021-05-03 15:21:02.0008   73     77 2021-05-03 15:21:02.0009   73     73

Thanks for your work. Really great. Will need to refresh python skills now...

pfeerick commented 3 years ago

I might be able to throw something together that does simply that in a day or two, but for starters, but I don't think InifiTime reports back that frequently or reports raw data... so it would probably have to be wasp-os specific, and I'd need to find out how it gives the raw data back... perhaps Daniel was just running a script on the pinetime that spat the info out in realtime, rather than via GATT BLE stuff..

My script as is isn't suitable, as it connects, does it's thing, and then disconnects... you really want it to connect, stay connected, and poll the HR until you Ctrl+C and then disconnect (as the absolute simplest way to implement it).

3.88.2.1 is one of the headings in this document . Basically the Heart Rate characteristic is documented at 3.88, and consists of

octet   1 = a bunch of flags - see 3.88.2.1 for the five flags
octet   2 = uint8 HR or first half uint16 HR if bit 0 of flags is 1
octet   3 = second half of  uint16 HR if bit 0 of flags is 1
octet 4-5 = energy expended if bit 3 of flags set to 1
octet 6-? = RR intervals (something about time between two R-Wave detection?) if bit 4 of flags set to 1 
limoncelli commented 3 years ago

thanks for the update. I will reach out to Daniel to see what his approach was and what data was actually displayed. All the best, robin

05.05.2021 11:07:21 Peter @.***>:

I might be able to throw something together that does simply that in a day or two, but for starters, but I don't think InifiTime reports back that frequently or reports raw data... so it would probably have to be wasp-os specific, and I'd need to find out how it gives the raw data back... perhaps Daniel was just running a script on the pinetime that spat the info out in realtime, rather than via GATT BLE stuff..

My script as is isn't suitable, as it connects, does it's thing, and then disconnects... you really want it to connect, stay connected, and poll the HR until you Ctrl+C and then disconnect (as the absolute /simplest/ way to implement it).

3.88.2.1 is one of the headings in this document [https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=429632]. Basically the Heart Rate characteristic is documented at 3.88, and consists of

octet   1 = a bunch of flags - see 3.88.2.1 for the five flags octet   2 = uint8 HR or first half uint16 HR if bit 0 of flags is 1 octet   3 = second half of  uint16 HR if bit 0 of flags is 1 octet 4-5 = energy expended if bit 3 of flags set to 1 octet 6-? = RR intervals (something about time between two R-Wave detection?) if bit 4 of flags set to 1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub[https://github.com/alexr4535/siglo/issues/33#issuecomment-832535229], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ACZMNYK6IGGME6LD3Y3727DTMEDERANCNFSM437MS66A]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAABHNCSVQICAgIfAhkiAAAABxJREFUWIXtwTEBAAAAwqD1T20Hb6AAAAAAAH4DFGQAAUvJX8QAAAAASUVORK5CYII=###24x24:true###][Verfolgungsbild][https://github.com/notifications/beacon/ACZMNYPBEVTJD6NIPVVNN6DTMEDERA5CNFSM437MS66KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGGPXVPI.gif]

limoncelli commented 3 years ago

Link to the request to Daniel in his wasp-os repo https://github.com/daniel-thompson/wasp-os/issues/204

05.05.2021 11:07:21 Peter @.***>:

I might be able to throw something together that does simply that in a day or two, but for starters, but I don't think InifiTime reports back that frequently or reports raw data... so it would probably have to be wasp-os specific, and I'd need to find out how it gives the raw data back... perhaps Daniel was just running a script on the pinetime that spat the info out in realtime, rather than via GATT BLE stuff..

My script as is isn't suitable, as it connects, does it's thing, and then disconnects... you really want it to connect, stay connected, and poll the HR until you Ctrl+C and then disconnect (as the absolute /simplest/ way to implement it).

3.88.2.1 is one of the headings in this document [https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=429632]. Basically the Heart Rate characteristic is documented at 3.88, and consists of

octet   1 = a bunch of flags - see 3.88.2.1 for the five flags octet   2 = uint8 HR or first half uint16 HR if bit 0 of flags is 1 octet   3 = second half of  uint16 HR if bit 0 of flags is 1 octet 4-5 = energy expended if bit 3 of flags set to 1 octet 6-? = RR intervals (something about time between two R-Wave detection?) if bit 4 of flags set to 1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub[https://github.com/alexr4535/siglo/issues/33#issuecomment-832535229], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ACZMNYK6IGGME6LD3Y3727DTMEDERANCNFSM437MS66A]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAABHNCSVQICAgIfAhkiAAAABxJREFUWIXtwTEBAAAAwqD1T20Hb6AAAAAAAH4DFGQAAUvJX8QAAAAASUVORK5CYII=###24x24:true###][Verfolgungsbild][https://github.com/notifications/beacon/ACZMNYPBEVTJD6NIPVVNN6DTMEDERA5CNFSM437MS66KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGGPXVPI.gif]

limoncelli commented 3 years ago

Reading this at stackoverflow it looks lie one is to receive BPM directly from the device. I still think that postprocessing via trained model will enhance the result. Daniel talks in his video also about some filtering

pfeerick commented 3 years ago

So that must be what the RR-Intervals bit is, which is not implemented in InfiniTime, hence bit 4 of the flags octet is not set to 1.

But it looks like you'll have more luck with wasp-os anyway, since Daniel just happens to be working on the same thing... how about that for timing! :laughing: I thought you'd have more luck that way anyway since you could probably write a python script that extracts the heart rate over the console... but being able to have it saved to device for later extraction is perfect... you can then run the HR app when you want to track the HR, for different training profiles, etc.

limoncelli commented 3 years ago

Somethings seem to land in infinitime

https://github.com/JF002/InfiniTime/commit/e3ead332b9db3ad7b6acde933b6a7943b3ac81e2

they are referencing Daniels code which contains the way he calculates the heartrate

https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py

pfeerick commented 3 years ago

That's regarding an old PR, and just changes the variable(s) used so it does use as much runtime memory.

When JF converted the code over, he erred in the side of caution when setting the types, and made them signed rather than unsigned.

On Fri, 7 May 2021, 3:58 pm limoncelli, @.***> wrote:

Somethings seem to land in infinitime

@.*** https://github.com/JF002/InfiniTime/commit/e3ead332b9db3ad7b6acde933b6a7943b3ac81e2

they are referencing Daniels code which contains the way he calculates the heartrate

https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/alexr4535/siglo/issues/33#issuecomment-834089033, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ66KMGYRI747H5XLZBFO3TMN6O3ANCNFSM437MS66A .

pfeerick commented 3 years ago

Sorry, int8 rather than int, not signed Vs unsigned.

On Fri, 7 May 2021, 5:38 pm Peter Feerick, @.***> wrote:

That's regarding an old PR, and just changes the variable(s) used so it does use as much runtime memory.

When JF converted the code over, he erred in the side of caution when setting the types, and made them signed rather than unsigned.

On Fri, 7 May 2021, 3:58 pm limoncelli, @.***> wrote:

Somethings seem to land in infinitime

@.*** https://github.com/JF002/InfiniTime/commit/e3ead332b9db3ad7b6acde933b6a7943b3ac81e2

they are referencing Daniels code which contains the way he calculates the heartrate

https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/alexr4535/siglo/issues/33#issuecomment-834089033, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ66KMGYRI747H5XLZBFO3TMN6O3ANCNFSM437MS66A .

theironrobin commented 3 years ago

I would rather have something like MyGNUHealth do heartrate and step counting than have siglo handle it.