1)实验过程:受试者想象左手运动、右手、舌头或脚的运动,想象四种动作的顺序随机。每次想象动作8 s钟。 2)数据格式:s1文件夹为运动想象数据,数据一共包含2个block,block1和block2,数据格式为:采样频率为250 Hz,block1{1,1}为运动想象数据,数据格式为通道试次采样点(3472000),一共三个通道,第一个通道为Cz,第二个通道为C3,第三个通道为C4。block1{1,2}为数据的标签,左手(1)、右手(2)、双脚(3)和舌头(4)。每一个block数据一共包含47个试次。47个试次对应的标签见block{1,2}。每个Block每种运动大概11-12个试次。 3、任务要求: 给出C3、Cz、C4两个通道下左右手、舌和脚平均功率谱图,观察ERD/ERS现象。(将每个试次脑电信号求功率谱,然后所有个试次叠加平均) 提供MATLAB代码和思路
时间: 2024-02-19 12:59:16 浏览: 38
思路:
1. 对每个试次的脑电信号进行傅里叶变换,求出该试次的功率谱
2. 将所有试次的功率谱叠加平均,得到每个通道下左右手、舌和脚的平均功率谱
3. 观察平均功率谱中的ERD/ERS现象,判断脑区在不同任务下的激活情况
MATLAB代码:
```matlab
% 读取数据
data_path = 's1/';
load([data_path 's1.mat']);
% 设置参数
fs = 250; % 采样频率
epoch_len = 8; % 每个试次的时长
n_epoch = 47; % 试次数
n_channel = 3; % 通道数
% 初始化功率谱矩阵
p = zeros(n_epoch, n_channel, fs/2+1);
% 计算功率谱
for i = 1:n_epoch
epoch_data = squeeze(block1{1,1}(:,:,i));
for j = 1:n_channel
[pxx, f] = pwelch(epoch_data(:,j), fs, fs/2, fs, fs);
p(i,j,:) = pxx';
end
end
% 计算平均功率谱
mean_p = mean(p, 1);
% 绘制平均功率谱
figure;
for i = 1:n_channel
subplot(n_channel,1,i);
plot(f, 10*log10(squeeze(mean_p(1,i,:))));
xlim([0 30]);
title(['Channel ' num2str(i)]);
end
% 计算ERD/ERS指数
task_labels = block1{1,2};
left_hand_idx = find(task_labels == 1);
right_hand_idx = find(task_labels == 2);
foot_idx = find(task_labels == 3);
tongue_idx = find(task_labels == 4);
for i = 1:n_channel
% 左手任务
left_hand_p = squeeze(mean_p(1,i,left_hand_idx,:));
baseline_p = mean(left_hand_p(f<10));
erd = (baseline_p - left_hand_p) ./ baseline_p * 100;
ers = (left_hand_p - baseline_p) ./ baseline_p * 100;
disp(['Channel ' num2str(i) ' left hand ERD: ' num2str(mean(erd(f>8 & f<12))) '%']);
disp(['Channel ' num2str(i) ' left hand ERS: ' num2str(mean(ers(f>18 & f<22))) '%']);
% 右手任务
right_hand_p = squeeze(mean_p(1,i,right_hand_idx,:));
baseline_p = mean(right_hand_p(f<10));
erd = (baseline_p - right_hand_p) ./ baseline_p * 100;
ers = (right_hand_p - baseline_p) ./ baseline_p * 100;
disp(['Channel ' num2str(i) ' right hand ERD: ' num2str(mean(erd(f>8 & f<12))) '%']);
disp(['Channel ' num2str(i) ' right hand ERS: ' num2str(mean(ers(f>18 & f<22))) '%']);
% 脚任务
foot_p = squeeze(mean_p(1,i,foot_idx,:));
baseline_p = mean(foot_p(f<10));
erd = (baseline_p - foot_p) ./ baseline_p * 100;
ers = (foot_p - baseline_p) ./ baseline_p * 100;
disp(['Channel ' num2str(i) ' foot ERD: ' num2str(mean(erd(f>8 & f<12))) '%']);
disp(['Channel ' num2str(i) ' foot ERS: ' num2str(mean(ers(f>18 & f<22))) '%']);
% 舌任务
tongue_p = squeeze(mean_p(1,i,tongue_idx,:));
baseline_p = mean(tongue_p(f<10));
erd = (baseline_p - tongue_p) ./ baseline_p * 100;
ers = (tongue_p - baseline_p) ./ baseline_p * 100;
disp(['Channel ' num2str(i) ' tongue ERD: ' num2str(mean(erd(f>8 & f<12))) '%']);
disp(['Channel ' num2str(i) ' tongue ERS: ' num2str(mean(ers(f>18 & f<22))) '%']);
end
```
解释说明:
1. 对每个试次的脑电信号进行傅里叶变换,求出该试次的功率谱。使用MATLAB的pwelch函数进行功率谱估计,其中fs表示采样频率,fs/2表示截止频率,fs表示窗口长度,fs表示重叠长度,由于本数据采样频率为250Hz,因此截止频率为125Hz,窗口长度为250,重叠长度为250。
2. 将所有试次的功率谱叠加平均,得到每个通道下左右手、舌和脚的平均功率谱。使用MATLAB的mean函数求平均值。
3. 观察平均功率谱中的ERD/ERS现象,判断脑区在不同任务下的激活情况。根据ERD/ERS指数的定义,我们只需要计算特定频段内的功率下降/上升的百分比即可。在本例中,我们使用了8-12Hz作为ERD的频段,使用18-22Hz作为ERS的频段。