16

I am trying to use heartRateVariabilitySDNN. I successfully get heartRate by query and I use the following code for getting heartRateVariabilitySDNN but have no idea how it works. Also there is no proper documentation about this query or sample code from Apple.

func createheartRateVariabilitySDNNStreamingQuery(_ workoutStartDate: Date) -> HKQuery? {

    let typeHeart = HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)
    let predicate: NSPredicate? = HKQuery.predicateForSamples(withStart: workoutStartDate, end: nil, options: HKQueryOptions.strictEndDate)

    let squery = HKStatisticsQuery(quantityType: typeHeart!, quantitySamplePredicate: predicate, options: .discreteAverage, completionHandler: {(query: HKStatisticsQuery,result: HKStatistics?, error: Error?) -> Void in
        DispatchQueue.main.async(execute: {() -> Void in

            print("got: \(String(describing: result))")
        })
    })

    return squery
}
Curiosity
  • 544
  • 1
  • 15
  • 29
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • Do you have any update on this, Nitin? I'd love to get more frequent HRV data – but right now I get the *same HRV value* every time I query for the HRV. – DeveloBär Oct 27 '18 at 06:22
  • I quote: "[...] While there are multiple ways of computing HRV, HealthKit uses SDNN heart rate variability, which is calculated using the standard deviation of the inter-beat (RR) intervals between normal heartbeats (typically measured in milliseconds)" from the Apple docs (https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier/2881127-heartratevariabilitysdnn). More info https://en.wikipedia.org/wiki/Heart_rate_variability#Analysis. It's a way to analyse the interval on time domain – Bram Nov 23 '18 at 10:25

0 Answers0