
written by Ki-Young Jung, MD
ENSLab. Neuroscience Research Institute
Seoul National University College of Medicine
last updated July 12, 2019
This tutorial is made using a ERP data published in following paper.
Byun J-I, Lee BU, Kim M, Sunwoo J-S, Lim J-A, Moon J, Lee S-T, Jung K-H,
Chu K, Kim M-H, Jeong MH, Cha KS, Choi JW, Kim KH, Lee SK, Jung K-Y.
Reduced P300 amplitude during a visuospatial attention task in idiopathic
rapid eye movement % sleep behavior disorder. Sleep Medicine 2017;38:78-84.
https://www.sciencedirect.com/science/article/abs/pii/S1389945717303155
Contents
- load data
- EEG structure
- data extraction
- data merge, divide
- find specific time period
- make ERP
- plot erp
- save figure and variable into file
load data
clc; clear all;
load rbd_erp_data.mat;
whos
% help whos
Name Size Bytes Class Attributes
EEG 1x1 18244950 struct global
EEG structure
EEG
data = EEG.data;
time = EEG.times;
srate = EEG.srate;
size(data) % 60 ch, 1200 data point, 120 epochs
EEG =
setname: ''
filename: 'RBD_3_Invalid1000.set'
filepath: 'C:\Users\jky\Dropbox\0713\매트랩...'
subject: ''
group: ''
condition: ''
session: []
comments: ''
nbchan: 60
trials: 63
pnts: 1200
srate: 400
xmin: -1.6000
xmax: 1.3975
times: [1x1200 double]
data: [60x1200x63 single]
icaact: []
icawinv: []
icasphere: []
icaweights: []
icachansind: []
chanlocs: [1x60 struct]
urchanlocs: []
chaninfo: [1x1 struct]
ref: 'common'
event: []
urevent: []
eventdescription: {}
epoch: []
... .... ....
ans =
60 1200 63
data extraction
% 특정 채널, 에폭, 시간대 데이터 뽑아내기
% epch 10, 20 만 추출
data_10 = data(:,:,10) ;
data_20 = data(:,:,20) ;
% channel 10 추출
data_ch10 = data(10, :, :);
data merge, divide
% 합치기
data_2D = [data_10 data_20]; % 가로 배열 붙이기
% cat 명령어로 A와 B를 2nd dimension 에서 붙인다.
data_30 = cat(2,data_10,data_20) ; % 서로 다른 데이터를 붙이기
% 3. 2차원 데이터 두개를 합쳐서 3차원 데이터로 만들기
data_3D(:,:,1) = data_10 ;
data_3D(:,:,2) = data_20 ;
% reshape
data_sum = reshape(data_2D, 60, 1200, []);
% data 차원 순서 바꾸기
aa = permute(data, [2, 3,1]); % time, epoch, channel 로 변경
find specific time period
% 특정 time index 찾기
[junk, tim_idx] = min(abs(time - 0)); % time 0 --> 640
% p300 구간대: 300 -500 ms
[junk, tim1] = min(abs(time - 400))
[junk, tim2] = min(abs(time - 600))
data_p300 = data(:, [tim1:tim2], :);
junk =
0
tim1 =
801
junk =
0
tim2 =
881
make ERP
% make ERP data: epoch을 평균시킴. 3D --> 2D
data_erp = mean(data, 3); % epoch을 평균냄
% p300 amplitude 구하기
data_erp_p300 = mean(data_erp(:, [tim1:tim2]), 2);
data_erp_p300 = squeeze(data_erp_p300);
% P300 amplitude at Pz channel
chan_idx = find(strcmpi({EEG.chanlocs.labels}, {'Fz'}))
chan_idx = find(strcmpi({EEG.chanlocs.labels}, {'Cz'}))
chan_idx = find(strcmpi({EEG.chanlocs.labels}, {'Pz'}))
data_erp_p300_Pz = data_erp_p300(48)
chan_idx =
12
chan_idx =
30
chan_idx =
48
data_erp_p300_Pz =
1.2367
plot erp
% plot all channels: butterfly plot
figure;
plot(time, data_erp)
% plot Pz channel
figure;
plot(time, data_erp(48, :))
xlim([-400, 800])
ylim([-4, 4])
% plot several channels
figure;
for k = 1:10
subplot(5,2,k); plot(time, data_erp(k, :));
end
% plot major 9 channels
chan_list = [10 12 14 28 30 32 46 48 50]; % frontal, centra, parietal
figure;
for k = 1:9
subplot(3,3,k);
plot(time, data_erp(chan_list(k), :));
axis([-200 1000 -4 4]);
hold on; plot([0 0], [-4 4])
end
save figure and variable into file
% saveas :
saveas(gcf, 'rbd_erp_plot', 'jpg');
% print명령을 사용
print( gcf, '-djpeg', 'rbd_erp_plot1');
% 여러 파일이름들을 자동으로 변수로 할당하기
list = dir('*.mat')
name1 = list(1).name(1:end-4)
% name2 = list(2).name(1:end-4)
% 위 할당 변수를 이용하여 저장하기
save([list(1).name(1:end-4) '_data'], 'data', '-v7.3');
% end of file. Enjoy! by JKY
list =
2x1 struct array with fields:
name
date
bytes
isdir
datenum
name1 =
rbd_erp_data
Comments (0)
You don't have permission to comment on this page.