% Compute the Sound Absorption Average (SAA)
% from absorption measurements in diffuse field.
%
% Measurements performed on a 40 mm-thick rock wool 
% by Mickael Duranteau during his 'DEUST VAS 2'
% internship at ENTPE in 2006. 
% 
% Commands for the rotation of tick labels are
% borrowed from rotateticklabel.m
%   Written Oct 14, 2005 by Andy Bliss
%   Copyleft 2005 by Andy Bliss
%
% Everything else is copyleft 2006 luc.jaouen@matelys.com
% cf. APMR on the web,
% Standards/SAA
% for more information


clear all
close all


%%%%%
%%%%% Load measurements in 1/3 octave bands 
%%%%% ranging from 100 to 8000 Hz 
%%%%% and compute the SAA
%%%%%
measurements = [0.19 0.15 0.50 0.67 0.89 0.86 1.04 1.05 1.01 1.07 0.67 0.80 0.76 0.82 0.71 0.74 0.71 0.74 0.78 0.99];
SAA = sum( measurements(4:15) ) / 12;
string = sprintf('SAA: %.2f', SAA);
disp(string);

%%%%%
%%%%% Show results
%%%%%
figure(1)
set(gca,'FontSize',16)
plot(measurements,'ko-','LineWidth',2)

% Add two vertical red lines at 200 and 2500 Hz
line([4 4],[0 1],'Color','red','Linewidth',2);
line([15 15],[0 1],'Color','red','Linewidth',2);

% Axis and their labels
ylabel('Sound absorption coefficient')
hh  = xlabel('Frequency band (Hz)');
pos = get(hh,'pos');
set(hh,'pos',pos+[-0.5 0.2 0])
xt = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
xtlab = {'100';'125';'160';'200';'250';'315';'400';'500';'630';'800';'1000';'1250';'1600';'2000';'2500';'3150';'4000';'5000';'6300';'8000'};
set(gca,'Xtick',xt,'XTickLabel',xtlab,'xminortick','off') 
set(gca,'Ylim',[0 1.2])
set(gca,'Xlim',[0 21])
h   = gca;
rot = 45;
a   = get(h,'XTickLabel');
set(h,'XTickLabel',[]);
b   = get(h,'XTick');
c   = get(h,'YTick');
if rot < 180
    th = text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','rotation',rot,'FontSize',16);
else
    th = text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','left','rotation',rot,'FontSize',16);
end
