eeyhsong / EEG-Conformer

EEG Transformer 2.0. i. Convolutional Transformer for EEG Decoding. ii. Novel visualization - Class Activation Topography.
GNU General Public License v3.0
389 stars 55 forks source link

promote on dataset1(Dataset 2a) S05 #15

Open Sacamore opened 1 year ago

Sacamore commented 1 year ago

I found that using my preprocessing program below

% 获取文件夹中的所有 gdf 文件
gdfFolder = './BCICIV_2a_gdf/'; % 指定文件夹路径
matFolder = './true_labels/';
outFolder = './Data/';
gdfFiles = dir(fullfile(gdfFolder, '*.gdf')); % 获取文件夹中的所有 gdf 文件
nfiles = length(gdfFiles); % 获取文件个数
disp(nfiles);
% 逐个处理 gdf 文件
for k = 1:nfiles
    % 获取当前文件名
    [gdfpath,gdfname,gdfExt] = fileparts(gdfFiles(k).name); % 获取文件名
    gdfpath = fullfile(gdfFolder, [gdfname,gdfExt]); % 获取完整路径
    matpath = fullfile(matFolder, [gdfname,'.mat']);
    % 读取 gdf 文件
    [signal, HDR] = sload(gdfpath); % 读取信号和头文件
    load(matpath);
    label = classlabel;

    % 获取事件信息
    % Event type   Description
    % 276   0x0114 Idling EEG (eyes open)
    % 277   0x0115 Idling EEG (eyes closed)
    % 768   0x0300 Start of a trial
    % 769   0x0301 Cue onset left (class 1)
    % 770   0x0302 Cue onset right (class 2)
    % 771   0x0303 Cue onset foot (class 3)
    % 772   0x0304 Cue onset tongue (class 4)
    % 783   0x030F Cue unknown
    % 1023  0x03FF Rejected trial
    % 1072  0x0430 Eye movements
    % 32766 0x7FFE Start of a new run
    event_pos = HDR.EVENT.POS; % 获取事件发生的位置(采样点)
    event_typ = HDR.EVENT.TYP; % 获取事件类型(数字编码)
    event_dur = HDR.EVENT.DUR; % 获取事件持续时间(数字)

    % 创建数据列表
    data = []; % 创建一个空列表
    cnt = 1;
    for i = 1:length(event_pos) % 对每个事件进行循环
        event_type = event_typ(i); % 获取事件类型
        if event_type == 768 % 如果事件类型为0x0300
            start_pos = event_pos(i) + 500; % 获取事件开始位置
            end_pos = start_pos + event_dur(i) - 1 - 875; % 获取事件结束位置
            data(cnt,:,:) = transpose(signal(start_pos:end_pos,1:22)); % 将信号中对应的信息添加到列表中
            cnt =  cnt + 1;
        end
    end

    data = fillmissing(data,'constant',0);

    % 设计6阶切比雪夫II型带通滤波器
    Fs = HDR.SampleRate; % 采样频率
    Wp = [0.1 60] / (Fs/2); % 通带截止频率归一化
    Ws = [0.05 100] / (Fs/2); % 阻带截止频率归一化
    Rp = 1; % 通带纹波
    Rs = 40; % 阻带衰减
    [n, Wn] = cheb2ord(Wp, Ws, Rp, Rs); % 计算滤波器阶数和截止频率
    [b, a] = cheby2(n, Rp, Wn); % 计算滤波器系数

    % 对信号进行滤波
    for i = 1:length(label)
        data(i,:,:) = filter(b,a,data(i,:,:));
    end

    % 保存为 mat 文件
    save([outFolder,gdfname,'.mat'], 'data', 'label'); % 保存为 mat 文件,包括信号、头文件、标记数列和数据列表

    % 显示进度信息
    disp(['Processed file ' num2str(k) ' of ' num2str(nfiles)]);
end

% 完成处理
disp('All files processed.');

would efficiently promote on S05 as:

acc: 52.08% --> 76.02%

and the other maintain a mild fluctuation I believe that it's only a preprocessing problem, hope this will help :D

eeyhsong commented 1 year ago

Thanks a lot for your help !!! Best wishes for your work. 🤝

eeyhsong commented 1 year ago