-
Notifications
You must be signed in to change notification settings - Fork 7
/
plot_mch_energy.m
324 lines (282 loc) · 10.2 KB
/
plot_mch_energy.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Energy Spectrogram Plotting Script
% ----------------------------------
% A script for plotting energy spectrograms of loudspeaker array room
% impulse responses (RIRs), using different rendering methods.
%
% DEPENDENCES
% Spherical-Harmonic-Transform Matlab library
% https://github.com/polarch/Spherical-Harmonic-Transform
% Higher-Order-Ambisonics Matlab library
% https://github.com/polarch/Higher-Order-Ambisonics
% Vector-Base-Amplitude-Panning
% https://github.com/polarch/Vector-Base-Amplitude-Panning
% Higher-Order-Ambisonics
% https://github.com/polarch/Higher-Order-Ambisonics
% (Optional) SDM Toolbox
% https://se.mathworks.com/matlabcentral/fileexchange/56663-sdm-toolbox
%
% REFERENCES
% [1] Favrot, S. and Buchholz, J.M., 2010.
% LoRA: A loudspeaker-based room auralization system. Acta Acustica
% united with Acustica, 96(2), pp.364-375.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Leo McCormack, 07/08/2019
% Ville Pulkki, 23/05/2019
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all, close all %#ok
addpath '_Simulated_Rooms_' '_Stimuli_'
viewangs = [70 60];
display_lpf_cutoff_freq_hz = 100;
enableSDMplots = exist('SDMbf', 'file');
%% PLOT REFERENCE
% This is a simulated Auditorium room using ODEON and LoRA [1], which is
% configured for DTU's AVIL anechoic listening room.
% We will use this as a reference.
[ref, fs] = audioread('Auditorium_64ch_DTU_AVIL.wav');
load('DTU_ls_dirs_deg.mat')
% apply low-pass filter with the specified cut-off, and compute the energy for
% each channel
[blp,alp]=butter(1, display_lpf_cutoff_freq_hz/(fs/2)); % low-pass filter
e_ref=filter(blp,alp,ref.^2);
e_ref=10*log10(e_ref+eps);
maxx=max(max(e_ref));
e_ref=e_ref-maxx;
mean_e_ref = mean( mean(e_ref( (end-2048):end, :)) );
e_ref=max(-59.8,e_ref);
% plot resulting energy spectrogram
figure
[m,n]=size(e_ref);
mesh([1:n]',[1:m]'/fs*1000,e_ref) %#ok
view(viewangs)
title('Reference')
set(gca,'fontsize', 14)
xlabel('Channel #')
ylabel('Time [ms]')
zlabel('Scaled energy [dB]')
set(gca,'Xtick',[size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)]) %#ok
axis([1, size(ls_dirs_deg,1), 20, 400, -60, 0 ])
caxis([-60 -15])
colormap('jet')
%print -deps2c wfall_ref.eps
%% HO-SIRR
orders = [1 3 5];
% config
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
pars.ls_dirs_deg = ls_dirs_deg;
pars.fs = fs;
pars.multires_winsize = 128;
pars.multires_xovers = [];
%pars.multires_winsize = [512, 128, 64];
%pars.multires_xovers = [500, 2e3];
pars.RENDER_DIFFUSE = 1;
pars.BROADBAND_FIRST_PEAK = 1;
pars.BROADBAND_DIFFUSENESS = 1;
pars.maxDiffFreq_Hz = 3000;
pars.decorrelationType = 'noise';
pars.alpha_diff = 0.5;
% loop through the different input orders
for order = orders
shir = ref * getRSH(order, ls_dirs_deg).';
sirr = HOSIRR(shir, pars); %orderPerBand
% apply same post-processing as with the reference
e_sirr=filter(blp,alp,sirr.^2);
e_sirr=10*log10(e_sirr+eps);
maxx=max(max(e_sirr));
e_sirr=e_sirr-maxx;
mean_e_sirr = mean( mean(e_sirr( (end-2048):end, :)) );
% compensate for the change in maximum level, by normalising it to the
% reference, based on the total energy in the last 2048 samples of the
% response
e_sirr = e_sirr-(mean_e_sirr-mean_e_ref);
e_sirr=max(-59.8,e_sirr);
% plot resulting energy spectrogram
figure
[m,n]=size(e_sirr);
mesh([1:n]',[1:m]'/fs*1000,e_sirr) %#ok
view(viewangs)
title(['SIRR order: ' num2str(order)])
set(gca,'fontsize', 14)
xlabel('Channel #')
ylabel('Time [ms]')
zlabel('Scaled energy [dB]')
set(gca,'Xtick',[size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)]) %#ok
axis([1, size(ls_dirs_deg,1), 20, 400, -60, 0 ])
caxis([-60 -15])
colormap('jet')
%print -deps2c wfall_sirr.eps
end
%% MODE-MATCHING AMBISONIC DECODER (MMD)
orders = [1 3 5];
% loop through the different input orders
for order = orders
shir = ref * getRSH(order, ls_dirs_deg).';
ambi = shir * pinv(getRSH(order, ls_dirs_deg).');
% apply same post-processing as with the reference
e_ambi=filter(blp,alp,ambi.^2);
e_ambi=10*log10(e_ambi+eps);
maxx=max(max(e_ambi));
e_ambi=e_ambi-maxx;
mean_e_ambi = mean( mean(e_ambi( (end-2048):end, :)) );
% compensate for the change in maximum level, by normalising it to the
% reference, based on the total energy in the last 2048 samples of the
% response
e_ambi = e_ambi-(mean_e_ambi-mean_e_ref);
e_ambi=max(-59.8,e_ambi);
% plot resulting energy spectrogram
figure
[m,n]=size(e_ambi);
mesh([1:n]',[1:m]'/fs*1000,e_ambi) %#ok
view(viewangs)
title(['Ambisonics (MMD) order: ' num2str(order)])
set(gca,'fontsize', 14)
xlabel('Channel #')
ylabel('Time [ms]')
zlabel('Scaled energy [dB]')
set(gca,'Xtick',[size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)]) %#ok
axis([1, size(ls_dirs_deg,1), 20, 400, -60, 0 ])
caxis([-60 -15])
colormap('jet')
%print -deps2c wfall_ambi.eps
end
%% SPATIAL DECOMPOSITION METHOD (B-FORMAT VARIANT)
if ~enableSDMplots; return; end
shir = ref * getRSH(1, ls_dirs_deg).';
% convert shir to the ambisonic conventions used by SDM
shir = shir(:, [1 4 2 3]); % convert from ACN to WXYZ ordering
shir(:, 2:4) = shir(:, 2:4)./sqrt(3); % convert from N3D to SN3D normalisation
% configure and apply SDM
% (note that these values were taken from the b-format demo script in the
% SDM toolbox) - Except a window length of 1, instead of 15
a = createSDMStruct('DefaultArray','Bformat','fs',fs,'winLen',1);
DOA = SDMbf(shir, a);
P = shir(:,1);
ls_dirs_deg_w_r = [ls_dirs_deg ones(size(ls_dirs_deg,1),1)]; % add radius
s = createSynthesisStruct('lspLocs',ls_dirs_deg_w_r,'snfft',length(P) ,...
'ShowArray',false,'fs',fs,'c',343,...
'LFEchannel',[]);
sdmir = synthesizeSDMCoeffs(P,DOA, s);
% figure, subplot(2,1,1)
% plot(shir(1:end/8,1)), title('input pressure')
% subplot(2,1,2)
% plot(sum(sdmir(1:end/8,:),2)), title('combined response')
% apply same post-processing as with the reference
e_sdmir=filter(blp,alp,sdmir.^2);
e_sdmir=10*log10(e_sdmir+eps);
maxx=max(max(e_sdmir));
e_sdmir=e_sdmir-maxx;
mean_e_sirr = mean( mean(e_sdmir( (end-2048):end, :)) );
% compensate for the change in maximum level, by normalising it to the
% reference, based on the total energy in the last 2048 samples of the
% response
e_sdmir = e_sdmir-(mean_e_sirr-mean_e_ref);
e_sdmir=max(-59.8,e_sdmir);
% plot resulting energy spectrogram
figure
[m,n]=size(e_sdmir);
mesh([1:n]',[1:m]'/fs*1000,e_sdmir) %#ok
view(viewangs)
title('SDM (B-Format) order: 1')
set(gca,'fontsize', 14)
xlabel('Channel #')
ylabel('Time [ms]')
zlabel('Scaled energy [dB]')
set(gca,'Xtick',[size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)]) %#ok
axis([1, size(ls_dirs_deg,1), 20, 400, -60, 0 ])
caxis([-60 -15])
colormap('jet')
%print -deps2c wfall_sdm.eps
%% SIRR 1ST ORDER NO DIFFUSE STREAM
order = 1;
% config
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
pars.ls_dirs_deg = ls_dirs_deg;
pars.fs = fs;
pars.multires_winsize = 16; % more in line with SDM
pars.multires_xovers = [];
pars.RENDER_DIFFUSE = 0; % disabled here
pars.BROADBAND_FIRST_PEAK = 1;
pars.BROADBAND_DIFFUSENESS = 1;
pars.maxDiffFreq_Hz = 3000;
pars.decorrelationType = 'noise';
pars.alpha_diff = 0.5;
shir = ref * getRSH(order, ls_dirs_deg).';
sirr = HOSIRR(shir, pars);
% apply same post-processing as with the reference
e_sirr=filter(blp,alp,sirr.^2);
e_sirr=10*log10(e_sirr+eps);
maxx=max(max(e_sirr));
e_sirr=e_sirr-maxx;
mean_e_sirr = mean( mean(e_sirr( (end-2048):end, :)) );
% compensate for the change in maximum level, by normalising it to the
% reference, based on the total energy in the last 2048 samples of the
% response
e_sirr = e_sirr-(mean_e_sirr-mean_e_ref);
e_sirr=max(-59.8,e_sirr);
% plot resulting energy spectrogram
figure
[m,n]=size(e_sirr);
mesh([1:n]',[1:m]'/fs*1000,e_sirr) %#ok
view(viewangs)
title(['SIRR without diffuse stream order: ' num2str(order)])
set(gca,'fontsize', 14)
xlabel('Channel #')
ylabel('Time [ms]')
zlabel('Scaled energy [dB]')
set(gca,'Xtick',[size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)]) %#ok
axis([1, size(ls_dirs_deg,1), 20, 400, -60, 0 ])
caxis([-60 -15])
colormap('jet')
%print -deps2c wfall_sirr.eps
%% HO-SIRR (ORDER PER BAND VERSION)
order = 4;
pars.freqLimits = [375 1e3 2e3 6.5e3 7.5e3 8.5e3];
pars.procOrders = [1 2 3 4 3 2 1];
% config
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
pars.ls_dirs_deg = ls_dirs_deg;
pars.fs = fs;
pars.multires_winsize = 128;
pars.multires_xovers = [];
%pars.multires_winsize = [512, 128, 64];
%pars.multires_xovers = [500, 2e3];
pars.RENDER_DIFFUSE = 1;
pars.BROADBAND_FIRST_PEAK = 1;
pars.decorrelationType = 'noise';
pars.alpha_diff = 0.975;
shir = ref * getRSH(order, ls_dirs_deg).';
sirr = HOSIRR_orderPerBand(shir, pars);
% apply same post-processing as with the reference
e_sirr=filter(blp,alp,sirr.^2);
e_sirr=10*log10(e_sirr+eps);
maxx=max(max(e_sirr));
e_sirr=e_sirr-maxx;
mean_e_sirr = mean( mean(e_sirr( (end-2048):end, :)) );
% compensate for the change in maximum level, by normalising it to the
% reference, based on the total energy in the last 2048 samples of the
% response
e_sirr = e_sirr-(mean_e_sirr-mean_e_ref);
e_sirr=max(-59.8,e_sirr);
% plot resulting energy spectrogram
figure
[m,n]=size(e_sirr);
mesh([1:n]',[1:m]'/fs*1000,e_sirr) %#ok
view(viewangs)
title('SIRR step-wise order (Eigenmike ranges)')
set(gca,'fontsize', 14)
xlabel('Channel #')
ylabel('Time [ms]')
zlabel('Scaled energy [dB]')
set(gca,'Xtick',[size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)/8:size(ls_dirs_deg,1)]) %#ok
axis([1, size(ls_dirs_deg,1), 20, 400, -60, 0 ])
caxis([-60 -15])
colormap('jet')
%print -deps2c wfall_sirr.eps