-
Notifications
You must be signed in to change notification settings - Fork 21
Added PPG raw decoding for Verity Sense #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ense in SDK mode (I could not modify core.py as the installed library wouldn't be edited)
fsmeraldi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the easiest way when developing would be to check out the repo so that you have bleakheart in your PYTHONPATH or your working directory, without installing the package - but never mind, this is great, I'll merge it with core.py - no problem at all.
I have a couple of questions:
- what would be a good set of default setting values for PPG that one can add to default_settings? I guess it would be better if they do not require the SDK mode so that they won't cause errors if one just calls start_streaming
- related to this, can RESOLUTION and CHANNELS actually change on the Verity? If so, we should probably store the values passed to start_streaming as object attributes so that the decode function can have the right values.
- Related to this I realised I implicitly assumed fixed values for RESOLUTION in ECG and ACC decoders since on the H10 they do not change, is this still ok to do that?
- In fact, are the default settings I listed for the other measurements on H10 compatible with the Verity? I guess ECG does not apply, but what about ACC?
|
That's a great point, for the default settings for the verity sense I just iterated through all of the available sensors with the help of list measurements and got this: So sadly they do seem to change and as I am sure you are aware this is what the H10 returns But it seems like resolution and range only change for the H10's accelerometer so those being fixed with a dictionary should be sufficient. I can check and see if adding the SDK mode changes anything if you would like more information regarding that also. I am not sure why the H10's accelerometer is giving different results from your hard coded range and sample rate, I wonder if they changed that in a newer hardware version. I know in the verity threads they made a fix for some sampling rate issue, could be similar to that and if it is the devices can be updated with their app. Do the settings listed answer all of your questions? One of my own so I understand it a bit better, any reason why the main file was renamed to core.py instead of it's old bleakheart.py? Is that so it can work better as an installed library? |
|
Thank you, very interesting!
Concerning filenames: I decided to organise the library as a package, and then I did not want to have the same name to avoid doubts about what "import" was doing. My intention was to implement another module with accessory functions for reading offline measurements, but I had no luck getting documentation from Polar on the offline mode for the H10, and so far have not got very far with figuring that out. |
Available PPG settings: Available ACC settings: Available PPI settings: Available GYRO settings: Available MAG settings:
Is there anything you'd like me to work on to get this more integrated? |
|
Thank you @HufflyCodes, this is very interesting! It seems that on the verity RESOLUTION=16 for everything except for PPG where it is 22, and likewise CHANNELS=3 for everything (as expected) except PPG (where I gather it is 3 LEDs plus a background reading). Looking at the example you quoted, are the frame type listed there for ACC (129) and the one you decoded for PPG (128) essentially the same? If so, it would seem that if one
However, I may be over-simplifying. For one thing, Incidentally, I am not sure I understand what is PPI - I read it as peak-to-peak intervals, but on the H10 this is bundled with the heart rate - maybe this is separate on the Verity because the heart rate standard requires proper RR intervals, and those returned by the Verity are not? Finally: I had gotten the PPG frame type wrong in |
|
I will look into the ACC frames here and see what I can find, from the reading I have previously done I do remember there being a scaling factor but only for certain frame types? We will see if any more reading clears things up or makes it more convoluted haha, I know for example I read (directly from their issues forum and it wasn't corrected anywhere...) the three channels were IR, Red, Green thinking I could do some SPO2 analysis with this and NOPE they are all green so who knows what the forums will bring. I think the code for decoding should be the same, I did my best to make it 'modular' with allowing inputs for frame and header length and such so that should work well there, assuming it doesn't break with new changes, again pending the conversion factor. They mention in their description of it that the PPI is: PP interval (milliseconds) representing cardiac pulse-to-pulse interval extracted from PPG signal. So same as the ECG one it seems, just different data source? I can try it out but also from that page they mention this
|
|
Hello @HufflyCodes , apologies for the very late reply, I've been swamped by work
aah, that would have been nice... too bad it isn't possible!
Well the scaling factor can be checked by making sure that the norm of the acceleration vector when the sensor is at rest is g. As for the rest, I would not know - fancy ways I have seen for testing accelerometers (in fact, with mobile phones) included putting them on the turntable of a vinyl player or attaching them to a string or a spring to form a pendulum... which may still result in dropping them, but only as an unintended consequence! ;)
I'd agree the PPG sensor is probably in arbitrary units... ECG is in microvolt
From a note I had made at the end of
Thank you, that clarifies it! |
|
No worries work has been the same for me, this is my first week back on a computer in over two weeks.
Welp that is what thinking before doing will get you! That is much easier than the other methods and such. Once I get it spooled up I will look into that and try to derive the scaling factor.
Speaking of the scaling factor I will look at the notes you left at the end of the start_streaming function but upon reading that specification, I am only left with more confusion as they somehow convert 964680256 to 0.000244 using the IEEE-754 Floating point converter which is the first I have ever encountered that so I will look into implementing that if you haven't already. Doesn't seem too hard upon initial googling, I am just unsure how I would modify reading it from the start_streaming function so once I have that figured out I will probably just add another helper function to convert the scaling factor and store it for decoding the values. Or should the scaling factor be simply printed out along with the rest of the data? |
|
Hello Wesley, I tried decoding the example given in the specification, this way seems to work: so basically |
|
Awesome thank you for the snippet! I will check it out to confirm the response returns what is expected, and I had no idea struct.unpack was so powerful, python is awesome! For the H10 I would assume that is does not contain it at all as the documents do not list any conversion factors but that could be old so good to check. So for storing the conversion factor that should be a part of core.py where it can then be used to call the conversion helper function? If that's the case I can work on getting that implemented after some initial testing to make sure that everything we have discussed checks out. |
|
I just checked for the H10 there are no conversion factors - the control point response is 6 bytes only and seems to end in 0x01 for ACC and 0x00 for ECG. So I took it that 0x05 indicates the Verity and the factor, and in that case I added a couple of lines to decode the factor and save it in By the way, I had some time today so I published a new release with the PPG decoding (thanks again!) and merged some minor changes (including renaming core.py to _core.py) into verity_dev. Let me know if you find any issues! |
As I was working on the library in windows I could not modify core.py directly as it wouldn't point to that but instead the installed library so all of the changes I made were to bleakheart.py. That being said with those changes being added to core.py the package should work as intended for decoding the ppg values by running the corresponding ppg_parse.py. I am unsure of proper conventions and typical guidelines for doing pull requests so let me know if anything needs to be changed