我有一個iOS健身應用程序,它從藍牙胸帶收集心率數據。我最近添加了Apple Watch擴展功能,並將其插入手錶的心率傳感器中,作爲胸帶的替代品。不幸的是,我發現它是不準確的,基本上是無用的。這裏有一個3英里的徒步旅行,其中紅線表示從胸帶和藍線收集的數據的例子顯示了從Apple關注收集的數據:來自Apple Watch的心率數據非常不準確
我可以告訴胸帶數據這兩者的準確性更高,因爲當疊加在高程數據上時,較高的心率與上坡部分非常接近。 (另外,我不希望我的心跳速度從蘋果手錶所顯示的從60跳到120或110到160 ......也不一定每次坐在同一個值上。)
這裏是我用來收集手錶數據的代碼。有沒有其他的方法來配置這個來獲得更準確的數據,或者這是否與這個硬件一樣好?
- (void)startWorkoutSession {
if (self.workoutSession) {
return;
}
// configure a HealthKit workout
HKWorkoutConfiguration *configuration = [[HKWorkoutConfiguration alloc] init];
configuration.activityType = HKWorkoutActivityTypeHiking;
configuration.locationType = HKWorkoutSessionLocationTypeOutdoor;
// start the workout
NSError *error = nil;
self.workoutSession = [[HKWorkoutSession alloc] initWithConfiguration:configuration error:&error];
if (!self.workoutSession) {
//NSLog(@"*** Unable to create the workout session: %@ ***", error.localizedDescription);
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
@"createWorkoutSession", @"error",
error.localizedDescription, @"description",
nil];
[self.iosApp sendMessage:data replyHandler:nil errorHandler:^(NSError * _Nonnull error) {
// maybe show a local alert here?
}];
return;
}
self.workoutSession.delegate = self;
[self.healthStore startWorkoutSession:self.workoutSession];
// update the controls view and show the tracking view
self.controls.status = StatusStarted;
if (![self.activeController isEqual:self.tracking]) {
[self.tracking becomeCurrentPage];
}
}
- (void)workoutSession:(HKWorkoutSession *)workoutSession didChangeToState:(HKWorkoutSessionState)toState fromState:(HKWorkoutSessionState)fromState date:(NSDate *)date {
// required method
if (toState == HKWorkoutSessionStateRunning) {
[self requestHeartRate:date];
}
}
- (void)requestHeartRate:(NSDate *)date {
__weak typeof(self) weakSelf = self;
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:date endDate:nil options:HKQueryOptionNone];
HKSampleType *heartRateType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
HKAnchoredObjectQuery *query = [[HKAnchoredObjectQuery alloc] initWithType:heartRateType predicate:predicate anchor:0 limit:0 resultsHandler:^(HKAnchoredObjectQuery *query, NSArray<HKSample *> *samples, NSArray<HKDeletedObject *> *deletedObjects, HKQueryAnchor *anchor, NSError *error) {
if ((!error)&&(samples.count > 0)) {
[weakSelf receiveHeartRate:(HKQuantitySample *)[samples objectAtIndex:0]];
} else {
NSLog(@"error with initial heart rate query: %@", error);
}
}];
[query setUpdateHandler:^(HKAnchoredObjectQuery *query, NSArray<HKSample *> *samples, NSArray<HKDeletedObject *> *deletedObjects, HKQueryAnchor *anchor, NSError *error) {
if ((!error)&&(samples.count > 0)) {
[weakSelf receiveHeartRate:(HKQuantitySample *)[samples objectAtIndex:0]];
} else {
NSLog(@"error with updated heart rate query: %@", error);
}
}];
[self.healthStore executeQuery:query];
}
- (void)receiveHeartRate:(HKQuantitySample *)sample {
HKQuantity *quantity = sample.quantity;
int value = (int)[quantity doubleValueForUnit:[HKUnit unitFromString:@"count/min"]];
//NSLog(@"got heart rate %i", value);
// display the heart rate in the tracking view
[self.tracking updateHeartRate:value];
}
更新:
我是看着this comparison chart我應該從Apple關注期待精度的指示。現在我意識到,這只是將Apple Watch與另一款基於手錶的(手腕)傳感器進行比較。所以也許這張圖表只是表明這兩種腕式模型同樣是不準確的。
這令人困惑,因爲您可以在網上搜索「Apple Watch心率準確性」,並找到很多關於準確度的報道,但沒有人會看到我看到的結果,我認爲這很糟糕。
順便說一句,我爲了這個測試把手錶綁得很緊。 – arlomedia
基於手腕的心臟監護儀總是比胸部佩戴的模型更不準確。只有Apple可以使原始數據更好,但是您可以嘗試使用最近N次測量的運行平均值,而不是直接使用原始值。 –
@湯姆哈靈頓,好主意。我在測試數據上嘗試了多達5分鐘的平均滾動時間,但令人遺憾的是,顯示的數值仍然以每分鐘25-50次的速度下降。較短的時間段會導致基本上與原始手錶數據相匹配的數據。我認爲這種方法會更好地清理偶爾出現的異常值,而不是像這樣的數據往往是錯誤的而不是正確的。 – arlomedia