A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.
<cdcm>% STROOP W/ SOUND RECORDING EXPERIMENT DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
<cdcm>% Same as Stroop experiment demo except here the subject actually SAYS the ink<cdcm>
<cdcm>% color and the experiment records it as sound, then the subject presses any key<cdcm>
<cdcm>% when they're ready for the next word. The disadvantage is results analysis is<cdcm>
<cdcm>% a bit more work: For each trial, the start times of sound recording and visual<cdcm>
<cdcm>% stimulus are in experiment results output, but the sound recording itself is<cdcm>
<cdcm>% saved to a .wav file in your MATLAB current folder. To measure response<cdcm>
<cdcm>% latency, you could use a sound editor app to visualize and measure the time of<cdcm>
<cdcm>% onset of the subject speaking relative to stimulus onset, based on the two<cdcm>
<cdcm>% time numbers in results.<cdcm>
newExperiment
<cdcm>% TASK TRIALS<cdcm>
<cdcm>% ==========<cdcm>
<cdcm>% Define 3 words<cdcm>
words = [
<cdsm>"RED"<cdsm>
<cdsm>"GREEN"<cdsm>
<cdsm>"BLUE"<cdsm>
];
<cdcm>% Define 3 ink colors (RGB)<cdcm>
colors = [
1 0 0 <cdcm>% red<cdcm>
0 1 0 <cdcm>% green<cdcm>
0 0 1 <cdcm>% blue<cdcm>
];
<cdcm>% 9 trial definitions numbered 1-9: 3 words x 3 ink colors<cdcm>
<cdkm>for<cdkm> w = 1:3
<cdkm>for<cdkm> i = 1:3
<cdcm>% Text<cdcm>
<cdcm>% ---<cdcm>
text = textObject;
<cdcm>% Set word and display color using word #, color #<cdcm>
text.text = words(w);
text.color = colors(i,:);
<cdcm>% Make this text a bit bigger than default (deg)<cdcm>
text.fontSize = 1.5;
<cdcm>% Start at 0.5 sec from trial start to give some buffer from when sound recording starts (below).<cdcm>
<cdcm>% Just in case there is some latency in sound recording start, so we don't miss a response.<cdcm>
<cdcm>% End at key press.<cdcm>
text.start.t = 0.5;
text.end.response = true;
<cdcm>% See word #, ink color #, congruent (true/false), text, color, start time in results<cdcm>
text.info.n_word = w;
text.info.n_ink = i;
<cdcm>% Congruent if word # matches ink color #<cdcm>
text.info.congruent = w == i;
text.report = <cdsm>"startTime"<cdsm>;
<cdcm>% ---<cdcm>
<cdcm>% Sound recorder<cdcm>
<cdcm>% ---<cdcm>
response = soundRecorderObject;
<cdcm>% Base file name to record to in MATLAB current folder.<cdcm>
<cdcm>% Sound recorder will automatically add 01, 02, 03, ...<cdcm>
response.fileName = <cdsm>"stroop.wav"<cdsm>;
response.minNumDigitsInFileName = 2;
<cdcm>% Start at trial start; End at key press<cdcm>
response.start.t = 0;
response.end.response = true;
<cdcm>% See file name and number, recording start time in results<cdcm>
response.report = [<cdsm>"fileName_r"<cdsm> <cdsm>"n_file"<cdsm> <cdsm>"startTime"<cdsm>];
<cdcm>% ---<cdcm>
<cdcm>% Key press<cdcm>
<cdcm>% ---<cdcm>
anyKey = keyPressObject;
<cdcm>% By default listens for any key, then ends on its own.<cdcm>
<cdcm>% Just need to say start when text starts:<cdcm>
anyKey.start.t = 0.5;
<cdcm>% ---<cdcm>
<cdcm>% Add trial definition with default numbering (1, 2, 3, ...)<cdcm>
addTrial(text, response, anyKey);
<cdkm>end<cdkm>
<cdkm>end<cdkm>
<cdcm>% ==========<cdcm>
<cdcm>% INTRO, BREAK, OUTRO TRIALS<cdcm>
<cdcm>% ==========<cdcm>
<cdcm>% Intro.<cdcm>
<cdcm>% dialogue object to show text until subject presses any key.<cdcm>
<cdcm>% (Could have used dialogue object for stimuli as well but separate text, keyPress objects were okay too.)<cdcm>
text = dialogueObject;
<cdcm>% Each string in the array is a new line<cdcm>
text.text = [
<cdsm>"Say the color of the ink, not what the word says. Respond as fast as possible while still trying to be correct. Then press any key for the next word."<cdsm>
<cdsm>""<cdsm>
<cdsm>"Press any key to begin..."<cdsm>
];
<cdcm>% Change font color from default white to black cause we will use a white background<cdcm>
text.color = [0 0 0];
<cdcm>% Align left instead of center<cdcm>
text.alignment = <cdsm>"l"<cdsm>;
<cdcm>% Add trial definition with name "intro"<cdcm>
addTrial(text, <cdsm>"intro"<cdsm>);
<cdcm>% Break.<cdcm>
<cdcm>% Use same object from above, just change the text.<cdcm>
text.text = <cdsm>"Take a break! Press any key when you are ready to continue..."<cdsm>;
<cdcm>% Add trial definition with name "break"<cdcm>
addTrial(text, <cdsm>"break"<cdsm>);
<cdcm>% Outro<cdcm>
text.text = <cdsm>"Done--thank-you!"<cdsm>;
addTrial(text, <cdsm>"outro"<cdsm>);
<cdcm>% ==========<cdcm>
<cdcm>% Set trial list:<cdcm>
<cdcm>%<cdcm>
<cdcm>% - intro trial<cdcm>
<cdcm>% - 2 repetitions of each task trial definition in random order<cdcm>
<cdcm>% - break trial<cdcm>
<cdcm>% - 2 repetitions of each task trial definition in random order<cdcm>
<cdcm>% - outro trial<cdcm>
<cdcm>%<cdcm>
<cdcm>% Random order just to randomize left/right<cdcm>
nn = {<cdsm>"intro"<cdsm> randomOrder(rep(1:9, 2)) <cdsm>"break"<cdsm> randomOrder(rep(1:9, 2)) <cdsm>"outro"<cdsm>};
setTrialList(nn)
<cdcm>% Set experiment background color to white in an experiment object<cdcm>
experiment = experimentObject;
experiment.backColor = [1 1 1];
addToExperiment(experiment)
<cdcm>% You can call "viewExperiment" and "viewExperiment -d" to visualize trials<cdcm>
[results, resultsMatrix] = runExperiment;