-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_coherence_average.m
144 lines (113 loc) · 3.94 KB
/
normalize_coherence_average.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
%%
%{
For each condition in each of the two groups, produces a weighed
average of coherences across each relevant pair of electrodes
(e.g., for graham_exp and roman_exp belonging to same
condition and group, take weighed average of the coherences
across electrode pairs O2-T8, and T8-FC6 - plot these in same
figure... as such, get 4 figures in total)
NOTE: this .m file contains multiple instances of the same code that
process all the group conditions in the way described above - this
is something the author of the code is not proud of (if time allows,
the code will be made more efficient).
%}
Fs = 128; % Emotiv sampling freq
wSize = 2048;
cols = 'kbm';
figure
%{
Musical background condition - experimental (graham_exp, roman_exp)
%}
for ii = 2:3
[C,F] = mscohere(graham_exp{ii-1},graham_exp{ii},hanning(wSize/4),wSize/8,[],Fs);
X{ii-1} = F;
Y{ii-1} = C;
end
for ii = 2:3
[C,F] = mscohere(roman_exp{ii-1},roman_exp{ii},hanning(wSize/4),wSize/8,[],Fs);
M{ii-1} = F;
N{ii-1} = C;
end
subplot(2,2,1)
for ii = 1:2
result{ii} = (length(graham_exp{1})*Y{ii} + length(roman_exp{1})*N{ii})/(length(graham_exp{1})+length(roman_exp{1}));
plot(M{ii},result{ii}, cols(ii), 'LineWidth', 2);
hold on
end
xlabel('Frequency (Hz)'); ylabel('Coherence');
set(gca,'XLim',[0 25],'XTick',0:5:25, 'YLim',[0 0.8],'YTick',0:0.2:0.8, 'FontSize',12); grid on;
legend('O2-T8','T8-FC6');
title('Musical background - musical imagery (N=2)');
%'YLim',[-20 0],'YTick',-20:5:0
%
% NOTE - code below is made of instances of the code above
%
%{
Musical background condition - control (graham_ctrl, roman_ctrl)
%}
for ii = 2:3
[C,F] = mscohere(graham_ctrl{ii-1},graham_ctrl{ii},hanning(wSize/4),wSize/8,[],Fs);
X{ii-1} = F;
Y{ii-1} = C;
end
for ii = 2:3
[C,F] = mscohere(roman_ctrl{ii-1},roman_ctrl{ii},hanning(wSize/4),wSize/8,[],Fs);
M{ii-1} = F;
N{ii-1} = C;
end
subplot(2,2,2)
for ii = 1:2
result{ii} = (length(graham_ctrl{1})*Y{ii} + length(roman_ctrl{1})*N{ii})/(length(graham_ctrl{1})+length(roman_ctrl{1}));
plot(M{ii},result{ii}, cols(ii), 'LineWidth', 2);
hold on
end
xlabel('Frequency (Hz)'); ylabel('Coherence');
set(gca,'XLim',[0 25],'XTick',0:5:25,'YLim',[0 0.8],'YTick',0:0.2:0.8,'FontSize',12); grid on;
legend('O2-T8','T8-FC6');
title('Musical background - visual imagery (N=2)');
%{
No musical background condition - experimental (savos_exp, angel_exp)
%}
for ii = 2:3
[C,F] = mscohere(savos_exp{ii-1},savos_exp{ii},hanning(wSize/4),wSize/8,[],Fs);
X{ii-1} = F;
Y{ii-1} = C;
end
for ii = 2:3
[C,F] = mscohere(angel_exp{ii-1},angel_exp{ii},hanning(wSize/4),wSize/8,[],Fs);
M{ii-1} = F;
N{ii-1} = C;
end
subplot(2,2,3)
for ii = 1:2
result{ii} = (length(savos_exp{1})*Y{ii} + length(angel_exp{1})*N{ii})/(length(savos_exp{1})+length(angel_exp{1}));
plot(M{ii},result{ii}, cols(ii), 'LineWidth', 2);
hold on
end
xlabel('Frequency (Hz)'); ylabel('Coherence');
set(gca,'XLim',[0 25],'XTick',0:5:25,'YLim',[0 0.8],'YTick',0:0.2:0.8,'FontSize',12); grid on;
legend('O2-T8','T8-FC6');
title('No musical background - musical imagery (N=2)');
%{
No musical background condition - control (savos_ctrl, angel_ctrl)
%}
for ii = 2:3
[C,F] = mscohere(savos_ctrl{ii-1},savos_ctrl{ii},hanning(wSize/4),wSize/8,[],Fs);
X{ii-1} = F;
Y{ii-1} = C;
end
for ii = 2:3
[C,F] = mscohere(angel_ctrl{ii-1},angel_ctrl{ii},hanning(wSize/4),wSize/8,[],Fs);
M{ii-1} = F;
N{ii-1} = C;
end
subplot(2,2,4)
for ii = 1:2
result{ii} = (length(savos_ctrl{1})*Y{ii} + length(angel_ctrl{1})*N{ii})/(length(savos_ctrl{1})+length(angel_ctrl{1}));
plot(M{ii},result{ii}, cols(ii), 'LineWidth', 2);
hold on
end
xlabel('Frequency (Hz)'); ylabel('Coherence');
set(gca,'XLim',[0 25],'XTick',0:5:25,'YLim',[0 0.8],'YTick',0:0.2:0.8,'FontSize',12); grid on;
legend('O2-T8','T8-FC6');
title('No musical background - visual imagery (N=2)');