help with audio experiment assignment

I have this script that i need to fix for an assignment that should (1) Implement a 2 up – 1 down adaptive threshold procedure. This means, you should start with a frequency difference that is easy and obvious, and adapt that frequency difference based on the subjects responses. If the subject gets 2 trials correctly then make the task harder by decreasing the frequency difference by a fixed increment before the next trial. If the subject gets 1 trial incorrect the frequency difference should be increased by a fixed increment before the next trials. (2) The number of trials should be allowed to vary depending on the subject responses. The experiment should stop when there are a certain number of reversals specified by the users in a parameter at the top of the script. A reversal occurs when the subject gets a trial wrong. So the number of reversals is equal to the number of incorrect trials. (3) Your program should save out a .mat file which has all of the relevant information to make the plots given below. This is the script i have been given:
%playnoise
%clear everything
clear all
%EXPERIMENTAL PARAMETERS
ntrials = 3; %number of trials in the experiment
duration = 0.2; %duration is .2 secs
frequency = 2000; %this is the frequency of the tone.
%frequency_do = 261.6
%frequency_re = 293.6
%frequency_mi = 329.6
frequencydifference = 50; % the difference between the two tones
%HERE ARE SOME RECOMMENDATIONS OF STARTING FREQUENCY DIFFERENCES
%500 Hz - FREQUENCY DIFFERENCE = 50 Hz STEPSIZE = 1 Hz
%1500 Hz - FREQUENCY DIFFERENCE = 150 Hz STEPSIZE = 3 Hz
%4500 Hz - FREQUENCY DIFFERENCE = 450 Hz STEPSIZE = 9 Hz
% YOU MAY HAVE TO ADJUST THESE VALUES BASED ON YOUR SKILLS
Amplitude = 0.25;% this is the amplitude of the tone
%keep this low and adjust your volume until its comfortable
%making it loud DOES NOT HELP.
%set random number seed
seed = 1234;
rng(seed);
%prepare stimuli fs = 44100; %sampling rate, i.e. NUMBER of samples per second. %most sound cards work best if fs = 44100 (native resolution) %if you ue a different sampling rate, it is likely the sound %card will resample your sound deltat = 1/fs; %the amount of time between samples is one divided by the %sampling rate
time = [deltat:deltat:duration]; %the time points at which we are going to define %sound vector.
%make one tone which at frequency + frequency difference frequencyhigh = frequency + frequencydifference; tonehigh = Amplitude*sin(2*pi*frequencyhigh*time); %this defines the higher tone
%make one tone which at frequency - frequency difference frequencylow = frequency - frequencydifference; tonelow = Amplitude*sin(2*pi*frequencylow*time); %this defines the lower tone
%make silence silence = zeros(1,length(time));
%here is the actual experiment for n = 1:ntrials %this is the loop over trials
trialorder = randperm(2); %i want to randomize order of tones
switch trialorder(1) case 1 stimulus = [tonelow silence tonehigh]; case 2 stimulus = [tonehigh silence tonelow]; end
correctanswer(n) = trialorder(2); %If the task is to identify the higher tone %should be trialorder(1) if task is to %identify lower tone.
p = audioplayer(stimulus,fs); % the minimum information to creata an %audioplayer object is one vector of sound %values ranging from -1 to 1 %and the sampling rate
%play the sound synchronously playblocking(p)
%get a response x = input('Which was the higher tone [1/2]: ','s'); %query the subject response(n) = str2double(x); %this function converts a character string into a number end; %close the for loop over trials.

Answers (0)

This question is closed.

Tags

Asked:

on 20 Mar 2018

Closed:

on 21 Mar 2018

Community Treasure Hunt

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

Start Hunting!