Open Nav

Odczytywanie EKG na iOS w czasie rzeczywistym

Author avatar

Jakub Domaszewicz

Ostatnia aktualizacjaDecember 3, 2021

Want to capture ECG data from your Aidlab chest strap without being tied to a desktop? The latest Aidlab SDK has you covered. Just use the new func didReceiveECG(_ aidlab: IAidlab, timestamp: UInt64, values: [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

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 an 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. Install the Aidlab SDK.

Inside the ViewController.swift, initialize the SDK by setting aidlabSDK: AidlabSDK? variable:

private var aidlab: AidlabSDK?

override func viewDidLoad() {

    aidlabSDK = AidlabSDK(delegate: self)

Make sure your ViewController conforms to AidlabSDKDelegate. Inside the body of the didDiscover method, stop the scan, select appropriate signals and connect to Aidlab:

func didDiscover(_ aidlab: CBPeripheral, rssi: NSNumber) {
    let signals: [Signal] = [.ecg]
    aidlabSDK?.connect(signals: signals, peripheral: aidlab, aidlabDelegate: self)

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

func didReceiveECG(_ aidlab: IAidlab, timestamp: UInt64, values: [Float]) {

    values.forEach { print($0) }

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 wearStateDidChange(_ aidlab: IAidlab, state wearState: WearState).

Your console should be filled with values similar to:


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 the 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:


Enjoy your untethered ECG data!

Powrót do Bloga



Zapisz się do naszego newslettera - poinformujemy Cię o wszelkich nowościach i promocjach.


Aidlab's Logo

Aidlab™ jest zarejestrowanym znakiem towarowym. Copyright © 2023

Aidlab™ jest zarejestrowanym znakiem towarowym. Copyright © 2023