在毕设中学习04——mat数据导入与预处理,ICA处理


import scipy.io as scio
import numpy as np
import mne
import matplotlib.pyplot as plt


#导入mat类型的原始数据,分别读取到训练集train和测试集tesr
path = '/Users/sgfile/Downloads/BaiduNetdisk/20220528毕业论文(半完成)/BCI大赛第二届第三组数据-运动想象EEG/dataset_BCIcomp1.mat'
path2 ='/Users/sgfile/Downloads/BaiduNetdisk/20220528毕业论文(半完成)/BCI大赛第二届第三组数据-运动想象EEG/labels_data_set_iii.mat'
raw_data_1 = scio.loadmat(path)
raw_data_2 = scio.loadmat(path2)

# 获取【训练集数据,训练集标签,测试集数据】
x_train = raw_data_1['x_train'].T   # 原本数据是1152,3,140转置后位140,3,1152
y_train = raw_data_1['y_train']
x_test = raw_data_1['x_test'].T  
# 获取【测试集标签】
y_test = raw_data_2['y_test']

#查看数据集可以 print(y_train, y_train.shape)
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)


# 获得events:140*3
events = np.zeros([140, 3], dtype=int)
print('打印events的类型:', type(events))
print('打印出训练集标签的第一个元素:', y_train[0][0])

for i in range(0, 140, 1):
    events[i, 0] = i
    events[i, 2] = y_train[i][0]

# 事件标签,左1右2
events_id = dict(right_hand=1, left_hand=2)

# 创建epochs对象
sfreq1 = 128
ch_names1 = ['C3', 'CZ', 'C4']
ch_types1 = ['eeg', 'eeg', 'eeg']
info = mne.create_info(ch_names=ch_names1, ch_types=ch_types1, sfreq=sfreq1)

custom_epochs = mne.EpochsArray(x_train, info, events, tmin=0,event_id=events_id)
# 打印epochs信息
print(custom_epochs)

# ICA处理——————这个数据集里用不到
# ori_custom_epochs=custom_epochs.copy()

# ica = mne.preprocessing.ICA(n_components=3, random_state=97, method='fastica')
# ica.fit(ori_custom_epochs)

# 绘制
_ = custom_epochs['right_hand'].average().plot(time_unit='s')
#_ = ori_custom_epochs['right_hand'].average().plot(time_unit='s')
plt.show()

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fortunate.F

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值