-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcn_plotEEGqEEGpair_MGH.m
More file actions
186 lines (144 loc) · 6.16 KB
/
Copy pathfcn_plotEEGqEEGpair_MGH.m
File metadata and controls
186 lines (144 loc) · 6.16 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function fcn_plotEEGqEEGpair_MGH(local)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Got input arguements %
dataDir = local.dataDir;
fileName = local.fileName;
ii = local.ii_target;
ekgScale = local.ekgScale;
zScale = local.zScale;
w = local.w; % eeg duration 14 sec span %
W = local.W; % Spe seg [sec] - 1 hr spectrogram / 2 sec resolution %
switch W/60
case 15
spect_x_step = 5; thr_ = .5;
case 30
spect_x_step = 10; thr_ = 1;
case 60
spect_x_step = 20; thr_ = 2;
end
montageFlag = local.montageFlag;
Fs = local.Fs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(['Process ', fileName])
% Load data %
tmp = load([dataDir,fileName]);
Sdata_disp = tmp.Sdata;
S_x = tmp.S_x;
S_y = tmp.S_y;
seg_disp = tmp.seg_disp;
tc = tmp.tc;
tt = tmp.tt;
tto = tt(1); % [pts]
tt1 = tt(end); % [pts]
timeStampo = tmp.timeStampo;
timeStamps = tmp.timeStamps;
timeStamp_s = tmp.timeStamp_s;
channel_withspace = {'Fp1-F7' 'F7-T3' 'T3-T5' 'T5-O1' '' 'Fp2-F8' 'F8-T4' 'T4-T6' 'T6-O2' '' 'Fp1-F3' 'F3-C3' 'C3-P3' 'P3-O1' '' 'Fp2-F4' 'F4-C4' 'C4-P4' 'P4-O2' '' 'Fz-Cz' 'Cz-Pz' '' 'EKG'};
if strcmp(montageFlag, 'bipolarNoMidline')
seg_disp = seg_disp([1:end-5, end-1:end], :);
channel_withspace = channel_withspace([1:end-5, end-1:end]);
end
M = size(seg_disp, 1);
DCoff = repmat(flipud((1:M)'), 1, size(seg_disp, 2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot EEG %
f1 = figure('units','normalized','outerposition',[0 0 1 1]);
hold on
% grid lines per sec %
for iSec = 2:round((tt1-tto+1)/Fs)
ta = tto + Fs*(iSec-1);
line([ta ta], [0 M+1], 'linestyle', '--', 'color', [.5 .5 .5])
end
plot(gca, tt, zScale*seg_disp(1:end-1,:)+DCoff(1:end-1,:),'k');
ekg_ = seg_disp(end,:);
ekg_ = (ekg_-mean(ekg_))/(eps+std(ekg_));
plot(gca, tt, ekgScale*ekg_+DCoff(end,:),'r');
box on;
set(gca, 'ytick',1:M,'yticklabel',fliplr(channel_withspace),'box','on', 'ylim', [0 M+1], 'xlim', [tto tt1], 'xtick',round(tt(1):2*Fs:tt(end)),'xticklabel',timeStamps)
% Scale rulers % for sanity check %
dt = tt1-tto+1;
a = round(dt*4/5);
xa1 = tto+[a a+Fs-1];
ya1 = [3 3];
xa2 = tto+[a a];
ya2 = ya1+[0 abs(100*zScale)];
% Move the scale rulers if any %
text(-100+xa1(1)-.4*a/10, 1+mean(ya2), '100 \muV','Color', 'b','FontSize',12);
text(-100+mean(xa1)-0.15*a/10,1+2.7, '1 sec','Color', 'b','FontSize',12);
line(-100+xa1, 1+ya1, 'LineWidth', 1, 'Color','b');
line(-100+xa2, 1+ya2, 'LineWidth', 1, 'Color','b');
color = get(f1,'Color');
set(gca,'XColor',color,'YColor',color,'TickDir','out')
for i = 1:M
text(tto, i, [channel_withspace{length(channel_withspace)+1-i}, ' '], 'HorizontalAlignment', 'right')
end
eeg_xticks = round(tt(1):2*Fs:tt(end))+Fs;
for i = 1:length(eeg_xticks)
text(eeg_xticks(i), -.2, timeStamps(i,:), 'HorizontalAlignment', 'center')
end
if strcmp(montageFlag,'averageWithMoreInteriors')
set(gca, 'position', [0.04 .05 .95 .92])
else
set(gca, 'position', [0.03 .05 .95 .92])
end
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot Spectrograms %
f2 = figure('units','normalized','outerposition',[0 0 1 1]);
Ax_spect = {subplot('position',[0.03 .05 .95 .225]); subplot('position',[0.03 .28 .95 .225]);
subplot('position',[0.03 .51 .95 .225]); subplot('position',[0.03 .74 .95 .225]);
subplot('position',[0.03 .975 .95 .02])};
% Display %
labelsS = {'RP ','LP ','RL ','LL '};
col=[-10 25]; % range of color scale
colormap jet
for iReg = 1:4
cla(Ax_spect{iReg});
set(f2,'CurrentAxes',Ax_spect{iReg});
spec = imdiffusefilt(Sdata_disp{5-iReg});
imagesc(S_x, S_y, pow2db(spec), col); axis(Ax_spect{iReg},'xy'); box on
if iReg==1
set(Ax_spect{iReg},'XAxisLocation','bottom','YAxisLocation','right')
else
set(Ax_spect{iReg},'xtick',[],'XAxisLocation','bottom','YAxisLocation','right')
end
% time line %
hold(Ax_spect{iReg}, 'on')
plot([tc tc], [S_y(1) S_y(end)], 'k--','linewidth',1);
hold(Ax_spect{iReg}, 'off')
set(Ax_spect{iReg},'ytick',0:5:20,'yticklabel',{'0' '5' '10' '15' '20Hz'})
set(get(Ax_spect{iReg},'YLabel'),'Rotation',270)
% 4 regions label %
s_title = title(Ax_spect{iReg},labelsS{iReg}, 'Position', [0 0 0]);
set(s_title, 'horizontalAlignment', 'right');
set(s_title, 'units', 'normalized');
pos = get(s_title, 'position');
set(s_title, 'position', [0 pos(2)+0.45 pos(3)])
end
% indicator %
set(f2,'CurrentAxes',Ax_spect{end});
cla(Ax_spect{end})
plot(tc, 0,'rv','markersize', 8,'MarkerFaceColor','r'); axis off;
set(Ax_spect{end},'xtick',[],'xlim',get(Ax_spect{end-1},'xlim'), 'ylim', [0 .5])
% Real time stamps at the bottom %
timeStamp_sc = timeStampo + seconds(tc);
to = S_x(1);
t1 = S_x(end);
spec_xticks = [(to-1):spect_x_step*60:(t1-1), t1];
set(Ax_spect{1}, 'xtick', spec_xticks, 'xticklabel', [])
for i = 1:length(spec_xticks)
dt = abs(seconds(timeStamp_s(i) - timeStamp_sc));
if dt>=thr_*60
text(Ax_spect{1}, spec_xticks(i), -.2, datestr(timeStamp_s(i), 'hh:MM:ss'), 'HorizontalAlignment', 'center');
end
end
% event time in red bold %
text(Ax_spect{1}, tc, -.2, datestr(timeStamp_sc, 'hh:MM:ss'), 'HorizontalAlignment', 'center', 'Color', 'r', 'FontWeight', 'bold')
% % export images %
if local.exportFlag
picName = local.imageKey;
print(f1, '-dtiff', '-r300',strrep([pwd, '\Pics\', picName,'_EEG_',montageFlag,'.tif'], '_Bipolar', ''));
print(f2, '-dtiff', '-r300',[pwd, '\Pics\', picName,'_qEEG.tif'])
end
save([pwd, '\SegMats\', fileName], 'S_x', 'S_y', 'Sdata_disp', 'timeStampo', 'timeStamp_s', 'timeStamps', 'tc', 'tt', 'spec_xticks','seg_disp', 'channel_withspace','w', 'W', 'Fs', 'local', 'ekgScale', 'zScale');
close all