How to get HRV (Heart Rate Variability) from HR (Heart Rate)
Asked Answered
S

1

6

I am working on application in which I have to read heart beat till one minute and calculate heart rate variability from it.

for reading heart beat I am using strap(Polar)

Heart beat reading code I have used from link

for calculating HRV I gone through following links but nothing helps:

  1. Research article on SDNN/RMSSD

  2. RMSSD for HRV Analysis

  3. Comparison between HR and HRV

Please provide formula from which i can get HRV(RMSSD) from HR and duration to get HR is one minute.

Any help would be appreciated..

EDIT:

I have got RR value with following code:

- (void) updateWithHRMData:(NSData *)datas {

const uint8_t *reportData = [datas bytes];

uint16_t bpm = 0;
uint16_t bpm2 = 0;

if ((reportData[0] & 0x04) == 0)
{
    NSLog(@"%@", @"Data are not present");
}
else
{

    bpm = CFSwapInt16LittleToHost(*(uint16_t *)(&reportData[2]));

    bpm2 = CFSwapInt16LittleToHost(*(uint16_t *)(&reportData[4]));

    if (bpm != 0 || bpm2 != 0) {

            NSLog(@"%u", bpm);

            if (bpm2 != 0) {
                NSLog(@"%u", bpm2);
            }
    }

}

}

My Question is I am getting RR values like:666,636,645 .... etc but when I use HRV + application and export RR values via email it shows values like 0.785,0.734,0.724 etc.. and if I do calculation with RR values of mine with following formula:

RMSSD = enter image description here

It gives me completely wrong result.

Please help.

EDIT:

 //==================RR
if ((reportData[0] & 0x04) == 0)
{
    NSLog(@"%@", @"Data are not present");
}
else
{
    uint16_t rr2 = CFSwapInt16LittleToHost(*(uint16_t *)(&reportData[2]));
    RR = CFSwapInt16LittleToHost(*(uint16_t *)(&reportData[4]));

    //sometimes two values of RR may found so there are two RR: RR and rr2 which added in array and all calculation goes after one minute

    if (rr2 > 0 || RR > 0) {

        NSLog(@"RR2 %u", rr2);
        if (rr2>0) {
            [RRArray addObject:[NSNumber numberWithInt:rr2]];
        }
        if (RR != 0) {
            NSLog(@"RR %u", RR);
            [RRArray addObject:[NSNumber numberWithInt:RR]];

            }

        }

    }

}
Standby answered 8/7, 2014 at 5:1 Comment(4)
I don't think this is programming related questionGrandmotherly
I am confused about I have formula but for reading HR Peripheral delegate "didUpdateValueForCharacteristic" is called and get time stamp from this or something else is biggest question..Standby
Can you update your question with the output of NSLog(@"%@",datas) - I need to see the raw data of the value from the sensor. I suspect your decoding code is incorrect. You need to check bit 3 to see if energy expended is present and there may be multiple RR values per packet. Also from reading the paper it seems that SSDN is HRV, not RMSSD. Also note that RR values are in 1/1024ths of a second in the data packet.Crummy
As also suggested by Paulw11, you should check if the data does or does not contain EnergyExpended data. Also be aware, there might be more than 2 RR-values. The number of RR-values varies and needs to be calculated. You can check my post, and full code example here: #17422718Tandem
C
2

You need to perform the statistical calculations described in section 2.2.1 of your first linked article.

You cannot calculate the HRV from the heart rate - your need to use RR intervals.

You need to check the data returned by your sensor to see if bit 4 of the flag byte is set - this indicates the presence of RR data. You can then read the RR data into an array, converting the 16 bit sample data into NSNumbers . You can adapt the code from the tutorial that converts the 16 bit heart beat values to an int.

Once you have collected enough samples (And I am not sure that 1 minutes worth of samples will be statistically valid, but I am not a statistician) then you can perform the analysis.

THB will be the number of RR intervals in your array

MRR or I(BAR) you can calculate as follows -

float rrTotal=0;

for (int i=1;i<[rrIntervals count]; i++) {
   rrTotal+=[[rrIntervals objectAtIndex:i] intValue];
}

float mrr = rrTotal/([rrIntervals count]-1);

SDNN (which is your HRV) is calculated as follows -

float sdnnTotal = 0;

for (int i=1;i<[rrIntervals count]; i++) {
   sdnTotal+=pow( [[rrIntervals objectAtIndex:i] intValue] - mrr,2) ;
}

float sdnn = sqrt(sdnTotal/([rrIntervals count]-1));

You can keep recalculating the HRV as you add more data to the array.

Crummy answered 8/7, 2014 at 8:38 Comment(2)
I have added multiple packets of RR using link : #17422718 hope that might correct oneStandby
You should try and convert Daniel's code from that link. It is better than the other answerCrummy

© 2022 - 2024 — McMap. All rights reserved.