Contents

%%---------------------------------------------------------------------

how to calculate visual angle

Objects look smaller the further away you go... i.e. their visual angle gets smaller. Knowing visual angle is useful because the same stimulus dimensions can be described independently of viewing distance. Here's a handy function to convert between screen dimensions and visual angle.

help visang                     % help on this function

% let's say we're viewing from 1 metre
viewDist = 100;

% how many degrees are subtended by a stimulus measuring 1cm from this
% viewing distance?
visang(viewDist, [], 1)

% how big should a stimulus be on the screen when viewed from 1 metre?
visang(viewDist, 1, [])

% How many pixels should this 1 degree image have?
screenWidthCm = 40;             % width of a standard psychophysics monitor
screenWidthDeg = visang(viewDist, [], 40);  % converted to degrees
screenWidthPix = 1024;          % how many pixels across the screen?
pixPerDeg = screenWidthPix / screenWidthDeg   % one degree = this many pixels

% what's this look like?
imshow(zeros(pixPerDeg));       % plot a matrix of zeros

% We can actually use Cogent to display images in coordinates of visual angle
cgscale('h')                    % help on this function

% here's a demo of how to do this
cgScaleDemo

%%---------------------------------------------------------------------

how to correct gamma

Most displays are non-linear: as voltage input increases, luminance output increases by a power.

voltage = [0 : .01 : 1];                % input voltage
gammaValue = 2.2;                       % a typical value
luminance = voltage .^ gammaValue;      % power function

plot(voltage, luminance, 'b-');         % plot the function
hold on;

% this might be good for everyday use, but bad for psychophysics
% 'gamma correction' aims to linearize the monitor output
correctedLuminance = luminance .^ (1 / gammaValue); % inverse function
plot(voltage, correctedLuminance, 'r-');    % result is linear again
legend('Original', 'Corrected');

% a Cogent demo showing how to linearize a graylevel image
cgGammaDemo_directColour

% to calibrate your monitor, use a photometer with this script
edit calibDisplay

%%---------------------------------------------------------------------

how to summarize group data

data from experiments usually comes in a list with trial number, condition codes and responses.

% here is a typical experimental protocol with trial number, condition
% codes for two factors (two and three levels respectively). The last
% column might be for subjects (5)
%
design = fullfact([10 2 3 5]);          % generate factorial design
imagesc(design);                        % visualize
set(gca, 'xtick', 1:4, 'xticklabel', {'trial', 'cond1', 'cond2', 'subjects'});

% now let's make up some data...
data = rand(length(design),1);          % random variable
data = data .* sum(design(:,2:3),2);    % multiply by sum of condition codes

% We usually want to get the summary stats for each condition or
% combination of conditions. A great Matlab function for doing this is
% GRPSTATS
grpstats(data, {design(:,2), design(:,3)}, .95);
[MEANS,SEM,COUNTS,GNAME] = grpstats(data, {design(:,2), design(:,3)})

% we even do an ANOVA on these data
rmaov2([data design(:,2:4)])

% another method to do a similar operation is to put all the data into a
% multidimensional array
dataMD = reshape(data,10,2,3,5);

% you can then slice it up in different ways
trialMean = squeeze(mean(dataMD,1));     % mean across trials (dimension 1)
% after averaging across the trials, the first dimension has just one level
% 'squeeze' removes this 'singleton' dimension

ssMean = squeeze(mean(trialMean, 3));    % mean across subjects (dimension 3)
ssSE = squeeze(std(trialMean, 0, 3)) / sqrt(5-1);  % standard error

% plot results
errorbar(ssMean', ssSE');
legend('condition 1', 'condition 2');

%%---------------------------------------------------------------------

how to make an anaglyph

for experiments on binocular rivalry it is useful to display two different images, one in red and one in blue or green. When looked at through red-green glasses, each eye sees a different image. This demo shows how to do this...

edit makeAnaglphDemo