%
%     plot the amplitude characteristic for the two-reflection pinna model
%     of Exercise 7-6
%
%     call:   Chapter_Exc7_6(dT1, dT2)   (default: 0.0004 and 0.00073 sec)
%
function Chapter7_Exc7_6(dT1, dT2)

if nargin<2 dT2 = 0.00073; end
if nargin<1 dT1 = 0.0004; end

Fs = 50000;
dt = 1/Fs;
t = 0:dt:1.0;

Fmax = 0.5/dt;   % 25 kHz
freqs = 0:Fmax/2048:Fmax-Fmax/2048;
omega = 2*pi*freqs;

Gain = 1/3*sqrt(3 + 2*cos(omega * dT1)+2*cos(omega*dT2)+2*cos(omega*(dT1-dT2)));
figure(1); clf;
loglog(freqs, Gain, 'r-','linewidth',3);
axis([100 14000 0.01 1.5])
set(gca, 'fontsize',12,'fontweight','bold');
xlabel('Frequency [Hz]', 'fontsize',13,'fontweight','bold');
ylabel('Amplitude [a.u.]', 'fontsize',13,'fontweight','bold');
title('Two-reflections pinna model', 'fontsize',13,'fontweight','bold');

s=sprintf('dT1 = %5.5f s',dT1);
text(150, 0.015, s, 'fontsize',11,'fontweight','bold','color','k');
s=sprintf('dT2 = %5.5f s',dT2);
text(150, 0.012, s, 'fontsize',11,'fontweight','bold','color','b');

hold on
Gain1 = 1/2*sqrt(2 + 2*cos(omega * dT1));  % the single delay model
loglog(freqs, Gain1, 'k--','linewidth',1);
Gain2 = 1/2*sqrt(2 + 2*cos(omega * dT2));
loglog(freqs, Gain2, 'b--','linewidth',1);

print -djpeg Fig_Exc7_6
end
