


FORMAT [conds] = prt_check_design(cond,tr,units,hrfoverlap)
Check the design and discards scans which are either overlapping between
conditions or which do not respect a minimum time interval between
conditions (due to the width of the HRF function).
INPUT
- cond : structure containing the names, durations and onsets of the
conditions
- tr : interscan interval (TR)
- units : 1 for seconds, 0 for scans
- hrfoverlap : value to correct for BOLD overlap (in seconds)
- hrfdelay : value to correct for BOLD delay (in seconds)
OUTPUT
the same cond structure containing supplementary fields:
- scans : scans retained for further classification
- discardedscans: scans discarded because they overlapped between
conditions
- hrfdiscardedscans: scans discarded because they didn't respect the
minimum time interval between conditions
- blocks: represents the grouping of the stimuli (for
cross-validation)
- stats: struct containing the original time intervals, the
time interval with only the 'good' scans, their
means and standard deviation
_______________________________________________________________________
Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

0001 function [conds] = prt_check_design(cond,tr,units,hrfoverlap,hrfdelay) 0002 % FORMAT [conds] = prt_check_design(cond,tr,units,hrfoverlap) 0003 % 0004 % Check the design and discards scans which are either overlapping between 0005 % conditions or which do not respect a minimum time interval between 0006 % conditions (due to the width of the HRF function). 0007 % 0008 % INPUT 0009 % - cond : structure containing the names, durations and onsets of the 0010 % conditions 0011 % - tr : interscan interval (TR) 0012 % - units : 1 for seconds, 0 for scans 0013 % - hrfoverlap : value to correct for BOLD overlap (in seconds) 0014 % - hrfdelay : value to correct for BOLD delay (in seconds) 0015 % 0016 % OUTPUT 0017 % the same cond structure containing supplementary fields: 0018 % - scans : scans retained for further classification 0019 % - discardedscans: scans discarded because they overlapped between 0020 % conditions 0021 % - hrfdiscardedscans: scans discarded because they didn't respect the 0022 % minimum time interval between conditions 0023 % - blocks: represents the grouping of the stimuli (for 0024 % cross-validation) 0025 % - stats: struct containing the original time intervals, the 0026 % time interval with only the 'good' scans, their 0027 % means and standard deviation 0028 %_______________________________________________________________________ 0029 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory 0030 0031 % Written by J. Schrouff 0032 % $Id$ 0033 0034 % get the number of conditions 0035 ncond=length(cond); 0036 %get defaults 0037 def=prt_get_defaults('datad'); 0038 %suppose design is in seconds if no units specified 0039 if nargin<3 0040 units=1; 0041 end 0042 0043 %no correction for HRF BOLD overlap if none specified 0044 if nargin<4 0045 hrfw=def.hrfw; 0046 else 0047 hrfw=hrfoverlap; 0048 end 0049 %no correction for HRF BOLD delay if none specified 0050 if nargin<5 0051 hrfd=def.hrfd; 0052 else 0053 hrfd=hrfdelay; 0054 end 0055 0056 %check the level of overlapping between the different conditions 0057 all=[]; 0058 conds=[]; 0059 for i=1:ncond 0060 condsc=[]; 0061 bl=[]; 0062 if units 0063 cs=round((cond(i).onsets+hrfd)/tr+1); 0064 cdur=floor(cond(i).durations/tr); 0065 else 0066 cs=round(cond(i).onsets+(hrfd/tr)+1); 0067 cdur=round(cond(i).durations); 0068 end 0069 cdur=max(1,cdur); 0070 for j=1:length(cs) 0071 temp=cs(j):cs(j)+cdur(j)-1; 0072 condsc=[condsc,temp]; 0073 bl=[bl j*ones(1,length(temp))]; 0074 end 0075 cond(i).scans=unique(condsc); 0076 cond(i).blocks=bl; 0077 conds=[conds;i*ones(length(cond(i).scans),1)]; 0078 all=[all; cond(i).scans']; 0079 end 0080 index=1:length(all); 0081 [allc,indexc]=unique(all); 0082 conds=conds(indexc); 0083 interind=setdiff(index,indexc); 0084 %Check if the same scans are implied in different conditions 0085 if ~isempty(interind) 0086 intervect=all(interind); 0087 [allgood,indgood]=setxor(allc,intervect); 0088 conds=conds(indgood); 0089 flag=1; 0090 else 0091 allgood=allc; 0092 flag=0; 0093 end 0094 if flag 0095 for i=1:ncond 0096 [dumb,indd]=setdiff(cond(i).scans,intervect); 0097 cond(i).blocks=cond(i).blocks(indd); 0098 cond(i).discardedscans=intersect(cond(i).scans,intervect); 0099 cond(i).scans=dumb; 0100 end 0101 disp('The same scans are implied in different conditions') 0102 disp('They will be discarded') 0103 disp('Review the data set for more information') 0104 else 0105 for i=1:ncond 0106 cond(i).discardedscans=[]; 0107 end 0108 end 0109 0110 %Check for the overlapping between conditions: will not allow an 0111 %overlapping smaller than hrfw seconds (the Haemodynamic Response FWHM) / by 0112 %the TR. 0113 thresh=ceil(hrfw/tr); 0114 overlap=abs(diff(allgood)); 0115 changecond=diff(conds); 0116 chan=find(changecond~=0); 0117 0118 alldisc=[]; 0119 for i=1:length(chan) 0120 intvl=overlap(chan(i)); 0121 if ~(intvl>=thresh) 0122 togap=thresh-intvl; 0123 disc_c=allgood(chan(i)+1):allgood(chan(i)+1)+togap-1; 0124 interall=intersect(allgood,disc_c); 0125 alldisc=[alldisc;interall]; 0126 end 0127 end 0128 if ~isempty(alldisc) 0129 for i=1:ncond 0130 [dumb,indd]=setdiff(cond(i).scans,alldisc); 0131 cond(i).blocks=cond(i).blocks(indd); 0132 cond(i).hrfdiscardedscans=intersect(cond(i).scans,alldisc); 0133 cond(i).scans=dumb; 0134 end 0135 else 0136 for i=1:ncond 0137 cond(i).hrfdiscardedscans=[]; 0138 end 0139 end 0140 0141 stats=struct(); 0142 stats.overlap=overlap; 0143 stats.goodscans=setdiff(allgood,alldisc); 0144 stats.discscans=alldisc; 0145 stats.meanovl=mean(overlap); 0146 stats.stdovl=std(overlap); 0147 ovlgood=abs(diff(stats.goodscans)); 0148 stats.mgoodovl=mean(ovlgood); 0149 stats.sgoodovl=std(ovlgood); 0150 stats.goodovl=ovlgood; 0151 0152 %output structure 0153 conds=struct(); 0154 conds.conds=cond; 0155 conds.stats=stats; 0156 conds.TR=tr; 0157 conds.unit=units; 0158 return