Basic Biosignal Manipulation Full

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

BASIC BIOSIGNAL MANIPULATION

John Fredy Ochoa Gómez


Bioengineering Department
University of Antioquia
Biomedical Signal Processing 2

CONTENT
1. Introduction

2. File formats

3. Montage

4. Signal manipulation

5. Basic statistics
Biomedical Signal Processing 3

BASIC EEG ANALYSIS


Introduction
• In this part of the course we need to use the data commonly
acquired by the biomedical instrumentation in a format
commonly use in a data science environment using libraries
commonly used in the industry
Acquisition Manipulation Analysis

PYTHON DATA
SCIENCE
FRAMEWORK

NUMPY
PANDAS
MATPLOTLIB
Biomedical Signal Processing 4

CONTENT
1. Introduction

2. File formats

3. Montage

4. Signal manipulation

5. Basic statistics
Biomedical Signal Processing 5

BASIC EEG ANALYSIS


File formats
• Different to medical imaging, there are so many formats for
Biosignals.

• The initiative to establish the EDF or Biosig as standard file


format doesn’t has the force that has the DICOM format

• All the Biosignals files format are structured to have


information about the number of channels and the sampling
rate

• The following slides will show different formats and examples,


existing different possibilities, to load in Python
Biomedical Signal Processing 6

BASIC EEG ANALYSIS


File formats
• Matlab format: the scipy library is used to load the information
in the .mat file. The information loaded is assigned to a
dictionary variable where is necessary to extract the field with
the signal and related information
Biomedical Signal Processing 7

BASIC EEG ANALYSIS


File formats
• Otherwise, for formats as OpenBCI Raw we have plain text

Information


The file is commonly know as a comma separated values
(csv)
Biomedical Signal Processing 8

BASIC EEG ANALYSIS


File formats
• The following code is a propose of algorithm to read OpenBCI
Raw format

• First, some variables


Biomedical Signal Processing 9

BASIC EEG ANALYSIS


File formats
• The following code is a propose of algorithm to read OpenBCI
Raw format
• Now, the algorithm to load the data
Biomedical Signal Processing 10

BASIC EEG ANALYSIS


To solve
• Write the code in the preceding slides
• For the eight EEG channels loaded, obtain a plot similar, not
equal because the picture is from the web, to:

• To obtain the space between points remember that each


second 250 samples are acquired
Biomedical Signal Processing 11

BASIC EEG ANALYSIS


To solve
• Evaluate a strategy to load the data using the PANDAS
routines (see also: https://www.shanelynn.ie/python-pandas-
read_csv-load-data-from-csv-files/ )
Biomedical Signal Processing 12

CONTENT
1. Introduction

2. File formats

3. Montage

4. Signal manipulation

5. Basic statistics
Biomedical Signal Processing 13

BASIC EEG ANALYSIS


Montage / Visualization
• Given that is impossible to have many sensor a common
practice is to locate some electrodes using position that can
be compared between subjects or center. The location, of the
active and the reference electrode, is known as montage
• In the picture the common location of EEG electrodes
Biomedical Signal Processing 14

BASIC EEG ANALYSIS


Montage / Visualization
• For the OpenBCI we have used the following electrodes
Biomedical Signal Processing 15

BASIC EEG ANALYSIS


Montage / Visualization
• OpenBCI
Biomedical Signal Processing 16

BASIC EEG ANALYSIS


Montage / Visualization
• The signal used is the difference between active and passive or
reference electrodes. So, for the loaded signal we have:
Biomedical Signal Processing 17

BASIC EEG ANALYSIS


To solve
• Plot the six biosignal obtained in the previous slide using a
subplot of 3x2 and assign the corresponding title, and the
titles of the axis, to each plot
• To obtain the space between points remember that each second 250
samples are acquired
Biomedical Signal Processing 18

CONTENT
1. Introduction

2. File formats

3. Montage

4. Signal manipulation

5. Basic statistics
Biomedical Signal Processing 19

