Commit a32ab663 authored by Joanna Luberadzka's avatar Joanna Luberadzka

mostly user file edited - setting levels

parent e659f4ce
......@@ -25,7 +25,7 @@ def.ollodir='/media/joanna/daten/user/joanna/Data/my_OLLO/OLLO_data/OLLO2.0_NO/'
def.measurementProcedure = 'transformedUpDown'; % measurement procedure
def.intervalnum = 3; % number of intervals
def.rule = [1 2]; % [up down]-rule: [1 2] = 1-up 2-down
def.varstep = [8 5 1]; % [starting stepsize ... minimum stepsize] of the tracking variable
def.varstep = [6 5 1]; % [starting stepsize ... minimum stepsize] of the tracking variable
def.steprule = -1; % stepsize is changed after each upper (-1) or lower (1) reversal
def.reversalnum = 6; % number of reversals in measurement phase
def.repeatnum = 1; % number of repeatitions of the experiment
......@@ -43,7 +43,7 @@ def.terminate = 1; % terminate execution on min/maxvar hit: 0 = warning, 1 =
def.endstop = 3; % Allows x nominal levels higher/lower than the limits before terminating (if def.terminate = 1)
% experimental parameter (independent variable)
def.exppar1 = [45 90 0]; % vector containing experimental parameters for which the exp is performed
def.exppar1 = [0 45 90]; % vector containing experimental parameters for which the exp is performed
def.exppar1unit = 'deg'; % unit of experimental parameter
def.exppar1description = 'reference angle';% description of the experimental parameter
......@@ -63,7 +63,7 @@ def.control_path = ''; % where to save control files
def.savefcn = 'default'; % function which writes results to disk
% samplerate and sound output
def.samplerate = 44100; % sampling rate in Hz
def.samplerate = 48000; % sampling rate in Hz
def.intervallen = 22050; % length of each signal-presentation interval in samples (might be overloaded in 'expname_set')
def.pauselen = 22050; % length of pauses between signal-presentation intervals in samples (might be overloaded in 'expname_set')
def.presiglen = 100; % length of signal leading the first presentation interval in samples (might be overloaded in 'expname_set')
......
......@@ -54,15 +54,16 @@ switch work.condition
case 'babble'
setup.noise=audioread('.wav');
case 'white'
n=randn(10*def.samplerate,1);
setup.noise=[n n];
n1=randn(10*def.samplerate,1);
n2=randn(10*def.samplerate,1);
setup.noise=[n1 n2];
otherwise
error('condition not recognized');
end
% define the calibration level (assume 90 dB SPL for 0 dB FS)
work.currentCalLevel =90;
work.currentCalLevel=90;
setup.level=40;
% make a list of files from which one file should be
......
% example_user - stimulus generation function of experiment 'example' -
% experimentDOA_user - stimulus generation function of experiment 'example' -
%
% This function is called by afc_main when starting
% the experiment 'example'. It generates the stimuli which
% the experiment 'experimentDOA'. It generates the stimuli which
% are presented during the experiment.
% The stimuli must be elements of the structure 'work' as follows:
%
......@@ -20,12 +20,8 @@
% work.pausesig = def.pausesiglen by 2 matrix.
% The pause-signal.
% (column 1 = left, column 2 = right).
%
% To design an own experiment, e.g., 'myexperiment',
% make changes in this file and save it as 'myexperiment_user.m'.
% Ensure that the referenced elements of structure 'work' are existing.
%
% See also help example_cfg, example_set, afc_main
% ------------------------------
function experimentDOA_user
......@@ -33,94 +29,77 @@ global def
global work
global setup
% 1000 ... 4000 Hz bandlimited Gaussian noise
% The experiment is meant to be 3-interval 3-alternative forced choice, so we need 3 signals.
% One signal holds the target amplitude modulation.
% work.expvaract holds the current value of the tracking variable of the experiment.
disp(num2str(setup.level))
disp(num2str(work.expvaract))
% -------------CHOOSE HRIRS ----------------
% * find which reference angle is currently tested
% * randomly choose +or- 5° or 10°
indx=find(def.exppar1==work.exppar1);
hrir_ref=setup.HRIRs{indx}.hrir_ref.data;
plusorminus=round(rand);%0 or 1
if plusorminus==1
hrir_targ=setup.HRIRs{indx}.hrir_refplus.data;
elseif plusorminus==0
hrir_targ=setup.HRIRs{indx}.hrir_refminus.data;
end
%-------------- SPEECH -----------------
% load a random wav file for this trial
% Speech
numberOfFiles = length(setup.waveFiles);
fileToPlay = randi(numberOfFiles, 1);
baseWavFileName = setup.waveFiles(fileToPlay).name;
fullWavFileName = fullfile([setup.filedir, baseWavFileName]);
[sig fssig]=audioread(fullWavFileName);
[sig, fssig]=audioread(fullWavFileName);
% resample the signal
[P,Q] = rat(def.samplerate/fssig);
sig=resample(sig,P,Q);
sig_level=work.expvaract;
sig=sig.*10^((sig_level - work.currentCalLevel)/20);
% choose hrir:
% * find which reference angle is currently tested
% * randomly choose +or- 5or10 deg
def.exppar1
indx=find(def.exppar1==work.exppar1);
hrir_ref=setup.HRIRs{indx}.hrir_ref.data;
plusorminus=randi(2);
if plusorminus==1
hrir_targ=setup.HRIRs{indx}.hrir_refplus.data;
elseif plusorminus==2
hrir_targ=setup.HRIRs{indx}.hrir_refminus.data;
end
% convolve signals with IRs
sig_ref(:,1)=conv(sig,hrir_ref(:,1));
sig_ref(:,2)=conv(sig,hrir_ref(:,2));
sig_targ(:,1)=conv(sig,hrir_targ(:,1));
sig_targ(:,2)=conv(sig,hrir_targ(:,2));
% convolve signals
sig_ref(1,:)=conv(sig,hrir_ref(:,1));
sig_ref(2,:)=conv(sig,hrir_ref(:,2));
sig_targ(1,:)=conv(sig,hrir_targ(:,1));
sig_targ(2,:)=conv(sig,hrir_targ(:,2));
noise_level=setup.level;
noise=setup.noise.*10^((noise_level - work.currentCalLevel)/20);
%-------------- NOISE -----------------
% provide 3 randomly cut excerpts of noise
L=length(sig)+length(hrir_targ)-1;
start1=randi(length(noise)-L);
noise1=noise(start1+1:start1+L);
start2=randi(length(noise)-L);
noise2=noise(start2+1:start2+L);
start3=randi(length(noise)-L);
noise3=noise(start3+1:start3+L);
% LEVELS: here scale the noise so that it has level according
% to the current tracking variable work.expvaract
% tref1 = real(ifft(scut(fft(randn(def.intervallen,1)),1000,4000,def.samplerate))) * 10^((setup.level - work.currentCalLevel)/20);
% tref2 = real(ifft(scut(fft(randn(def.intervallen,1)),1000,4000,def.samplerate))) * 10^((setup.level - work.currentCalLevel)/20);
% tuser = real(ifft(scut(fft(randn(def.intervallen,1)),1000,4000,def.samplerate))) * 10^((setup.level - work.currentCalLevel)/20) .* ... // holds the target signal
% (1 + (10^(work.expvaract/20) * setup.modsine));
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 -----------
%window
setup.hannlen = round(0.05*def.samplerate);
setup.window = hannfl(L,setup.hannlen,setup.hannlen)';
tref11=(sig_ref(1,:)+noise1).* setup.window;
tref12=(sig_ref(2,:)+noise1).* setup.window;
tref21=(sig_ref(1,:)+noise2).* setup.window;
tref22=(sig_ref(2,:)+noise2).* setup.window;
tuser1=(sig_targ(1,:)+noise3).* setup.window;
tuser2=(sig_targ(2,:)+noise3).* setup.window;
setup.window = hannfl(L,setup.hannlen,setup.hannlen);
% signal + noise
tref11=(sig_ref(:,1)+noise1(:,1)).* setup.window;
tref12=(sig_ref(:,2)+noise1(:,2)).* setup.window;
tref21=(sig_ref(:,1)+noise2(:,1)).* setup.window;
tref22=(sig_ref(:,2)+noise2(:,2)).* setup.window;
tuser1=(sig_targ(:,1)+noise3(:,1)).* setup.window;
tuser2=(sig_targ(:,2)+noise3(:,2)).* setup.window;
% pre-, post- and pausesignals (all zeros)
presig = zeros(def.presiglen,2);
postsig = zeros(def.postsiglen,2);
pausesig = zeros(def.pauselen,2);
% make required fields in work
work.signal = [tuser1' tuser2' tref11' tref12' tref21' tref22']; % left = right (diotic) first two columns holds the test signal (left right)
work.signal = [tuser1 tuser2 tref11 tref12 tref21 tref22]; % left = right (diotic) first two columns holds the test signal (left right)
work.presig = presig; % must contain the presignal
work.postsig = postsig; % must contain the postsignal
work.pausesig = pausesig; % must contain the pausesignal
......
% example_user - stimulus generation function of experiment 'example' -
%
% This function is called by afc_main when starting
% the experiment 'example'. It generates the stimuli which
% 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).
%
% To design an own experiment, e.g., 'myexperiment',
% make changes in this file and save it as 'myexperiment_user.m'.
% Ensure that the referenced elements of structure 'work' are existing.
%
% See also help example_cfg, example_set, afc_main
function experimentDOA_user
global def
global work
global setup
% 1000 ... 4000 Hz bandlimited Gaussian noise
% The experiment is meant to be 3-interval 3-alternative forced choice, so we need 3 signals.
% One signal holds the target amplitude modulation.
% work.expvaract holds the current value of the tracking variable of the experiment.
% load a random wav file for this trial
numberOfFiles = length(setup.waveFiles);
fileToPlay = randi(numberOfFiles, 1);
baseWavFileName = setup.waveFiles(fileToPlay).name;
fullWavFileName = fullfile([setup.filedir, baseWavFileName]);
[sig fssig]=audioread(fullWavFileName);
% resample the signal
[P,Q] = rat(def.samplerate/fssig);
sig=resample(sig,P,Q);
% sig_level=work.expvaract;
% sig=sig.*10^((sig_level - work.currentCalLevel)/20);
% choose hrir:
% * find which reference angle is currently tested
% * randomly choose +or- 5or10 deg
def.exppar1;
indx=find(def.exppar1==work.exppar1);
hrir_ref=setup.HRIRs{indx}.hrir_ref.data;
plusorminus=randi(2);
if plusorminus==1
hrir_targ=setup.HRIRs{indx}.hrir_refplus.data;
elseif plusorminus==2
hrir_targ=setup.HRIRs{indx}.hrir_refminus.data;
end
% convolve signals
sig_ref(:,1)=conv(sig,hrir_ref(:,1));
sig_ref(:,2)=conv(sig,hrir_ref(:,2));
sig_targ(:,1)=conv(sig,hrir_targ(:,1));
sig_targ(:,2)=conv(sig,hrir_targ(:,2));
% noise_level=setup.level;
% *10^((noise_level - work.currentCalLevel)/20);
% provide 3 randomly cut excerpts of noise
noise=setup.noise;
L=length(sig)+length(hrir_targ)-1;
start1=randi(length(noise)-L);
noise1=noise(start1+1:start1+L,:);
start2=randi(length(noise)-L);
noise2=noise(start2+1:start2+L,:);
start3=randi(length(noise)-L);
noise3=noise(start3+1:start3+L,:);
% LEVELS: here scale the noise so that it has level according
% to the current tracking variable work.expvaract
% tref1 = real(ifft(scut(fft(randn(def.intervallen,1)),1000,4000,def.samplerate))) * 10^((setup.level - work.currentCalLevel)/20);
% tref2 = real(ifft(scut(fft(randn(def.intervallen,1)),1000,4000,def.samplerate))) * 10^((setup.level - work.currentCalLevel)/20);
% tuser = real(ifft(scut(fft(randn(def.intervallen,1)),1000,4000,def.samplerate))) * 10^((setup.level - work.currentCalLevel)/20) .* ... // holds the target signal
% (1 + (10^(work.expvaract/20) * setup.modsine));
%window
setup.hannlen = round(0.05*def.samplerate);
setup.window = hannfl(L,setup.hannlen,setup.hannlen);
SNR=work.expvaract-setup.level;
[sig_ref1, noise_ref1]=compute_snr_signals(SNR,sig_ref,noise1,work.expvaract-work.currentCalLevel);
tref11=(sig_ref1(:,1)+noise_ref1(:,1)).* setup.window;
tref12=(sig_ref1(:,2)+noise_ref1(:,2)).* setup.window;
[sig_ref2, noise_ref2]=compute_snr_signals(SNR,sig_ref,noise2,work.expvaract-work.currentCalLevel);
tref21=(sig_ref2(:,1)+noise_ref2(:,1)).* setup.window;
tref22=(sig_ref2(:,2)+noise_ref2(:,2)).* setup.window;
[sig_targ, noise_targ]=compute_snr_signals(SNR,sig_ref,noise3,work.expvaract-work.currentCalLevel);
tuser1=(sig_targ(:,1)+noise_targ(:,1)).* setup.window;
tuser2=(sig_targ(:,2)+noise_targ(:,2)).* setup.window;
% pre-, post- and pausesignals (all zeros)
presig = zeros(def.presiglen,2);
postsig = zeros(def.postsiglen,2);
pausesig = zeros(def.pauselen,2);
% make required fields in work
work.signal = [tuser1 tuser2 tref11 tref12 tref21 tref22]; % left = right (diotic) first two columns holds the test signal (left right)
work.presig = presig; % must contain the presignal
work.postsig = postsig; % must contain the postsignal
work.pausesig = pausesig; % must contain the pausesignal
% eof
\ No newline at end of file
% revision 1.00.1 beta, 07/01/04
function response = exampleDOA_detect
global def
global work
global simwork
% we select only the left channels, the model is monaural
simwork.tmpSig = work.signal(:,1:2:end);
simwork.actStd = [];
for i=1:def.intervalnum
simwork.actStd(i) = eval([work.vpname '_preproc(simwork.tmpSig(:,2*i-1:2*i))']); % actual sig processing
end
% now select the interval with the maximum standard deviation
[tmp,response] = max(simwork.actStd); % select max power
% if it is another interval than the first, the response is wrong, since in the work.signal always carries the
% signal interval in the first column
if response ~= 1
response = 0;
end
% eof
% revision 1.00.1 beta, 07/01/04
function out = exampleDOA_preproc(in)
% in contains one of the 3 intervals presented in
global def
global work
global simwork
% this is the Viemeister JASA 1979 leaky-integrator model
% 4-6 kHz four-pole Butterworth Bandpass (missing)
% halfwave rectification
tmp = max(in,0);
% first-order lowpass filter @ 65 Hz
tmp = filter(simwork.lp_b, simwork.lp_a, tmp);
% ac-coupled rms = std
out = std(tmp,1);
% that's it
% eof
function sig_out=set_level(sig_in,L_des)
sig_zeromean=sig_in-repmat(mean(sig_in,1),size(sig_in,1),1);
sig_norm_en=sig_zeromean./std(sig_zeromean(:));
sig_out =sig_norm_en.*10^(L_des/20);
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment