-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBatch_03_Fusion_Fig6.m
263 lines (225 loc) · 9.49 KB
/
Batch_03_Fusion_Fig6.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Name: Experiment_Fusion_Fig6
% Date of Revision: 2016-08
% Programmer: Thomas Praetzlich
% Resources: https://dx.doi.org/10.6084/m9.figshare.3398545
%
% Description:
% Compute results for different fusion strategies (no fusion, averaging
% over trials of a given participant, averaging over all trials of a
% given stimulus).
% See Figure 6 in [SPG16].
%
% Reference:
% [SPG16] Sebastian Stober; Thomas Prätzlich & Meinard Müller.
% Brain Beats: Tempo Extraction from EEG Data.
% International Society for Music Information Retrieval
% Conference (ISMIR), 2016
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
addpath('matlab_helpers');
close all
clear;
% filename = 'raw-agg_temphist_twin8';
filename = 'sce-agg_temphist_twin8';
numPeaks = 1; % use best match from top 1 tempo estimate
% numPeaks = 2; % use best match from top 2 tempo estimates
% numPeaks = 3; % use best match from top 3 tempo estimates
% intervals for bining values in colormap
intervals = [ 0 3; 3 5; 5 7; 8 8.5];
mat_tresh = [ 0 3 5 7];
data_suffix = '';
% printPaperPosition = [0.6350 6.3500 10.1600 7.6200];
printPaperPosition = [0 0 6 6];
% printPaperPosition = [0.6350 6.3500 10.1600 7.6200];
dir_figures = ['figure' data_suffix '/'];
dir_results = ['results' data_suffix '/'];
% audioTempo = readtable('results/table_tempo_tempogram.csv');
% audioTempoV1 = readtable('data/bpm_annotation.txt');
% audioTempoV1 = readtable('results/table_tempo-v1_tempogram.csv');
audioTempoV2 = readtable('results/table_tempo-v2_tempogram.csv');
% audioTempo = audioTempoV1;
d=load( [ dir_results filename ] );
cell_temphist = d.cell_temphist;
BPM = d.BPM;
% mat_pIDs = [ 01 04 06 07 09 11 12 13 14 ];
mat_pIDs = [ 09 11 12 13 14 ];
mat_sIDs = [ ...
01 02 03 04 ...
11 12 13 14 ...
21 22 23 24 ...
];
P = length(mat_pIDs);
S = length(mat_sIDs);
T = 5;
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% no fusion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mat_beatError_single = zeros(S,P,T);
mat_beatError_meanTrial = zeros(S,P);
mat_beatError_meanStim = zeros(S,1);
mat_errorRate = zeros( length(mat_tresh), 3);
for p = 1:P
pID = mat_pIDs(p);
if pID > 8 % all participants after P09 had a modified stimulus
audioTempo = audioTempoV2;
else
audioTempo = audioTempoV1;
end
for s = 1:S
sID = mat_sIDs(s);
for t = 1:T
mean_tempogram = cell_temphist{p,s}(t,:);
[ mat_peakVal, mat_peakIdx ] = pickPeaks( mean_tempogram, numPeaks, 10 );
curAudioTempo = audioTempo.BPM(audioTempo.sID == sID);
mat_beatError_single( s, p, t ) = min( abs( curAudioTempo - BPM( mat_peakIdx ) ) );
end
end
end
mat_errorRate(:,1) = compute_bpmErrorRate( mat_beatError_single, mat_tresh);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fusion: average over participant's trials
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for p = 1:P
pID = mat_pIDs(p);
if pID > 8 % all participants after P09 had a modified stimulus
audioTempo = audioTempoV2;
else
audioTempo = audioTempoV1;
end
for s = 1:S
sID = mat_sIDs(s);
mean_tempogram = mean( cell_temphist{p,s} );
[ mat_peakVal, mat_peakIdx ] = pickPeaks( mean_tempogram, numPeaks, 10 );
curAudioTempo = audioTempo.BPM(audioTempo.sID == sID);
mat_beatError_meanTrial( s, p ) = min( abs( curAudioTempo - BPM( mat_peakIdx ) ) );
end
end
mat_errorRate(:,2) = compute_bpmErrorRate( mat_beatError_meanTrial, mat_tresh);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fusion: average over all trials for a stimulus
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
audioTempo = audioTempoV2;
for s = 1:S
sID = mat_sIDs(s);
mean_tempogram = mean( cell2mat(cell_temphist(:,s)) );
[ mat_peakVal, mat_peakIdx ] = pickPeaks( mean_tempogram, numPeaks, 10 );
curAudioTempo = audioTempo.BPM(audioTempo.sID == sID);
mat_beatError_meanStim( s ) = min( abs( curAudioTempo - BPM( mat_peakIdx ) ) );
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Results table (LaTeX)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mat_errorRate(:,3) = compute_bpmErrorRate( mat_beatError_meanStim, mat_tresh);
for t = 1:length(mat_tresh)
fprintf('$%d$ & ',mat_tresh(t))
fprintf('$%02.2f$ & $%02.2f$ & $%02.2f$ \\\\ \n',100*mat_errorRate(t,:))
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Visualization single trials -> Figure 6a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FigureFilename = [ 'Fusion_SingleTrials_' filename 'max' num2str(numPeaks)];
mat_results_meanStim = reshape( permute(mat_beatError_single,[1 3 2]),12,[]);
figure;
% imagesc(); % this is only to get the axis position of an imagesc without colorbar ...
pos_old = get(gca,'position');
paramVis = [];
% paramVis.intervals = [ 0 0;1 3; 3 5; 5 7; 8 8.5];
paramVis.intervals = intervals;
paramVis.drawSeparator = true;
paramVis.XTick = 3:5:P*T;
paramVis.XTickLabel = cellfun( @(x) num2str( x,'%02d' ), num2cell( mat_pIDs) , 'UniformOutput', 0);
paramVis.YTick = 1:S;
paramVis.YTickLabel = cellfun( @(x) num2str( x,'%02d' ), num2cell( mat_sIDs) , 'UniformOutput', 0);
[ h_figure, h_axis ] = visualize_singleTrials( mat_results_meanStim, paramVis );
pos = get(gcf,'PaperPosition');
set(gcf,'PaperPosition',printPaperPosition)
c= findall(gcf,'type','colorbar');
% export without colorbar
%------------------------
delete(c)
axes_h = findall(gcf,'type','axes');
linkprop(axes_h,'position');
set(h_axis,'Position',pos_old)
set(gcf,'PaperPosition',printPaperPosition)
box on;
print('-dpng', [dir_figures FigureFilename '_noCBar'],'-r600')
print('-dpdf', [dir_figures FigureFilename '_noCBar'])
% export with numbers ...
%------------------------
% plotNumberInMatrix( mat_results )
% box on;
%
% print('-dpng', [dir_figures FigureFilename '_withNumbers'])
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Visualization participant (averaged trials) -> Figure 6b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FigureFilename = [ 'Fusion_ParticipantTrials_' filename 'max' num2str(numPeaks)];
mat_results_meanStim = mat_beatError_meanTrial;
figure;
% imagesc(); % this is only to get the axis position of an imagesc without colorbar ...
pos_old = get(gca,'position');
paramVis = [];
% paramVis.intervals = [ 0 0;1 3; 3 5; 5 7; 8 8.5];
paramVis.intervals = intervals;
paramVis.drawSeparator = false;
paramVis.XTick = 1:P;
paramVis.XTickLabel = cellfun( @(x) num2str( x,'%02d' ), num2cell( mat_pIDs) , 'UniformOutput', 0);
paramVis.YTick = 1:S;
paramVis.YTickLabel = cellfun( @(x) num2str( x,'%02d' ), num2cell( mat_sIDs) , 'UniformOutput', 0);
[ h_figure, h_axis ] = visualize_singleTrials( mat_results_meanStim, paramVis );
pos = get(gcf,'PaperPosition');
set(gcf,'PaperPosition',printPaperPosition)
c = findall(gcf,'type','colorbar');
% export without colorbar
%------------------------
delete(c)
axes_h = findall(gcf,'type','axes');
linkprop(axes_h,'position');
set(h_axis,'Position',pos_old)
set(gcf,'PaperPosition',printPaperPosition)
box on;
print('-dpng', [dir_figures FigureFilename '_noCBar'],'-r600')
print('-dpdf', [dir_figures FigureFilename '_noCBar'])
% export with numbers ...
%------------------------
% plotNumberInMatrix( mat_results )
% box on;
%
% print('-dpng', [dir_figures FigureFilename '_withNumbers'])
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Visualization participant (averaged trials) -> Figure 6a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FigureFilename = [ 'Fusion_StimulusTrials_' filename 'max' num2str(numPeaks)];
myPrintPaperPosition = printPaperPosition;
myPrintPaperPosition(3) = myPrintPaperPosition(3)/2;
mat_results_meanStim = mat_beatError_meanStim;
figure;
% imagesc(); % this is only to get the axis position of an imagesc without colorbar ...
pos_old = get(gca,'position');
paramVis = [];
% paramVis.intervals = [ 0 0;1 3; 3 5; 5 7; 8 8.5];
paramVis.intervals = intervals;
paramVis.drawSeparator = false;
paramVis.XTick = [];
paramVis.XTickLabel = cellfun( @(x) num2str( x,'%02d' ), num2cell( mat_pIDs) , 'UniformOutput', 0);
paramVis.YTick = 1:S;
paramVis.YTickLabel = cellfun( @(x) num2str( x,'%02d' ), num2cell( mat_sIDs) , 'UniformOutput', 0);
[ h_figure, h_axis ] = visualize_singleTrials( mat_results_meanStim, paramVis );
pos = get(gcf,'PaperPosition');
set(gcf,'PaperPosition',myPrintPaperPosition)
c = findall(gcf,'type','colorbar');
% export without colorbar
%--------------------------------------------------------------------------
delete(c)
axes_h = findall(gcf,'type','axes');
linkprop(axes_h,'position');
% set(h_axis,'Position',pos_old)
set(gcf,'PaperPosition',myPrintPaperPosition)
box on;
print('-dpng', [dir_figures FigureFilename '_noCBar'],'-r600')
% print('-dpdf', [dir_figures FigureFilename '_noCBar'])
% export with numbers ...
%--------------------------------------------------------------------------
plotNumberInMatrix(mat_results_meanStim)
print('-dpng', [dir_figures FigureFilename '_withNumbers'],'-r600')
% print('-dpdf', [dir_figures FigureFilename '_withNumbers'])