Technology

Dynamic Bayesian Networks for EEG Motor Imagery Feature Extraction

1- Introduction

Brain-computer interface (BCI) is an interaction between the human brain and computer that enables the brain to control something just by thinking, The interface enables direct communications between the brain and the object to be controlled.

BCI provides people with motor disabilities another chance to control their environment, recording the signals on the sensorimotor cortex is very efficient in developing such applications. BCI can enable a person suffering from paralysis to write a book or control a motorized wheelchair or prosthetic limb through thought alone. (reference here).

a lot of research and experiments were done to achieve this goal control something only by thinking about it. This paper explains one of the experiments to use Dynamic Bayesian Networks for EEG Motor Imagery Feature Extraction. The title seems a bit technical but through this blog post, we will go into more details to understand how the brain-controlled wheelchair works and the impact of using DBNs on enhancing the results.

Recording brain signals
There are two popular ways of recording brain activity
1- Invasive: By implanting a chip into the subject’s brain, this gives very high signal accuracy.

https://mindmatters.ai/2021/06/can-implanted-computer-chips-cure-depression/


2- Non-Invasive: Neuroimaging technologies as interfaces to record brain signals without surgeries. although it provides poor signals quality compared to invasive but it is very good for development projects

https://hal.inria.fr/hal-00688344/documen
https://www.bitbrain.com/blog/wet-eeg-cap

Brain Controlled Wheelchair

1- Data Acquisition: Recording the EEG signal which represents the brain activity when the subject does motor imagery action.
Brain oscillations are categorized according to specific frequency bands (delta: < 4 Hz, theta: 4 – 7 Hz, alpha: 8 – 12 Hz, beta: 12 – 30 Hz, gamma: > 30 Hz).
2- Pre-Processing: Applying filters to the recorded data to filter the input signals into several ranges and remove any unwanted noise.
3- Feature Extraction: Which EEG electrode value is relevant to the right or left movement action and which frequency band should be used.
4- Classification: applying classifiers to classify the new trial as left or right action that is then translated to control signal to the wheelchair.

Brain Controlled Wheelchair working diagram (photo reference here)


2- Using DPN to enhance left and right imagery movement discrimination

Dynamic Bayesian Networks
Before answering this question we need to understand the Bayesian Networks.
Bayesian Networks are a type of Probabilistic Graphical Model that can be used to build models from data (reference here)
This demo demonstrates the Bayesian Network showing the impact of changing evidence on other probabilities.
Dynamic Bayesian Networks extend the Bayesian network with the concept of time, which can be used to detect causal relations in multivariate systems.

In this paper, DBNs are used to model the statistical dependencies between different electrodes during right and left hands imagery movement. it examines how the inferred connectivity between different electrodes could be used as a new feature for motor imagery movement classification. it utilizes a Support Vector Machine (SVM) as a classifier that uses features extracted from both the inferred connectivity and the band power of different electrodes.
In DPNs
Nodes -> represents EEG Electrodes
Edges -> Statistical causal dependency

Proposed approach for using DBNs (reference here)

A- Dataset (Concatenating Trials)
BCI competition 2008 – Graz A dataset (BCIIV2a) which consists of EEG data recorded from 9 subjects. each subject was recorded using 22 electrodes for 4 different motor imagery tasks: right hand, left hand, both feet, and tongue movements.
In this experiment, we are only interested in left and right-hand movements.

B- Data Pre-processing
1- Common Average Reference (CAR) is used to cancel the noise that may have occurred from all channels
2- 6th order Butterworth band-pass filter to filter the input signals in 7 different bands: 7-13Hz, 18-25Hz,
25-35Hz, 35-45Hz, 35-50Hz, 45-55Hz, and 55-65Hz. The ranges include the Alpha, Beta, and Gamma bands that have been demonstrated to be correlated with motor imagery tasks/ actions

https://www.researchgate.net/figure/Common-bands-in-EEG-signal-and-example-of-filtered-wave_fig5_305370349

C- Dynamic Bayesian Networks
Dynamic Bayesian Network (DBN) is a graphical representation that models the statistical dependencies between a given set of variables
G -> The graph represents the statistical dependency between variables.
V -> The nodes which represent the input variables which are denoted by ei(t) it represents the
preprocessed signal of electrode i at time t
E -> The set of connections, where each connection represents the existence of statistical dependency between the connected pair of variables.
P -> set of conditional probabilities for the dependencies between nodes measured at different time lags.

