Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

R-R calculations with the new Android APIs

Rank

Total Posts: 25

Joined 0

PM

Hi,

with the old APIs I get the correct R-R values. However, using the new ANT+ Android APIs I cannot get the correct R-R values.
What am I doing wrong? The code is very simple.

From the onNewHeartRateData function I have:

if ((heartBeatCounter heartBeatCounter_pre) == 1){
                        usR_R_Interval 
=   estTimestamp-estTimestamp_pre
                        
usR_R_Interval_ms = (long) ((usR_R_Interval 1000) / 1024);
                    
}
heartBeatCounter_pre
heartBeatCounter


with estTimestamp_pre coming from the estimated time stamp of the onNewPage4AddtData()

     
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi,

The estimated timestamp field or "estTimestamp" is an Android specific field present in most plugin events meant to help with correlating events to received data messages, ie. multiple events could be thrown by the reception of a single message, so the timestamp would be the same on those events.

The R-R interval should be calculated from the "timestampOfPreviousToLastHeartBeatEvent" parameter in the "IPage4AddtDataReceiver" and the "timestampOfLastEvent" parameter in the "IHeartRateDataTimestampReceiver". Which correspond to the "Previous Heart Beat Event Time" and "Heart Beat Event Time" fields in the Heart Rate Device profile.

If page 4 is unavailable, caching the "timestampOfLastEvent" parameter will also allow you to calculate the R-R after a 1 event delay.

Would it be beneficial to you for the plugins to add the R-R calculation as an event? There is also the option to rename these fields to better match the device profile in the next version of the API.

Cheers      
Rank

Total Posts: 25

Joined 0

PM

Hi Harrison,

thanks for the reply. Yes, it would be nice to have the R-R calculation included in the API.
I have tried to use the parameters you suggested, unfortunately there is still something wrong in the data I get.

if ((heartBeatCounter heartBeatCounter_pre) == 1){
                                             rr_interval 
=HeartBeatEventTime.subtract(PreviousHeartBeatEventTime).doubleValue(); 
                                             
rr_interval_ms = (long) ((rr_interval 1000.0) / 1024.0);
                     
}
                                         }
                     heartBeatCounter_pre
heartBeatCounter


the calculation is done in onNewHeartRateData.
The HeartBeatEventTime field is coming from IHeartRateDataTimestampReceiver and the PreviousHeartBeatEventTime is from IPage4AddtDataReceiver.
Suggestions?
Thanks.

Cheers,

     
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi cdelrosso,

The timebase of the heart beat event time's have automatically been converted to seconds from 1/1024s by the plugin. If you'd like the R-R interval to be converted to milliseconds, you should only multiply by 1000.

if ((heartBeatCounter heartBeatCounter_pre) == 1){
                                             rr_interval 
=HeartBeatEventTime.subtract(PreviousHeartBeatEventTime).doubleValue(); 
                                             
rr_interval_ms = (double) (rr_interval 1000.0);
                     
}
                                         }
                     heartBeatCounter_pre
heartBeatCounter


To maintain accuracy and scale you may also wish to keep your calculations in BigDecimal's. The plugin's send decimal values as "BigDecimal" in order to maintain full control over accuracy and scale vs Java's primitive types.

Cheers,
Harrison      
Rank

Total Posts: 25

Joined 0

PM

Hi Harrison,

I have got some good progresses. To have milliseconds, I believe I should multiply by 1000.
And now I use BigDecimal for the calculations. However, the values I get across sessions are not consistent.
In some sessions everything is OK, in others I see a lot of variations, out of scale and even negative values sometimes.

I have tried different hrm brands with the same inconsistent results.
And I have tried the same application running on two different Android devices (one with ANT+ built-in,the other one with the external ANT+ accessory) connected to the same ANT+ HRM giving me sometimes very different rr values, the hr values are always correct though.

These inconsistencies are across sessions close to each other.
Could it be something related to the ANT Radio Service or the heart rate plugin?

The PreviousHeartBeatEventTime comes from onNewPage4AddtData, and the HeartBeatEventTime comes from onNewHeartRateDataTimestamp.

if ((heartBeatCounter heartBeatCounter_pre) == 1){
  rr_interval 
=   HeartBeatEventTime.subtract(PreviousHeartBeatEventTime).multiply(new BigDecimal(1000)).doubleValue(); 
                     
}
heartBeatCounter_pre
heartBeatCounter
     
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi,

Thanks for pointing out my mistake, that has been corrected in my previous post.

