-
Is it possible to integrate PupilEXT functions with Psychtoolbox projects? For example, we would like to embed codes about the timing and types of stimuli that are presented in psychtoolbox into our pupil recordings. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Of course, you can synch PupilEXT with other experimental devices or software tools like the Psychotoolbox. It is easy to do, and there is also a Matlab script from an experiment in this repository where you can see how this can be done in principle, but let me start step by step. Let's say we plan an experiment in which we need to measure the pupil diameter in response to different coloured lights. To carry out the experiment, we have three systems: Firstly, we have PupilEXT to record the pupil diameter. Secondly, we have the luminaire for generating different light stimuli. Thirdly, we have a software with which the luminaire can be controlled to turn on different lights. Further, let's say that the protocol of the experiment looks as follows: In other words, each light setting is turned on for two seconds. We assume that the luminaire can be controlled using Matlab, which is similar to your question as you want to use the Psychtoolbox in Matlab to generate different types of stimuli. The basic idea is to run the PupilEXT measurement in the background and leave it on while you start your experimental script in Matlab or Python. Then after the experiment is finished, you manually turn off the measurement in PupilEXT. The PupilEXT software will provide a log file as *.csv, where each pupil diameter is associated with a timestamp, right? Okay, the problem is how we can sync the signalling times of the experiment, which are, in our example, the light-onset times of the light stimuli, with the log file of PupilEXT. For this, you need a sort of "Marker-tables", in which the timestamps of the light-onsets are saved, which you can use to combine the PupilEXT log with the signalling times. Let me give you an example. Coming back to our example with the light stimuli, a Matlab script to carry out the experiment with Matlab would look as follows (see the Matlab script below). The important part is how the light onset timestamps are saved in a table, which can be used later to synch the signalling times with the PupilEXT log file. % Order of stimuli:
% 1. 2 Seconds on: White Light (Reference),
% 2. 2 Seconds on: Blue Light (Wavelength- 450 nm),
% 3. 2 Seconds on: White Light (Reference),
% 4. 2 Seconds on: Red Light (Wavelength - 630 nm)
TurnOnTimeRef = 2;
TurnOnTimeStimuli = 2;
TrialNumber = 1;
Date = {datestr(now,'mm/dd/yyyy')};
Time = {datestr(now,'HH:MM:SS.FFF')};
Type = {'Initial'};
SpectrumLabel = {'-'};
SpectrumCode = {'-'};
CodeOfSubject = {'A'};
NameOfSubject = {'John'};
SurnameOfSubject = {'Doe'};
AgeSubject = 30;
DateExperiment = {datestr(now,'mm_dd_yyyy')};
TimeExperiment = {datestr(now,'HH_MM')};
switch TrialNumber
case 1
ExperimentLabel = {'Const_Luminance_Quasi'};
otherwise
disp('Error')
end
% Create table
T = table(Date, Time, Type, CodeOfSubject,...
NameOfSubject, SurnameOfSubject, AgeSubject, SpectrumLabel,...
SpectrumCode, ExperimentLabel);
StimuliLabels = {'450_nm', '630_nm'};
StimuliCodes = {'B', 'D'};
ReferenceLabels = {'Referenz_1', 'Referenz_2'};
ReferenceCode = {'A', 'C'};
Index = [1, 2]; % Order of stimuli
% Experiment begins ========================
for i = 1:size(Index,2)
% 1. Reference light is turned on
CurrentTime = datetime('now'); % Save the current time
fprintf(cell2mat(strcat('Reference spectrum: ', ' ', ReferenceLabels(Index(i)), ' turned on', '\n')));
% 2. Make entry into the maker table at which time the reference was turned on. Use currentTime.
T(size(T,1)+1,:)=table({datestr(now,'mm/dd/yyyy')}, {datestr(CurrentTime, 'HH:MM:SS.FFF')}, {'Begin'}, CodeOfSubject,...
NameOfSubject, SurnameOfSubject, AgeSubject, ReferenceLabels(Index(i)), ReferenceCode(Index(i)), ExperimentLabel);
% 3.Keep the reference light on
pause(TurnOnTimeRef); % keep the reference light on
% 4. Turn on stimuli
CurrentTime = datetime('now'); % Save the current time
fprintf(cell2mat(strcat('Stimuli Spectrum: ',' ', StimuliLabels(Index(i)), ' turned on', '\n')))
% 5. Make entry into the maker table at which time the stimuli was turned on. Use currentTime.
T(size(T,1)+1,:)=table({datestr(now,'mm/dd/yyyy')}, {datestr(CurrentTime, 'HH:MM:SS.FFF')}, {'Begin'}, CodeOfSubject,...
NameOfSubject, SurnameOfSubject, AgeSubject, StimuliLabels(Index(i)), StimuliCodes(Index(i)), ExperimentLabel);
% Keep the stimuli time on
pause(TurnOnTimeStimuli);
end
% The last entry in the table should be at which the the experiment is over
CurrentTime = datetime('now'); % Save the current time
T(size(T,1)+1,:)=table({datestr(now,'mm/dd/yyyy')}, {datestr(CurrentTime, 'HH:MM:SS.FFF')}, {'End'}, CodeOfSubject,...
NameOfSubject, SurnameOfSubject, AgeSubject, {'-'}, {'-'}, ExperimentLabel);
disp('Experiment is over !!');
disp(T);
filename = strcat(CodeOfSubject, '_', NameOfSubject, '_' ,SurnameOfSubject, '_',ExperimentLabel,'.mat');
MarkerTable = T;
save(cell2mat(strcat('Marker_',DateExperiment, '_', TimeExperiment, '_', filename{1})), 'MarkerTable') As you can see in the script, the different lights settings will be turned on, which is indicated in the script using the In the "Marker-table" the different light-onset times for each light setting are saved. Since PupilEXT was running in parallel on the same computer while the Matlab script was executed for the experiment, the timestamps of the PupilEXT's log file are identical to those of the "Marker-table", meaning the counters are already synced as Matlab and PupilEXT both apply the computer's system time. The only thing you need to do is to combine these two tables using a preprocessing script. The experiment with the different chromatic light settings was recently performed. The pupil data and the"Marker-tables" for this experiment are made available in the repository. Please go to this page, download the folder and open it in Matlab: https://github.com/openPupil/Open-PupilEXT/tree/main/Misc/Matlab_Pupil_Data_Evaluation The folder A tutorial on how to sync a "Marker-tables" with the PupilEXT log files is provided in the You can see the pupil diameter values (raw data and pre-processed) in the plot for the different chromatic light stimuli, which were evaluated using the different algorithms provided in PupilEXT. The light on times are highlighted using the plot's background colour, i.e. a yellow background shows that the white light was on, and the first blue background indicates the blue light. The second blue background in the plot indicates at what time the red light was switched on. Something similar can be done with the stimulus times saved by the psychophysics toolbox. I hope it is straightforward how to proceed, but if you have further questions, don't hesitate to ask as this is an important topic. |
Beta Was this translation helpful? Give feedback.
Of course, you can synch PupilEXT with other experimental devices or software tools like the Psychotoolbox. It is easy to do, and there is also a Matlab script from an experiment in this repository where you can see how this can be done in principle, but let me start step by step.
Let's say we plan an experiment in which we need to measure the pupil diameter in response to different coloured lights. To carry out the experiment, we have three systems: Firstly, we have PupilEXT to record the pupil diameter. Secondly, we have the luminaire for generating different light stimuli. Thirdly, we have a software with which the luminaire can be controlled to turn on different lights.
Further, let's…