Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now HR can be obtained through the device's back camera. Feature #376 #981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 42 additions & 2 deletions ResearchKit.xcodeproj/project.pbxproj
Expand Up @@ -557,6 +557,15 @@
D442397E1AF17F7600559D96 /* ORKImageCaptureStepViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D442397C1AF17F7600559D96 /* ORKImageCaptureStepViewController.m */; };
D458520A1AF6CCFA00A2DE13 /* ORKImageCaptureCameraPreviewView.h in Headers */ = {isa = PBXBuildFile; fileRef = D45852081AF6CCFA00A2DE13 /* ORKImageCaptureCameraPreviewView.h */; };
D458520B1AF6CCFA00A2DE13 /* ORKImageCaptureCameraPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = D45852091AF6CCFA00A2DE13 /* ORKImageCaptureCameraPreviewView.m */; };
DBBF16A41ECBC72700602B86 /* ORKHrCaptureStepViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DBE4AF0D1ECBBC3100C9EE78 /* ORKHrCaptureStepViewController.m */; };
DBE4AEB41ECBB62300C9EE78 /* ORKHealthAnswerFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5424521DF1513B00A86918 /* ORKHealthAnswerFormat.swift */; };
DBE4AF081ECBBB7200C9EE78 /* ORKHrCaptureStep.h in Headers */ = {isa = PBXBuildFile; fileRef = DBE4AF071ECBBB7200C9EE78 /* ORKHrCaptureStep.h */; settings = {ATTRIBUTES = (Public, ); }; };
DBE4AF0A1ECBBBCD00C9EE78 /* ORKHrCaptureStep.m in Sources */ = {isa = PBXBuildFile; fileRef = DBE4AF091ECBBBCD00C9EE78 /* ORKHrCaptureStep.m */; };
DBE4AF0C1ECBBC1F00C9EE78 /* ORKHrCaptureStepViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = DBE4AF0B1ECBBC1F00C9EE78 /* ORKHrCaptureStepViewController.h */; };
DBE4AF121ECBBCBD00C9EE78 /* ORKHrCaptureView.h in Headers */ = {isa = PBXBuildFile; fileRef = DBE4AF111ECBBCBD00C9EE78 /* ORKHrCaptureView.h */; };
DBE4AF141ECBBCCD00C9EE78 /* ORKHrCaptureView.m in Sources */ = {isa = PBXBuildFile; fileRef = DBE4AF131ECBBCCD00C9EE78 /* ORKHrCaptureView.m */; };
DBE4AF181ECBBF8600C9EE78 /* ORKFFTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = DBE4AF171ECBBF8600C9EE78 /* ORKFFTUtils.h */; };
DBE4AF1A1ECBBF9B00C9EE78 /* ORKFFTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = DBE4AF191ECBBF9B00C9EE78 /* ORKFFTUtils.m */; };
FA7A9D2B1B082688005A2BEA /* ORKConsentDocumentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA7A9D2A1B082688005A2BEA /* ORKConsentDocumentTests.m */; };
FA7A9D2F1B083DD3005A2BEA /* ORKConsentSectionFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = FA7A9D2D1B083DD3005A2BEA /* ORKConsentSectionFormatter.h */; };
FA7A9D301B083DD3005A2BEA /* ORKConsentSectionFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = FA7A9D2E1B083DD3005A2BEA /* ORKConsentSectionFormatter.m */; };
Expand All @@ -572,7 +581,6 @@
FF5051ED1D668FF80065E677 /* ORKPageStep_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FF5051EC1D668FF80065E677 /* ORKPageStep_Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
FF5051F01D66908C0065E677 /* ORKNavigablePageStep.h in Headers */ = {isa = PBXBuildFile; fileRef = FF5051EE1D66908C0065E677 /* ORKNavigablePageStep.h */; settings = {ATTRIBUTES = (Public, ); }; };
FF5051F11D66908C0065E677 /* ORKNavigablePageStep.m in Sources */ = {isa = PBXBuildFile; fileRef = FF5051EF1D66908C0065E677 /* ORKNavigablePageStep.m */; };
FF5424531DF1513B00A86918 /* ORKHealthAnswerFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5424521DF1513B00A86918 /* ORKHealthAnswerFormat.swift */; };
FF5CA6121D2C2670001660A3 /* ORKTableStep.h in Headers */ = {isa = PBXBuildFile; fileRef = FF5CA6101D2C2670001660A3 /* ORKTableStep.h */; settings = {ATTRIBUTES = (Public, ); }; };
FF5CA6131D2C2670001660A3 /* ORKTableStep.m in Sources */ = {isa = PBXBuildFile; fileRef = FF5CA6111D2C2670001660A3 /* ORKTableStep.m */; };
FF5CA61B1D2C6453001660A3 /* ORKSignatureStep.h in Headers */ = {isa = PBXBuildFile; fileRef = FF5CA6191D2C6453001660A3 /* ORKSignatureStep.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -1185,6 +1193,14 @@
D442397C1AF17F7600559D96 /* ORKImageCaptureStepViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKImageCaptureStepViewController.m; sourceTree = "<group>"; };
D45852081AF6CCFA00A2DE13 /* ORKImageCaptureCameraPreviewView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKImageCaptureCameraPreviewView.h; sourceTree = "<group>"; };
D45852091AF6CCFA00A2DE13 /* ORKImageCaptureCameraPreviewView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKImageCaptureCameraPreviewView.m; sourceTree = "<group>"; };
DBE4AF071ECBBB7200C9EE78 /* ORKHrCaptureStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKHrCaptureStep.h; sourceTree = "<group>"; };
DBE4AF091ECBBBCD00C9EE78 /* ORKHrCaptureStep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKHrCaptureStep.m; sourceTree = "<group>"; };
DBE4AF0B1ECBBC1F00C9EE78 /* ORKHrCaptureStepViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKHrCaptureStepViewController.h; sourceTree = "<group>"; };
DBE4AF0D1ECBBC3100C9EE78 /* ORKHrCaptureStepViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKHrCaptureStepViewController.m; sourceTree = "<group>"; };
DBE4AF111ECBBCBD00C9EE78 /* ORKHrCaptureView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKHrCaptureView.h; sourceTree = "<group>"; };
DBE4AF131ECBBCCD00C9EE78 /* ORKHrCaptureView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKHrCaptureView.m; sourceTree = "<group>"; };
DBE4AF171ECBBF8600C9EE78 /* ORKFFTUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKFFTUtils.h; sourceTree = "<group>"; };
DBE4AF191ECBBF9B00C9EE78 /* ORKFFTUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKFFTUtils.m; sourceTree = "<group>"; };
FA7A9D2A1B082688005A2BEA /* ORKConsentDocumentTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKConsentDocumentTests.m; sourceTree = "<group>"; };
FA7A9D2D1B083DD3005A2BEA /* ORKConsentSectionFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKConsentSectionFormatter.h; sourceTree = "<group>"; };
FA7A9D2E1B083DD3005A2BEA /* ORKConsentSectionFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKConsentSectionFormatter.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1824,6 +1840,7 @@
B12EFF341AB2111200A80147 /* Step */ = {
isa = PBXGroup;
children = (
DBE4AF061ECBBA4800C9EE78 /* HR capture Step */,
86C40BB91A8D7C5C00081FAC /* ORKStep.h */,
86C40BBA1A8D7C5C00081FAC /* ORKStep.m */,
86C40BBB1A8D7C5C00081FAC /* ORKStep_Private.h */,
Expand Down Expand Up @@ -2492,6 +2509,21 @@
name = "Image Capture Step";
sourceTree = "<group>";
};
DBE4AF061ECBBA4800C9EE78 /* HR capture Step */ = {
isa = PBXGroup;
children = (
DBE4AF071ECBBB7200C9EE78 /* ORKHrCaptureStep.h */,
DBE4AF091ECBBBCD00C9EE78 /* ORKHrCaptureStep.m */,
DBE4AF0B1ECBBC1F00C9EE78 /* ORKHrCaptureStepViewController.h */,
DBE4AF0D1ECBBC3100C9EE78 /* ORKHrCaptureStepViewController.m */,
DBE4AF111ECBBCBD00C9EE78 /* ORKHrCaptureView.h */,
DBE4AF131ECBBCCD00C9EE78 /* ORKHrCaptureView.m */,
DBE4AF171ECBBF8600C9EE78 /* ORKFFTUtils.h */,
DBE4AF191ECBBF9B00C9EE78 /* ORKFFTUtils.m */,
);
name = "HR capture Step";
sourceTree = "<group>";
};
FA7A9D2C1B083D90005A2BEA /* Formatters */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2564,9 +2596,11 @@
86C40CE41A8D7C5C00081FAC /* ORKAnswerFormat.h in Headers */,
25ECC0951AFBD68300F3D63B /* ORKReactionTimeStep.h in Headers */,
86C40D0A1A8D7C5C00081FAC /* ORKCustomStepView.h in Headers */,
DBE4AF121ECBBCBD00C9EE78 /* ORKHrCaptureView.h in Headers */,
BCD192EE1B81255F00FCC08A /* ORKPieChartView_Internal.h in Headers */,
86C40DCE1A8D7C5C00081FAC /* ORKTaskViewController_Internal.h in Headers */,
25ECC09F1AFBD92D00F3D63B /* ORKReactionTimeContentView.h in Headers */,
DBE4AF181ECBBF8600C9EE78 /* ORKFFTUtils.h in Headers */,
10FF9AC31B79EF2800ECB5B4 /* ORKHolePegTestRemoveStep.h in Headers */,
86C40C361A8D7C5C00081FAC /* ORKSpatialSpanGame.h in Headers */,
86C40CAC1A8D7C5C00081FAC /* ORKRecorder.h in Headers */,
Expand Down Expand Up @@ -2673,6 +2707,7 @@
86C40D621A8D7C5C00081FAC /* ORKQuestionStep_Internal.h in Headers */,
86C40D641A8D7C5C00081FAC /* ORKQuestionStepViewController.h in Headers */,
10BAA2CA1B5FCB4F004FE478 /* ORKProgressView.h in Headers */,
DBE4AF081ECBBB7200C9EE78 /* ORKHrCaptureStep.h in Headers */,
BCB6E6601B7D534C000D5B34 /* ORKLineGraphChartView.h in Headers */,
86C40E241A8D7C5C00081FAC /* ORKEAGLMoviePlayerView.h in Headers */,
B183A4DD1A8535D100C76870 /* ResearchKit.h in Headers */,
Expand Down Expand Up @@ -2726,6 +2761,7 @@
BC8FC6781CA9B17C00D12768 /* ORKVoiceEngine_Internal.h in Headers */,
86C40C1E1A8D7C5C00081FAC /* ORKAudioStepViewController.h in Headers */,
FFDDD8491D3555EA00446806 /* ORKPageStep.h in Headers */,
DBE4AF0C1ECBBC1F00C9EE78 /* ORKHrCaptureStepViewController.h in Headers */,
147503AF1AEE8071004B17F3 /* ORKAudioGenerator.h in Headers */,
86AD91141AB7B97E00361FEB /* ORKQuestionStepView.h in Headers */,
86C40C621A8D7C5C00081FAC /* CLLocation+ORKJSONDictionary.h in Headers */,
Expand Down Expand Up @@ -3068,6 +3104,7 @@
959A2C011D68B9DA00841B04 /* ORKRangeOfMotionStepViewController.m in Sources */,
861D2AF11B8409D9008C4CD0 /* ORKTimedWalkContentView.m in Sources */,
86C40DC41A8D7C5C00081FAC /* ORKTapCountLabel.m in Sources */,
DBE4AF0A1ECBBBCD00C9EE78 /* ORKHrCaptureStep.m in Sources */,
25ECC0A01AFBD92D00F3D63B /* ORKReactionTimeContentView.m in Sources */,
86C40D4C1A8D7C5C00081FAC /* ORKLabel.m in Sources */,
86C40C9E1A8D7C5C00081FAC /* ORKDeviceMotionRecorder.m in Sources */,
Expand All @@ -3077,6 +3114,7 @@
86C40DF81A8D7C5C00081FAC /* ORKSignatureStepViewController.m in Sources */,
959A2BFD1D68B98700841B04 /* ORKRangeOfMotionStep.m in Sources */,
BCB6E6531B7D533B000D5B34 /* ORKPieChartLegendCell.m in Sources */,
DBE4AF141ECBBCCD00C9EE78 /* ORKHrCaptureView.m in Sources */,
866DA52A1D63D04700C9AF3F /* ORKOperation.m in Sources */,
86C40D8C1A8D7C5C00081FAC /* ORKSkin.m in Sources */,
86C40D221A8D7C5C00081FAC /* ORKFormStep.m in Sources */,
Expand Down Expand Up @@ -3170,6 +3208,7 @@
86C40DC01A8D7C5C00081FAC /* ORKTableViewCell.m in Sources */,
24A4DA111B8D0F21009C797A /* ORKPasscodeStepView.m in Sources */,
BC41942A1AE8453A00073D6B /* ORKObserver.m in Sources */,
DBE4AEB41ECBB62300C9EE78 /* ORKHealthAnswerFormat.swift in Sources */,
86C40C681A8D7C5C00081FAC /* CMAccelerometerData+ORKJSONDictionary.m in Sources */,
86C40C701A8D7C5C00081FAC /* CMMotionActivity+ORKJSONDictionary.m in Sources */,
147503B01AEE8071004B17F3 /* ORKAudioGenerator.m in Sources */,
Expand Down Expand Up @@ -3222,6 +3261,7 @@
86C40DEC1A8D7C5C00081FAC /* UIBarButtonItem+ORKBarButtonItem.m in Sources */,
106FF2AF1B6FACA8004EACF2 /* ORKDirectionView.m in Sources */,
BF1D438A1D4905FC007EE90B /* ORKVideoInstructionStepViewController.m in Sources */,
DBBF16A41ECBC72700602B86 /* ORKHrCaptureStepViewController.m in Sources */,
86C40CAA1A8D7C5C00081FAC /* ORKPedometerRecorder.m in Sources */,
BCA5C0361AEC05F20092AC8D /* ORKStepNavigationRule.m in Sources */,
106FF2A71B665CF5004EACF2 /* ORKHolePegTestPlaceContentView.m in Sources */,
Expand Down Expand Up @@ -3250,13 +3290,13 @@
86C40C441A8D7C5C00081FAC /* ORKSpatialSpanMemoryStep.m in Sources */,
BCB080A11B83EFB900A3F400 /* ORKStepNavigationRule.swift in Sources */,
24898B0E1B7186C000B0E7E7 /* ORKScaleRangeImageView.m in Sources */,
DBE4AF1A1ECBBF9B00C9EE78 /* ORKFFTUtils.m in Sources */,
86C40DD81A8D7C5C00081FAC /* ORKUnitLabel.m in Sources */,
86C40D361A8D7C5C00081FAC /* ORKHelpers.m in Sources */,
86C40C181A8D7C5C00081FAC /* ORKAudioContentView.m in Sources */,
86C40C8E1A8D7C5C00081FAC /* ORKActiveStepViewController.m in Sources */,
10864CA51B27146B000F4158 /* ORKPSATKeyboardView.m in Sources */,
86C40CE61A8D7C5C00081FAC /* ORKAnswerFormat.m in Sources */,
FF5424531DF1513B00A86918 /* ORKHealthAnswerFormat.swift in Sources */,
25ECC0961AFBD68300F3D63B /* ORKReactionTimeStep.m in Sources */,
BC13CE3A1B0660220044153C /* ORKNavigableOrderedTask.m in Sources */,
B11C54A11A9EF4A700265E61 /* ORKConsentSharingStepViewController.m in Sources */,
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion ResearchKit.xcodeproj/xcshareddata/xcschemes/docs.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
88 changes: 88 additions & 0 deletions ResearchKit/Common/ORKFFTUtils.h
@@ -0,0 +1,88 @@
/*
Copyright (c) 2017, Apple Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder(s) nor the names of any contributors
may be used to endorse or promote products derived from this software without
specific prior written permission. No license is granted to the trademarks of
the copyright holders even if such marks are included in this software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#import <Foundation/Foundation.h>
#include <Accelerate/Accelerate.h>

NS_ASSUME_NONNULL_BEGIN

static const int FftMinSamplesN = 64; //The minimum number of samples required for the first fft calculation. Around 2 seconds if Fs=30
static const int FftInnerStepSamplesN = 128; // Start using this number rather than fftMinSamplesN as soon as we have enough data
static const int FftMaxSamplesN = 256; // The maximum number of samples to be used for fft calculations. Around 8 seconds if Fs=30
static const int SamplingRate = 30; //How many samples per second are we getting. Fs
static const float FftMinHzForHR = 0.8; //Spectrum lower limit on FFT to be considered (according to a possible HR of 48 bpm)
static const float FftMaxHzForHR = 4.0; //Spectrum upper limit on FFT to be considered (according to a possible HR of 204 bpm)
static const float FftCalculationFrequency = 1; //Seconds between each HR estimation using fft for timer


@interface ORKFFTUtils : NSObject {

}

/**
Get RGB bits from a 32 bit string
*/
- (UInt32)Mask8:(UInt32)x;

/**
Gets the blue channel bits
*/
- (UInt32)getBlue:(UInt32)x;

/**
Gets the green channel bits
*/
- (UInt32)getGreen:(UInt32)x;

/**
Gets the red channel bits
*/
- (UInt32)getRed:(UInt32)x;

/**
Returns absolute value of a complex number
*/
- (float *)absOfComplex:(COMPLEX_SPLIT)complex withSize:(int)size;

/**
Gets the desired amount of samples needed to perform FFT
*/
- (NSMutableArray *)getProperSamples:(NSMutableArray *)ppgSignal;

/**
Calculates FFT of the ppgSignal then estimates HR from it
*/
- (float)getHrFromPpg:(NSMutableArray *)ppgSignal;

@end


NS_ASSUME_NONNULL_END