DBN models the conditional probability of the state of electrode ei(t) given the state of other electrodes that have a direct influence on it at the selected time lag which can be represented by P(ei(t)|eπ ( i) (t -1)), where eπ(i) is the set of electrodes that have a direct statistical influence on ei.

EEG Data discretization
It is transforming continuous EEG signals into 5 discrete levels using the quantile discretization method, which quantizes the data points based on their underlying distribution. This method can eliminate the impact of outliers in the data.

The DBN output for each trial is an n × n binary matrix N, where ‘n’ is the total number of electrodes and each element N(i, j) takes the value 0 or 1 to represent the existence or absence of connectivity from electrode i to j, respectively. Networks inferred from all trials are then concatenated to form a matrix of size T × n2, where T -> represents the total number of trials.
D -> represents T × n2

In This experiment the result matrix was of size 24 x 484 for each class the two matrices of the two classes are concatenated to form a single matrix 48 x 484

D- Dimensionality Reduction
Principal Component Analysis (PCA) is a classical technique in statistical data analysis, feature extraction, and data reduction. Given a set of multivariate measurements(D), the purpose is to find a smaller set of variables with less redundancy that maximize the variance in the network data.

This was used to extract the most relevant features from the 484 features representing the connectivity between electrodes for each trial.

The result will be Dpc[14]

E- Band Power Features Extraction
Only the most 4 relevant electrodes were selected 8,14,12,18 and only the 7-13 Hz band was considered because it has been shown that it acheives the best descrimination between movements.
P-> matrix with only 4 features representing the power in the 7-13 Hz band for electrodes 8, 14, 12 and 18

F- Classifier
Support Vector Machine (SVM) with radial basis function (RBF) kernel function.
SVN main idea is to transform the data into higher dimensional space so that it is linearly separable (reference here). The accuracy of the classifier was calculated based on the mean of the 10 iterations. using cross-validation.

3- Results

A- Frequency-band for Connectivity Features

Based on the figure below the connectivity feature generated by DBN has been inferred in the alpha band in the range 7-13Hz resulting in the best classification accuracy with an average of 60±14%, followed by the beta band in the range 18-25Hz with an average of 55±7%. These results are consistent with previous reports that indicated the significance of these two bands in motor imagery tasks

photo reference (here)

B- Combining Band Power and Connectivity Features

This figure shows that using the power band features and the connectivity features generated by DBNs has improved the classification results.
To compare the results to the results reported by the BCI competition IV, the kappa value was computed for the confusion matrix obtained for each subject. kappa of 0.502 as the mean was obtained which is comparable to the winners of the competition. In addition, the kappa value obtained for each subject is consistent with the kappa values reported by the competition winners.

photo reference (here)

4- Conclusion

Although using DBN connectivity feature has improved the classification result among two movements. but more analysis is still required to assess the relationship between inferred connections and the underlying brain dynamics in addition to analyzing the performance for more than two imagery tasks

Installing OpenWRT on a Raspberry Pi from Ubuntu!

Create Boot SD Card

  • Download OpenWrt Linux distribution for Rpi from here
    – Choose the image according to the amount of RAM you want to give to the system (_128, _192, _224) or according to the Pi memory size, if 256MB choose the _128 else you can choose _192 or _224
  • Flash Rpi SD Card
    * Format the SD Card using the Disk Utility application in Ubuntu (Select your SD card and format as FAT)
    * Identify the SD card card
                          sudo fdisk -l
    you will see something like this
    aa
    So, the SD card is /dev/sdb1 (if unsure of your computer’s naming convention, run prior to inserting SD then again after to identify mounted card)
    OR
    use df -h command 
    bb
    *
    Flash the SD card
                          cd Downloads/
                           replace “Downloads” with the location of the downloaded .img file
                                 
                          un mount the SD card   
                          umount /dev/sdb1

                          write the image to the SD card
                           sudo dd if=openwrt-raspi.img of/dev/sdb1 bs=2M
                           replace “openwrt-raspi.img” with the img name, and “/dev/sdb1” with the device name detected from “fdisk -l” or “df -h”. The process of flashing the SD card will take around two or three minutes. Once the SD card has been flashed, you will see a further message in the terminal window.When “dd” finish writing the image to the SD card a message showing the number of bytes copied and the copying rate will appear indicating the end of flashing process.* Unmount the SD card and it is now ready for use in your Raspberry Pi.

           -if you are windows 7 user follow the instructions in this link-

