Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions +eui/AlyxPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ function dispWaterReq(obj, src, ~)
obj.WaterRemaining = remainder;
end
catch me
d = me.message; %FIXME: JSON no longer returned
d = me.message;
if isfield(d, 'detail') && strcmp(d.detail, 'Not found.')
set(obj.WaterRequiredText, 'ForegroundColor', 'black',...
'String', sprintf('Subject %s not found in alyx', obj.Subject));
Expand Down Expand Up @@ -761,12 +761,12 @@ function log(obj, varargin)
% Examples:
% eui.AlyxPanel.round(0.8437, 'up') % 0.85
% eui.AlyxPanel.round(12.65, 'up', 3) % 12.6
% eui.AlyxPanel.round(12.6, 'down'), 12);
% eui.AlyxPanel.round(12.6, 'down') % 12
%
% See also ROUND
if nargin < 2; direction = 'nearest'; end
if nargin < 3; N = 2; end
c = 10.^(N-ceil(log10(a)));
c = 10.^(N-ceil(log10(abs(a))));
c(c==Inf) = 0;
switch direction
case 'up'
Expand Down
71 changes: 46 additions & 25 deletions +hw/+ptb/Window.m
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,35 @@ function applyCalibration(obj, cal)
Screen('LoadNormalizedGammaTable', obj.PtbHandle, gammaTable);
end

function c = calibration(obj, dev, lightIn, clockIn, clockOut)
% Creates a calibration file automatically using the light meter
function c = calibration(obj, dev, lightIn, clockIn, clockOut, makePlot)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you feel about something like this?

      function c = calibration(obj, dev, lightIn, varargin)
      %  Creates a file that specifies gamma calibration for a screen.
      %  This function requires a user to hold a photodiode, connected to a NI-DAQ, against a screen in order
      %  to perform gamma calibration, and save the calibration settings to a file.
      %
      %  Inputs:
      %    dev (int) : NI DAQ device ID to which the photodiode is
      %      connected
      %    lightIn (char) : analogue input channel name to which the
      %      photodiode is connected
      % 
      %  Optional Inputs:
      %    clockIn (char) : analogue input channel name for clocking pulse
      %    clockOut (char) : digital output channel name for clocking pulse
      %    makePlot (bool) : flag for making photodiode signal plot
      %
      %  Outputs:
      %    c (struct) : calibration struct containing refresh rate and
      %      gamma tables
      %
      %  Examples:
      %
      % See also: `calibrationStruct`

I think having varargin and those optional inputs is clarifying here, and then an args struct could be used to specify default input args in the function body, which I like better than the if nargin < n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine

% CALIBRATION Performs a gamma calibration for the screen
% Requires the user to hold a photodiode, connected to a NI-DAQ,
% against the screen in order to perform gamma calibration, and
% returns the results as a struct.
%
% Inputs:
% dev (int) : NI DAQ device ID to which the photodiode is
% connected
% lightIn (char) : analogue input channel name to which the
% photodiode is connected
% clockIn (char) : analogue input channel name for clocking pulse
% clockOut (char) : digital output channel name for clocking pulse
% makePlot (bool) : flag for making photodiode signal plot
%
% Output:
% c (struct) : calibration struct containing refresh rate and
% gamma tables
%
% See also calibrationStruct, applyCalibration

%first load a default gamma table
stdGammaTable = repmat(linspace(0, 1 - 1/256, 256)',[1 3]);
disp('Loading standard gamma table');
Screen('LoadNormalizedGammaTable', obj.PtbHandle, stdGammaTable);

if nargin < 6
makePlot = true;
end
if nargin < 5
clockOut = 'port1/line0';
end
Expand Down Expand Up @@ -647,37 +668,37 @@ function applyCalibration(obj, cal)
%% assess the delay between digital and analog

[xc, lags ] = xcorr(light, clock, 1000, 'coeff');
% figure; plot(lags,xc)
[~,imax] = max(xc);
ishift = lags(imax);
delay = 1000*ishift/acqRate; % in ms
fprintf('Digital is ahead of screen by %2.2f ms\n',delay);

delayMsg = sprintf('Digital is ahead of screen by %2.2f ms\n', delay);
fprintf(delayMsg);

% correct the data
clock = circshift(clock,[ishift,0]);

%% plot the data

ns = length(light);
tt = (1:ns)/acqRate;

figure; plot(tt,clock);
ylabel('clock signal'); title('Clock');

upCrossings = find(diff( clock > 1 ) == 1);
dnCrossings = find(diff( clock > 1 ) == -1);

figure; clf
for iC = 1:length(upCrossings)
plot(tt(upCrossings(iC))*[1 1],[0 5],'-', ...
'color', 0.8*[1 1 1] ); hold on
if makePlot
ns = length(light);
tt = (1:ns)/acqRate;

figure; plot(tt,clock);
ylabel('clock signal'); title('Clock');

upCrossings = find(diff( clock > 1 ) == 1);
dnCrossings = find(diff( clock > 1 ) == -1);

figure; clf
for iC = 1:length(upCrossings)
plot(tt(upCrossings(iC))*[1 1],[0 5],'-', ...
'color', 0.8*[1 1 1] ); hold on
end
plot( tt, light ); hold on
xlabel('Time (s)');
ylabel('Photodiode Signal (Volts)');
set(gca,'ylim',[0 1.1*max(light)]);
title(delayMsg);
end
plot( tt, light ); hold on
xlabel('Time (s)');
ylabel('Photodiode Signal (Volts)');
set(gca,'ylim',[0 1.1*max(light)]);
title(sprintf('In this plot. digital has been delayed by %2.2f ms', delay));

%% interpret the results

nsteps = length(steps); % length(UpCrossings)/3;
Expand Down
14 changes: 11 additions & 3 deletions +hw/Window.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
end

methods (Abstract)
% Opens a window into which stimuli can be drawn
open(obj)

% Closes the window if currently open
close(obj)

% Flips offscreen buffer to window, "validating" it
%
% [TIME, INVALIDFRAMES, VALIDATIONLAG] = flip(WHEN) performs flip as
Expand All @@ -63,14 +69,16 @@
% fillRect(COLOUR, RECT)
fillRect(obj, colour, rect)

%Creates the texture on this device from an image matrix
% Creates the texture on this device from an image matrix
tex = makeTexture(obj, image)

deleteTextures(obj) %Deletes any textures created on this device
% Deletes any textures created on this device
deleteTextures(obj)

%Change alpha blending factors
% Changes alpha blending factors
[oldSrcFactor, oldDestFactor] = setAlphaBlending(obj, srcFactor, destFactor)

% Draws text to the screen
[nx, ny] = drawText(obj, text, x, y, colour, vSpacing, wrapAt)
end

Expand Down
Loading