LOADING
Biosignals Processing In Python: Best Ways For Its Implementation

Biosignals Processing In Python: Best Ways For Its Implementation

The information about our body such as heart rate, blood pressure, oxygen saturation levels, blood glucose, nerve conduction, brain activity, etc. can be regularly measured by different medical devices to provide us insight into the state of our health. With the help of biosignals processing, clinicians can get more in-depth, real-time data about patient health without needing to use invasive measures. In this blog post, you’ll learn about biosignals processing in Python and building a toolbox for this purpose.

Biosignals Processing In Python

According to Statista, Python remained the most popular programming language in 2020. Python continues to pass Java and JavaScript—languages with much longer histories—in popularity.

Image by Proxet. Python Remains Most Popular Programming Language
Python Remains Most Popular Programming Language

Python has a lot of open-source libraries for different purposes. Since it’s an object-oriented programming language, it’s often employed by academicians for education and research.

Analytics libraries such as NumPy, Pandas, SciPy, and several others have created an efficient way to build and test data models for use in analytics. In previous years, data scientists were confined to using proprietary platforms and C, and custom-building machine learning algorithms. But with Python libraries, data solutions can be built much faster and with more reliability.

— Matt Ratliff, who is a Senior Data Science Mentor at NextUp Solutions.

When it comes to biosignal processing, developers can extract the necessary knowledge from biosignals and use it for other purposes with the help of Python and its innovative algorithms.

Thankfully, there are a lot of contributors to biosignal processing in Python. For instance, there’s a special Python toolbox called BioSPPy dedicated to various signal processing and pattern recognition methods for analysis of biosignals on Github. It includes the following features:

  • Support for various biosignals: PPG, ECG, EDA, EEG, EMG, Respiration
  • Signal analysis primitives: filtering, frequency analysis
  • Clustering
  • Biometrics

Moreover, biosignals processing in Python includes such use cases as automatic emotion recognition to detect changes in emotions based on a user’s biosignals. For example, this research focuses on using multimodal biosignal data to predict the target emotion of audiovisual stimuli.

The large and varied Python libraries can model and analyze biological and physiological functions, structures, and dynamics. Also, Python provides many good data analytics tools for biometrics and signal processing like NumPy, SciPy, and Pandas. Python has a strong foundation on which flexible applications can be built, as it leverages C, C++, and even FORTRAN libraries.

To conclude, here are the main benefits of biosppy biosignals processing in Python:

  • A development environment suitable to both computational and visualization tasks
  • A large number of open-source libraries for this purpose
  • Availability of packages with advanced capabilities such as array and matrix manipulation, image processing, amg alarms, digital signal processing, and visualization

If you’re interested in learning more about using Python for audio analysis, read our blog post,

Now, let’s see what types of biosignals can be processed with the help of Python.

Types of Biosignals and their Characteristics

Let’s start with a definition. So, a biosignal is any signal in a living organism that can be continually measured and monitored. Here’s what types of biosignals can be recorded:

  • Electroencephalogram (EEG)
    EEG signals are generated by the electrical activity of brain cells. An action potential is created after the neuron is fired because of the exchange of ions that occurs inside and outside the neuron’s cell. It results in an alteration in the electrical charge from negative to positive. Then, it results in ionic current being propagated through the neuronal axons to other neurons which generates the electrical field.
  • Electrocardiogram (ECG)
    ECG signals record the electrical activity that results from the depolarization and repolarization activity of the heart. ECGs are widely used for studying arrhythmias, coronary artery disease, and other heart failure conditions.
  • Electromyogram (EMG)
    EMG signals are produced by the electric currents that are generated by muscle contraction. EMG signals are used to detect anomalies in the activity of the muscles such as myopathy and neuropathy, and also to study biomechanics for body prosthetics development.
  • Electrooculogram (EOG)
    EOG signals record the electrical activity that occurs because of the depolarization and repolarization activity of the heart. EOGs are widely used for studying heart failure conditions such as arrhythmias, coronary artery disease, etc.
  • Electrocorticography (PPG)
    PPG signals record the sounds that are produced by the heart’s beat and the blood flow between the heart valves. With the help of PPG signals, it’s possible to study abnormalities in heart sound for the detection of heart defects as well as to identify biometric signatures. It’s also used to detect high frequency noise in biosignals.

