-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean_ERP_MAK.m
More file actions
112 lines (103 loc) · 3.73 KB
/
clean_ERP_MAK.m
File metadata and controls
112 lines (103 loc) · 3.73 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
function [Final_ERP probemap_chrem] = clean_ERP_MAK (ERP,timing,probemap_chrem,shank)
% modified by MAK 6/6/17 - type in ch to remove rather than selecting
% EGM edited 5/18/2016 to suit 64D probes & track which channels were
% deleted & do normalization
norm_ERP = ERP;
for i=1:length(ERP(:,1))
if ~isnan(ERP(i,1))
norm_ERP(i,:) = ERP(i,:)-nanmean(ERP,1);
end
end
figure;
plot(timing,ERP','DisplayName',sprintf('ERP_shk%d',shank),'YDataSource',sprintf('ERP_shk%d',shank));figure(gcf)
xlabel({'Time from stimulus onset (s)'});
ylabel({'Voltage (uV)'})
xlim([-0.05 0.4])
fig_title=sprintf('%s','Raw ERP ');
title(strrep(fig_title,'_','\_'));
for i=1:size(ERP,1)
legend_cell{1,i} = num2str(i);
end
legend(legend_cell);
figure;
plot(timing,norm_ERP','DisplayName',sprintf('ERP_shk%d',shank),'YDataSource',sprintf('ERP_shk%d',shank));figure(gcf)
xlabel({'Time from stimulus onset (s)'});
ylabel({'Voltage (uV)'})
xlim([-0.05 0.4])
fig_title=sprintf('%s','Raw ERP - Normalized to mean');
title(strrep(fig_title,'_','\_'));
for i=1:size(ERP,1)
legend_cell{1,i} = num2str(i);
end
legend(legend_cell);
reply = input('Do you want to remove any electodes? Y/N: ','s');
if reply == 'Y' || reply == 'y';
electrode_position = input('Which electrode would you like to remove? ', 's');
i = str2num(electrode_position);
ERP(i,:)=nan;
probemap_chrem(i,shank) = nan;
end
while reply ~= 'N' && reply ~= 'n'
close all
%display corrected
norm_ERP = ERP;
for i=1:length(ERP(:,1))
if ~isnan(ERP(i,1))
norm_ERP(i,:) = ERP(i,:)-nanmean(ERP,1);
end
end
figure;plot (timing,ERP', 'DisplayName', sprintf('ERP_shk%d',shank), 'YDataSource', sprintf('ERP_shk%d',shank)); figure(gcf);
xlabel({'Time from stimulus onset (s)'});
ylabel({'Amplitude(uV)'});
xlim([-0.05 0.4])
fig_title=sprintf('%s','Electrode removed ERP - RAW');
title(strrep(fig_title,'_','\_'));
for i=1:size(ERP,1)
legend_cell{1,i} = num2str(i);
end
legend(legend_cell);
figure;plot (timing,norm_ERP', 'DisplayName', sprintf('ERP_shk%d',shank), 'YDataSource', sprintf('ERP_shk%d',shank)); figure(gcf);
xlabel({'Time from stimulus onset (s)'});
ylabel({'Amplitude(uV)'});
xlim([-0.05 0.4])
fig_title=sprintf('%s','Electrode removed ERP - Normalized to mean');
title(strrep(fig_title,'_','\_'));
for i=1:size(ERP,1)
legend_cell{1,i} = num2str(i);
end
legend(legend_cell);
% remove another electrode
reply = input('Do you want to remove another electode? Y/N: ','s');
if reply == 'Y' || reply == 'y'
electrode_position = input('Which electrode would you like to remove? ', 's');
i = str2num(electrode_position);
ERP(i,:)=nan;
probemap_chrem(i,shank) = nan;
end
end
%display figure
close all
disp('Plot new and improved ERP and save mat file for CSD analysis');
figure;plot (timing,ERP', 'DisplayName', sprintf('ERP_shk%d',shank), 'YDataSource', sprintf('ERP_shk%d',shank)); figure(gcf);
xlabel({'Time from stimulus onset (s)'});
ylabel({'Amplitude(mV)'});
xlim([-0.05 0.4])
fig_title=sprintf('%s','Final ERP - RAW ');
title(strrep(fig_title,'_','\_'));
for i=1:size(ERP,1)
legend_cell{1,i} = num2str(i);
end
legend(legend_cell);
figure;plot (timing,norm_ERP', 'DisplayName', sprintf('ERP_shk%d',shank), 'YDataSource', sprintf('ERP_shk%d',shank)); figure(gcf);
xlabel({'Time from stimulus onset (s)'});
ylabel({'Amplitude(mV)'});
xlim([-0.05 0.4])
fig_title=sprintf('%s','Final ERP - NORMALIZED ');
title(strrep(fig_title,'_','\_'));
for i=1:size(ERP,1)
legend_cell{1,i} = num2str(i);
end
legend(legend_cell);
% end
Final_ERP=norm_ERP;
end