Basic Eyetracking Analysis


All of your eyetracking data is in a file called an EDF file. This EDF file needs to be converted using a very well titled application: EDFConverter. An EDF file has sample data and event data. Event data includes all header information like date, calibration and validation information, and any other messages about fixation, blinks, saccades, and messages you sent about your timing. Sample data is simply a timestamp with pupil position and diameter. The EDF converter creates a new text file, ASC, that can have events and samples or either individually. I like to create two ASC files one with events only and one with samples. I think events will tend to be most important anyway so having a smaller file with just these is best.

How to use EDFConverter:

The application looks this:


Click on the folder, circled in red, and find your EDF file. Your EDF filename will then show up in the white area that I outlines in blue. 

Before you click "Convert to ASC" you have to change your preferences.

In the top menu bar, drop down “Preferences.” You will see something similar to the picture above. Under Samples/Events, you can decide what you want in your new ASC file. As mentioned before, I think having samples and events in two different files is useful, so if that’s something you want to do check “Output Samples Only” or “Output Events Only.” If you’re doing it this was, you’ll have to run it twice to get both the samples and events files.

Now click “Convert to ASC” and a new file will be created in the same folder and the same name as the EDF file unless you changed the preferences otherwise.

Now that your EDF file has been converted, you have a regular text file that MATLAB can use. To extract the data you want, we will use the unix command “grep” in MATLAB. There may be an easier way or a MATLAB command that works the same way, but this was the first thing I found and it works so I didn’t look further. Grep searches a text document for a word and then creates a new text document with only the lines that contain this word. The grep command will look like this: “grep keyword inputDocument > outputDocument”

For example:
Imagine you had a text file called alissaWork.txt and it contained the following 3 lines:
Alissa works at Hopkins.
Alissa works in the Fischer Lab.
Alissa works with people she likes.

And you used the following grep command: grep the alissaWork.txt > newFile.txt

Then a new text file would be created called “newFile.txt” and it would contain all lines from alissaWork.txt that contained the word “the”, so it would just be “Alissa works in the Fischer Lab”. If I had chosen “Alissa” or “works” as the keyword instead of “the” newFile.txt would be identical to alissaWork.txt.


Your keywords will be different depending on what messages you sent to the eyetracker. First, it is important to extract time information related to your trial timing. The EDF file contains data for every millisecond so you don’t need to use all of the data and your trial timing will help you narrow down your eyetracking data to the times of interest.

In my study, I sent the following message to the eyetracker each time a new trial began Eyelink('message', 'Trial %d trialStart', trial);


In the text file, this line looks like this: MSG 387123 Trial 1 start
To extract all start times, I used the following commands:

%Create a separate text file with all lines containing the word trialStart:
commandStart=['grep trialStart subjIDRun.asc > subjIDStart.txt'];

%Now that the text file has been created, open it and read everything (as strings even if they’re numbers) into a cell array. The timestamp is all I am after and that is in the 2nd column and then I change that from a cell array to a matrix of doubles
startFile= fopen('subjIDstart.txt','r');

If I also had end times for all trials, I could then make a matrix of all timing that looks like this:
timing=[startTimes endTimes];

You should be able to use the commands above to extract any information you want from the EDF files.