%
% HUTear_intro
%
% A tutorial script

warning off;

% Page 1
close all;figure(1);axis off; 
t1=['             HUTear                 '];
t2=['     Auditory Toolbox for MATLAB    '];
h=text(0.1,0.95,t1);set(h,'FontSize',24);
h=text(0.1,0.85,t2);set(h,'FontSize',16);

t1=char('A complete user´s guide is available at',...
'http://www.acoustics.hut.fi/~aqi/software/HUTear');   
h=text(0.1,0.5,t1);set(h,'FontSize',16);
pause(1);clf

% Page 2
figure(1);subplot(3,1,1),axis off; 
t1=char('Let us make a small test signal (44.1 kHz sampling rate)',...
    ' It is a brief 4 kHz tone burst               ',... 
    '>> sig=[noise(1000,0.01) tone(4000,1000) noise(1000,0.01)];');
h=text(0,0.95,t1);set(h,'FontSize',12);
sig=[noise(1000,0.01) tone(4000,1000) noise(1000,0.01)];
subplot(3,1,2),plot(sig);text(10,0.5,'ORIGINAL SIGNAL');
pause(1);
t1=char('In order to use the functions of the toolbox, the magnitude',...
    'should correspond to some real sound pressure level [dB]     ',...
    'The following command scales the signal so that              ',...
    'its SPL is 60 dB:                                            ',...
    '>> Sig=Pascalize(sig,60);                                    ');
Sig=Pascalize(sig,60);
subplot(3,1,1),h=text(0,0.2,t1);set(h,'FontSize',12); 
subplot(3,1,3),plot(Sig);text(10,2000,'SCALED SIGNAL (~60 dB)');
h=text(1000,-8000,'<Press any key>');set(h,'FontSize',12);
pause;clf

% Page 3
t1=char('Next, we could use one of the ready-made profiles to           ',...
    'to produce an {\it auditory representation} for the signal.    ',...
    'The following command uses a temporal window model (Plack,1998)',...
    '>> A=AudMod(Sig,´Profile\_Plack98´);                           ');
subplot(2,1,1),h=text(0,0.9,t1);axis off;set(h,'FontSize',12);
drawnow;
A=AudMod(Sig,'Profile_Plack98');

subplot(2,1,2),imagesc(A');xlabel('Time [samples]');
ylabel('Gammatone channels');

t1=char('This ready-made profile defines a model consisting of a 64     ',...
    'channel {\it gammatone} filterbank followed by some            ',...
    'non-linearities, and a sliding temporal interation             ',...
    'The outputs of the model are shown below                       ');
subplot(2,1,1),h=text(0,0.3,t1);set(h,'FontSize',12);  
h=text(0.3,0,'<Press any key>');set(h,'FontSize',12);
pause;clf

% Page 4
t1=char('It is also easy to design a customized auditory model.          ',...
    'In this example we first design a three-channel gammatone       ',...
    'filterbank with center frequencies 3, 4, and 5 kHz using an ',...
    'interactive design tool [f,b]=Make\_GTbank;                     ',...
    'Go bank to your command shell and answer the questions          ',...
    'Hint: answer 1 to the first and second questions, then 44100,',...
    ' and then [3000 4000 5000]          ',...
    'and finally, press enter                           ');
subplot(2,1,1),h=text(0,0.8,t1);axis off;set(h,'FontSize',12);  

[f,b,CentFreqs]=Make_GTbank;

save mybank.mat f b CentFreqs

F1=freqz(f(1,:),b(1,:));F2=freqz(f(2,:),b(2,:));F3=freqz(f(3,:),b(3,:));
F=20*log10(abs([F1 F2 F3]));
subplot(2,1,2),plot(linspace(0,22,512),F);xlabel('Frequency [kHz]');
ylabel('Magnitude [dB]');title('Frequency responses');

t1=char('The filter coefficients are now saved into file mybank.mat. ',...
    'The frequency responses of the filters are shown below      ',...
    '                                                            ',...
    '            <press any key>                                 ');
subplot(2,1,1),h=text(0,0.1,t1);axis off;set(h,'FontSize',12);   
pause;clf

t1=char(' Now we may write a profile description file for a new auditory',...
    ' model which uses the filterbank. For convenience, this has    ',...
    ' already been done. It is called Profile\_test.m and its       ',...
    ' contents are shown now in the command window.                 ');
  
subplot(2,1,1),h=text(0,0.8,t1);axis off;set(h,'FontSize',12);  
type Profile_test;

t1=char(' Next, we use the model:                                       ',...
    '>> A=AudMod(Sig,´Profile\_test´);                              ');
subplot(2,1,1),h=text(0,0.2,t1);set(h,'FontSize',12);  
drawnow;
A=AudMod(Sig,'Profile_test');

t1=char(' The outputs of the three channels are shown below. ',...
    '                                                    ',...
    '            <press any key exit>                         ');
h=text(0,-0.1,t1);set(h,'FontSize',12);  
subplot(2,1,2),plot(A);
pause;
close all
t1=char(' See demo1, demo2, demo3, etc. for more',...
    'examples how to parametrize models and use HUTear.',...
    'in different applications');

figure(1); axis off
h=text(0.01,0.5,t1);set(h,'FontSize',15);  
pause
close all