BASIC EEG ANALYSIS


Signal manipulation
• For the following examples we will load a pre-processed
signal
Biomedical Signal Processing 20

BASIC EEG ANALYSIS


Signal manipulation
• This signal is divided in trials, also named epochs or
segments, where each trial is composed of points

• So, we have: 8 channels, 2000 points (for trial), and 180 trials
Biomedical Signal Processing 21

BASIC EEG ANALYSIS


To solve

• For the signal, plot the trial 120, channel 2


• Plot all the channels, separated, trial 100
• Plot the first channel, first epoch
• To obtain the space between points remember that each second 1000
samples are acquired
Biomedical Signal Processing 22

BASIC EEG ANALYSIS


Signal manipulation
• This signal is divided in trials, also named epochs or
segments, where each trial is composed of points

• So, we have: 8 channels, 2000 points (for trial), and 180 trials

To solve

• How we can change the shape of the signal to obtain a new


signal with dimensions: 8 channels, 2000 x 180 points?
• Use the numpy’s method reshape and evaluate the different options, A,
B, C, F, comparing the signal obtained (compare with the first channel
first epoch of the segmented signal)
Biomedical Signal Processing 23

BASIC EEG ANALYSIS


To solve
• For a continuous signal develop an algorithm in Python to test
if the signal is random using the following theory

• Test for randomness: Random signals are generally expected to display more
excursions about a certain reference level within a specified interval than signals that are
predictable.

• A peak or a trough is defined by a set of three consecutive samples of the signal, with the
central sample being either the maximum or minimum, respectively.

• As the direction of excursion of the signal changes at peaks and troughs, such points are
collectively known as turning points.

• A simple test for a turning point is that the sign of the first-order difference (derivative) at the current
sample of the signal be not equal to that at the preceding sample.

• Given a signal of N samples, the signal may be labeled as being random if the number of
turning points is greater than the threshold ( − 2)
Biomedical Signal Processing 24

BASIC EEG ANALYSIS


To solve
• For a continuous signal develop an algorithm in Python to test
if the signal is random using the following theory
Biomedical Signal Processing 25

BASIC EEG ANALYSIS


Signal manipulation
• The division of the signal in epochs is a common approach in
exams where a stimuli or condition is frequently repeated
Biomedical Signal Processing 26

BASIC EEG ANALYSIS


To solve
• Average all the epochs for each signal to obtain two new
signals with dimensions 58x1150

• Construct a subplot of 5x4, in each entry plot one of the last


20 channels for the average of epochs for
condicion_frecuente and condicion_infrecuente

• To obtain the space between points remember that each second 1000 samples
are acquired
Biomedical Signal Processing 27

CONTENT
1. Introduction

2. File formats

3. Montage

4. Signal manipulation

5. Basic statistics
28

BASIC EEG ANALYSIS

• A deterministic signal is one whose value at a given instant of


time may be computed using a closed-form mathematical
function of time, or predicted from a knowledge of a few past
values of the signal.

• A signal that does not meet these condition may be labeled


as a nondeterministic signal or a random signal.

• Most of the physiological signals (EEG, ECG, blood flow,


human gait, etc.) are characterize by complex dynamics
including both non-stationarities and non-linearities.
29

BASIC EEG ANALYSIS

• Although not necessary, lets introduce some DataFrame


manipulation
30

BASIC EEG ANALYSIS

To solve

Use the method pandas.DataFrame.describe and discuss the


obtained values

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.describe.html
31

BASIC EEG ANALYSIS

Types of Data

There are two main types of data: qualitative or categorical


data and quantitative or numerical data.

• Qualitative: non-numerical information such as race, gender,


marital status, etc.

• Quantitative: measurement or count such as age, salary,


height, weight, etc.
32

BASIC EEG ANALYSIS

Basic DataFrame description


All the data are numeric
33

BASIC EEG ANALYSIS

Centrality measures

One common way to summarize our numerical data is to find


