stereoDemo.m

A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.

<cdcm>% STEREO DISPLAY DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
 
 
<cdcm>% Each trial shows a different random dot stereogram until the subject presses<cdcm>
<cdcm>% any key. This is a stimulus consisting of a background of noise with a smaller<cdcm>
<cdcm>% patch of noise on top. The smaller patch is offset horizontally by a small<cdcm>
<cdcm>% amount on one eye only. This simulates a binocular parallax depth cue when<cdcm>
<cdcm>% viewed in stereo. Trials test 6 noise offsets = -0.1, -0.2, -0.3, +0.1, +0.2,<cdcm>
<cdcm>% +0.3 deg. The direction of offset informs the direction of depth perceived (on<cdcm>
<cdcm>% top / behind). We run 2 repetitions of each offset for a total of 12 trials,<cdcm>
<cdcm>% all in random order.<cdcm>
 
 
 
<cdcm>% Mark start of experiment script<cdcm>
newExperiment
 
 
            <cdcm>% Background noise - same in all trials<cdcm>
            <cdcm>% ---<cdcm>
            backgroundNoise = noiseObject;
 
            <cdcm>% Rectangular intensity probability distribution from intensity 0-1, quantized<cdcm>
            <cdcm>% to 0/1 -> black/white noise<cdcm>
            backgroundNoise.sigma = inf;
            backgroundNoise.numLevels = 2;
 
            <cdcm>% Leave .size = default to show full screen.<cdcm>
            <cdcm>% Leave all other noise parameters like .maxFrequency at default.<cdcm>
            <cdcm>% Leave .nn_eyes = default [1 2] to show on both left/right eyes.<cdcm>
 
            <cdcm>% Default start at trial start.<cdcm>
            <cdcm>% End at any response.<cdcm>
            backgroundNoise.end.response = true;
            <cdcm>% ---<cdcm>
 
 
            <cdcm>% Object to listen for any key press - same in all trials<cdcm>
            <cdcm>% ---<cdcm>
            anyKey = keyPressObject;
            <cdcm>% ---<cdcm>
 
 
<cdcm>% 12 trial definitions: 6 offsets x 2 random patterns each.<cdcm>
<cdcm>% Each random pattern is potentially a different value for noise property .seed<cdcm>
<cdcm>% (see below), so each is a DISTINCT TRIAL which needs a separate trial<cdcm>
<cdcm>% definition.<cdcm>
offsets = [-0.1 -0.2 -0.3 +0.1 +0.2 +0.3];
<cdkm>for<cdkm> o = 1:6
    <cdkm>for<cdkm> r = 1:2
        offset = offsets(o);
 
        <cdcm>% Generate a MATLAB random number generate state for this rep to use in .seed below<cdcm>
        seed = rng(<cdsm>'shuffle'<cdsm>);
 
 
        <cdcm>% Foreground noise patch<cdcm>
        <cdcm>% ---<cdcm>
        <cdcm>% Same parameters as background noise except we make two foreground noise<cdcm>
        <cdcm>% objects, one for left eye and one for right. They will be identical except for<cdcm>
        <cdcm>% position.<cdcm>
 
            foregroundNoises = noiseObject(2);
        <cdkm>for<cdkm> n = 1:2
            <cdcm>% Patch size = 8 deg square<cdcm>
            foregroundNoises(n).size = 8;
 
            foregroundNoises(n).sigma = inf;
            foregroundNoises(n).numLevels = 2;
 
            <cdcm>% Tell each foreground noise patch to use MATLAB's random number generator<cdcm>
            <cdcm>% seeded to the same state so they have precisely the same (pseudo)random<cdcm>
            <cdcm>% pattern<cdcm>
            foregroundNoises(n).seed = seed;
 
            foregroundNoises(n).end.response = true;
        <cdkm>end<cdkm>
 
            <cdcm>% One foreground noise patch is shown on left eye, other on right eye, with opposite horizontal shifts with magnitude = 1/2 total offset<cdcm>
            foregroundNoises(1).position = [-offset/2 0];
            foregroundNoises(1).nn_eyes = 1;
            foregroundNoises(2).position = [+offset/2 0];
            foregroundNoises(2).nn_eyes = 2;
        <cdcm>% ---<cdcm>
 
 
        <cdcm>%See offset in trial results.<cdcm>
        <cdcm>%Use trial object cause not specific to one element.<cdcm>
        trial = trialObject;
        trial.info.offset = offset;
 
 
        <cdcm>% Add trial definition with default numbering (1, 2, 3, ...)<cdcm>
        addTrial(backgroundNoise, foregroundNoises, anyKey, trial);
    <cdkm>end<cdkm>
<cdkm>end<cdkm>
 
 
<cdcm>% Set stereo mode using screen object: 6 = red/green anaglyph.<cdcm>
<cdcm>% You can change this if you want to try different modes--see www.psychbench.org/docs/screen#stereo.<cdcm>
screen = screenObject;
screen.stereo = 6;
 
addToExperiment(screen)
 
 
<cdcm>% Trial list: run the trial definitions in random order<cdcm>
nn = randomOrder(1:12);
setTrialList(nn)
 
 
<cdcm>% Run<cdcm>
runExperiment;