More about ECG

Do you like to explore and understand things at low levels? If Yes. This post is for you! 😃

👉 Let’s get started on ECG Signal (Pre)-Processing

It is relatively simple for anyone to access their own Electrocardiogram (ECG) from anywhere. The majority of us, however, are unable to decipher an ECG and gather the necessary details regarding this biosignal. If you are among those who are unaware of what goes on "behind the scenes," don't worry, we can help you unveil this signal.

We will dive you on the ECG signal by sharing some notes on how to approach the signal using Python programming. We will also introduce you to our biosignals notebooks, a set of documents and a Python library to provide programming examples in the form of Jupyter Notebooks, as companion to the OpenSignals biosignals acquisition tools.

Let’s go…

Step 1: Python & Anaconda. Let’s talk about snakes. 

After collecting the ECG data and to be able to analyze it, you will need to extract the relevant parameters from the raw signal. To do so you need to select a proper tool to analyze the signal. You can use either pre-built toolboxes for ECG signal processing or you can learn how to do it from the scratch and follow, for example, our biosignals notebooks where you will have access to code snippets for signal plotting, filtering, peak detection, etc.

Python is a programming language used for different activities ranging from machine learning to web design and software. It is also a very useful and popular tool to process and analyze the different biosignals. Other popular programming languages and toolboxes are also, commonly, used for signal processing including MATLAB, R, Octave, C/C++, etc.

Anaconda is a platform that bundle the different programming languages, including Python. This is the software required to work with our biosignals notebooks.

What do you need to onboard to get started

🐍Download, Install and Execute Anaconda [] (Difficulty Level 1/5)

🐍Download, Install and Execute Jupyter Notebook Environment (Difficulty Level 1/5)

 

Step 2: Let the snake eat! Load & Plot your ECG data

Now you have everything set, you can upload the ECG data.

Wait! I don’t have a data sample yet. What can I do?

No problem, once you’re getting started and learning the first steps for signal processing you can use a sample set we prepared for you. Alternatively, you can follow our guide Exploring Cardiac Signals at the Skin Surface and get your ECG acquisition system (our recommendation is BITalino HeartBIT) to acquire your own ECG data sample.

 

You can save your data in different formats, including, text file (.txt), hierarchical data format (.h5) for storing large amounts of data and European data format (.edf) which is a standard file format designed for exchange and analyze data from commercial devices in a format that is independent on the acquisition system.

In the following biosignals notebooks you can learn how to:

📖Load acquired data from .h5 file (Difficulty Level 1/5)

📖Load acquired data from .txt file (Difficulty Level 1/5)

📖Load Signals after Acquisition [OpenSignals] (Difficulty Level 1/5)

Each one of the OpenSignals outputted file formats has some metadata linked to it. Acquisition parameters such as sensor type, sampling rate, resolution, active channels, etc., can be found in the file metadata. For the .txt file this info is stored in the header while in .h5 files is passed as attributes of the hierarchical objects.

In the 📖 “Signal Loading - Working with File Header” notebook, you can find a detailed procedure for accessing file metadata (.txt and .h5) together with a simplified approach through the use of a biosignals notebooks specialized function.

Can you tell me how can I plot the ECG data?

ECG signal is usually represented as a function of time (time-domain). By plotting an ECG you will get the time in the x axis and amplitude in the y axis, hence obtaining time-amplitude representation of the signal.

Indeed, plotting the data brings other perspectives to the person who’s analyzing it, making it easier to communicate and interpret the data. You may plot your data with interactive visuals using a tool called Bokeh (Python library). Please refer to our Python Notebook Tutorial 📖 "Plotting of Acquired Data with Bokeh" (Difficulty Level 2/5) for instructions on how to plot your signal.

Step 3: Snakes do not like the noise! Tips for signal Filtering

Noisy signal biosignals
When you are acquiring an ECG or any other signals it is normal to observe some artefacts or perturbations on the data. You can obviously apply all the good practices while acquiring a biosignal, in order to minimize the internal and external sources that are originating the noise.

Fortunately, you have also other tools available to remove the noise from the signal, namely digital filters (Learn more in “Signal Artifacts and Techniques for Artifacts and Noise Removal”) .

By applying digital filtering, you can remove all the noise that constitutes non-relevant information for your study, maximizing your signal-to-noise ratio. Furthermore, in medical applications it is necessary to have a clean signal to be able to distinguish each part of the ECG signal (PQRST complex).

Open the next notebook to preform your first signal filtering.

📖Digital Filtering - A Fundamental Pre-Processing Step

Filtered signal

After you get your signal clean the next step is to start learning and extracting the relevant features of the ECG signal. Well, this is a topic for another post.😎

 

If you’re getting started don’t forget to read “How to dive in the world of biosignals?” and “How do I know I am alive?”

And that’s it, folks. Keep tuned, keep your heart beating.

Author: Madalena Proença (Product manager at PLUX Biosignals)