-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTest.m
335 lines (281 loc) · 13.7 KB
/
Test.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
325
326
327
328
clear all, close all, dbstop if error %#ok
% this code is reliant on the following Matlab libraries:
% https://github.com/polarch/Spherical-Harmonic-Transform
% https://github.com/polarch/Higher-Order-Ambisonics
%
% Leo McCormack, 22/09/2018, [email protected]
addpath('_Simulated_Rooms_')
%% FIRST-ORDER SIRR EXAMPLE USING A-FORMAT MIC
%% HO-SIRR EXAMPLE USING EIGENMIKE (FREQUENCY-DEPENDENT ANALYSIS ORDER)
%(not implemented yet)
%% CHECKS
%return;
%% HO-SIRR COMPARED WITH REFERENCE AND AMBISONICS
% A simulated Auditorium using LoRA, configured for a 36point t-design
% loudspeaker array [1].
LS_REFERENCE_FILE_NAME = 'Auditorium_64ch_DTU_AVIL';
% USER PARAMETERS
pars.order = 3;
pars.fs = 48e3;
[~,dirs_rad] = getTdesign(8);
pars.ls_dirs_deg = dirs_rad*180/pi;
load('DTU_ls_dirs_deg.mat')
pars.ls_dirs_deg = ls_dirs_deg;
pars.multires_winsize = [256];
pars.multires_xovers = [];
pars.RENDER_DIFFUSE = 1;
pars.BROADBAND_FIRST_PEAK = 1;
pars.nBroadbandPeaks = 1;
pars.decorrelationType = 'noise';
pars.BROADBAND_DIFFUSENESS = 1;
pars.maxDiffFreq_Hz = 3000;
pars.alpha_diff = 0.5;
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
% Encode reference audio into spherical harmonics
[refir, fs] = audioread([LS_REFERENCE_FILE_NAME '.wav']); % load input SHD IR, (ACN/N3D)
shir = refir * (sqrt(4*pi).*getRSH(pars.order, pars.ls_dirs_deg)');
% APPLY HO-SIRR
[sirr,sirr_ndiff,sirr_diff,pars,~] = HOSIRR(shir, pars);
audiowrite([LS_REFERENCE_FILE_NAME '_HOSIRR_o' num2str(pars.order) '.wav'], 0.3.*sirr, fs);
% AMBISONICS
ambiIR = shir * (sqrt(4*pi).*getRSH(pars.order, pars.ls_dirs_deg)./size(pars.ls_dirs_deg, 1));
% Plots
subplot(1,3,1), s = surf(10*log10(abs(refir.')));
zlim([-50 0]), xlim([0 pars.fs/4]), xlabel('time'), ylabel('# channel'), title('ref')
s.EdgeColor = 'none';
colormap jet
subplot(1,3,2), s = surf(10*log10(abs(sirr.')));
zlim([-50 0]), xlim([0 pars.fs/4]), xlabel('time'), ylabel('# channel'), title('HO-SIRR')
s.EdgeColor = 'none';
colormap jet
subplot(1,3,3), s = surf(10*log10(abs(ambiIR.')));
zlim([-50 0]), xlim([0 pars.fs/4]), xlabel('time'), ylabel('# channel'), title('Ambisonics')
s.EdgeColor = 'none';
colormap jet
set(gcf,'Position',[40 40 1200 400])
clear pars;
% [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.
%% FIRST-ORDER SIRR CHECKS
pars.order = 1;
pars.fs = 48e3;
[~,dirs_rad] = getTdesign(2*(pars.order+1));
pars.ls_dirs_deg = dirs_rad*180/pi;
pars.multires_winsize = 256;
pars.multires_xovers = [];
pars.RENDER_DIFFUSE = 1;
pars.BROADBAND_FIRST_PEAK = 1;
pars.nBroadbandPeaks = 1;
pars.decorrelationType = 'noise';
pars.BROADBAND_DIFFUSENESS = 1;
pars.maxDiffFreq_Hz = 3000;
pars.alpha_diff = 0.5;
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
% --- Single plane-wave input ---
src_dir = [-45 -45]; % try adding more than 1 plane-wave, to see the first-order analysis break
shir = randn(pars.fs, size(src_dir,1)) * (sqrt(4*pi).*getRSH(pars.order, src_dir)).';
[~,~,~,~,analysis] = HOSIRR(shir, pars);
% In this case, we would expect:
% - [azimuth elevation] should correspond to 'src_dir'
% - diffuseness should be 0
% - non-diffuse energy should be similar to input sound-field energy, and
% diffuse energy ~0
figure, subplot(4,1,1), imagesc(analysis.azim{1}*180/pi), colorbar, axis xy, caxis([-180 180]), title('azimuth (degrees)')
subplot(4,1,2), imagesc(analysis.elev{1}*180/pi), colorbar, axis xy, caxis([-90 90]), title('elevation (degrees)')
subplot(4,1,3), imagesc(10*log10(analysis.energy{1})), colorbar, axis xy, title('energy (dB)')
subplot(4,1,4), imagesc(analysis.diff{1}), colorbar, axis xy, caxis([0 1]), title('diffuseness')
figure, plot(10*log10(analysis.sf_energy{1})), hold on
plot(10*log10(analysis.ndiff_energy{1})), hold on
plot(10*log10(analysis.diff_energy{1}))
title('energy (dB)'), grid on
legend('sound-field', 'non-diffuse', 'diffuse')
figure, plot(analysis.diff{1}(1,:)), title('diffuseness'), grid on, ylim([0 1])
% --- Diffuse input ---
[~, diff_dirs] = getTdesign(21); % approximate diffuse-field with 240 incoherent noise sources
shir = randn(pars.fs, size(diff_dirs,1)) * (sqrt(4*pi).*getRSH(pars.order, diff_dirs*180/pi)).';
[~,~,~,~,analysis] = HOSIRR(shir, pars);
% In this case, we would expect:
% - [azimuth elevation] should be random
% - diffuseness should be close to 1
% - diffuse energy should be similar to the input sound-field energy, and
% non-diffuse energy much lower than diffuse energy
figure, subplot(4,1,1), imagesc(analysis.azim{1}*180/pi), colorbar, axis xy, caxis([-180 180]), title('azimuth (degrees)')
subplot(4,1,2), imagesc(analysis.elev{1}*180/pi), colorbar, axis xy, caxis([-90 90]), title('elevation (degrees)')
subplot(4,1,3), imagesc(10*log10(analysis.energy{1})), colorbar, axis xy, title('energy (dB)')
subplot(4,1,4), imagesc(analysis.diff{1}), colorbar, axis xy, caxis([0 1]), title('diffuseness')
figure, plot(10*log10(analysis.sf_energy{1})), hold on
plot(10*log10(analysis.ndiff_energy{1})), hold on
plot(10*log10(analysis.diff_energy{1}))
title('energy (dB)'), grid on
legend('sound-field', 'non-diffuse', 'diffuse')
figure, plot(analysis.diff{1}(1,:)), title('diffuseness'), grid on, ylim([0 1])
clear pars
%% HO-SIRR CHECKS
pars.order = 3;
pars.fs = 48e3;
[~,dirs_rad] = getTdesign(2*(pars.order+1));
pars.ls_dirs_deg = dirs_rad*180/pi;
pars.multires_winsize = 256;
pars.multires_xovers = [];
pars.RENDER_DIFFUSE = 1;
pars.BROADBAND_FIRST_PEAK = 1;
pars.nBroadbandPeaks = 1;
pars.decorrelationType = 'phase'; % TODO plotting only correct with phase, as noise happens after
pars.BROADBAND_DIFFUSENESS = 1;
pars.maxDiffFreq_Hz = 3000;
pars.alpha_diff = 0.5;
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
% --- Single plane-wave input ---
src_dir = [0 0]; % single pw
shir = randn(pars.fs, size(src_dir,1)) * (sqrt(4*pi).*getRSH(pars.order, src_dir)).';
[~,~,~,pars_out,analysis] = HOSIRR(shir, pars);
figure, grid on, hold on;
title('Single PW')
plot(10*log10(analysis.sf_energy{1}))
plot(10*log10(analysis.ndiff_energy{1}))
plot(10*log10(analysis.diff_energy{1}))
plot(10*log10(analysis.total_energy{1}))
ylabel('energy (dB)')
legend('sound-field', 'non-diffuse', 'diffuse', 'total')
% --- Three plane-wave input ---
src_dir = rad2deg(pars_out.sectorDirs([1, 5, 16], :)); % plane-waves landing in sectors: 1, 5, and 16
shir = randn(pars.fs, size(src_dir,1)) * (sqrt(4*pi).*getRSH(pars.order, src_dir)).';
[~,~,~,pars_out,analysis] = HOSIRR(shir, pars);
% In this case, for sectors (1,5,16) we would expect:
% - [azimuth elevation] should correspond to 'src_dir' for their respective sectors
% - These 3 sectors should have diffuseness values close to 0
for sectorIndex = [1,5,16]
figure, subplot(4,1,1), imagesc(analysis.azim{1}(:,:,sectorIndex)*180/pi)
colorbar, axis xy, caxis([-180 180]), title(['azimuth (degrees), sector: ' num2str(sectorIndex) ])
subplot(4,1,2), imagesc(analysis.elev{1}(:,:,sectorIndex)*180/pi)
colorbar, axis xy, caxis([-90 90]), title(['elevation (degrees), sector: ' num2str(sectorIndex) ])
subplot(4,1,3), imagesc(10*log10(analysis.energy{1}(:,:,sectorIndex))),
colorbar, axis xy, title(['energy (dB), sector: ' num2str(sectorIndex) ])
subplot(4,1,4), imagesc(analysis.diff{1}(:,:,sectorIndex))
colorbar, axis xy, caxis([0 1]), title(['diffuseness, sector: ' num2str(sectorIndex) ])
end
% Whereas, sectors (2,20) we should expect:
% - [azimuth elevation] should be more random
% - Higher diffuseness values
for sectorIndex = [2,20]
figure, subplot(4,1,1), imagesc(analysis.azim{1}(:,:,sectorIndex)*180/pi)
colorbar, axis xy, caxis([-180 180]), title(['azimuth (degrees), sector: ' num2str(sectorIndex) ])
subplot(4,1,2), imagesc(analysis.elev{1}(:,:,sectorIndex)*180/pi)
colorbar, axis xy, caxis([-90 90]), title(['elevation (degrees), sector: ' num2str(sectorIndex) ])
subplot(4,1,3), imagesc(10*log10(analysis.energy{1}(:,:,sectorIndex))),
colorbar, axis xy, title(['energy (dB), sector: ' num2str(sectorIndex) ])
subplot(4,1,4), imagesc(analysis.diff{1}(:,:,sectorIndex))
colorbar, axis xy, caxis([0 1]), title(['diffuseness, sector: ' num2str(sectorIndex) ])
end
% - Output non-diffuse energy should be similar to input sound-field
% energy, and also much higher than the diffuse energy
figure, grid on, hold on;
title('Three PWs')
plot(10*log10(analysis.sf_energy{1}))
plot(10*log10(analysis.ndiff_energy{1}))
plot(10*log10(analysis.diff_energy{1}))
plot(10*log10(analysis.total_energy{1}))
ylabel('energy (dB)')
legend('sound-field', 'non-diffuse', 'diffuse', 'total')
% --- Diffuse-field input ---
dur = 1; % in s
[~, diff_dirs] = getTdesign(21); % approximate diffuse-field with 240 incoherent noise sources
diff_in = randn(dur*pars.fs, size(diff_dirs,1)) * ...
sqrt(4*pi)*getRSH(pars.order, diff_dirs*180/pi).';
diff_in = randn(size(diff_in));
[~,~,~,pars_out,analysis] = HOSIRR(diff_in, pars);
figure, grid on, hold on;
title('Diffuse Field')
plot(10*log10(analysis.sf_energy{1}))
plot(10*log10(analysis.ndiff_energy{1}))
plot(10*log10(analysis.diff_energy{1}))
plot(10*log10(analysis.total_energy{1}))
ylabel('energy (dB)')
legend('sound-field', 'non-diffuse', 'diffuse', 'total')
clear pars
%% HO-SIRR_orderPerBand CHECKS
pars.order = 4;
pars.freqLimits = [375 1e3 2e3];
pars.procOrders = [1 2 3 4];
%pars.procOrders = [4 4 4 4 4 4 4];
%pars.procOrders = [1 1 1 1 1 1 1];
%pars.freqLimits = [ 500 6000];
%pars.procOrders = [3 3 3];
pars.fs = 48e3;
[~,dirs_rad] = getTdesign(2*(pars.order+1));
pars.ls_dirs_deg = dirs_rad*180/pi;
pars.multires_winsize = 128;
pars.multires_xovers = [];
pars.RENDER_DIFFUSE = 1;
pars.BROADBAND_FIRST_PEAK = 1;
pars.nBroadbandPeaks = 1;
pars.decorrelationType = 'noise';
pars.BROADBAND_DIFFUSENESS = 1;
pars.maxDiffFreq_Hz = 3000;
pars.alpha_diff = 0.5;
pars.chOrdering = 'ACN';
pars.normScheme = 'N3D';
% % --- Single plane-wave input ---
% src_dir = [-45 -45]; % try adding more than 1 plane-wave, to see the first-order analysis break
% shir = randn(pars.fs, size(src_dir,1)) * (sqrt(4*pi).*getRSH(pars.order, src_dir)).';
% [~,~,~,~,analysis] = HOSIRR_orderPerBand(shir, pars, 0);
%
% % In this case, we would expect:
% % - [azimuth elevation] should correspond to 'src_dir'
% % - diffuseness should be 0
% % - non-diffuse energy should be similar to input sound-field energy, and
% % diffuse energy ~0
% sectorIndex = 1;
% figure, subplot(4,1,1), imagesc(analysis.azim{1}(:,:,sectorIndex)*180/pi), colorbar, axis xy, caxis([-180 180]), title('azimuth (degrees)')
% subplot(4,1,2), imagesc(analysis.elev{1}(:,:,sectorIndex)*180/pi), colorbar, axis xy, caxis([-90 90]), title('elevation (degrees)')
% subplot(4,1,3), imagesc(10*log10(analysis.energy{1}(:,:,sectorIndex))), colorbar, axis xy, title('energy (dB)')
% subplot(4,1,4), imagesc(analysis.diff{1}(:,:,sectorIndex)), colorbar, axis xy, caxis([0 1]), title('diffuseness')
% figure, plot(10*log10(analysis.sf_energy{1}(:,:,sectorIndex))), hold on
% plot(10*log10(analysis.ndiff_energy{1}(:,:,sectorIndex))), hold on
% plot(10*log10(analysis.diff_energy{1}(:,:,sectorIndex)))
% title('energy (dB)'), grid on, ylim([-40 20])
% legend('sound-field', 'non-diffuse', 'diffuse')
% % %figure, plot(analysis.diff{1}(,:)), title('diffuseness'), grid on, ylim([0 1])
%
%--- Diffuse input ---
%src_dir = [-45 -45]; % try adding more than 1 plane-wave, to see the first-order analysis break
%shir = randn(pars.fs, size(src_dir,1)) * (sqrt(4*pi).*getRSH(pars.order, src_dir)).';
[~, diff_dirs] = getTdesign(21); % approximate diffuse-field with 240 incoherent noise sources
shir = randn(pars.fs/4, size(diff_dirs,1)) * (sqrt(4*pi).*getRSH(pars.order, diff_dirs*180/pi)).';
[sirr,sirr_ndiff,sirr_diff,~,analysis] = HOSIRR_orderPerBand(shir, pars); %
fs = 48e3;
sirr_diff_fft = fft(sirr_diff, 256);
figure,semilogx(0:fs/256: fs/2-fs/256, mean(10*log10(abs(sirr_diff_fft(1:end/2,:).^2)),2)), xlim([200 20e3])
hold on
sirr_ndiff_fft = fft(sirr_ndiff, 256);
semilogx(0:fs/256: fs/2-fs/256, mean(10*log10(abs(sirr_ndiff_fft(1:end/2,:).^2)),2)), xlim([200 20e3])
hold on
shir_fft = fft(shir, 256);
semilogx(0:fs/256: fs/2-fs/256, mean(10*log10(abs(shir_fft(1:end/2,:).^2)),2)./25), xlim([200 20e3])
hold on
semilogx(0:fs/256: fs/2-fs/256,mean(10*log10(abs(sirr_diff_fft(1:end/2,:).^2)+abs(sirr_ndiff_fft(1:end/2,:).^2)),2)), xlim([200 20e3])
legend('diff', 'ndiff', 'sf', 'total')
% %--- Single plane-wave input ---
% src_dir = [-45 -45]; % try adding more than 1 plane-wave, to see the first-order analysis break
% shir = randn(pars.fs, size(src_dir,1)) * (sqrt(4*pi).*getRSH(pars.order, src_dir)).';
% [~,~,~,~,analysis] = HOSIRR_orderPerBand(shir, pars, 0); % _orderPerBand
% In this case, we would expect:
% - [azimuth elevation] should be random
% - diffuseness should be close to 1
% - diffuse energy should be similar to the input sound-field energy, and
% non-diffuse energy much lower than diffuse energy
% figure, subplot(4,1,1), imagesc(analysis.azim{1}(:,:,sectorIndex)*180/pi), colorbar, axis xy, caxis([-180 180]), title('azimuth (degrees)')
% subplot(4,1,2), imagesc(analysis.elev{1}(:,:,sectorIndex)*180/pi), colorbar, axis xy, caxis([-90 90]), title('elevation (degrees)')
% subplot(4,1,3), imagesc(10*log10(analysis.energy{1}(:,:,sectorIndex))), colorbar, axis xy, title('energy (dB)')
% subplot(4,1,4), imagesc(analysis.diff{1}(:,:,sectorIndex)), colorbar, axis xy, caxis([0 1]), title('diffuseness')
% figure, plot(10*log10(analysis.sf_energy{1}(:,:,sectorIndex))), hold on
% plot(10*log10(analysis.ndiff_energy{1}(:,:,sectorIndex))), hold on
% plot(10*log10(analysis.diff_energy{1}(:,:,sectorIndex)))
% title('energy (dB)'), grid on, ylim([-40 20])
% legend('sound-field', 'non-diffuse', 'diffuse')
% %figure, plot(analysis.diff{1}(1,:)), title('diffuseness'), grid on, ylim([0 1])
clear pars