-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoBIDS_handson_1_xdf2bids.m
165 lines (140 loc) · 5.63 KB
/
MoBIDS_handson_1_xdf2bids.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
% configure paths
fieldTripPath = 'P:\Sein_Jeung\Project_BIDS\Workshops\Workshop_2024_MoBI\Tools\fieldtrip-20240515';
xdfFileName = 'P:\Sein_Jeung\Project_BIDS\Workshops\Workshop_2024_MoBI\Hands-on\data\sourcedata\1\control_body.xdf';
bidsFolder = 'P:\Sein_Jeung\Project_BIDS\Workshops\Workshop_2024_MoBI\Hands-on\data\bidsdata';
% add fieldtrip
addpath(fieldTripPath)
ft_defaults
[filepath,~,~] = fileparts(which('ft_defaults'));
addpath(fullfile(filepath, 'external', 'xdf'))
% 1. load and inspect xdf
%--------------------------------------------------------------------------
streams = load_xdf(xdfFileName);
[streamNames, channelMetaData] = xdf_inspect(streams);
% keep track of data modalities (find entries from output)
% indices are better found this way because stream order may differ between
% recordings
EEGStreamName = 'BrainVision RDA';
EEGStreamInd = find(strcmp(streamNames, EEGStreamName));
EventStreamName = 'ExperimentMarkerStream';
EventStreamInd = find(strcmp(streamNames, EventStreamName));
MotionStreamName = 'headRigid';
MotionStreamInd = find(strcmp(streamNames, MotionStreamName));
% 2. convert streams to fieldtrip data structs
%--------------------------------------------------------------------------
EEGftData = stream_to_ft(streams{EEGStreamInd});
MotionftData = stream_to_ft(streams{MotionStreamInd});
% 3. Save time synch information
%--------------------------------------------------------------------------
% compute difference between onset times
onsetDiff = MotionftData.hdr.FirstTimeStamp - EEGftData.hdr.FirstTimeStamp;
% time synchronization using scans.tsv acq field
% later to be entered as cfg.scans.acq_time = string, should be formatted according to RFC3339 as '2019-05-22T15:13:38'
eegOnset = [1990,01,01,00,00,0.000]; % [YYYY,MM,DD,HH,MM,SS]
motionOnset = [1990,01,01,00,00,onsetDiff];
eegAcqNum = datenum(eegOnset);
eegAcqTime = datestr(eegAcqNum,'yyyy-mm-ddTHH:MM:SS.FFF');
motionAcqNum = datenum(motionOnset);
motionAcqTime = datestr(motionAcqNum,'yyyy-mm-ddTHH:MM:SS.FFF');
% 4. enter generic metadata
%--------------------------------------------------------------------------
cfg = [];
cfg.bidsroot = bidsFolder;
cfg.sub = '001';
cfg.task = 'SpotRotation';
cfg.scans.acq_time = datetime('now');
cfg.dataset_description.Name = 'Example spot rotation data';
cfg.motion.TaskName = 'Rotation';
cfg.datatype = 'motion';
cfg.InstitutionName = 'Technische Universitaet zu Berlin';
cfg.InstitutionalDepartmentName = 'Biological Psychology and Neuroergonomics';
cfg.InstitutionAddress = 'Strasse des 17. Juni 135, 10623, Berlin, Germany';
cfg.TaskDescription = 'Participants equipped with VR HMD rotated either physically or using a joystick.';
% required for dataset_description.json
cfg.dataset_description.Name = 'EEG and motion capture data set for a full-body/joystick rotation task';
cfg.dataset_description.BIDSVersion = 'unofficial extension';
% optional for dataset_description.json
cfg.dataset_description.License = 'CC0';
cfg.dataset_description.Authors = {"Gramann, K.", "Hohlefeld, F.U.", "Gehrke, L.", "Klug, M"};
cfg.dataset_description.Acknowledgements = 'n/a';
cfg.dataset_description.Funding = {""};
cfg.dataset_description.ReferencesAndLinks = {"Human cortical dynamics during full-body heading changes"};
cfg.dataset_description.DatasetDOI = 'https://doi.org/10.1038/s41598-021-97749-8';
% 5. enter eeg metadata and feed to data2bids function
%--------------------------------------------------------------------------
cfg.datatype = 'eeg';
cfg.eeg.Manufacturer = 'BrainProducts';
cfg.eeg.ManufacturersModelName = 'n/a';
cfg.eeg.PowerLineFrequency = 50;
cfg.eeg.EEGReference = 'REF';
cfg.eeg.SoftwareFilters = 'n/a';
% time synch information in scans.tsv file
cfg.scans.acq_time = eegAcqTime;
data2bids(cfg, EEGftData);
% 6. enter motion metadata and feed to dat2bids functino
%--------------------------------------------------------------------------
cfg.datatype = 'motion';
cfg = rmfield(cfg, 'eeg');
cfg.tracksys = 'HTCVive';
cfg.motion.TrackingSystemName = 'HTCVive';
cfg.motion.DeviceSerialNumber = 'n/a';
cfg.motion.SoftwareVersions = 'n/a';
cfg.motion.Manufacturer = 'HTC';
cfg.motion.ManufacturersModelName = 'Vive Pro';
% specify channel details, this overrides the details in the original data structure
cfg.channels = [];
cfg.channels.name = {
'HTCVive_posX'
'HTCVive_posY'
'HTCVive_posZ'
'HTCVive_quatX'
'HTCVive_quatY'
'HTCVive_quatZ'
'HTCVive_quatW'
'HTCVive_ori'
};
cfg.channels.component= {
'x'
'y'
'z'
'quat_x'
'quat_y'
'quat_z'
'quat_w'
'n/a'
};
cfg.channels.type = {
'POS'
'POS'
'POS'
'ORI'
'ORI'
'ORI'
'ORI'
'MISC'
};
cfg.channels.units = {
'm'
'm'
'm'
'n/a'
'n/a'
'n/a'
'n/a'
'n/a'
};
cfg.channels.tracked_point = {
'head'
'head'
'head'
'head'
'head'
'head'
'head'
'head'
};
% rename the channels in the data to match with channels.tsv
MotionftData.label = cfg.channels.name;
% time synch information in scans.tsv file
cfg.scans.acq_time = motionAcqTime;
data2bids(cfg, MotionftData);