How to get HRV (Heart Rate Variability) from HR (Heart Rate)

Chitra Khatri picture Chitra Khatri · Jul 8, 2014 · Viewed 8.5k times · Source

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]];

            }

        }

    }

}

Answer

Paulw11 picture Paulw11 · Jul 8, 2014

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.