experimentDOA_user.m 3.76 KB
Newer Older
1
% experimentDOAMHA_user - stimulus generation function of experiment 'example' -
2 3
%
% This function is called by afc_main when starting
4
% the experiment 'experimentDOA'. It generates the stimuli which
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
% are presented during the experiment.
% The stimuli must be elements of the structure 'work' as follows:
%
% work.signal = def.intervallen by 2 times def.intervalnum matrix.
%               The first two columns must contain the test signal
%               (column 1 = left, column 2 = right) ...
% 
% work.presig = def.presiglen by 2 matrix.
%               The pre-signal. 
%               (column 1 = left, column 2 = right).
%
% work.postsig = def.postsiglen by 2 matrix.
%                The post-signal. 
%               ( column 1 = left, column 2 = right).
%
% work.pausesig = def.pausesiglen by 2 matrix.
%                 The pause-signal. 
%                 (column 1 = left, column 2 = right).
23 24
% ------------------------------

25

26
function experimentDOA_user
27 28 29 30 31

global def
global work
global setup

32 33
disp(num2str(setup.level))
disp(num2str(work.expvaract))
34

35 36 37
% -------------CHOOSE HRIRS ----------------
% * find which reference angle is currently tested
% * randomly choose +or- 5° or 10°
38 39
indx=1;%find(def.exppar1==work.exppar1);
hrir_fs=setup.HRIRs{indx}.hrir_ref.fs;
40
hrir_ref=setup.HRIRs{indx}.hrir_ref.data;
41
plusorminus=1;%round(rand);%0 or 1
42 43 44 45 46
if plusorminus==1
hrir_targ=setup.HRIRs{indx}.hrir_refplus.data;
elseif plusorminus==0
hrir_targ=setup.HRIRs{indx}.hrir_refminus.data; 
end
47

48
%-------------- SPEECH ----------------- 
49

50
% Speech 
51 52 53
numberOfFiles = length(setup.waveFiles);
fileToPlay = randi(numberOfFiles, 1);
baseWavFileName = setup.waveFiles(fileToPlay).name;
54
fullWavFileName = fullfile([setup.filedir, baseWavFileName]);
55
[sig, fssig]=audioread(fullWavFileName);
56

57
% resample the signal
58
sig=resample(sig,def.samplerate,fssig);
59 60

% resample the impulse response
61 62
hrir_ref=resample(hrir_ref,def.samplerate,hrir_fs);
hrir_targ=resample(hrir_targ,def.samplerate,hrir_fs);
63

64 65 66 67 68
% convolve speech signal with IRs
for c=1:def.outputChannels 
sig_ref(:,c)=conv(sig,hrir_ref(:,c));
sig_targ(:,c)=conv(sig,hrir_targ(:,c));
end
69 70


71
%-------------- NOISE ----------------- 
72

73 74
% provide 3 randomly cut excerpts of noise 
L=length(sig)+length(hrir_targ)-1;
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
start1=randi(length(setup.noise)-L);
noise1=setup.noise(start1+1:start1+L,:);
start2=randi(length(setup.noise)-L);
noise2=setup.noise(start2+1:start2+L,:);
start3=randi(length(setup.noise)-L);
noise3=setup.noise(start3+1:start3+L,:);

% ------------- LEVELS --------------
noise1=set_level(noise1,setup.level-work.currentCalLevel);
noise2=set_level(noise2,setup.level-work.currentCalLevel);
noise3=set_level(noise3,setup.level-work.currentCalLevel);
sig_ref=set_level(sig_ref, work.expvaract-work.currentCalLevel);
sig_targ=set_level(sig_targ, work.expvaract-work.currentCalLevel);


% ----------- AFC INTERVAL SIGNALS  -----------
91 92
%window
setup.hannlen = round(0.05*def.samplerate);
93 94
setup.window = hannfl(L,setup.hannlen,setup.hannlen);
% signal + noise
95 96 97 98 99
for c=1:def.outputChannels
tref1(:,c)=(sig_ref(:,c)+noise1(:,c)).* setup.window;
tref2(:,c)=(sig_ref(:,c)+noise2(:,c)).* setup.window;
tuser(:,c)=(sig_targ(:,c)+noise3(:,c)).* setup.window;
end
100 101

% pre-, post- and pausesignals (all zeros)
102 103 104
presig = zeros(def.presiglen, def.outputChannels);
postsig = zeros(def.postsiglen, def.outputChannels);
pausesig = zeros(def.pauselen, def.outputChannels);
105 106

% make required fields in work
107
work.signal = [tuser tref1 tref2];% left = right (diotic) first two columns holds the test signal (left right)
108 109 110 111 112
work.presig = presig;											% must contain the presignal
work.postsig = postsig;											% must contain the postsignal
work.pausesig = pausesig;										% must contain the pausesignal

% eof