You may only use the PreviousHeartBeatEventTime and HeartBeatEventTime to calculate R-R if the estTimestamp field in both the IHeartRateDataTimestampReceiver and IPage4AddtDataReceiver match.

if ((heartBeatCounter heartBeatCounter_pre) == && IHeartRateDataTimestampReceiver.estTimestamp == IPage4AddtDataReceiver.estTimestamp){
  rr_interval 
=   HeartBeatEventTime.subtract(PreviousHeartBeatEventTime).multiply(new BigDecimal(1000)).doubleValue(); 
                     
}
heartBeatCounter_pre
heartBeatCounter


Otherwise you may be using values which came from different pages received at different times.

It may be easier to cache the heart beat event time, so PreviousHeartBeatEventTime = HeartBeatEventTime, instead of using IPage4AddtDataReceiver. If the estTimestamp fields do not match, to use the cached value instead.

if ((heartBeatCounter heartBeatCounter_pre) == 1)
{
   
if(IHeartRateDataTimestampReceiver.estTimestamp == IPage4AddtDataReceiver.estTimestamp)
   
{
      
//Use IPage4AddtDataReceiver.PreviousHeartBeatEventTime
   
}
   
else
   
{
      
//Use Cached HeartBeatEventTime
   
}
     
Rank

Total Posts: 25

Joined 0

PM

Thanks, it clarifies how it works.
Unfortunately the same problems persist. Any ideas?
     
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

We're currently investigating if there are any plugin level issues, but we will be adding a calculated R-R interval event to the HR plugin. It will likely be present in the next release.      
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

We've discovered a potential issue with how the plugin starts tracking the event times which we should correct in a future release. In the meantime you should only calculate R-R interval using the heart beat event time and the last seen value.      
Rank

Total Posts: 1

Joined 2014-01-26

PM

Could you elaborate on "using the heart beat event time and the last seen value"? What event time and what last seen value?

We are also seeing the same as cdelrosso. Timestamps (timestampOfLastEvent and timestampOfPreviousToLastHeartBeatEvent) seem not to be very reliable in current version, and you can get even negative values occasionally if you calculate r-r based on them.

Sounds great if you have found an issue there. Hopefully you'll get a fix release out soon!

Br,
-Mikko-
     
RankRankRankRank

Total Posts: 122

Joined 2010-10-25

PM

How long for a new version? I am adding RR recording into IpBike and the Plugin solution as it stands is considerably inferior to the version I have with my old legacy decode stuff or BTLE even.

To be honest I can not see why you are splitting the data up into the various different messages it just makes life really hard if you want all the data for an event having to register for multiple events then marry them back up together is really pain full and inefficient when at the underlying ANT+ level they all come together.      
RankRankRankRank

Total Posts: 313

Joined 2011-09-12

PM

Just to clarify, timestampOfPreviousToLastHeartBeatEvent is broken in the current version because it is not correlated directly with the timestampOfLastEvent field due to the way page toggling is handled. So don't use it.

To calculate RR interval use timestampOfLastEvent exclusively by caching the last value between subsequent events. (ie. timestampOfLastEvent - lastSeenTimestampOfLastEvent)

As Harrison noted, we will just be adding RR as its own event since so many people are using it. We will also fix the timestampOfPreviousToLastHeartBeatEvent bug and we will probably also be refactoring the events to be more friendly (specifically I believe we will be combining the heartRate and timestamp into the same event). We are expecting to add this in our next release by May. Watch the forums for announcements of a public beta.      

Signature

Dynastream Developer

Rank

Total Posts: 16

Joined 2014-04-09

PM

Hi.
Thanks for supplying lots of detail.
I used the following line (adapted from the default code included with SimulANT+):
logger.writerow([page.HeartBeatEventTime, page.HeartBeatCount, page.ComputedHeartRate, getDateAndTime(0)])
and logged to a laptop or desktop. (Yes, I realise this is the "mobile phones" section of the forum, but AFAIK it may still be relevant.)
Not sure about your device, but with one of my devices HeartBeatEventTime was correlated exactly with HR, but seems to have been a 'smoothed' (and perhaps shifted) version of the actual event time. With another device, HeartBeatEventTime seemed to be poorly correlated with HR, hence I wouldn't trust it. The point is, for this data to be meaningful relies on both the logging (software & code) done on the smart-phone/laptop and the HR monitoring device (detection & reporting).
See : https://www.thisisant.com/forum/viewthread/6653/
(Please excuse my cross-pollination.)
—DIV