Boot the Pi

  • Insert the SD card and plug in the power —more details here (Skip installing new distribution, startx command won’t work too)–

HTML5/CSS3 beginners tutorial

This tutorial is to explain some HTML5/CSS3 basics

we used to use HTML, CSS and JS to create interactive and media based websites. HTML5 provides more tags to make creating interactive websites an interesting easy process.

To start you need

  1. Text editor
  2. web browser

HTML5 provide better development experience as instead of using tables or divs to layout web pages, it provides more tags like header, footer, nav, ….. which represent the main logical parts of any website

html5

  • lets start our first HTML5/CSS3 web-page

Like any HTML page it has 2 main parts head and body

onehead-onebodyso the head of our page will be

<head>
    <meta charset="utf-8" />
    <title>HTML5  </title>
    <link rel="stylesheet" href="layout.css"></link> <!--we will see layout.css later-->
</head>

if you previewed this code in your browser you won’t see anything except the page title! let’s continue by filling the page body with some content

<body>
    <div id="big_wrapper">
        <!--where most of the stuff goes-->
        <!-- header has the logo name, ... -->
        <header  id="top_header">
            <h1>Welcome to IEEE</h1>
        </header>
        <!--navigation is the menu that takes you every where in the site-->
        <nav id="top_nav">
            <ul>
                <li>Home</li>
                <li>News</li>
                <li>About</li>
            </ul>
        </nav>
        
        <!--the main info about your weaite-->
        <section id="main_sec">
            <!--a way to group similar info together--->
            <article>
                <header>
                    <hgroup>
                        <h1>new title in this article 111</h1>
                        <h2>more details later</h2>
                    </hgroup>
                </header>
                <p>
                    new article in this page!
                </p>
                <footer>
                    <!--we can see more aw ay 7aga baseta--->
                    <p>written by IT team</p>
                </footer>
            </article>
            
            <article>
                <header>
                    <hgroup>
                        <h1>new title in this article 222</h1>
                        <h2>more details later</h2>
                    </hgroup>
                </header>
                <p>
                    new article in this page!
                </p>
                <footer>
                    <!--we can see more aw ay 7aga baseta--->
                    <p>written by IT team</p>
                </footer>
            </article>
        </section>
        <!--the side bar is used for news or shortcuts-->
        <aside id="side_news">
            <h3>news feed</h3>
            IEEE is learning new staff
        </aside>
        <!--footer is where copyrights are written or company info-->
        <footer id="down_footer">
            Copyright IEEE IT Team !
        </footer>
    </div>
</body>

download file

Read the above script carefully and check the comments to know the function of each HTML5 tag.

  • Let’s style this page using traditional box model


*{
    margin: 0px;
    padding: 0px;
}/*to avid errors due to default values of some elements and '*' is used to style all tags*/
/*change h2 and h2 styling defaults*/
h1{
    font: bold 20px Tomoha;
}
h2{
    font: bold 14px Tomoha;
}
/*to make sure HTML5 tags are working in the same way across all browsers*/
header, section, article, aside, footer, naw, hgroup {
    display:block;
}
/*to avoid errors with older browsers -centralize the website-*/
body{
    text-align: center;
}
#big_wrapper{
    /*centralize the website and fix text alignment*/
    border: 1px solid black;
    width: 1000px;
    margin: 20px auto;
    text-align: left;
    /*end of centralization*/
}
#top_header{
    background: yellow;
    border: 1px solid blue;
    padding: 20px;/*padding: distance inside the border, margin: distance out side the border*/
}

#top_nav{
    background: blue;
    color: white;
}


#top_nav li{
    /*to be previewed beside each other not over each other*/
    display: inline-block;
    list-style: none;
    padding: 5px;
    font: bold 14px Arial;
}
#main_sec {
    float: left;
    width: 660px;
    margin: 30px;/*720px, 280 left*/
}
#side_news{
    float: left;
    width: 220px;
    margin: 20px 0px;
    padding: 30px;
    background: #66cccc;
}
#down_footer{
    clear: both; /*remove any floating options*/
    text-align: center;
    padding: 20px;
    border-top: 2px solid green;
}
article {
    background: #FFFBCC;
    border: 1px solid red;
    padding: 20px;
    margin-bottom:  15px;
}
article footer{
    text-align: right;
}

  download file

here you have to read the comments carefully too to understand what is going on

the output will look like that ^_^

Screenshot from 2014-02-16 20:53:54this is enough for this tutorial next we will try flexible box model instead of the traditional one !