First, thanks in advance! I need some feedback on my script. I'm using python 3.7 to capture my various device data streams for later analysis. That later portion will eventually deal with DFA-a1 analysis using this data.
Here's the code portion that calculates the R-R interval based on Package (Page 4) as noted on Section 7.2, page 33 of the HR device profile (file excerpt attached to this message):
# This section is for the POLAR sensor, deviceNumber=18990
if msg.deviceType == 120:
mv = memoryview(msg._content)
# Page 0x04. Use the recommended main page 4 only
if mv[0] == 4:
# Assembled computation elements (LSB/MSB)
val_HR = mv[7] # Calculated HR (bpm)
val_HRV = abs( ((mv[5]<<8 | mv[4]) - (mv[3]<<8 | mv[2])) *1000/1024 ) # HRV (milliseconds)
The resulting R-R interval value (val_HRV) seems reduced a bit when compared to a concurrently running HRV reader app. using the same Polar H10 strap as my script above... close, but not a match. They should be the same correct? This brings me to the next part, rollover handling. I'm certain I don't have the intent coded correctly to address rollover for the heartbeat count and the heartbeat event time. I'm not certain what to do with the differences. Here's what the code portion looks like:
# Handle rollover events
self.heartbeatCount = mv[6]
self.heartbeatEventTime = val_HRV
if self.heartbeatCountOld > self.heartbeatCount:
# The rollover correction at 2^8
heartbeatCountDiff = (self.heartbeatCount + 256) - self.heartbeatCountOld
else:
heartbeatCountDiff = self.heartbeatCount - self.heartbeatCountOld
if self.heartbeatEventTimeOld > self.heartbeatEventTime:
# Rollover correction at 2^16 = 65536, or 63.999 * 1024 either is about 65,534.976
heartbeatEventTimeDiff = (self.heartbeatEventTime + 65536) - self.heartbeatEventTimeOld
else:
heartbeatEventTimeDiff = self.heartbeatEventTime - self.heartbeatEventTimeOld
Also, I'm not certain that the "else" conditions belong as Section 7.1 doesn't mention it. I sure would appreciate where I'm going off-track as I don't want to get into the DFAa1 phase with inaccurate data.
What to do with the rollover adjustments/corrections?
TIA,
Eric
Image Attachments
Click thumbnail to see full-size image