out the central tendency of our data.

“What is the most typical value of the voltage in our dataset?”.


To address this question, we can use common measures of
center: mean and median.

To solve

Which is the difference between mean and median?


34

BASIC EEG ANALYSIS

Centrality measures
35

BASIC EEG ANALYSIS

Variability measures

Variation is always observed in a dataset.

The Standard Deviation (SD) is a measurement of how a set of


values spread out from their mean.

• SD is a positive number
• SD is affected by outliers
• The smallest possible value of SD is zero.
• If SD is zero, all the numbers in a dataset have the same value.
36

BASIC EEG ANALYSIS

Variability measures
37

BASIC EEG ANALYSIS

Graphical inspection

Boxplot
One approach to reveal the data distribution is to find a Five-
Number Summary from our dataset. The Five-Number
Summary includes:
• The minimum
• The 25th percentile or the first quartile (Q1)
• The median
• The 75th percentile or the third quartile (Q3)
• The maximum

To solve: What is the definition of percentile?


38

BASIC EEG ANALYSIS

Graphical inspection

Boxplot
39

BASIC EEG ANALYSIS

Graphical inspection

Boxplot
40

BASIC EEG ANALYSIS

Graphical inspection

Histogram
Is a graphical display that uses rectangular bars to show the
frequency distribution of a set of numerical data.
41

BASIC EEG ANALYSIS

Graphical inspection

Histogram
42

BASIC EEG ANALYSIS

Graphical inspection

To solve

Explore, and show examples, of others alternatives to plot and


describe the data in the DataFrame
43

BASIC EEG ANALYSIS


TEST FOR STATIONARITY

- Look at plots: scatter, histogram

- Summary statistics: mean, variance, etc

- Statistical tests: Augmented Dickey-Fuller Test


- H0: The time-series is non-stationary
- H1: The time-series is stationary
44

BASIC EEG ANALYSIS Testing procedures for non-stationarity and non-linearity in physiological signals

TEST FOR STATIONARITY


• The first simple test may be to observe the amplitude distribution.

• In most of the methods for data processing based on stochastic models,


gaussian distribution is assumed.
45

BASIC EEG ANALYSIS


Testing procedures for non-stationarity and non-linearity in physiological signals
46

BASIC EEG ANALYSISTesting procedures for non-stationarity and non-linearity in physiological signals

TEST FOR STATIONARITY

• The histograms are constructed for the first and second half of data
separately and obvious non-gaussianity could be seen during the task
performance.

• Then, we have a non-stationary signal


47

BASIC EEG ANALYSIS Testing procedures for non-stationarity and non-linearity in physiological signals

TEST FOR STATIONARITY

• The second test is based on inspection of the shape of the autocorrelation


function (ACF).

• The slow decrease of ACF for large lags indicates long-range correlation,
which may be due to non-stationarity and/or dynamic non-linearity.

• In case of non-stationarity due to additive (e.g. trend-like) components,


they could be removed in order to test the ACF on the residuals.

• If the shape of ACF remains the same, this may be a typical case of non-
stationarity.
48

BASIC EEG ANALYSIS


Testing procedures for non-stationarity and non-linearity in physiological signals

TEST FOR STATIONARITY


49

BASIC EEG ANALYSIS


TEST FOR STATIONARITY

• The possible non-linearity may be tested by the comparison of the shape


of square of ACF with that of ACF of squares of samples.

• If ( )≠( ( )) , non-linear process is suggested.

• Fig. 2 shows the plots of ACF computed for the part of the same EEG.

• The long-range correlation and different shapes of ( ) and


( ( )) suggest both non-stationarity and non-linear dynamics.
50

BASIC EEG ANALYSIS


Testing procedures for non-stationarity and non-linearity in physiological signals
51

BASIC EEG ANALYSIS


To solve

• Discuss, using all the posible graphs and data previously discussed, the
stationarity and nonlinearity in the signals in the DataFrame

You might also like