How can I change the SNR over trials in a staircase threshold?

1 view (last 30 days)
Hello everyone!
I have a task which consists in presenting for 20 times a beep signal of 5 different pitches immerse in noise. In the end I would have 100 presentations, 20 for each pitch of the signal. The signal must be presented randomly to one ear at a time and, depending on the response of the subject, the SNR must increase or decrease. Here is my code (sorry it's quite long!):
samplingRate = 48000;
myPitches = [500, 1000, 1500, 2000, 2500];
howLong = .5;
[beep] = MakeBeep(500, howLong, samplingRate); % I only need this to make the noise
noise = rand(size(beep));
mySNR = .1; % initial value
condition_fs = [1 2 3 4 5];
numCondition = {'1', '2'}; % left and right
% Start presentation
RandPitches = Shuffle(myPitches); %Randomising order of pitches
presentedPitches = [];
subSNR = [];
for condition_fs = 1:5 % five frequencies
for trial = 1:20 % presentation for each frequency
pause(1.5)
[beep] = MakeBeep(RandPitches(condition_fs), howLong, samplingRate); % each pitch is presented for 20 times
presentedPitches(condition_fs, trial) = RandPitches(condition_fs); % save pitches
% Randomising ear presentation
RandCondition = randperm(length(numCondition),1);
if RandCondition == 1 % if the randperm gives 1, then play left_ear
left_ear = [beep+noise; noise].*mySNR;
PsychPortAudio('FillBuffer', pahandle, left_ear)
PsychPortAudio('Start', pahandle)
else
% if condition 2 (beep right) then play stimulus with beep right
right_ear = [noise; beep+noise].*mySNR;
PsychPortAudio('FillBuffer', pahandle, right_ear);
PsychPortAudio('Start', pahandle);
end
end
% interpreting key press
keyPress = false;
while ~keyPress
[keyPress, pressTime, keyCode] = KbCheck(-1);
end
keyName = KbName(keyCode);
if keyName(1) == 'q'
disp('exiting')
sca
break
end
% This if statement should terminate the experiment if q is pressed
if keyName(1) == '1' && RandCondition == 1 % Correct answer, response matches presentation
mySNR = mySNR*.9; % decrease by 10%
else % if response does not match presentation
mySNR = mySNR*1.1; % increase by 10%
end
if keyName(1) == '9' && RandCondition == 2 % Correct answer, response matches presentation
mySNR = mySNR*.9;
else
mySNR = mySNR*1.1;
end
% Save each mySNR in a variable
subSNR(condition_fs, trial) = mySNR; % 5 rows_fs and 20 columns_trials
end
My main problem here is that the SNR does not change over trials. In the subSNR are stored all zeros, except in the very last trial.
I guess my problem regards the interpretation of the keypress. I tried everything to solve it, but I fail all the time! I really hope someone is able to help me here!
Thank you!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!