├── Web App
├── READ ME.txt
├── img
│ ├── home.PNG
│ ├── ica
│ │ ├── 1.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ ├── 2.png
│ │ ├── 3.png
│ │ ├── 4.png
│ │ ├── 5.png
│ │ ├── 6.png
│ │ ├── 7.png
│ │ ├── 8.png
│ │ └── 9.png
│ ├── swt
│ │ ├── a5.png
│ │ ├── d2.png
│ │ ├── d3.png
│ │ ├── d4.png
│ │ └── d5.png
│ ├── class
│ │ ├── ha.PNG
│ │ ├── hv.PNG
│ │ ├── la.PNG
│ │ ├── lv.PNG
│ │ ├── hahv.PNG
│ │ ├── halv.PNG
│ │ ├── lahv.PNG
│ │ └── lalv.PNG
│ ├── fft
│ │ ├── alpha.png
│ │ ├── beta.png
│ │ ├── delta.png
│ │ ├── gamma.png
│ │ └── theta.png
│ ├── raw_data
│ │ ├── 1.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ ├── 2.png
│ │ ├── 3.png
│ │ ├── 4.png
│ │ ├── 5.png
│ │ ├── 6.png
│ │ ├── 7.png
│ │ ├── 8.png
│ │ └── 9.png
│ └── emotiv_channel.png
├── input.txt
├── css
│ ├── accuracy.css
│ └── dashboard.css
└── cgi-bin
│ ├── index.py
│ ├── input_predict.py
│ └── find_accuracy.py
├── Data Processing
├── Classification
│ ├── getTwoClass.m
│ ├── getDatasets.m
│ ├── getDatasetsPrediction.m
│ ├── separateClass.m
│ ├── separateClassPrediction.m
│ ├── predictClassification.m
│ ├── doAccuracy.m
│ ├── kNN.m
│ ├── saveDatasets.m
│ ├── findAccuracy.m
│ └── getPrediction.m
├── Global Code
│ └── createFolder.m
├── Preprocessing
│ ├── ownFFT.m
│ ├── computeICAPredict.m
│ ├── ownSWT.m
│ ├── pca_ica
│ │ ├── myCenter.m
│ │ ├── myWhiten.m
│ │ ├── myCenterAndWhiten.m
│ │ ├── myMultiGaussian.m
│ │ ├── demo_PCA1.m
│ │ ├── demo_ICA.m
│ │ ├── demo_PCA2.m
│ │ ├── myPCA.m
│ │ └── myICA.m
│ ├── preProcessingPredict.m
│ ├── computeICA.m
│ ├── ownFastICA.m
│ ├── preProcessing.m
│ ├── computeSWTPredict.m
│ ├── computeFFTPredict.m
│ ├── computeSWT.m
│ └── computeFFT.m
├── Process Data
│ ├── processData.m
│ ├── cutDataPredict.m
│ ├── cutData.m
│ └── divideFiveSeconds.m
└── Statical Analysis
│ ├── statisticalAnalysis.m
│ ├── correlation.m
│ ├── processCorrelation.m
│ └── absolute.m
├── .gitattributes
├── .gitignore
└── README.md
/Web App/READ ME.txt:
--------------------------------------------------------------------------------
1 | python -m CGIHTTPServer 8080
--------------------------------------------------------------------------------
/Web App/img/home.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/home.PNG
--------------------------------------------------------------------------------
/Web App/img/ica/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/1.png
--------------------------------------------------------------------------------
/Web App/img/ica/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/10.png
--------------------------------------------------------------------------------
/Web App/img/ica/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/11.png
--------------------------------------------------------------------------------
/Web App/img/ica/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/12.png
--------------------------------------------------------------------------------
/Web App/img/ica/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/13.png
--------------------------------------------------------------------------------
/Web App/img/ica/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/14.png
--------------------------------------------------------------------------------
/Web App/img/ica/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/2.png
--------------------------------------------------------------------------------
/Web App/img/ica/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/3.png
--------------------------------------------------------------------------------
/Web App/img/ica/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/4.png
--------------------------------------------------------------------------------
/Web App/img/ica/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/5.png
--------------------------------------------------------------------------------
/Web App/img/ica/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/6.png
--------------------------------------------------------------------------------
/Web App/img/ica/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/7.png
--------------------------------------------------------------------------------
/Web App/img/ica/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/8.png
--------------------------------------------------------------------------------
/Web App/img/ica/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/ica/9.png
--------------------------------------------------------------------------------
/Web App/img/swt/a5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/swt/a5.png
--------------------------------------------------------------------------------
/Web App/img/swt/d2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/swt/d2.png
--------------------------------------------------------------------------------
/Web App/img/swt/d3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/swt/d3.png
--------------------------------------------------------------------------------
/Web App/img/swt/d4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/swt/d4.png
--------------------------------------------------------------------------------
/Web App/img/swt/d5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/swt/d5.png
--------------------------------------------------------------------------------
/Web App/img/class/ha.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/ha.PNG
--------------------------------------------------------------------------------
/Web App/img/class/hv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/hv.PNG
--------------------------------------------------------------------------------
/Web App/img/class/la.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/la.PNG
--------------------------------------------------------------------------------
/Web App/img/class/lv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/lv.PNG
--------------------------------------------------------------------------------
/Web App/img/fft/alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/fft/alpha.png
--------------------------------------------------------------------------------
/Web App/img/fft/beta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/fft/beta.png
--------------------------------------------------------------------------------
/Web App/img/fft/delta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/fft/delta.png
--------------------------------------------------------------------------------
/Web App/img/fft/gamma.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/fft/gamma.png
--------------------------------------------------------------------------------
/Web App/img/fft/theta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/fft/theta.png
--------------------------------------------------------------------------------
/Web App/img/class/hahv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/hahv.PNG
--------------------------------------------------------------------------------
/Web App/img/class/halv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/halv.PNG
--------------------------------------------------------------------------------
/Web App/img/class/lahv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/lahv.PNG
--------------------------------------------------------------------------------
/Web App/img/class/lalv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/class/lalv.PNG
--------------------------------------------------------------------------------
/Web App/img/raw_data/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/1.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/10.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/11.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/12.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/13.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/14.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/2.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/3.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/4.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/5.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/6.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/7.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/8.png
--------------------------------------------------------------------------------
/Web App/img/raw_data/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/raw_data/9.png
--------------------------------------------------------------------------------
/Web App/img/emotiv_channel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nadzeri/Significant-Preprocessing-Method-In-EEG-Based-Emotion-Classification/HEAD/Web App/img/emotiv_channel.png
--------------------------------------------------------------------------------
/Web App/input.txt:
--------------------------------------------------------------------------------
1 | people are not as beautiful as they look,
2 | as they walk or as they talk.
3 | they are only as beautiful as they love,
4 | as they care as they share.
--------------------------------------------------------------------------------
/Data Processing/Classification/getTwoClass.m:
--------------------------------------------------------------------------------
1 | function [datasets,label] = getTwoClass(datasets,label)
2 | idx = (label(:)~=2);
3 | label = label(idx);
4 | datasets = datasets(idx,:);
5 | end
--------------------------------------------------------------------------------
/Data Processing/Classification/getDatasets.m:
--------------------------------------------------------------------------------
1 | function Datasets = getDatasets(project_path,method,class)
2 | Datasets = csvread(strcat(project_path,'\Metadata\datasets_',method,'_',class,'.csv'));
3 | end
--------------------------------------------------------------------------------
/Data Processing/Global Code/createFolder.m:
--------------------------------------------------------------------------------
1 | function createFolder(total_folder,path)
2 | mkdir(path);
3 | for i = 1:total_folder
4 | mkdir(strcat(path,'\',sprintf('S%02d',i)));
5 | end
6 | end
--------------------------------------------------------------------------------
/Data Processing/Classification/getDatasetsPrediction.m:
--------------------------------------------------------------------------------
1 | function Datasets = getDatasetsPrediction(project_path,method,class)
2 | Datasets = csvread(strcat(project_path,'\Metadata\datasets_',method,'_',class,'.csv'));
3 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/ownFFT.m:
--------------------------------------------------------------------------------
1 | function [xFFT] = ownFFT(X)
2 | X = double(X);
3 | N = length(X);
4 | n = 0:N-1;
5 | k = n';
6 | M = exp(-2j*pi*k*n/N);
7 | %disp(M);
8 | xFFT = (M*X')';
9 | end
--------------------------------------------------------------------------------
/Data Processing/Process Data/processData.m:
--------------------------------------------------------------------------------
1 | function processData(dataset_path)
2 | dataset_path = 'D:\TUGAS AKHIR\Datasets';
3 | project_path = strcat(pwd,'\..\..');
4 | %%%%%%%%%%%%%
5 |
6 | cutData(dataset_path,project_path);
7 | divideFiveSeconds(dataset_path,project_path);
8 | end
--------------------------------------------------------------------------------
/Data Processing/Classification/separateClass.m:
--------------------------------------------------------------------------------
1 | function label = separateClass(project_path,method,class)
2 | kelas = csvread(strcat(project_path,'\Metadata\kelas_',method,'_',class,'.csv'));
3 |
4 | for i = 1:length(kelas)
5 | if(kelas(i)<=4)
6 | label(i) = 1;
7 | elseif (kelas(i)>=6)
8 | label(i) = 3;
9 | else
10 | label(i) = 2;
11 | end
12 | end
13 | end
14 |
15 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/Data Processing/Classification/separateClassPrediction.m:
--------------------------------------------------------------------------------
1 | function label = separateClassPrediction(project_path,method,class)
2 | kelas = csvread(strcat(project_path,'\Metadata\kelas_',method,'_',class,'.csv'));
3 |
4 | for i = 1:length(kelas)
5 | if(kelas(i)<=4)
6 | label(i) = 1;
7 | elseif (kelas(i)>=6)
8 | label(i) = 3;
9 | else
10 | label(i) = 2;
11 | end
12 | end
13 | end
14 |
15 |
--------------------------------------------------------------------------------
/Data Processing/Classification/predictClassification.m:
--------------------------------------------------------------------------------
1 | function kelas = predictClassification(feature,datasets,label,method)
2 | TrainingSet=datasets;
3 | TestSet=feature;
4 | GroupTrain=label;
5 |
6 | if strcmp(method,'svm')
7 | svmStruct = svmtrain(TrainingSet,GroupTrain);
8 | kelas = svmclassify(svmStruct,TestSet);
9 | elseif strcmp(method,'knn')
10 | kelas = kNN(TrainingSet, GroupTrain, TestSet, 3);
11 | end
12 | end
--------------------------------------------------------------------------------
/Data Processing/Classification/doAccuracy.m:
--------------------------------------------------------------------------------
1 | function [jmlBenar,rata_rata,tp,tn,fp,fn] = doAccuracy(method,class,method_classification)
2 | project_path = strcat(pwd,'\..\..');
3 | % method='ica_swt';%'ica_fft','swt','ica_swt';
4 | % class='valence';%'valence';
5 | % method_classification='svm';%'svm';
6 |
7 | datasets = saveDatasets(project_path,method,class);
8 | label = separateClass(project_path,method,class);
9 | [datasets,label] = getTwoClass(datasets,label);
10 | [jmlBenar,rata_rata,tp,tn,fp,fn] = findAccuracy(datasets,label,method_classification);
11 | end
--------------------------------------------------------------------------------
/Data Processing/Process Data/cutDataPredict.m:
--------------------------------------------------------------------------------
1 | function raw_data = cutDataPredict(file_path)
2 | normRows = @(XXX) bsxfun(@times,XXX,1 ./ sqrt(sum(XXX.^2,2))); %Normalisasi Euclidean
3 | len1 = 640;
4 |
5 | dataEEG = csvread(file_path,1,0);
6 | start = mod(length(dataEEG),4)+1;
7 | dataEEG = dataEEG(start:end,3:16);
8 | L = length(dataEEG);
9 |
10 | if L>=len1
11 | used = (L - len1)/2;
12 | end
13 |
14 | start = used+1;
15 | stop = L - used;
16 |
17 | raw_data = transpose(dataEEG(start:stop,:));
18 | %raw_data = normRows(raw_data);
19 |
20 | for i=1:14
21 | path = strcat('../../Web App/img/raw_data/',num2str(i),'.png');
22 |
23 | set(gcf,'Visible','off');
24 | plot(raw_data(i,:));
25 | print(path,'-dpng');
26 | end
27 | end
--------------------------------------------------------------------------------
/Data Processing/Statical Analysis/statisticalAnalysis.m:
--------------------------------------------------------------------------------
1 | function [sum_ch_arousal,sum_ch_valence,sum_fb_arousal,sum_fb_valence,sum_sb_arousal,sum_sb_valence] = statisticalAnalysis(method)
2 | project_path = strcat(pwd,'\..\..');
3 | method = 'fft';%'ica_fft','swt','ica_swt';
4 | %%%%%%%%%%%%%%%
5 |
6 | if strcmp(method,'ica_fft')||strcmp(method,'ica_swt')
7 | if exist(strcat(project_path,'\ICA_EEG'), 'dir')==0
8 | addpath(genpath('..\Preprocessing'));
9 | computeICA(project_path);
10 | end
11 | end
12 |
13 | absolute_power = absolute(project_path,method);
14 | correlation_data = correlation(project_path,absolute_power);
15 | [sum_ch_arousal,sum_ch_valence,sum_fb_arousal,sum_fb_valence,sum_sb_arousal,sum_sb_valence] = processCorrelation(correlation_data);
16 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/computeICAPredict.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %Author : Muhammad Nadzeri Munawar
3 | %
4 | %
5 | %This code is to create absolute_power variable of subject no. 20 such as :
6 | %delta, theta, alpha, beta, gamma with shape 32x5x40. 32 mean total of
7 | %channel, 5 mean total absolute power, 40 mean 40 trial
8 | %
9 | % project_path -> 'D:\TUGAS AKHIR\Progress\24. (08-12-2015)'
10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 |
12 | function ica_data = computeICAPredict(raw_data)
13 | addpath(genpath('pca_ica'));
14 |
15 | ica_data = myICA(raw_data,14);
16 |
17 | for i=1:14
18 | path = strcat('../../Web App/img/ica/',num2str(i),'.png');
19 |
20 | set(gcf,'Visible','off');
21 | plot(ica_data(i,:));
22 | print(path,'-dpng');
23 | end
24 | end
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 |
--------------------------------------------------------------------------------
/Data Processing/Classification/kNN.m:
--------------------------------------------------------------------------------
1 |
2 | function [results] = kNN(TrainingSet,GroupTrain,TestSet,k)
3 | [L,L1] = size(TestSet);
4 | results = zeros(L);
5 | for i = 1:L
6 | [L2,L3] = size(TrainingSet);
7 | data_distance = zeros(L2);
8 | for j = 1:L2
9 | p = TrainingSet(j,:);
10 | q = TestSet(i,:);
11 |
12 | data_distance (j) = sum(abs(p-q)./(abs(p) + abs(q)));
13 | end
14 |
15 | [B,I] = sort(data_distance);
16 |
17 | nearest = GroupTrain(I(1:k));
18 | nearest_distance = B(1:k);
19 | sse = nearest_distance(1)/nearest_distance(2);
20 | % disp(sse);
21 | % disp(nearest);
22 | if sse<=0.97
23 | results(i)=nearest(1);
24 | else
25 | results(i)=mode(nearest);
26 | end
27 | %results(i)=mode(nearest);
28 | end
29 | end
30 |
31 |
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/ownSWT.m:
--------------------------------------------------------------------------------
1 | function [swa,swd] = ownSWT(A,level,wname)
2 | [h,g]=wfilters(wname,'r');
3 | wLength = length(h)/2-1;
4 |
5 | L = size(A,2);
6 | for i=1:level
7 | shift = 2^(i-1);
8 | start = L-(shift*wLength)+1;
9 | if(i==1)
10 | decompose = A;
11 | else
12 | decompose = swa(i-1,:);
13 | end
14 |
15 | for j=1:L
16 | swa(i,j)=0;
17 | swd(i,j)=0;
18 | shiftIdx=start;
19 | for k=1:length(h)
20 | swa(i,j)=swa(i,j)+decompose(shiftIdx)*h(k);
21 | swd(i,j)=swd(i,j)+decompose(shiftIdx)*g(k);
22 | shiftIdx=shiftIdx+shift;
23 | if(shiftIdx>L)
24 | shiftIdx=shiftIdx-L;
25 | end
26 | end
27 | start=start+1;
28 | if(start>L)
29 | start=start-L;
30 | end
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/Data Processing/Statical Analysis/correlation.m:
--------------------------------------------------------------------------------
1 | function correlation_data = correlation(project_path,absolute_power)
2 | basePath = strcat(project_path,'\USED_EEG\');
3 |
4 | kuesioner = csvread(strcat(project_path,'\Metadata\newDataKuesioner.csv'));
5 | kuesioner = transpose(kuesioner);
6 | start = 0;
7 | stop = 0;
8 |
9 | subject = size(absolute_power);
10 | subject = subject(1);
11 |
12 | for h=1:subject
13 | directory = sprintf('S%02d',h);
14 | allList = dir( strcat(basePath,directory ));
15 | allFiles = { allList(3:end).name };
16 | trial = length(allFiles);
17 |
18 | start = stop+1;
19 | stop = stop + trial;
20 |
21 | for k=1:2
22 | for i=1:14
23 | for j=1:5
24 | temp = corrcoef(kuesioner(k,start:stop), reshape(absolute_power(h,i,j,1:trial),1,trial));
25 | correlation_data(h,k,i,j) = temp(1,2);
26 | end
27 | end
28 | end
29 | end
30 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/myCenter.m:
--------------------------------------------------------------------------------
1 | function [Zc mu] = myCenter(Z)
2 | %--------------------------------------------------------------------------
3 | % Syntax: Zc = myCenter(Z);
4 | % [Zc mu] = myCenter(Z);
5 | %
6 | % Inputs: Z is an (d x n) matrix containing n samples of a
7 | % d-dimensional random vector
8 | %
9 | % Outputs: Zc is the centered version of Z
10 | %
11 | % mu is the (d x 1) sample mean of Z
12 | %
13 | % Description: This function returns the centered (i.e., zero mean)
14 | % version of the input samples
15 | %
16 | % NOTE: Z = Zc + repmat(mu,1,n);
17 | %
18 | % Author: Brian Moore
19 | % brimoor@umich.edu
20 | %
21 | % Date: April 26, 2015
22 | %--------------------------------------------------------------------------
23 |
24 | % Compute sample mean
25 | mu = mean(Z,2);
26 |
27 | % Subtract mean
28 | Zc = bsxfun(@minus,Z,mu);
29 |
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/myWhiten.m:
--------------------------------------------------------------------------------
1 | function [Zw T] = myWhiten(Z)
2 | %--------------------------------------------------------------------------
3 | % Syntax: Zw = myWhiten(Z);
4 | % [Zw T] = myWhiten(Z);
5 | %
6 | % Inputs: Z is an (d x n) matrix containing n samples of a
7 | % d-dimensional random vector
8 | %
9 | % Outputs: Zw is the whitened version of Z
10 | %
11 | % T is the (d x d) whitening transformation of Z
12 | %
13 | % Description: This function returns the whitened (identity covariance)
14 | % version of the input samples
15 | %
16 | % NOTE: Must have n >= d to fully whiten Z
17 | %
18 | % NOTE: Z = T \ Zcw;
19 | %
20 | % Author: Brian Moore
21 | % brimoor@umich.edu
22 | %
23 | % Date: April 26, 2015
24 | %--------------------------------------------------------------------------
25 |
26 | % Compute sample covariance
27 | R = cov(Z');
28 |
29 | % Whiten data
30 | [U,S,~] = svd(R,'econ');
31 | T = U * diag(1 ./ sqrt(diag(S))) * U';
32 | Zw = T * Z;
33 |
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/preProcessingPredict.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %Author : Muhammad Nadzeri Munawar
3 | %
4 | %
5 | %This code is to create absolute_power variable of subject no. 20 such as :
6 | %delta, theta, alpha, beta, gamma with shape 32x5x40. 32 mean total of
7 | %channel, 5 mean total absolute power, 40 mean 40 trial
8 | %
9 | % project_path -> 'D:\TUGAS AKHIR\Progress\24. (08-12-2015)'
10 | % method -> fft;ica_fft;swt;ica_swt
11 | % subject -> [2,4,6,7,8,9,10,13,15,16,21,25,26,28,29,30];
12 | % channel -> [2,3,4,5,6,7,8,14];
13 | % fb -> for fft : 1.Delta;2.Theta;3.Alpha;4.Beta;5.Gamma - for swt : 1.A5;2.D5;3.D4;4.D3;5.D2
14 | % features -> 1. Min;2.Max;3.Std;4.Avg;5.Pow;6.Energy
15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 |
17 | function result = preProcessingPredict(raw_data,preprocessing_method,channel,fb,features)
18 | if strcmp(preprocessing_method,'fft') || strcmp(preprocessing_method,'ica_fft')
19 | result = computeFFTPredict(raw_data,preprocessing_method,channel,fb,features);
20 | elseif strcmp(preprocessing_method,'swt') || strcmp(preprocessing_method,'ica_swt')
21 | result = computeSWTPredict(raw_data,preprocessing_method,channel,fb,features);
22 | end
23 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/myCenterAndWhiten.m:
--------------------------------------------------------------------------------
1 | function [Zcw T mu] = myCenterAndWhiten(Z)
2 | %--------------------------------------------------------------------------
3 | % Syntax: Zcw = myCenterAndWhiten(Z);
4 | % [Zcw T] = myCenterAndWhiten(Z);
5 | % [Zcw T mu] = myCenterAndWhiten(Z);
6 | %
7 | % Inputs: Z is an (d x n) matrix containing n samples of a
8 | % d-dimensional random vector
9 | %
10 | % Outputs: Zcw is the centered and whitened version of Z
11 | %
12 | % T is the (d x d) whitening transformation of Z
13 | %
14 | % mu is the (d x 1) sample mean of Z
15 | %
16 | % Description: This function returns the centered (zero-mean) and whitened
17 | % (identity covariance) version of the input samples
18 | %
19 | % NOTE: Z = T \ Zcw + repmat(mu,1,n);
20 | %
21 | % Author: Brian Moore
22 | % brimoor@umich.edu
23 | %
24 | % Date: April 26, 2015
25 | %--------------------------------------------------------------------------
26 |
27 | % Center data
28 | [Zc mu] = myCenter(Z);
29 |
30 | % Whiten data
31 | [Zcw T] = myWhiten(Zc);
32 |
--------------------------------------------------------------------------------
/Data Processing/Classification/saveDatasets.m:
--------------------------------------------------------------------------------
1 | function Datasets = saveDatasets(project_path,method,class)
2 | if strcmp(method,'fft')
3 | basePath = strcat(project_path,'\FFT_EEG_',upper(class),'\');
4 | elseif strcmp(method,'swt')
5 | basePath = strcat(project_path,'\SWT_EEG_',upper(class),'\');
6 | elseif strcmp(method,'ica_fft')
7 | basePath = strcat(project_path,'\ICA_FFT_EEG_',upper(class),'\');
8 | elseif strcmp(method,'ica_swt')
9 | basePath = strcat(project_path,'\ICA_SWT_EEG_',upper(class),'\');
10 | end
11 |
12 | all_files = dir(basePath);
13 | all_files = all_files(3:end);
14 | all_dir = all_files([all_files(:).isdir]);
15 | subject = numel(all_dir);
16 |
17 | counterDatasets = 1;
18 |
19 | for h=1:subject
20 | directory = sprintf('S%02d',h);
21 | allList = dir( strcat(basePath,directory ));
22 | allFiles = { allList(3:end).name };
23 | trial = length(allFiles);
24 |
25 | for i = 1:trial
26 | rawData = csvread(strcat(basePath,directory,'\T',num2str(i),'.csv'));
27 | Datasets(counterDatasets,:) = rawData;
28 | counterDatasets=counterDatasets+1;
29 | end
30 | end
31 |
32 | csvwrite(strcat(project_path,'\Metadata\datasets_',method,'_',class,'.csv'),Datasets);
33 | end
--------------------------------------------------------------------------------
/Data Processing/Classification/findAccuracy.m:
--------------------------------------------------------------------------------
1 | function [jmlBenar,rata_rata,tp,tn,fp,fn] = findAccuracy(datasets,label,method)
2 | jmlData = length(label);
3 | %jmlTest = 20;
4 |
5 | tp = 0;
6 | fn = 0;
7 | fp = 0;
8 | tn = 0;
9 |
10 | indices = crossvalind('Kfold',jmlData,10);
11 | for h = 1:10
12 | test = (indices == h); train = ~test;
13 | jmlTest = sum(test);
14 | TrainingSet=datasets(train,:);
15 | TestSet=datasets(test,:);
16 | GroupTrain=label(train);
17 | dataAsli = label(test);
18 |
19 | if strcmp(method,'svm')
20 | svmStruct = svmtrain(TrainingSet,GroupTrain,'kernel_function','rbf');
21 | results = svmclassify(svmStruct,TestSet);
22 | elseif strcmp(method,'knn')
23 | results = kNN(TrainingSet, GroupTrain, TestSet, 3);
24 | end
25 |
26 | jmlBenar(h) = 0;
27 | for i = 1:jmlTest
28 | if(dataAsli(i)==results(i))
29 | if dataAsli(i)==3
30 | tp=tp+1;
31 | else
32 | tn=tn+1;
33 | end
34 | jmlBenar(h)=jmlBenar(h)+1;
35 | else
36 | if results(i)==3
37 | fp=fp+1;
38 | else
39 | fn=fn+1;
40 | end
41 | end
42 | end
43 | jmlBenar(h) = jmlBenar(h)/jmlTest;
44 | end
45 | rata_rata = mean2(jmlBenar);
46 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/computeICA.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %Author : Muhammad Nadzeri Munawar
3 | %
4 | %
5 | %This code is to create absolute_power variable of subject no. 20 such as :
6 | %delta, theta, alpha, beta, gamma with shape 32x5x40. 32 mean total of
7 | %channel, 5 mean total absolute power, 40 mean 40 trial
8 | %
9 | % project_path -> 'D:\TUGAS AKHIR\Progress\24. (08-12-2015)'
10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 |
12 | function computeICA(project_path)
13 | addpath(genpath('pca_ica'));
14 | addpath(genpath('..\Global Code'));
15 | basePath = strcat(project_path,'\USED_EEG\');
16 | all_files = dir(basePath);
17 | all_files = all_files(3:end);
18 | all_dir = all_files([all_files(:).isdir]);
19 | subject = numel(all_dir);
20 |
21 | if exist(strcat(project_path,'\ICA_EEG'), 'dir')
22 | system(strcat('rmdir /S /Q "',project_path,'\ICA_EEG"'));
23 | end
24 |
25 | createFolder(subject,strcat(project_path,'\ICA_EEG'));
26 |
27 | for h=1:subject
28 | directory = sprintf('S%02d',h);
29 | allList = dir( strcat(basePath,directory ));
30 | allFiles = { allList(3:end).name };
31 | trial = length(allFiles);
32 |
33 | for i = 1:trial
34 | rawData = csvread(strcat(basePath,directory,'\T',num2str(i),'.csv'));
35 | rawData = myICA(rawData,14);
36 | csvwrite(strcat(project_path,'\ICA_EEG\',directory,'\T',num2str(i),'.csv'),rawData);
37 | end
38 | end
39 | end
--------------------------------------------------------------------------------
/Data Processing/Process Data/cutData.m:
--------------------------------------------------------------------------------
1 | function cutData(dataset_path,project_path)
2 | addpath(genpath('..\Global Code'));
3 |
4 | dataset_eeg_path = strcat(dataset_path,'\EEG');
5 |
6 | len1 = 640;
7 | len2 = 3200;
8 |
9 | allList = dir(dataset_eeg_path);
10 | allDir = { allList(3:end).name };
11 |
12 | if exist(strcat(project_path,'\EEG"'), 'dir')
13 | system(strcat('rmdir /S /Q "',project_path,'\EEG"'));
14 | end
15 | createFolder(length(allDir),strcat(project_path,'\EEG'));
16 |
17 | for i=1:length(allDir)
18 | dataOneDir = allDir{i};
19 | allFileList = dir(strcat(dataset_eeg_path,'\',dataOneDir));
20 | allFileName = { allFileList(3:end).name };
21 |
22 | for j = 1:length(allFileName)
23 | dataOneFile = allFileName{j};
24 | dataEEG = csvread(strcat(dataset_eeg_path,'\',dataOneDir,'\',dataOneFile),1,0);
25 | start = mod(length(dataEEG),4)+1;
26 | dataEEG = dataEEG(start:end,3:16);
27 | L = length(dataEEG);
28 |
29 | if L>=len2
30 | used = (L - len2)/2;
31 | elseif L>=len1
32 | used = (L - len1)/2;
33 | else
34 | continue;
35 | end
36 |
37 | start = used+1;
38 | stop = L - used;
39 |
40 | rawData = transpose(dataEEG(start:stop,:));
41 |
42 | fileNewName = dataOneFile(5:end-22);
43 |
44 | csvwrite(strcat(project_path,'\EEG\',dataOneDir,'\',fileNewName,'.csv'),rawData);
45 | end
46 | end
47 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/myMultiGaussian.m:
--------------------------------------------------------------------------------
1 | function Z = myMultiGaussian(MU,SIGMA,n)
2 | %--------------------------------------------------------------------------
3 | % Syntax: Z = myMultiGaussian(MU,SIGMA);
4 | % Z = myMultiGaussian(MU,SIGMA,n);
5 | %
6 | % Inputs: MU is the desired (d x 1) mean vector
7 | %
8 | % SIGMA is the desired (d x d) covariance matrix
9 | %
10 | % [OPTIONAL] n is the desired number of samples. The default
11 | % value is n = 1
12 | %
13 | % Outputs: Z is a (d x n) matrix containing n multivariate Gaussian
14 | % samples
15 | %
16 | % Description: This function generates samples from a d-dimensional
17 | % multivariate Gaussian random variable with mean vector MU
18 | % and covariance matrix SIGMA
19 | %
20 | % NOTE: mean(Z,2) ~ MU
21 | % cov(Z') ~ SIGMA
22 | %
23 | % Author: Brian Moore
24 | % brimoor@umich.edu
25 | %
26 | % Date: April 26, 2015
27 | %--------------------------------------------------------------------------
28 |
29 | % Parse inputs
30 | [d d2] = size(SIGMA);
31 | if (d ~= d2) || (d ~= length(MU))
32 | % Syntax error
33 | error('Syntax error... Type "help myMultiGaussian" for more info');
34 | end
35 | if nargin < 3
36 | % Default # samples
37 | n = 1;
38 | end
39 |
40 | % Generate samples
41 | L = chol(SIGMA,'lower');
42 | Z = repmat(MU,1,n) + L * randn(d,n);
43 |
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/demo_PCA1.m:
--------------------------------------------------------------------------------
1 | %
2 | % Name: demo_PCA1.m
3 | %
4 | % Description: Demonstrates the performance of PCA by decomposing
5 | % correlated multivariate Gaussian samples into
6 | % their principal components
7 | %
8 | % When d == r, the PCA reconstruction is *exact*. Thus
9 | % PCA effectively transforms the input data into
10 | % orthogonal, maximal variance components while preserving
11 | % information
12 | %
13 | % Author: Brian Moore
14 | % brimoor@umich.edu
15 | %
16 | % Date: April 26, 2015
17 | %
18 |
19 | rng(1);
20 |
21 | % Knobs
22 | n = 100; % # samples
23 | d = 3; % Sample dimension
24 | r = 2; % # principal components
25 |
26 | % Generate Gaussian data
27 | MU = 10 * rand(d,1);
28 | sigma = (2 * randi([0 1],d) - 1) .* rand(d);
29 | SIGMA = 3 * (sigma * sigma');
30 | Z = myMultiGaussian(MU,SIGMA,n);
31 |
32 | % Perform PCA
33 | [Zpca T U mu] = myPCA(Z,r);
34 | Zr = U / T * Zpca + repmat(mu,1,n);
35 |
36 | % Plot principal components
37 | figure;
38 | for i = 1:r
39 | subplot(r,1,i);
40 | plot(Zpca(i,:),'b');
41 | grid on;
42 | ylabel(sprintf('Zpca(%i,:)',i));
43 | end
44 | subplot(r,1,1);
45 | title('Principal Components');
46 |
47 | % Plot r-dimensional approximations
48 | figure;
49 | for i = 1:d
50 | subplot(d,1,i);
51 | hold on;
52 | p1 = plot(Z(i,:),'--r');
53 | p2 = plot(Zr(i,:),'-.b');
54 | grid on;
55 | ylabel(sprintf('Z(%i,:)',i));
56 | end
57 | subplot(d,1,1);
58 | title(sprintf('%iD PCA approximation of %iD data',r,d));
59 | legend([p1 p2],'Z','Zr');
60 |
--------------------------------------------------------------------------------
/Data Processing/Classification/getPrediction.m:
--------------------------------------------------------------------------------
1 | function [valence,arousal] = getPrediction(file_path,preprocessing_method,classification_method)
2 | %%%%%%%%%%%%%%
3 | %file_path = 'D:\5112100136 - Muhammad Nadzeri Munawar\TUGAS AKHIR\Datasets\EEG\S04\S04-T13-10.11.15.11.40.03.csv';
4 | project_path = strcat(pwd,'\..\..');
5 | %preprocessing_method='fft';%'ica_fft','swt','ica_swt';
6 | %classification_method='knn';
7 | channel_v = [10,3,14,5,1,8,6,4,7,11];
8 | fb_v = [3,4,5];
9 | features_v = [2,3];
10 |
11 | channel_a = [3,13,10,2,1,12,4,7,8,11];
12 | fb_a = [3,4,5];
13 | features_a = [2,3];
14 | %%%%%%%%%%%%%%%
15 |
16 | addpath(genpath('..\Process Data'));
17 | addpath(genpath('..\Preprocessing'));
18 |
19 | raw_data = cutDataPredict(file_path);
20 | preprocessing_result_v = preProcessingPredict(raw_data,preprocessing_method,channel_v,fb_v,features_v);
21 | preprocessing_result_a = preProcessingPredict(raw_data,preprocessing_method,channel_a,fb_a,features_a);
22 |
23 | % Find Valence
24 | datasets = getDatasetsPrediction(project_path,preprocessing_method,'valence');
25 | label = separateClassPrediction(project_path,preprocessing_method,'valence');
26 | [datasets,label] = getTwoClass(datasets,label);
27 | valence = predictClassification(preprocessing_result_v,datasets,label,classification_method);
28 |
29 | % Find Arousal
30 | datasets = getDatasetsPrediction(project_path,preprocessing_method,'arousal');
31 | label = separateClassPrediction(project_path,preprocessing_method,'arousal');
32 | [datasets,label] = getTwoClass(datasets,label);
33 | arousal = predictClassification(preprocessing_result_a,datasets,label,classification_method);
34 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/demo_ICA.m:
--------------------------------------------------------------------------------
1 | %
2 | % Name: demo_ICA.m
3 | %
4 | % Description: Demonstrates the performance of ICA by decomposing
5 | % correlated multivariate Gaussian samples into
6 | % uncorrelated and maximally independent data streams
7 | %
8 | % When d == r, the ICA reconstruction is *exact*. Thus
9 | % ICA effectively transforms the input data into
10 | % uncorrelated, independent components while preserving
11 | % information
12 | %
13 | % Author: Brian Moore
14 | % brimoor@umich.edu
15 | %
16 | % Date: April 26, 2015
17 | %
18 |
19 | rng(1);
20 |
21 | % Knobs
22 | n = 100; % # samples
23 | d = 3; % Sample dimension
24 | r = 2; % # independent components
25 |
26 | % Generate Gaussian data
27 | MU = 10 * rand(d,1);
28 | sigma = (2 * randi([0 1],d) - 1) .* rand(d);
29 | SIGMA = 3 * (sigma * sigma');
30 | Z = myMultiGaussian(MU,SIGMA,n);
31 |
32 | % Perform ICA
33 | [Zica A T mu] = myICA(Z,r);
34 | Zr = T \ pinv(A) * Zica + repmat(mu,1,n);
35 |
36 | % Plot indpendent components
37 | figure;
38 | for i = 1:r
39 | subplot(r,1,i);
40 | plot(Zica(i,:),'b');
41 | grid on;
42 | ylabel(sprintf('Zica(%i,:)',i));
43 | end
44 | subplot(r,1,1);
45 | title('Independent Components');
46 |
47 | % Plot r-dimensional approximations
48 | figure;
49 | for i = 1:d
50 | subplot(d,1,i);
51 | hold on;
52 | p1 = plot(Z(i,:),'--r');
53 | p2 = plot(Zr(i,:),'-.b');
54 | grid on;
55 | ylabel(sprintf('Z(%i,:)',i));
56 | end
57 | subplot(d,1,1);
58 | title(sprintf('%iD ICA approximation of %iD data',r,d));
59 | legend([p1 p2],'Z','Zr');
60 |
--------------------------------------------------------------------------------
/Data Processing/Statical Analysis/processCorrelation.m:
--------------------------------------------------------------------------------
1 | function [sum_ch_arousal,sum_ch_valence,sum_fb_arousal,sum_fb_valence,sum_sb_arousal,sum_sb_valence] = processCorrelation(correlation_data)
2 | th = 0.35;
3 |
4 | subjects = size(correlation_data);
5 | subjects = subjects(1);
6 |
7 | fb_valence = zeros(subjects,5);
8 | fb_arousal = zeros(subjects,5);
9 |
10 | ch_valence = zeros(subjects,14);
11 | ch_arousal = zeros(subjects,14);
12 |
13 | correlation_data = abs(correlation_data);
14 |
15 | for i = 1:subjects
16 | correlation_value = reshape(correlation_data(i,1,:,:),14,5);
17 | idx_corr = correlation_value
EigenVector;D->EigenValue)
21 | resultWhitening = E * diag(1 ./ sqrt(diag(D))) * E' * resultCentering; %Main Whitening
22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 |
24 | %%%%%%%%%% Component Extraction %%%%%%%%%%
25 | % Random initial weights
26 | W = normRows(rand(r,size(resultWhitening,1)));
27 | %W = rand(r,size(resultWhitening,1));
28 | % Initial looping variable
29 | k = 0;
30 | err = inf;
31 | % Looping until convergen or until maxiter
32 | while (err > eps) && (k < maxIters)
33 | % Increment counter
34 | k = k + 1;
35 |
36 | % Update weights
37 | wLast = W; % Save last weights
38 | Sk = permute(wLast * resultWhitening,[1 3 2]);
39 | G = Sk .* exp(-0.5 * Sk.^2);
40 | Gp = Sk .* G;
41 | W = mean(bsxfun(@times,G,permute(resultWhitening,[3 1 2])),3) + bsxfun(@times,mean(Gp,3),wLast);
42 | W = normRows(W);
43 |
44 | % Decorrelate weights
45 | [U,S,~] = svd(W,'econ');
46 | W = U * diag(1 ./ diag(S)) * U' * W;
47 |
48 | % Update error
49 | err = max(1 - dot(W,wLast,2));
50 | end
51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 |
53 | xICA = W * resultWhitening;
54 | xICA = normRows(xICA);
55 | end
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/pca_ica/myPCA.m:
--------------------------------------------------------------------------------
1 | function [Zpca T U mu eigVecs] = myPCA(Z,r)
2 | %--------------------------------------------------------------------------
3 | % Syntax: Zpca = myPCA(Z,r);
4 | % [Zpca T U mu] = myPCA(Z,r);
5 | % [Zpca T U mu eigVecs] = myPCA(Z,r);
6 | %
7 | % Inputs: Z is an (d x n) matrix containing n samples of a
8 | % d-dimensional random vector
9 | %
10 | % r is the desired number of principal components
11 | %
12 | % Outputs: Zpca is a (r x n) matrix containing the r principal
13 | % components - scaled to variance 1 - of the input samples
14 | %
15 | % U and T are the PCA transformation matrices such that
16 | % Zr = U / T * Zpca + repmat(mu,1,n);
17 | % is the r-dimensional PCA approximation of Z
18 | %
19 | % mu is the (d x 1) sample mean of Z
20 | %
21 | % eigVecs is a (d x r) matrix containing the scaled
22 | % eigenvectors of the sample covariance of Z
23 | %
24 | % Description: This function performs principal component analysis (PCA)
25 | % on the input samples
26 | %
27 | % Author: Brian Moore
28 | % brimoor@umich.edu
29 | %
30 | % Date: April 26, 2015
31 | %--------------------------------------------------------------------------
32 |
33 | % Center data
34 | [Zc mu] = myCenter(Z);
35 |
36 | % Compute truncated SVD
37 | %[U S V] = svds(Zc,r); % Equivalent, but usually slower than svd()
38 | [U S V] = svd(Zc,'econ');
39 | U = U(:,1:r);
40 | S = S(1:r,1:r);
41 | V = V(:,1:r);
42 |
43 | % Compute principal components
44 | Zpca = S * V';
45 | %Zpca = U' * Zc; % Equivalent but slower
46 |
47 | % Whiten data, if desired
48 | %[Zpca T] = myWhiten(Zpca);
49 | T = eye(r); % No whitening
50 |
51 | % Return scaled eigenvectors, if necessary
52 | if (nargout >= 5)
53 | [~,n] = size(Z);
54 | eigVecs = bsxfun(@times,U,diag(S)' / sqrt(n));
55 | end
56 |
--------------------------------------------------------------------------------
/Data Processing/Preprocessing/preProcessing.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %Author : Muhammad Nadzeri Munawar
3 | %
4 | %
5 | %This code is to create absolute_power variable of subject no. 20 such as :
6 | %delta, theta, alpha, beta, gamma with shape 32x5x40. 32 mean total of
7 | %channel, 5 mean total absolute power, 40 mean 40 trial
8 | %
9 | % project_path -> 'D:\TUGAS AKHIR\Progress\24. (08-12-2015)'
10 | % method -> fft;ica_fft;swt;ica_swt
11 | % subject -> [2,4,6,7,8,9,10,13,15,16,21,25,26,28,29,30];
12 | % channel -> [2,3,4,5,6,7,8,14];
13 | % fb -> for fft : 1.Delta;2.Theta;3.Alpha;4.Beta;5.Gamma - for swt : 1.A5;2.D5;3.D4;4.D3;5.D2
14 | % features -> 1. Min;2.Max;3.Std;4.Avg;5.Pow;6.Energy
15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 |
17 | function preProcessing(project_path,method,class,subject,channel,fb,features)
18 |
19 | %%%%%%%%%%%%%%
20 | project_path = strcat(pwd,'\..\..');
21 | method='fft';%'ica_fft','swt','ica_swt';
22 |
23 | % class='arousal';%'valence';
24 | % subject = 1:34;
25 | fb = 1:5;
26 | features = 3:4;
27 | channel = 1:14;
28 |
29 | %Arousal
30 | class='arousal';%'valence';
31 | subject = [16,13,10,28,11,7,6,2,20,26,29,15,4,30,5,34,9,24,8,23];
32 | % fb = [3,4,5];
33 | % features = [2,3];
34 | % channel = [3,13,10,2,1,12,4,7,8,11];
35 |
36 | %Valence
37 | % class='valence';%'valence';
38 | % subject = [16,25,34,9,5,4,20,28,2,6,32,29,15,10,22,11,8,1,31,13];
39 | % fb = [3,4,5];
40 | % features = [2,3];
41 | % channel = [10,3,14,5,1,8,6,4,7,11];
42 |
43 | %%%%%%%%%%%%%%%
44 |
45 | if strcmp(method,'fft')
46 | computeFFT(project_path,method,class,subject,channel,fb,features);
47 | elseif strcmp(method,'ica_fft')
48 | if exist(strcat(project_path,'\ICA_EEG'), 'dir')==0
49 | computeICA(project_path);
50 | end
51 | computeFFT(project_path,method,class,subject,channel,fb,features);
52 | elseif strcmp(method,'swt')
53 | computeSWT(project_path,method,class,subject,channel,fb,features);
54 | elseif strcmp(method,'ica_swt')
55 | if exist(strcat(project_path,'\ICA_EEG'), 'dir')==0
56 | computeICA(project_path);
57 | end
58 | computeSWT(project_path,method,class,subject,channel,fb,features);
59 | end
60 | end
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Significant Preprocessing Method in EEG-Based Emotion Classification
2 | EEG preprocessing methods for classifying person emotions have been widely applied. However, there still remain some parts where determining significant preprocessing method can be improved. In this regards, this project proposes a method to determine the most significant preprocessing methods, among them to determine (i) denoising method; (ii) frequency bands; (iii) subjects; (iv) channels; and (v) features. The purposes are to improve the accuracy of emotion classification based on valence and arousal emotion model. EEG data from 34 participants will be recorded with the questionnaires (valence and arousal) that have been taken from the participants when they receive stimuli from picture, music, and video. EEG data will be divided into 5 seconds for each trial. Then, EEG data will be processed using denoising method and feature extraction. After that, the most significant preprocessing methods will be chosen using statistical analysis Pearson-Correlation. The preprocessed EEG data will be categorized. The average accuracy results using SVM are 66.09% (valence) and 75.66% (arousal) while the average accuracy results using KNN are 82.33% (valence) and 87.32% (arousal). For comparison, the average accuracy results without choosing the most significant preprocessing method are 52% (valence) and 49% (arousal) using SVM while the average accuracy results using KNN are 50.13% (valence) and 56% (arousal).
3 | ## Required Library
4 | ### Python
5 | Python is used as Web App GUI.
6 | 1. [Common Gateway Interface](https://docs.python.org/2/library/cgi.html)
7 | 2. [Cgitb](https://docs.python.org/2/library/cgitb.html)
8 | 3. [Matlab Engine for Python](http://www.mathworks.com/help/matlab/matlab-engine-for-python.html)
9 | ### Matlab
10 | Matlab is used as EEG analysis, preprocessing, and classification.
11 | 1. [PCA and ICA Package](http://www.mathworks.com/matlabcentral/fileexchange/38300-pca-and-ica-package)
12 | ## Paper Publication
13 | [JATIT - Significant Preprocessing Method in EEG-Based Emotion Classification](https://drive.google.com/file/d/0B9EQQ4nwB6CbdlpoX0tuSzRxbzg)
14 |
15 | ## Copyright
16 | Copyright (c) 2016 Muhammad Nadzeri Munawar