-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvalidation_Sharpness_DIN45692_narrowband_and_broadband_signals.m
304 lines (227 loc) · 13.6 KB
/
validation_Sharpness_DIN45692_narrowband_and_broadband_signals.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
% Script validation_Sharpness_DIN45692_narrowband_and_broadband_signals
%
% - Validation of sharpness calculation of narrowband and broadband using
% test signals from DIN 45692(2009)
%
% - Sharpness computed using:
% OUT = Sharpness_DIN45692_from_loudness(SpecificLoudness, weight_type, time, time_skip, show_sharpness)
% type <help Sharpness_DIN45692_from_loudness> for more info
%
% - Specific Loudness is computed within this code according to
% ISO 532:1-2017, stationary, free-field
%
% - Loudness computed using:
% OUT = Loudness_ISO532_1(insig, fs, field, method, time_skip, show)
% type <help Loudness_ISO532_1> for more info
%
% In order to run this code, the user needs to download the dataset of
% sound files from zenodo (https://doi.org/10.5281/zenodo.7933206).
% The obtained folder called `validation_SQAT_v1_0` has to be included in
% the `sound_files` folder of the toolbox.
%
% Author: Gil Felix Greco, Braunschweig 01.03.2023
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all; clc;
save_figs = 0; % save figure flag
%% Sharpness of narrowband test sounds
% Tabelle A.2 — Sollwerte der Schärfe für frequenzgruppenbreites Schmalbandrauschen mit
% der Lautheit 4 sone (entsprechend dem Standard-Prüfsignal bei 1 kHz und 60 dB)
% Reference values from the standard DIN45692 for the narrowband test sounds
freq_narrowband = [250 350 450 570 700 840 1000 1170 1370 1600 1850 2150 2500 2900 3400 4000 4800 5800 7000 8500 10500];
bark_narrowband = 2.5:22.5;
acum_narrowband = [.38 .49 .60 .71 .82 .93 1 1.13 1.26 1.35 1.49 1.64 1.78 2.06 2.4 2.82 3.48 4.43 5.52 6.81 8.55];
SQAT_version=1; % v1.0
dir_sounds = get_dir_validation_sounds('Sharpness_DIN45692',SQAT_version);
dir_ref_sounds = [basepath_SQAT 'sound_files' filesep 'reference_signals' filesep ];
% load calibration signal
[RefSignal,~]=audioread([dir_ref_sounds 'RefSignal_Sharpness_DIN45692.wav']);
%%% Calibration using the concept of dB full scale:
lvl_cal_signal = 60; % from file name: 'calibration signal sine 1kHz 60dB.wav'
[~,~,dBFS]=calibrate(RefSignal,RefSignal,lvl_cal_signal); % just to obtain the dBFS value
% load narrowband signals, calibrate, compute loudness and sharpness
for i=1:length(freq_narrowband)
% load test signal
fname_insig = ['narrowband_' sprintf( '%02d',freq_narrowband(i) ) '.wav'];
[insig,fs]=audioread([dir_sounds fname_insig]);
% calibrate .wav signal
[insig_cal]=calibrate(insig,RefSignal,lvl_cal_signal);
% stationary loudness calculation
L_narrow = Loudness_ISO532_1( insig_cal, fs,... % input signal and sampling freq.
0,... % field; free field = 0; diffuse field = 1;
1,... % method; stationary (from input 1/3 octave unweighted SPL)=0; stationary = 1; time varying = 2;
0.5,... % time_skip, in seconds for level (stationary signals) and statistics (stationary and time-varying signals) calculations
0); % show results, 'false' (disable, default value) or 'true' (enable)
% sharpness calculation (standard weighting function)
s_narrow(i) = Sharpness_DIN45692_from_loudness(L_narrow.SpecificLoudness,... % input (stationary) specific loudness
'DIN45692'); % type of weighting function used for sharpness calculation
% sharpness calculation (aures weighting function)
s_narrow_aures(i) = Sharpness_DIN45692_from_loudness(L_narrow.SpecificLoudness,... % input (stationary) specific loudness
'aures'); % type of weighting function used for sharpness calculation
% sharpness calculation (von bismarck weighting function)
s_narrow_bismarck(i) = Sharpness_DIN45692_from_loudness(L_narrow.SpecificLoudness,... % input (stationary) specific loudness
'bismarck'); % type of weighting function used for sharpness calculation
end
%% Sharpness of broadband test sounds
% Tabelle A.3: Sollwerte der Schärfe für Breitbandrauschen mit fester oberer Eckfrequenz
% von 10 kHz und variabler unterer Eckfrequenz fu mit der Lautheit 4 sone (entsprechend dem Standard-Prüfsignal bei 1 kHz und 60 dB)
% Reference values from the standard DIN45692 for the broadband test sounds
freq_broadband= [250 350 450 570 700 840 1000 1170 1370 1600 1850 2150 2500 2900 3400 4000 4800 5800 7000 8500];
bark_broadband=2.5:21.5;
acum_broadband=[2.7 2.74 2.78 2.85 2.91 2.96 3.05 3.12 3.20 3.3 3.42 3.53 3.69 3.89 4.12 4.49 5.04 5.69 6.47 7.46];
% load broadband signals, calibrate, compute loudness and sharpness
for i=1:length(freq_broadband)
% load test signal
[insig,fs]=audioread([dir_sounds 'broadband_' sprintf( '%02d',freq_broadband(i) ) '.wav']); 'sound_files\validation\Sharpness_DIN45692\';
% calibrated .wav signal
insig_cal=calibrate(insig,RefSignal,lvl_cal_signal);
% stationary loudness calculation
L_broad = Loudness_ISO532_1( insig_cal, fs,... % input signal and sampling freq.
0,... % field; free field = 0; diffuse field = 1;
1,... % method; stationary (from input 1/3 octave unweighted SPL)=0; stationary = 1; time varying = 2;
0.5,... % time_skip, in seconds for level (stationary signals) and statistics (stationary and time-varying signals) calculations
0); % show results, 'false' (disable, default value) or 'true' (enable)
% sharpness calculation (standard weighting function)
s_broad(i) = Sharpness_DIN45692_from_loudness(L_broad.SpecificLoudness,... % input (stationary) specific loudness
'DIN45692');... % type of weighting function used for sharpness calculation
% sharpness calculation (aures weighting function)
s_broad_aures(i) = Sharpness_DIN45692_from_loudness(L_broad.SpecificLoudness,... % input (stationary) specific loudness
'aures');... % type of weighting function used for sharpness calculation
% sharpness calculation (von bismarck weighting function)
s_broad_bismarck(i) = Sharpness_DIN45692_from_loudness(L_broad.SpecificLoudness,... % input (stationary) specific loudness
'bismarck');... % type of weighting function used for sharpness calculation
end
%% plot validation for narrowband and broadband
h =figure;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
% reference curves
plot(bark_narrowband,acum_narrowband,'k','Linewidth',1);hold all
plot(bark_broadband,acum_broadband,'b','Linewidth',1);hold all
% computed values
plot(bark_narrowband,vertcat(s_narrow.Sharpness),'ok','Linewidth',1,'MarkerSize',7);
plot(bark_broadband,vertcat(s_broad.Sharpness),'ob','Linewidth',1,'MarkerSize',7);
% title('DIN 45692 - Sharpness of narrowband noise');
legend('DIN 45692:2009 - ref. for narrowband signals','DIN 45692:2009 - ref. for broadband signals','SQAT - narrowband signals','SQAT - broadband signals','Location','NW','Interpreter','Latex');
legend boxoff
grid off
axis([0 24 0 11]);
ylabel('Sharpness, $S$ (acum)','Interpreter','Latex');
xlabel('Critical band, $z$ (Bark)','Interpreter','Latex');
ax = gca;
set(ax,'XTick',[0 4 8 12 16 20 24]);
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = 0:0.5:24;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = 0:0.5:20;
% hold off
set(gcf,'color','w');
if save_figs==1
figures_dir = [fileparts(mfilename('fullpath')) filesep 'figs' filesep];
if ~exist(figures_dir,'dir')
mkdir(figures_dir);
end
figname_short = 'sharpness_validation_narrowband_and_broadband';
figname_out = [figures_dir figname_short];
% saveas(gcf,figname_out, 'fig');
% saveas(gcf,figname_out, 'pdf');
saveas(gcf,figname_out, 'png');
fprintf('\n%s.m: figure %s was saved on disk\n\t(full name: %s)\n',mfilename,figname_short,figname_out);
end
%% plot error for narrowband and broadband
h =figure;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
a=plot(bark_narrowband,-0.05*ones(1,21),'r--','Linewidth',1);hold on; % error tolerance of -5%
plot(bark_narrowband,0.05*ones(1,21),'r--','Linewidth',1); % error tolerance of +5%
b=plot(bark_narrowband,vertcat(s_narrow.Sharpness)'-acum_narrowband,'k','Linewidth',1);hold all
c=plot(bark_broadband,vertcat(s_broad.Sharpness)'-acum_broadband,'b','Linewidth',1);hold all
legend([a,b,c],'DIN 45692:2009 tolerance','Narrowband signals','Broadband signals','Location','NW','Interpreter','Latex');
legend boxoff
% title('DIN 45692 - Sharpness of narrowband noise');
grid off
axis([0 24 -.12 .12]);
ylabel('SQAT minus DIN 45692:2009 (acum)','Interpreter','Latex');
% ylabel('Relative error [acum]','Interpreter','Latex');
xlabel('Critical band, $z$ (Bark)','Interpreter','Latex');
set(gcf,'color','w');
ax = gca;
set(ax,'XTick',[0 4 8 12 16 20 24]);
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = 0:0.5:24;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = -0.2:0.01:0.2;
if save_figs==1
figname_short = 'sharpness_validation_narrowband_broadband_error';
figname_out = [figures_dir figname_short];
% saveas(gcf,figname_out, 'fig');
% saveas(gcf,figname_out, 'pdf');
saveas(gcf,figname_out, 'png');
fprintf('\n%s.m: figure %s was saved on disk\n\t(full name: %s)\n',mfilename,figname_short,figname_out);
end
%% narrow band comparison between models
h =figure;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
plot(bark_narrowband,acum_narrowband,'k','Linewidth',1);hold all
plot(bark_narrowband,vertcat(s_narrow.Sharpness),'ob','Linewidth',1,'MarkerSize',7);
plot(bark_narrowband,vertcat(s_narrow_aures.Sharpness),'+r','Linewidth',1,'MarkerSize',8);
plot(bark_narrowband,vertcat(s_narrow_bismarck.Sharpness),'xc','Linewidth',1,'MarkerSize',8);
% title('DIN 45692 - Sharpness of narrowband noise');
legend('Ref. values from DIN 45692:2009','SQAT - DIN 45692:2009','SQAT - Aures','SQAT - von Bismarck','Location','NorthWest','Interpreter','Latex');
legend boxoff
grid off
axis([0 24 0 10]);
ylabel('Sharpness, $S$ (acum)','Interpreter','Latex');
xlabel('Critical band, $z$ (Bark)','Interpreter','Latex');
ax = gca;
set(ax,'XTick',[0 4 8 12 16 20 24]);
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = 0:0.5:24;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = 0:0.5:10;
% hold off
set(gcf,'color','w');
if save_figs==1
figname_short = 'sharpness_validation_narrowband_compare_models';
figname_out = [figures_dir figname_short];
% saveas(gcf,figname_out, 'fig');
% saveas(gcf,figname_out, 'pdf');
saveas(gcf,figname_out, 'png');
fprintf('\n%s.m: figure %s was saved on disk\n\t(full name: %s)\n',mfilename,figname_short,figname_out);
end
%% narrow band comparison
h =figure;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
plot(bark_broadband,acum_broadband,'k','Linewidth',1);hold all
plot(bark_broadband,vertcat(s_broad.Sharpness),'ob','Linewidth',1,'MarkerSize',7);
plot(bark_broadband,vertcat(s_broad_aures.Sharpness),'+r','Linewidth',1,'MarkerSize',8);
plot(bark_broadband,vertcat(s_broad_bismarck.Sharpness),'xc','Linewidth',1,'MarkerSize',8);
% title('DIN 45692 - Sharpness of broadband noise');
legend('Ref. values from DIN 45692:2009','SQAT - DIN 45692:2009','SQAT - Aures','SQAT - von Bismarck','Location','NorthWest','Interpreter','Latex');
legend boxoff
legend boxoff
grid off
axis([0 24 0 10]);
ylabel('Sharpness, $S$ (acum)','Interpreter','Latex');
xlabel('Critical band, $z$ (Bark)','Interpreter','Latex');
ax = gca;
set(ax,'XTick',[0 4 8 12 16 20 24]);
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = 0:0.5:24;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = 0:0.5:10;
% hold off
set(gcf,'color','w');
if save_figs==1
figname_short = 'sharpness_validation_broadband_model_comparison';
figname_out = [figures_dir figname_short];
% saveas(gcf,figname_out, 'fig');
% saveas(gcf,figname_out, 'pdf');
saveas(gcf,figname_out, 'png');
fprintf('\n%s.m: figure %s was saved on disk\n\t(full name: %s)\n',mfilename,figname_short,figname_out);
end