%% Measure Loudness and Sharpness of Stationary Signals
% Create two stationary signals with equivalent power: a pink noise signal and a white noise signal.

fs = 48e3;
dur = 5;
pnoise = 2*pinknoise(dur*fs);
wnoise = rand(dur*fs,1) - 0.5;
wnoise = wnoise*sqrt(var(pnoise)/var(wnoise));

%
% Call acousticLoudness using the default ISO 532-1 (Zwicker) method and no output arguments to plot the loudness of the pink noise. Call acousticLoudness again, this time with output arguments, to get the specific loudness.

figure
acousticLoudness(pnoise,fs)
[~,pSpecificLoudness] = acousticLoudness(pnoise,fs);

%
% Plot the loudness for the white noise signal and then get the specific loudness values.

figure
acousticLoudness(wnoise,fs)
[~,wSpecificLoudness] = acousticLoudness(wnoise,fs);

%
% Call the acousticSharpness function to compare the sharpness of the pink noise and white noise.

pSharpness = acousticSharpness(pSpecificLoudness);
wSharpness = acousticSharpness(wSpecificLoudness);
fprintf('Sharpness of pink noise = %0.2f acum\n',pSharpness)
fprintf('Sharpness of white noise = %0.2f acum\n',wSharpness)

%
% Copyright 2019 The MathWorks, Inc.