Also, depending on the source for measurement, biosignals are also divided into two main groups: active and passive.

Active biosignals include where the patient is the energy source for measurement. They include 2 types of biosignals: electrical biosignals such as EEG, ECG,  EMG and non-electrical biosignals such as thermography and pH. Passive biosignals are where the energy source for measurement is not the patient but some device. Examples of passive biosignals are electroencephalogram (EEG), electrocardiogram (ECG), and electromyogram (EMG).

The electrocardiogram (ECG) is a graphic provided by a device that tracks heart activity called an electrocardiograph.

Image by Proxet. The Electrocardiogram (ECG) Provided by a Device that Tracks Heart Activity
The Electrocardiogram (ECG) Provided by a Device that Tracks Heart Activity

Electroencephalography is the measurement of the brain’s electrical activity, recorded from electrodes placed on the scalp. When these signals are analyzed, they are used as a diagnostic tool to detect pathologies associated with strange electrical behavior. The use of biosignals for machine control can also be managed with Python. Let’s review the features of the most commonly used toolbox for biosignals processing.

An Overview of Most Popular Python Toolbox

BioSPPy

BioSPPy is a toolbox written in Python that is used for biomedical signal processing. BioSPPy contains numerous signal processing and pattern recognition algorithms fine-tuned for the analysis of biomedical signals. The library is open-source and developers can use it for both academic and commercial purposes. BioSPPy covers a range of functions adapted to biomedical signal processing. The syntax of these functions is considerably simplified due to the optimal manipulation of biomedical signals. The library is called from the Python environment using the “import” command.

Image by Proxet. Import of BioSPPy library into Python environment.
Import of BioSPPy library into Python environment.

BioSig

BioSig is an open-source software library for biomedical signal processing. It can be used in such areas as neuroinformatics, brain-computer interfaces, neurophysiology, psychology, cardiovascular systems, and sleep research.

BioSig consists of the following coherent parts:

  • BioSig for Octave and Matlab – a toolbox for Octave and Matlab with powerful data import and export filters, feature extraction algorithms, classification methods, and a powerful viewing and scoring software
  • BioSig  – a C/C++ library that provides reading and writing routines for different biosignal data formats.
  • rtsBCI – a real-time Brain-Computer Interface (BCI) system implemented in Matlab and Simulink.

BioSig contains a lot of algorithms and covers many aspects of biomedical signal processing. It’s divided into subcategories depending on the function of the algorithms it contains. BioSig can process such tasks as heart rate extraction, artifact processing, brain-computer interfacing, and provides a whole toolchain of data processing methods for BCI research.

Open Source vs Custom Writing Solutions

Open source will continue to grow as we see non-traditional industries like shipping, fashion, banking, and manufacturing continue down a path of transformation into software companies.

— Stephen Giguere, Sales Engineer at Synopsys Software Integrity Group

Here are the main benefits of open-source solutions:

  • It’s free and it saves a lot of resources
  • It’s constantly developing as the number of contributors grows each day
  • You can modify the open-source software to your needs
  • It’s used among a wide range of different types of users, so the software is always updated and tested in different situations.

On the other hand, custom solutions give you the following perks:

  • You get dedicated specialist support
  • It’s fully customized to your needs
  • Clean and flexible base code
  • Improved scalability and security

Once you have a specification of what system you want to build, you can easily select the most suitable configuration for solving problems in your projects. Not sure what solution to use? Proxet has significant experience in developing custom solutions with Python. Entrust the development process to us and we’ll help you get the most out of this technology.



Sal Magnone
Head of Special Projects

Stand with Ukraine

We stand with our friends and colleagues during this struggle for their freedom and independence—and lives, above all. To support Ukraine in its direst hours, visit this page.