%% Effect of Input Levels on Acoustic Sharpness
% Create a pink noise signal with a 48 kHz sample rate and a duration of 5 seconds.

fs = 48e3;
n = fs*5;
pnoise = pinknoise(n);

%
% Specify a vector to sweep over the dB range from -60 to 20. Create a gain vector which, when multiplied by the original signal, results in a signal with the desired output level.

dBSweep = -60:10:20;
coefSweep = sqrt((10.^(dBSweep/10))/var(pnoise));

%
% Call acousticSharpness in a loop with the different signal levels. Determine the sharpness using the default DIN 45692 frequency weighting and the Aures frequency weighting.

sharpnessDIN45692 = zeros(numel(dBSweep),1);
sharpnessAures = zeros(numel(dBSweep),1);
for ii = 1:numel(dBSweep)
    signal = pnoise*coefSweep(ii);
    sharpnessDIN45692(ii) = acousticSharpness(signal,fs);
    sharpnessAures(ii) = acousticSharpness(signal,fs,'Weighting','Aures');
end

%
% Display the effect of the input level on the acoustic sharpness. The Aures frequency weighting method is more sensitive to the input level.

plot(dBSweep,sharpnessDIN45692,dBSweep,sharpnessAures)
legend('Weighting = DIN45692','Weighting = Aures')
xlabel('Input Level (dB)')
ylabel('Sharpness (acum)')
title('Effect of Input Level on Sharpness')
axis([dBSweep(1) dBSweep(end) 0 20])
grid on

%
% Copyright 2019 The MathWorks, Inc.