Giter Site home page Giter Site logo

mhmohassan / eeg-signal-analysis-using-machine-learning Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lep13/eeg-signal-analysis-using-machine-learning

0.0 0.0 0.0 381 KB

This project uses machine learning algorithms to analyze EEG signals and identify patterns and abnormalities for improved diagnosis and treatment of neurological disorders. It involves pre-processing EEG data, feature extraction, and applying ML models to classify signals into different categories.

Jupyter Notebook 100.00%

eeg-signal-analysis-using-machine-learning's Introduction

EEG-SIGNAL-ANALYSIS-USING-MACHINE-LEARNING

This project uses machine learning algorithms to analyze EEG signals and identify patterns and abnormalities for improved diagnosis and treatment of neurological disorders. It involves pre-processing EEG data, feature extraction, and applying ML models to classify signals into different categories.

TOPIC:

EEG SIGNAL ANALYSIS USING MACHINE LEARNING IN JUPYTER NOTEBOOK

OBJECTIVES:

  1. To study brain activity using EEG sensors
  2. To detect and filter Raw EEG signals for analysis
  3. To analyse the signals and be able to specify whether the testing signal is normal or not
  4. To plot and analyse signals in the frequency and time domain
  5. To investigate characteristics and power of the signal

INTRODUCTION:

The classification and detection of cerebral diseases at early stages are vital tasks for patients in receiving proper treatment and being protected from significant mental decline EEG, which is short for Electroencephalogram, plays a dominant role in diagnosis and management of patients with epileptic disorders because it is a convenient and relatively inexpensive method to demonstrate the physiological manifestations of abnormal cortical excitability that underlie epilepsy. It measures the electrical activity in the brain using small metallic discs attached to the scalp. The EEG signal is normally a function of time and represents voltage fluctuations resulting from ionic current within the neurons of the brain. Epilepsy is a central nervous system disorder in which brain activity becomes abnormal, causing seizures or periods of unusual behaviour. EEG contributes to the determination of seizure type and epilepsy syndrome in patients with epilepsy, as well as choice of medication.

THEORETICAL BACKGROUND:

I. Electroencephalography (EEG): EEG is a medical monitoring technique that records scalp electrical activity generated by brain structures. The electroencephalogram is defined as electrical activity recorded from the scalp surface after being picked up by metal electrodes and conductive media. The waveforms of the brain patterns are usually sinusoidal and the patterns are measured from peak to peak with amplitude that ranges from 0.5 to 100 μV.

II. Epilepsy: Epilepsy, also known as seizure disorders, is one of the fourth most common cerebral diseases [68] and afflicts approximately 1% of the world population. There are more than 40 different types of seizures. A person with epilepsy might go through one or few types of seizures One typical feature of seizure EEG signal is that it usually involves spikes and sharp waves, which are transient high voltage waveforms and can sometimes be considered as an indication of seizure

III. Role of EEG in Epilepsy Detection and Treatment: The classification and detection of cerebral diseases at early stages are vital tasks for patients in receiving proper treatment and being protected from significant mental decline. EEG plays a dominant role in diagnosis and management of patients with epileptic disorders. Specifically, as a neurophysiological biomarker, EEG contributes to the determination of seizure type and epilepsy syndrome in patients with epilepsy, as well as choice of medication. Although the final diagnosis of epilepsy is usually based on thorough and professional medical examination, EEG is still considered as a useful tool because of the supportive evidence of epilepsy it provides.

IV. Methods used for Epileptic EEG Analysis:

1 Fast Fourier Transform: is an algorithm that computes the discrete Fourier transform (DFT) of a sequence and enables signal analysis such as power spectrum. If it is a

continuous waveform that needs to be analysed, it is necessary that the data be sampled at equally spaced intervals of time in order to present the data as a time series of discrete samples (Nyquist Rate).

2 Wavelet Transform: is a signal processing approach that decomposes a function or a signal into a set of functions which consist of contractions, expansions and translations of a mother function ψ(t), called the wavelet. The wavelet transform can be regarded as an extension of the Fourier transform. There are two main categories of wavelet transform, continuous wavelet transform (CWT) and discrete wavelet transform (DWT). The main difference between the two types of wavelet transform is that CWT uses infinite wavelets corresponding to infinite numbers of scales and locations, but DWT uses a finite number of wavelets.

MATERIALS REQUIRED:

  1. EEG Sensor
  2. Connecting wire
  3. Computer Control Module
  4. Display Device
  5. Amplifiers

EEG SENSOR:

EEG sensors are placed on a participant’s head. Then the electrodes non-invasively detect brainwaves from the subject. These sensors can record up to several thousands of snapshots of the electrical activity generated in the brain within a single second. image image

