TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
loading_MAHNOB.m
Go to the documentation of this file.
1 %we assume the pre-processed physilogical signals in mat file from DEAP data is being used
2 %this script loads the MAHNOB data and converts it to the EEGLAB format that
3 %is readable by TEAP
4 %I assume the data is in MAHNOB_path
5 %I added minimally required fields to the structure
6 %Mohammad Soleymani June 2015 mohammad.soleymani@unige.ch
7 %Takes the path physio_files_path and writes the mat files in eeglab format
8 %acceptable by TEAP
9 %for ECG we take the ECG2-ECG3 as the lead
10 %You should get the MAHNOB-HCI database here: mahnob-db.eu/hci-tagging
11 %Download only the physiological files and session metadata
12 
13 clc
14 clear
15 electrode_labels_orig = {'Fp1', 'AF3', 'F3', 'F7', 'FC5', 'FC1', 'C3', 'T7', 'CP5', ...
16  'CP1', 'P3', 'P7', 'PO3', 'O1', 'Oz', 'Pz', 'Fp2', 'AF4', ...
17  'Fz', 'F4', 'F8', 'FC6', 'FC2', 'Cz', 'C4', 'T8', 'CP6', ...
18  'CP2', 'P4', 'P8', 'PO4', 'O2','EXG1','EXG2','EXG3','EXG4','EXG5', ...
19  'EXG6','EXG7','EXG8','GSR1','GSR2','Erg1','Erg2','Resp','Temp','Status'};
20 electrode_labels = {'Fp1', 'AF3', 'F3', 'F7', 'FC5', 'FC1', 'C3', 'T7', 'CP5', ...
21  'CP1', 'P3', 'P7', 'PO3', 'O1', 'Oz', 'Pz', 'Fp2', 'AF4', ...
22  'Fz', 'F4', 'F8', 'FC6', 'FC2', 'Cz', 'C4', 'T8', 'CP6', ...
23  'CP2', 'P4', 'P8', 'PO4', 'O2','EXG2','EXG3', ...
24  'GSR1','Resp','Temp','Status'};
25 
26 feltEmotCode = 0:12;
27 feltEmos = {'Neutral', 'Anger', 'Disgust', 'Fear', 'Joy', 'Sadness', ...
28  'Surprise', 'Scream', 'Bored', 'Sleepy', 'Unknown','Amusement', 'Anxiety'};
29 
30 n_chans = 38;
31 %Update the following two lines with your local path
32 %Pleas
33 MAHNOB_path = 'MAHNOB-HCI/Sessions/';
34 path_towrite = 'MAHNOB-HCI/teapformat';
35 sessions = dir(MAHNOB_path);
36 cntr = 0;
37 
38 phys_data.srate = 256;
39 phys_data.ref= 'common';
40 phys_data.trials = 1;
41 phys_data.nbchan = n_chans; %added one since ground is added
42 phys_data.epoch = 1;
43 
44 for i = 1:n_chans
45  phys_data.chanlocs(i).labels = electrode_labels{i};
46 end
47 phys_data.chanlocs(n_chans+1).labels = 'GND';
48 for i = 1:length(sessions)
49  if strcmp(sessions(i).name(1) ,'.') || ~sessions(i).isdir
50  continue
51  end
52  cntr = cntr +1;
53  new_path = [MAHNOB_path sessions(i).name '/'];
54  files_of = dir([new_path '*.bdf']);
55  % we need at least one bdf file
56  if length(files_of)<1
57  continue
58  end
59  s = strsplit(files_of.name ,'_');
60  if strcmp(s{3},'N')
61  continue
62  end
63  subj_id = str2double(s{2});
64  trial_id = str2double(s{4}(6:end));
65  bdf = openbdf([new_path files_of.name]);
66  fprintf('loading and converting subject %0.2d trial %0.2d\n',subj_id,trial_id);
67  data = readbdf(bdf,1:bdf.Head.NRec);
68  triggers = find(diff(data.Record(47,:))~=0);
69  phys_data.data = zeros(n_chans+1,(triggers(3)-triggers(1)));
70  for j = 1:n_chans
71  phys_data.data(j,:) = data.Record(strcmp(electrode_labels{j},electrode_labels_orig),triggers(1)+1:triggers(3));
72  end
73  eeglab_file = sprintf('%s/s%0.2d_t%0.2d_eeglab.mat',path_towrite,subj_id,trial_id);
74  save(eeglab_file,'phys_data');
75  fid = fopen([new_path 'session.xml']);
76  fgetl(fid);
77  tmp_str = fgetl(fid);
78  if strcmp(tmp_str(strfind(tmp_str,'feltEmo')+10),'"')
79  feedback.felt_emotion = feltEmos{str2double(tmp_str(strfind(tmp_str,'feltEmo')+9))+1};
80  feedback.felt_emotion_id = str2double(tmp_str(strfind(tmp_str,'feltEmo')+9));
81  else
82  feedback.felt_emotion = feltEmos{str2double(tmp_str(strfind(tmp_str,'feltEmo')+9:strfind(tmp_str,'feltEmo')+10))+1};
83  feedback.felt_emotion_id = str2double(tmp_str(strfind(tmp_str,'feltEmo')+9:strfind(tmp_str,'feltEmo')+10));
84  end
85  feedback.felt_arousal = str2double(tmp_str(strfind(tmp_str,'feltArsl')+10));
86  feedback.felt_valence = str2double(tmp_str(strfind(tmp_str,'feltVlnc')+10));
87  feedback.felt_control = str2double(tmp_str(strfind(tmp_str,'feltCtrl')+10));
88  feedback.felt_predict = str2double(tmp_str(strfind(tmp_str,'feltPred')+10));
89  s= strsplit(tmp_str(strfind(tmp_str,'mediaFile'):end),'"');
90  feedback.media_file = s{2};
91  feedback_file = sprintf('%s/s%0.2d_t%0.2d_feedback.mat',path_towrite,subj_id,trial_id);
92  save(feedback_file,'feedback');
93 end
94 
95 
96 
97 
98 fprintf('Done! Successfully converted the mat files\n');
openbdf
function openbdf(in FILENAME)
str2double
function str2double(in s, in cdelim, in rdelim, in ddelim)
readbdf
function readbdf(in DAT, in Records, in Mode)