forked from st-ts/bci_up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_eeg_set.m
83 lines (66 loc) · 3.15 KB
/
make_eeg_set.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
<<<<<<< HEAD
% Load the data
data_folder = 'D:\BCI\large_eeg_19ch_13subj\';
subj_file = 'CLA-SubjectJ-170504-3St-LRHand-Inter.mat'; % test for 1 subject for now
load([data_folder subj_file]); % Load the dataset
eeglab;
EEG = eeg_emptyset(); % Create an empty EEG structure for EEGLAB
% Fill in the relevant fields from the structure wisely named as 'o'
EEG.setname = o.id; % Use the ID as the dataset name
EEG.srate = o.sampFreq; % Sampling frequency
EEG.data = o.data'; % EEG data (transposed for EEGLAB compatibility)
EEG.nbchan = size(o.data, 2); % Number of channels
EEG.pnts = size(o.data, 1); % Number of time points
EEG.trials = 1; % Assume continuous data for now
EEG.xmin = 0; % Start time
EEG.xmax = (EEG.pnts - 1) / EEG.srate; % End time in seconds
EEG.times = linspace(EEG.xmin, EEG.xmax, EEG.pnts); % Time vector
% Add channel labels
EEG.chanlocs = struct('labels', o.chnames);
% Create the event structure from markers
EEG.event = [];
for i = 1:length(o.marker)
EEG.event(i).type = num2str(o.marker(i)); % Marker code as string
EEG.event(i).latency = i; % Event latency (sample index)
end
% Finalize the EEG structure
EEG = eeg_checkset(EEG);
% Plot the data to verify it's loaded correctly
pop_eegplot(EEG, 1);
% Save the EEG dataset to EEGLAB format
EEG = pop_saveset(EEG, 'filename', 'SubjectJ_LRHand.set', 'filepath', data_folder);
=======
% Load the data
data_folder = 'D:\BCI\large_eeg_19ch_13subj\';
subj_file = 'CLA-SubjectJ-170504-3St-LRHand-Inter.mat'; % test for 1 subject for now
load([data_folder subj_file]); % Load the dataset
eeglab;
EEG = eeg_emptyset(); % Create an empty EEG structure for EEGLAB
% Since the name of the last channel is missing from the data:
o.chnames{end+1} = 'X3';
% Fill in the relevant fields from the structure wisely named as 'o'
EEG.setname = o.id; % Use the ID as the dataset name
EEG.srate = o.sampFreq; % Sampling frequency
EEG.data = o.data'; % EEG data (transposed for EEGLAB compatibility)
EEG.nbchan = size(o.data, 2); % Number of channels
EEG.pnts = size(o.data, 1); % Number of time points
EEG.trials = 1; % Assume continuous data for now
EEG.xmin = 0; % Start time
EEG.xmax = (EEG.pnts - 1) / EEG.srate; % End time in seconds
EEG.times = linspace(EEG.xmin, EEG.xmax, EEG.pnts); % Time vector
% Add channel labels
EEG.chanlocs = struct('labels', o.chnames);
% Create the event structure from markers
EEG.event = [];
for i = 1:length(o.marker)
EEG.event(i).type = num2str(o.marker(i)); % Marker code as string
EEG.event(i).latency = i; % Event latency (sample index)
end
% Finalize the EEG structure
EEG = eeg_checkset(EEG);
% Plot the data to verify it's loaded correctly
pop_eegplot(EEG, 1);
% Save the EEG dataset to EEGLAB format
EEG = pop_saveset(EEG, 'filename', 'SubjectJ_LRHand.set', 'filepath', data_folder);
>>>>>>> 9f810a4 (add the reference channel name)
disp('EEG data loaded, structure created, and dataset saved successfully yay!');