/temporal_sens_params.m
https://github.com/bnaecker/temporal-sens · MATLAB · 151 lines · 106 code · 8 blank · 37 comment · 0 complexity · b94de12fb5e296772db99370c017024a MD5 · raw file
- function ex = temporal_sens_params(ex, wntime, sens_time, sens_reps, ...
- adapt_time, probe_time, ntrials, nrounds)
- %
- % FUNCTION ex = temporal_sens_params(ex, wntime, sens_time, ...
- % adapt_time, probe_time, ntrials, nrounds)
- %
- % Sets up the stimulus parameters for the pure temporal frequency sensitization
- % experiment.
- %
- % INPUT:
- % ex - Experimental structure
- % wntime - Length of white noise stimulus block (seconds)
- % sens_time - Length of high/low blocks for sensitization stimulus (seconds)
- % sens_reps - Number of high/low blocks
- % adapt_time - Length of adapt blocks (seconds)
- % probe_time - Length of probe blocks (seconds)
- % ntrials - Number of adapt/probe trials per block
- % nrounds - Number of repetitions of each round
- %
- % OUTPUT:
- % ex - Experimental structure
- %
- % (c) bnaecker@stanford.edu 2014
- % 28 May 2014 - wrote it
- % 11 Jun 2014 - adding trials, blocks and sensitization stimulus
- %% Initialize the structure
- stim = struct();
- %% Basic info
- stim.name = 'temporal-sens'; % Experiment name
- stim.date = datestr(now, 31); % Date, ISO 8601 format
- ex.disp.aperture_size = 512; % Size of stimulus aperture
- ex.disp.dstrect = CenterRectOnPoint(... % Stimulus destination rectangle
- [0 0 ex.disp.aperture_size ex.disp.aperture_size], ...
- ex.disp.winctr(1), ex.disp.winctr(2));
- ex.disp.waitframes = 2; % Number of frames between monitor flips
- ex.disp.pdscale = 0.6; % Scale factor for photodiode signal
- flip_time = ex.disp.nominalifi * ex.disp.waitframes; % Nominal time between flips
- %% White noise information
- % NOTE: White noise stimuli themselves are generated on the fly.
- % After the experiment, the full white noise movies are saved, if they
- % don't already exist, using `stimdb('add', ...)`. They can be loaded
- % again with `stimdb('load', ... )`.
- stim.wntime = wntime; % Time the white noise stimulus (seconds)
- stim.nwnboxes = 32; % Number of boxes
- stim.wncontrast = 0.25; % Contrast of gaussian white noise
- stim.nwnframes = round(stim.wntime / flip_time); % Number of frames in the stimulus
- %% Basic sensitization stimulus
- stim.sens_time = sens_time; % Time of high/low contrast blocks
- stim.sens_reps = sens_reps; % Number of repetitions
- stim.sens_contrast = [0.35 0.10]; % High/low contrast blocks
- stim.nsens_frames_per_contrast = ... % Frames in each contrast
- round(stim.sens_time ./ flip_time);
- stim.nsens_frames_per_trial = ... % Frames in each trial
- sum(stim.nsens_frames_per_contrast);
- stim.nsens_frames = sum(stim.nsens_frames_per_trial * ... % Total frames
- stim.sens_reps);
- %% Temporal sensitization stimulus parameters
- stim.adapt_time = adapt_time; % Length of an adapt block (seconds)
- stim.probe_time = probe_time; % Length of a probe block (seconds)
- stim.ntrials = ntrials; % Number of adapt/probe trials per block
- stim.nrounds = nrounds; % Number of rounds
- stim.cutoff = 2; % Cutoff frequency for low/high pass filters (see ../notes/kernels)
- stim.nbands = 2; % Only using low/high pass bands
- stim.adapt_contrast = [0.20 0.40]; % Contrasts for adapting stimulus
- stim.probe_contrast = [0.10]; % Contrasts for probe stimulus
- stim.nadapt_contrasts = length(stim.adapt_contrast); % Number of adapt contrasts
- stim.nprobe_contrasts = length(stim.probe_contrast); % Number of probe contrasts
- %% Characteristics of filters used to construct the adapt stimuli
- stim.filter_order = 4; % Order of the Butterworth filter used to filter noise into bands
- stim.low_cutoff = 0.1; % Cutoff frequency, frequencies below this are zeroed to prevent mean adaptation
- %% Compute condition matrix
- stim.condition_desc = ... % Strings describing ordering of condition matrix
- {'band', 'adapt_contrast', 'probe_contrast'};
- stim.condition_list = cartprod(... % Condition matrix
- 1:stim.nbands, stim.adapt_contrast, stim.probe_contrast);
- stim.nconditions = ... % Number of conditions
- size(stim.condition_list, 1);
- %% Describe the rounds, which are constructed to have all possible
- % transitions between blocks of each unique condition (i.e., all
- % transitions A->B where A~=B).
- stim.single_round = vec(nchoosek(1:stim.nconditions, 2)');
- stim.round_list = repmat(stim.single_round, stim.nrounds, 1);
- stim.nblocks_per_round = length(stim.single_round);
- %% Compute number of frames
- stim.nframes_per_adapt = round(stim.adapt_time / ... % Frames in each adapt trial
- flip_time);
- stim.nframes_per_probe = round(stim.probe_time / ... % Frames in each probe trial
- flip_time);
- stim.nframes_per_trial = stim.nframes_per_adapt + ... % Frames in each adapt/probe trial
- stim.nframes_per_probe;
- stim.nframes_per_block = stim.nframes_per_trial * ... % Frames in each condition block
- stim.ntrials;
- stim.nframes_per_round = stim.nframes_per_block * ... % Frames in each round
- stim.nblocks_per_round;
- %% Compute ostensible total experiment time. Actual time will diverge slightly,
- % due to deviations in the true inter-frame interval.
- stim.exp_length = stim.wntime + ...
- (sum(stim.sens_time) * stim.sens_reps) + ...
- ((stim.adapt_time + stim.probe_time) * stim.ntrials) * ...
- stim.nblocks_per_round * stim.nrounds;
- %% Create a PRNG for the basic sensitization stimulus
- stim.sens_rn = getrng();
- stim.sens_rnseed = get(stim.sens_rn, 'Seed');
- stim.sens_rnstate = get(stim.sens_rn, 'State');
- %% Create a PRNG for the temporal sensitization stimulus
- stim.rn = getrng();
- stim.rnseed = get(stim.rn, 'Seed');
- stim.rnstate = get(stim.rn, 'State');
- %% Create the basic sensitization stimulus, with contrasts
- stim.sens_stim = ...
- [randn(stim.sens_rn, stim.nsens_frames_per_contrast(1), stim.sens_reps) ...
- * stim.sens_contrast(1); ...
- randn(stim.sens_rn, stim.nsens_frames_per_contrast(2), stim.sens_reps) * ...
- stim.sens_contrast(2)];
- %% Create the white noise probe stimuli, without resetting the PRNG state
- % so that the probe and filtered adapter are uncorrelated.
- stim.probe = randn(stim.rn, stim.nrounds, stim.nblocks_per_round, ...
- stim.ntrials, stim.nframes_per_probe);
- %% Initialize the VBL timestamp arrays
- ex.disp.wnvbl = zeros(stim.nwnframes, 1); % VBL for white noise block
- ex.disp.sens_vbl = zeros(stim.nsens_frames_per_trial, ... % VBL for basic sens trials
- stim.sens_reps);
- ex.disp.adapt_vbl = zeros(stim.nrounds, ... % VBL for adapting blocks
- stim.nblocks_per_round, stim.ntrials, stim.nframes_per_adapt);
- ex.disp.probe_vbl = zeros(stim.nrounds, ... % VBL for probe blocks
- stim.nblocks_per_round, stim.ntrials, stim.nframes_per_probe);
- ex.disp.flipmissed = []; % Array to hold index of any missed flips
- %% Initialize call to GetSecs MEX-function
- GetSecs();
- %% Attach stim substructure to experimental structure
- ex.stim = stim;
- %% Set smaller Screen font size, for printing condition description to the monitor
- Screen('TextSize', ex.disp.winptr, 18);