Software Stack

  1. EEG Dataset: MNE Module in Python specifically caters to EEG analysis. It is a software package that provides comprehensive analysis tools and workflows like time- frequency analysis, pre-processing etc It also includes data sets for sensors such as Magnetoencephalography (MEG), Electrooculogram (EOG), EEG etc. For this project we have only utilised the data given for EEG.

  2. Applications used: Using Machine Learning on Jupyter notebook and Python Programming language for EEG analysis.

  3. Modules used:
    Matplotlib for plotting graphs,
    NumPy for handling data,
    Pandas for extracting and handling files,
    MNE for extracting data sheet

WORKING:

image

The main steps followed are:

  1. Uploading EEG data set
  2. Finding positions of the sensors
  3. Filtering Raw EEG signal using FIR Filters
  4. Slicing continuous data into several small-time segments (epochs) for discrete data analysis

Signal Filtering:

Signal filtering is essential and is considered as the fundamental step for EEG analysis. It is crucial to perform signal filtering in order to smooth out random high frequency noises. Noises with high frequencies are considered as additive to the signal and are uncorrelated in time. Shown below are the graphs of Raw EEG signal (LHS) and Filtered EEG signal (RHS). A bandpass filter is set up with frequency range from 0.1Hz-40Hz, which is made up of a Low Pass Filter (cut off 0.1Hz) and High Pass Filter(40Hz) in cascade.

A finite impulse response filter or FIR Filter is a filter whose impulse response is of finite period. The impulse response of an Nth order discrete time FIR filter takes precisely N+1 samples before it then settles to zero. FIR Filter Analysis: Designing a one-pass, zero-phase, non-causal bandpass filter:

Hamming window with passband ripple: 0.0194 and stopband attenuation: 53dbl;
Lower passband edge: 0.10;
Lower Transition Bandwidth: 0.10;
Upper passband edge: 40.0Hz;
Upper Transition Bandwidth: 10.0Hz;
Filter Length: 19821 samples (33.001sec)

A Patient Specific Direction or PSD is an instruction to administer a medicine to a list of individually named patients on a list.

FREQUENCY ANALYSIS:

We start by exploring the frequency content of our epochs by analysing auditory brain signals. The auditory cortex is the part of the human brain that processes auditory information like sounds, voices or music. It receives inputs from the subcortical auditory pathways in the brainstem and thalamus. A growing number of studies indicate that multiple ranges of brain oscillations in the auditory cortex, especially the delta (δ, <4Hz), theta (θ, 4-8Hz), beta (β, 13-30Hz), and gamma (γ, 30-50Hz) bands, are engaged in speech and language processing.

TIME-DOMAIN ANALYSIS:

At any point of time, the power with respect to that point can be found.

TIME-FREQUENCY ANALYSIS:

When we perform time-frequency analysis, we are performing a moving window Fast Fourier Transform. The FFT returns Fourier coefficients for each combination of time and frequency - complex numbers with real and imaginary components that describe a position in a two-dimensional plane. These complex numbers represent both the magnitude and the phase of the signal.

Inter-trial coherence (ITC) is a measure that is computed from single trial EEG, which reflects the temporal and spectral synchronization within EEG. It is a measure of how consistent oscillatory phase is across an ensemble of trials.

SOURCE ESTIMATION

First, the necessary libraries are imported such as matplotlib, pathlib, mne_bids, and mne. These libraries are used for data manipulation, analysis, and visualization.

The bids_root directory path is specified where the raw data is stored in BIDS format. The BIDSPath function from mne_bids is used to define the specific path to the raw data file for subject 01, session 01, task audiovisual, run 01, and datatype meg.

The raw data is read using the read_raw_bids function and then filtered between the frequency range of 0.1 and 40 Hz.

The events are extracted from the raw data using the events_from_annotations function and specified time windows.

The epochs are then created by using the Epochs function, which segments the raw data into epochs using the event markers defined in step 4.

The epochs are then saved to a file, and information about the data is displayed using the info function.

The BEM model for the subject's brain is plotted using the plot_bem function from mne.viz.

The forward solution for the MEG data is read using the read_forward_solution function from mne.forward. The forward solution is then restricted to only MEG data using the pick_types_forward function.

Next, an inverse operator is created using the make_inverse_operator function from mne.minimum_norm, and then the inverse operator is saved using the write_inverse_operator function.

The apply_inverse function is used to calculate the source estimation using the dSPM method for the 'Auditory/Left' condition of the epochs. The lambda2 value is calculated based on the snr value, which is set to 3.

Finally, the source estimation is plotted using the plot function of the stc object, which was generated from the apply_inverse function.

In summary, this Jupyter Notebook code uses the MNE Python package for processing and analyzing MEG data. It reads the raw data from a BIDS formatted file, creates epochs, and applies an inverse operator to calculate the source estimation of the MEG data. It also provides a visualization of the source estimation on the subject's brain surface.

CONCLUSIONS:

  1. Obtained Power Spectrum of EEG Signals using different types of analysis.
  2. Filtered Raw Signal using FIR-BPF filter.
  3. Used Fast Fourier Transform for obtaining Power Distribution
  4. Converted continuous data to discrete for analysis by converting data into epochs

eeg-signal-analysis-using-machine-learning's People

Contributors

lep13 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.