% CheckEventCodes.m % This program checks the event codes count, timing, and counterbalancing. % Reads in cnt file % Writes output dat file with all event code checks for you to evaluate % 2010-11-20: JTK & JJC v1 % 2012-02-03: Updated to use Subject 0982 in DemoSTIM in Demos folder by JJC %% Variables to set % Edit the variables in this cell for your current study % No variables should typically need to be edited below this cell PathName = 'P:\Methods\Matlab\PhysBox\Demos\DemoSTIM\RawData\0982\'; %Change path to folder with input cnt file InFileName = 'stim1_maintask_0982.cnt'; % Change input cnt file name OutFileName = 'EventCodeChecks.dat'; % Change output dat file name % Edit the following event codes to match your study cues = [1 2]; % Event codes for cue onset habituation = [100]; % 100 is the even code for the first 3 habituation startles in most Curtin Lab studies probes = [101 102 103 111 112 113 121 122 123]; % Enter event codes for startle probes shocks = [254]; % Event code for shock. This is 1 in all Curtin Lab studies %% Open File EEG = pop_LoadCnt('0982', InFileName, PathName, 'int32'); % loads cnt file %% Event Count % Creates output file named (OutFileName) in the folder (PathName) % (e.g.,: P:\Methods\Matlab\PhysBox\Demos\DemoSTIM\RawData\0982\) % IMPORTANT: if there is already a file with the same name it will be deleted % and written over without prompting the user to check that is ok!!! % Outputs all event codes in study and the number of times they appear in % the cnt file % Do not need to modify anything in this cell [EventCountAll] = pop_EventCheck(EEG, [], [], [], [] ); fid = fopen([PathName OutFileName],'w'); % 'w' = open file for writing fprintf(fid,'Check Event Codes: Count, Timing/Spacing, Counterbalancing\n\nColumn 1 = Event\nColumn 2 = Counts\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,EventCountAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',5) %% Overall Timing/Spacing %Startle probe spacing % Check timing in column 4 makes sense for your study [~,TimingArrayAll] = pop_EventCheck(EEG, probes, [], [], [] ); TimingArrayAll(:,3) = TimingArrayAll(:,3)/1000; % divided by 1000 for display purposes TimingArrayAll(:,4) = TimingArrayAll(:,4)/1000; fid = fopen([PathName OutFileName],'a'); % 'a' = open file for writing and append to end of file fprintf(fid,'\n\nOverall Timing/Spacing\n\nTiming for Startle Probes\n\nColumn 1 = Trial #\nColumn 2 = Event Code\nColumn 3 = Time from start of exp (sec)\nColumn 4 = ISI to next event (sec)\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,TimingArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) % Display ISI between startle probes sorted from min to max % Check that min is large enough (usually 13 or 15 sec) % Check max value makes sense (eg: breaks between blocks) ProbeSort = (sort(TimingArrayAll(:,4))); fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nISI time between Startle Probes, sorted min to max (sec):\n\n'); fclose(fid); dlmwrite([PathName OutFileName] , ProbeSort,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) %Cue spacing % This section is often not necessary to check [EventCountAll,TimingArrayAll] = pop_EventCheck(EEG, cues, [], [], [] ); fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nISI for Cues\n'); fclose(fid); dlmwrite([PathName OutFileName] ,TimingArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) %% S1-S2 Checks % Cue to Startle % Confirm time in column 4 is the correct time between cue onset and % that startle probe [~,~, S1S2ArrayAll] = pop_EventCheck(EEG, [], cues, probes, [] ); S1S2ArrayAll(:,4) = S1S2ArrayAll(:,4)/1000; fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nS1-S2 Spacing\n\nTiming/ISI between Cue and Startle Probes\n\nColumn 1 = Trial #\nColumn 2 = Cue Event Code\nColumn 3 = Startle Probe Event Code\nColumn 4 = Cue-Probe ISI\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,S1S2ArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) %Cue to Shock % Confirm only shock cue event codes appear in column 2 % Confirm time in column 4 is the correct time between cue onset and shock [~,~, S1S2ArrayAll] = pop_EventCheck(EEG, [], cues, shocks, [] ); S1S2ArrayAll(:,4) = S1S2ArrayAll(:,4)/1000; fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nTiming/ISI between Cue and Shocks\n\nColumn 1 = Trial #\nColumn 2 = Cue Event Code\nColumn 3 = Shock Event Code\nColumn 4 = Cue-Shock ISI\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,S1S2ArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) %Shock to Startle % Confirm no startle probes occur too soon after a shock [~,~, S1S2ArrayAll] = pop_EventCheck(EEG, [], shocks, probes, [] ); S1S2ArrayAll(:,4) = S1S2ArrayAll(:,4)/1000; fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nTiming/ISI betewen Shock and Startle Probes\n\nColumn 1 = Trial #\nColumn 2 = Shocks Event Code\nColumn 3 = Startle Probe Event Code\nColumn 4 = Shock-Probe ISI\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,S1S2ArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) %% Counterbalancing %Startle % Values in column 3 should be very close (low variance) [~,~,~,AvePosArrayAll] = pop_EventCheck(EEG, [], [], [], probes); fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nCounterbalancing\n\nStartle Probes\n\nColumn 1 = Startle Probe Event Code\nColumn 2 = Count\nColumn 3 = Average Serial Position\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,AvePosArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) %Cue % Values in column 3 should be very close (low variance) [~,~,~,AvePosArrayAll] = pop_EventCheck(EEG, [], [], [], cues); fid = fopen([PathName OutFileName],'a'); fprintf(fid,'\n\nCues\n\nColumn 1 = Cue Event Code\nColumn 2 = Count\nColumn 3 = Average Serial Position\n\n'); fclose(fid); dlmwrite([PathName OutFileName] ,AvePosArrayAll,'-append', 'delimiter','\t', 'newline','pc', 'precision',7) fprintf('\n\nYour Output File is Here: %s%s \n', PathName, OutFileName); fprintf('\nCheckEventCodes Complete!\n');