Collecting ECG on iOS in real-time

Want to capture ECG data from your Aidlab chest strap without being tied to a desktop? The latest (1.0.2) Aidlab SDK has you covered. Just use the new func didReceiveECG( sample: Float ) method on Aidlab module and you'll get the ECG signal coming in at 500Hz. We know a lot of you have been wanting to analyze ECG data during sports and other athletic activities: Now you can.

Note: This tutorial assumes you are familiar with Xcode. If you are not, we encourage you to read Getting Started with Xcode at developer.apple.com

In the tutorial, you’ll start making a simple app that will communicate with Aidlab through Aidlab SDK. By the time you're finished, your app will present the current samples in the console. Later on, you can copy the samples from the console, and paste it to external file or save it to your iCloud storage using CloudKit.

  1. Create an empty iOS project (Single View App), and set your iPhone as a build target.
  2. Download the Aidlab SDK.
  3. Unpack it, and just drag the Aidlab.framework in the Project Navigator.

Inside the ViewController.swift, initialize the SDK by setting aidlab: Aidlab? variable:

var aidlab: Aidlab?

override func viewDidLoad() {

    aidlab = Aidlab( aidlabDelegate: self )
}

Make sure your ViewController conforms to AidlabDelegate. Leave all methods empty, except the didReceiveECG. To read the ECG samples, add simple print inside the method's body:

func didReceiveECG( _ value: Float ) {

    print(value)
}

Compile your project, turn the Aidlab on, and wait up to 3 seconds till you see a green diode blinking rapidly. Now wear Aidlab on your chest, otherwise Aidlab will collect noise.

Note: to determine if Aidlab is positioned correctly, you can use delegate method func aidlabTouched( properly: Bool ).

Your console should be feed with values similar to:

0.0004240349
0.0004235197
0.00042281693
0.00042105225
0.00041855738
0.0004155299
0.00041103555
0.00040524718
0.00039876136
0.00039205124
0.0003836968
0.00037371725
...

These are the ECG samples measured in Volts. There is no timestamp included with the data, but you don't really need it. The samples are read at a consistent rate (every 2ms), so you can figure out the time just based on array the data comes from. If a transmission gets lost, you'll just have a gap.

In case you are not happy with the ECG quality, feel free to change the filtering method to aggressive, directly from the ecgFiltrationMethod property:

aidlab?.ecgFiltrationMethod = .aggressive

Enjoy your untethered ECG data!

results matching ""

    No results matching ""