-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_psd_preprocessing.m
215 lines (187 loc) · 5.68 KB
/
plot_psd_preprocessing.m
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
function plot_psd_preprocessing(results_dir1,results_dir2)
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function to plot the PSD from 2-10Hz for all three runs, using:
% 1. Raw Data
% 2. Pre-processed sensor-level data
% 3. Beamformed data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Raw Data
% Subject 001
cd(results_dir1);
disp('Loading data...');
d{1} = load('rawData_MEG1.mat');
d{2} = load('rawData_MEG2.mat');
d{3} = load('rawData_MEG3.mat');
cfg = [];
cfg.channel = {'N3-TAN'};
cfg.trial_length = 10;
cfg.method = 'tim';
cfg.foi = [0 40];
cfg.plot = 'no';
cfg.plot_legend = 'no';
[p{1} freq] = ft_opm_psd(cfg,d{1}.rawData_MEG);
[p{2} freq] = ft_opm_psd(cfg,d{2}.rawData_MEG);
[p{3} freq] = ft_opm_psd(cfg,d{3}.rawData_MEG);
% Subject 002
cd(results_dir2);
disp('Loading data...');
d{1} = load('rawData_MEG1.mat');
d{2} = load('rawData_MEG2.mat');
d{3} = load('rawData_MEG3.mat');
cfg = [];
cfg.channel = {'1A-TAN'};
cfg.trial_length = 10;
cfg.method = 'tim';
cfg.foi = [0 40];
cfg.plot = 'no';
cfg.plot_legend = 'no';
[p{4} freq] = ft_opm_psd(cfg,d{1}.rawData_MEG);
[p{5} freq] = ft_opm_psd(cfg,d{2}.rawData_MEG);
[p{6} freq] = ft_opm_psd(cfg,d{3}.rawData_MEG);
% Plot
figure;
cols = [0.4275 0.9804 0.3922;0.9804 0.5686 0.3843;
0.2824 0.3137 0.9804];
for i=1:3
po = (mean(p{i}(:,:,:),3)+ mean(p{i+3}(:,:,:),3))/2;
po_mean = squeeze(mean(po,2));
set(gcf,'Position',[100 100 800 800]);
fig= gcf;
fig.Color=[1,1,1]; hold on;
% Plot all channels
h = plot(freq,po_mean','Color',cols(i,:),'LineWidth',3);
h.Color(4) = 0.9;
end
grid on
ax = gca; % current axes
ax.FontSize = 30;
ax.TickLength = [0.02 0.02];
set(gca, 'YScale', 'log'); hold on;
xlabel('Frequency (Hz)','FontSize',37)
labY = ['$$PSD (' 'fT' ' \sqrt[-1]{Hz}$$)'];
ylabel(labY,'interpreter','latex','FontSize',37)
xlim([0 100]);
ylim([10 1e+4]);
print('PSD_rawData_0_100' ,'-dpng','-r300');
xlim([2 10]);
print('PSD_rawData_0_10' ,'-dpng','-r300');
%% HP-Filter
% Subject 001
cd(results_dir1);
disp('Loading data...');
d{1} = load('data_out_si_hp1.mat');
d{2} = load('data_out_si_hp2.mat');
d{3} = load('data_out_si_hp3.mat');
cfg = [];
cfg.channel = {'N3-TAN'};
cfg.trial_length = 10;
cfg.method = 'tim';
cfg.foi = [0 40];
cfg.plot = 'no';
cfg.plot_legend = 'no';
[p{1} freq] = ft_opm_psd(cfg,d{1}.data_out_si_hp);
[p{2} freq] = ft_opm_psd(cfg,d{2}.data_out_si_hp);
[p{3} freq] = ft_opm_psd(cfg,d{3}.data_out_si_hp);
% Subject 002
cd(results_dir2);
disp('Loading data...');
d{1} = load('data_out_si_hp1.mat');
d{2} = load('data_out_si_hp2.mat');
d{3} = load('data_out_si_hp3.mat');
cfg = [];
cfg.channel = {'1A-TAN'};
cfg.trial_length = 10;
cfg.method = 'tim';
cfg.foi = [0 40];
cfg.plot = 'no';
cfg.plot_legend = 'no';
[p{4} freq] = ft_opm_psd(cfg,d{1}.data_out_si_hp);
[p{5} freq] = ft_opm_psd(cfg,d{2}.data_out_si_hp);
[p{6} freq] = ft_opm_psd(cfg,d{3}.data_out_si_hp);
% Plot
figure;
cols = [0.4275 0.9804 0.3922;0.9804 0.5686 0.3843;
0.2824 0.3137 0.9804];
for i=1:3
po = (mean(p{i}(:,:,:),3)+ mean(p{i+3}(:,:,:),3))/2;
po_mean = squeeze(mean(po,2));
set(gcf,'Position',[100 100 800 800]);
fig= gcf;
fig.Color=[1,1,1]; hold on;
% Plot all channels
h = plot(freq,po_mean','Color',cols(i,:),'LineWidth',3);
h.Color(4) = 0.9;
end
grid on
ax = gca; % current axes
ax.FontSize = 30;
ax.TickLength = [0.02 0.02];
set(gca, 'YScale', 'log'); hold on;
xlabel('Frequency (Hz)','FontSize',37)
labY = ['$$PSD (' 'fT' ' \sqrt[-1]{Hz}$$)'];
ylabel(labY,'interpreter','latex','FontSize',37)
xlim([0 100]);
ylim([10 1e+4]);
print('PSD_sensor_level_0_100' ,'-dpng','-r300');
xlim([2 10]);
print('PSD_sensor_level_0_10' ,'-dpng','-r300');
%% After Beamforming
disp('Loading data...');
cd(results_dir1);
d{1} = load('VE_1.mat');
d{2} = load('VE_2.mat');
d{3} = load('VE_3.mat');
cfg = [];
cfg.channel = 'all';
cfg.trial_length = 10;
cfg.method = 'tim';
cfg.foi = [0 40];
cfg.plot = 'no';
cfg.plot_legend = 'no';
[p{1} freq] = ft_opm_psd(cfg,d{1}.VE);
[p{2} freq] = ft_opm_psd(cfg,d{2}.VE);
[p{3} freq] = ft_opm_psd(cfg,d{3}.VE);
% Subject 002
disp('Loading data...');
cd(results_dir2);
d{1} = load('VE_1.mat');
d{2} = load('VE_2.mat');
d{3} = load('VE_3.mat');
cfg = [];
cfg.channel = 'all';
cfg.trial_length = 10;
cfg.method = 'tim';
cfg.foi = [0 40];
cfg.plot = 'no';
cfg.plot_legend = 'no';
[p{4} freq] = ft_opm_psd(cfg,d{1}.VE);
[p{5} freq] = ft_opm_psd(cfg,d{2}.VE);
[p{6} freq] = ft_opm_psd(cfg,d{3}.VE);
% Plot
figure;
cols = [0.4275 0.9804 0.3922;0.9804 0.5686 0.3843;
0.2824 0.3137 0.9804];
for i=1:3
po = (mean(p{i}(:,:,:),3) + mean(p{i+3}(:,:,:),3))/2;
po_mean = squeeze(mean(po,2));
set(gcf,'Position',[100 100 800 800]);
fig= gcf;
fig.Color=[1,1,1]; hold on;
% Plot all channels
h = plot(freq,po_mean','Color',cols(i,:),'LineWidth',3);
h.Color(4) = 0.9;
end
grid on
ax = gca; % current axes
ax.FontSize = 30;
ax.TickLength = [0.02 0.02];
set(gca, 'YScale', 'log'); hold on;
xlabel('Frequency (Hz)','FontSize',37)
labY = ['$$PSD (' 'dB' '/{Hz}$$)'];
ylabel(labY,'interpreter','latex','FontSize',37)
ylim([3e-9 2.6e-8]);
%print('PSD_beamformer_0_40' ,'-dpng','-r300');
xlim([2 10]);
print('PSD_beamformer_0_10' ,'-dpng','-r300');
end