Processing pupil diameter responses to pictures
First the program "pupil_mat2text" must be run to convert the corrected pupil diameter data contained on the second channel of the _mat.DAT files into ascii text values. Just set the Matlab directory to the one containing the *_mat.DAT files and type pupil_mat2text. The program will process all the DAT files in that directory into text files with the same base name with _60Hz.txt appended.
Next start the pupil diameter processing program by typing procPicPupDia at the Matlab prompt. An open file dialog will appear. Choose one of the _60Hz.txt files. Three windows will open: one for control, one with the pupil diameter data plotted (and a light blue threshold line), and a third window into which inter-trough times will be plotted (and later troughstart minus trough pupil diameter changes). The resulting windows should look similar to those shown below.

It is obvious from the data plot that good data ends at ~400 seconds. Use TextPad to remove data after line 24000 (60Hz x 400 sec) from this text file. Open the trimmed file and adjust the threshold level by clicking on the Up/Down buttons in the Threshold frame. Next click on the Find Troughs button.The pupil diameter troughs located by the program are shown by yellow o's and the number of them is shown in the #Troughs frame just above the Exit button. Note that the data have been adjusted so that the deepest trough value is plotted at zero.

The lower plot window now contains inter-trough interval times in seconds which will be useful for deciding where troughs have been missed or extra ones picked (missed troughs at 290 and 380 sec; extra trough at 365 sec. Select a trough by clicking on it which will turn it red (selected trough at ~300 sec ready to add trough to its left). Then add a trough to the right or left of the selected one or delete it by using the buttons in the Troughs frame. Click a second time on a selected o to deselect it or use the Deselect All button in the Troughs frame (useful if selected o's may be outside of plot range).

Adjust their positions using the buttons in the Move Trough frame. The #Samps dropdown menu can be used to choose how many samples to move at each click of the move button. Once all 40 troughs are properly located click the Do it button in the Find Trough Starts frame. The program estimates trough start times by backing up from each trough until the pupil diameter stops increasing. Trough starts are indicated by green o's. The lower plot now contains pupil diameter differences between trough starts and troughs.

Correct trough starts by selecting out of place ones and using the buttons in the Move Trough Starts frame. Often trough starts are out of place if the trough is not located in the leftmost minima or if there's a wiggle in pupil diameter data during the picture response. The figure below shows the final picks for trough starts and troughs. Clicking on the deltaPD button in the save frame will save the results in a text file with seven columns: trough start time, trough start diameter, trough time, trough diameter, change in pupil diameter (trough start minus trough diameters), time difference between trough start and trough, and slope of change (column 5 divided by column 6).
