Final Project
Neenu Baby, David Diaz, Saran Phatharodom
Emails: nb74@drexel.edu, dd564@drexel.edu, sp694@drexel.edu
12/7/2011
BMES 546
Final Project
Table of Contents
Abstract: ........................................................................................................................................................................3 Definition of term: .........................................................................................................................................................3 Background: ..................................................................................................................................................................3 Problem Description: .....................................................................................................................................................3 Program Description: .....................................................................................................................................................4 Input of the system: .......................................................................................................................................................5 Output of the system: .....................................................................................................................................................5 Data Representation .......................................................................................................................................................6 Process Flow ..................................................................................................................................................................6 Preprocessing ............................................................................................................................................................7 Run FFT analysis on each epoch ...............................................................................................................................7 GUI: Step by Step .....................................................................................................................................................7 GUI Prototype .......................................................................................................................................................8 Function Assignments ...................................................................................................................................................8 Challenges .....................................................................................................................................................................9 Results ...........................................................................................................................................................................9 Conclusions and Future Work .....................................................................................................................................10 Additions/Modifications (since Presentation) ..............................................................................................................10 Function Definitions ....................................................................................................................................................11 [1] savetomat(rawdatapath,matpath) .......................................................................................................................11 [2] runanalysis(input parameters listed in Section3 GUI at 3))ASASASASA ........................................................11 [3] result = checkconsistency(rawdatapath) ............................................................................................................11 [4] Fs = readvhdr(vhdrfilepath) ...............................................................................................................................11 [5] fieldparse(input parameters listed in Section3 Gui at 4)) ..................................................................................12 [6] signaldata = readeeg.m(txtfilepath,matpath,channel) .......................................................................................12 [7] [mkNum,evType,time] = readvmrk.m(vmrkfilepath) ........................................................................................12 [8] pnum = getperiodnum(periodendtime,currentperiod,time) ................................................................................13 [9] meanFFT = meanperiod(FFTepoch,periodNum,periodTotal) ...........................................................................13 [10] writefft(savefilename, outputbody, outputbodymean) .....................................................................................13 [11] plotfft(savefilename,expNum) .........................................................................................................................13 [12] [chName, chNum, totalChNum] = getchinfo(rawdatapath,chInput) ...............................................................13
BMES 546
Final Project
Abstract:
The project goal is to apply Fast Fourier Transform (FFT) analysis on specific time intervals of signal data from experiments that use electroencephalograpy (EEG) recordings. Each time interval consists of time periods before (pre) and after (post) the event of stimulus. Only the user-specified time intervals will be extracted for FFT analysis of each interval. Event marker data is given along with the EEG signal to mark the time of the stimulus event. There are 64 channels recording for each experiment result. The program should be able to perform FFT analysis on specified channels, at specified time intervals with a given maximum frequency. The program also divides a specific experiment (or EEG reading session) into a certain number of periods, chosen by the user. Then, the average of the FFT output within each period will be calculated, printed and plotted to compare the change in frequency spectrum throughout the progression of the experiment.
Definition of term:
Epoch: A time interval consisting of time intervals prior to and after an stimulus Period: One experiment is evenly divided into N-period based on time, where N is specified by the user input.
Background:
EEG is a test that measures and records the electrical activity of brain. EEG generally has complex characteristics and has a great significance in brain research and clinical. This motivated for the early introduction of signal analysis methods to EEG studies. EEG processing using spectral methods started with the first attempt of Fourier analysis application to EEG in 1932.
Figure 1: Example of EEG signal data of a channel and its transformation from time domain to frequency domain after applying FFT
The above graphs show the representation of the important fields that need to be extracted from the three data files (TXT, VMRK, and VHDR) of each experiment. The maximum (cutoff) frequency, the time intervals and event markers for both the event stimulus and event response, as well as the channel number and the Epoch are all important parameters that will be specified by the users as inputs to our program and will be used for specific data parsing and analysis (as indicated above).
Problem Description:
Fast Fourier transform (FFT) was used in EEG signal processing soon after its introduction. Even today, this method remains the most widespread method in EEG signal processing. The data used in this project
BMES 546
Final Project
contain three types of files generated by commercial software while recoding EEG signals. The recordings are used to test the responses of individuals with specific impairments (i.e dyslexia) and compare them to responses from individuals not suffering from the ailment/disorder in an attempt to better understand the expression of the disorder(s) and the similarities/differences between the two groups. Each experiment has data recorded from 64 channels. The problem is that, as of now, there is no current standard platform on which to analyze the specific frequency data from experiments using EEG recordings. The data can be analyzed more effectively if there is a way for analyzing the data from user specified channels. Therefore the goal of this project is to provide a way for EEG data collected in the time domain to be visualized in the frequency domain using the information in the three types of data files. The program will also allow researchers to specify channel and time interval information in order to obtain a more specific analysis of the specific stimulus.
Program Description:
The program will be taking inputs from the user and showing plot(s) in response to the user request for investigation and further adjust input parameters (e.g. requested channel number, time interval length, number of periods, etc.)
Figure 2: EEG signal with five periods (Left) and their respective average FFT plot (Right)
Implementation: (The process could be divided into three phases.) (1) Phase I Pre-processing (Use: I/O, string parsing, save Matlab variable, GUI) Since the raw data is in text file format and each column contains signal data for each EEG channel. Usually only signals of a few channels will be inquired. To improve speed of reading time, reading and saving the data as Matlab variables (binary format) would speed up columns reading. (2) Phase II FFT analysis (Use: I/O, string parsing, vector indexing, GUI) Information will be extracted from filenames and file contents. FFT analysis and averaging will be performed on signals for requested channels. Selecting data for selected period using vector indexing. Output will be written to files. (3) Phase III Post-processing (Use: I/O, plot) Plot will be shown. User will be able to call up the plot for each experiment in order to compare multiple experimental tests.
BMES 546
Final Project
All the files of EEG recording for all experiments of a study are in one folder to be analyzed. For each of the experiments, there are 3 files with the same filename but different file extensions. 1. .txt contains EEG signal data for all 64 channels. (The largest file of all three types) 2. .vmrk contains event marker information (event type and time of occurrence) 3. .vhdr contains system parameters (constant for each experiment), which are sampling frequency, channel positions, channel numbers and channel names.
Two .csv files (will be imported to SPSS program for further statistical analysis) 1. Output file containing each selected epoch, for all experiments within a study 2. Output file containing average FFT values within each period, for all experiments within a study Plot of average FFT values within each period, for each experiment. However, the user would probably select to show some but not all experiment, e.g. one every five experiment, show the plot.
BMES 546
Final Project
Data Representation
Process Flow
Figure 5: Flow chat describing the entire program: input and output system
BMES 546
Final Project
Preprocessing
(Optional) read each .txt file and save the data as MATLAB variable in binary format. Since the raw data is in text format and data of interest are in column-wise, data parsing time could be long. To minimize the paring time, we could store the data in MATLAB variable. It should be faster due to binary file reading and column-wise data parsing within MATLAB protocol. The drawback is the extra space taken, since the file size of .txt EEG signal data file is large. Note that the program will run analysis on each channel, thus it will read a column each time the analysis is run. Called functions: (1) savetomat.m
Final Project
Function Assignments
Figure 6: Main sections of the program. Each section has one to several functions. The color code in the function shows the division of work
BMES 546
Final Project
Challenges
1. The most challenging parts of the code were the lengthy debugging process and making sure all the variables matched the assignments by all three different authors. 2. Another challenge was working with big files with 60+ mb each and reading only one of the many columns. We solved it by using .mat version of the txt files and saving data for each column to one variable so that we could load each variable for respective columns. 3. Naming the variables and functions with small and easily understanding names. Also having consistency in the variable and function names used in different parts of the program was also an issue. 4. Coming up with the possible input errors the users can make in order to raise the error warning dialogues. For solving this problem, an inbuilt function called try&catch was used which is able to lump all the error dialogues. However, this solution has a disadvantage that the function generalizes the error. This will lead to display inappropriate error messages in some situations. 5. Another challenge in error handling was to decide whether the GUI or the individual functions should raise the error dialogue boxes. Finally, we end up dividing these tasks between the GUI and individual functions.
Results
The result of the program will output two excel file, output and mean of the output, and the plot of the result obtained. Following figures shows the examples of the output and mean output files.
In the figure shown above, the first four columns, A to D, are the result obtained from parsing option in the GUI. This function is optional and the user has the freedom to choose what information he/she wants to parse. For this reason, information in those columns is subjected to changes according to the user preferences. The information in columns E to L shows the channel name, period number, marker number, stimulus types, response type, response time and FFT data obtained, where the frequency goes from 1 to upper bound frequency chosen by the user. The following figure shows the output file for mean FFT obtained. Columns A to D will not be different from from the output csv file. The rest of the columns show the channel number, period number (1 to the period total), sample size (number of samples in the period) and the mean FFT data.
BMES 546
Final Project
Figure 8: : First four lines of the csv file with mean of the output obtained
Finally, the program also will output the plot of the average FFT of epochs in each periods specified by the use. Following figure is an example of such a plot.
BMES 546
Final Project
Function Definitions
[1] savetomat(rawdatapath,matpath)
The only input argument for this function is the rawdatapath or the folder where all the raw data for the experiments is located. The program will run through all the .txt files in the folder and check if .mat for each file exists in the matpath folder. If the .mat file exist, the function will skip to the next file. If not, the function will import the EEG signal data from the .txt file and read a matrix of Nx64 (N = number of data points, 64 channels). Finally, the function will save the Nx64 matrix to a binary format (.mat) into the matpath folder, using the save function. This function is invoked by the GUI preprocessing button.
[4] Fs = readvhdr(vhdrfilepath)
The input argument of the function is the vdhr file path and the output argument is the sampling frequency. The program will find the sampling frequency given in the vdhr file. Then it will run through vhdr given to see if data type is in time domain or frequency domain using regular expression. If data type is in time domain, sampling frequency will be (10^6)/sampling Interval, else if data type is frequency domain, sampling frequency will be sampling Interval captured.
BMES 546
Final Project
BMES 546
Final Project
[11] plotfft(savefilename,expNum)
This function takes an output filename as a string (savefilename), and the ith experiment number as an integer (expNum), and plots the mean of the FFT data. The function reads the mean FFT data from "(savefilename)mean.csv", which is located in the "Result" folder. The expNum is used to index the desired experimental test to be plotted.
BMES 546
Final Project
be either channel name (string) or channel number (positive integer). The function returns the specified channel name and number as well as the total number of channels.
[13] isposnum(num,isInt,inputname)
If (isInt) is true, the function checks if the input string (num) is a string of a positive integer. If (isInt) is false, the function checks if the input string is a string of a non-negative number. The function will raise an error dialog box if the condition above is false. It will show an error dialog box with the (inputname) string passed on in the title. If (inputname) is not given, error dialog box title would not add additional information of (inputname). If (isInt) is not given, (isInt) will be false by default.