123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- %% Subscript: Organises data from datasets in multiple variables
- % subdivide dataset into its components
- if remI==1
- data(remRec{repDaSe},:) = []; % remove certain recordings from analysis
- end
- filenames_stim = cat(1,data{:,1});
- bsPos = cell2mat(strfind(filenames_stim,'\')); % find positions of back slashes in filename
- % bsPos = strfind(filenames_stim,'\'); % find positions of back slashes in filename
- startPos = bsPos(:,end); % use last back slash position as starting point
- ptPos = cell2mat(strfind(filenames_stim,'.')); % find positions of points in filename (here only one)
- % ptPos = strfind(filenames_stim,'.'); % find positions of points in filename (here only one)
- endPos = ptPos; % use point position as ending point
- recID = extractBetween(filenames_stim,startPos,endPos,'Boundaries','Exclusive'); % extract between Positions
- param_stim = cat(1,data{:,2});
- date = cat(1,data{:,7});
- artDateI = date<datetime(trArtDate,'Format','yyyyMMdd'); % logical array that identifies recordings with artefact
- filenames_rec = cat(1,data{:,3});
- param_rec = struct2cell(cat(1,(data{:,4}))); % concatenate struct arrays, then convert to cell arrays
- rec_raw = cat(1,data(:,6)./100); % "/100" because data from EP-Preamp are amplified by 100
- nFiles = size(data,1); % number of files within the variable
- %% define some additional parameters that are needed for calculations
- % stimulation-parameters; ATTENTION: always uses the parameters of first
- % file --> parameters must be consistent across all files!
- fs_stim = param_stim(1,4);
- fdown_stim = param_stim(1,17);
- fIndx = param_stim(1,2);
- Alvl = param_stim(1,9);
- Afrq = param_stim(1,10);
- Blvl = param_stim(1,26);
- Bfrq = param_stim(1,25);
- AfrqI = 999; % frequency index in MR control --> redundant but required in other runTypes
- BfrqI = 999;
- nResp = param_stim(1,47);
- SOA = param_stim(1,48);
- % define number of blocks dependent on whether all blocks or just a
- % sbubsample should be used
- switch subSConS
- case 0
- nBlcks = param_stim(1,49);
- case 1 % if subSConS is active
- nBlcks = conST; % use only as many blocks as trials were used in the oddball condition
- end
- IBI = param_stim(1,50);
- pts2begin_stim = param_stim(1,41);
- stimDur = round(param_stim(1,7),4);
- trDel = spDis/343.2; % travelling delay time of stimulus in s (343.2 is the speed of sound in air)
- stimDelay = round(param_stim(1,13)+trDel,4); % stimulus delay in s (corrected for sound travelling time)
- repper = round(param_stim(1,8),4);
- recdur = repper;
- recdur = recdur*recDurMult; % adjust rec dur based on multiplicator
- % recording-parameters
- fs = cat(2,param_rec{1,1})';
- chLbl = string(cat(2,param_rec{3,:}))';
- pts2begin = round(stimDelay.*fs); % samples before stimulus onset
- % additional parameters
- nCh = zeros(1,nFiles); % preallocate
- rawLen = zeros(1,nFiles); % preallocate
- for f = 1:nFiles
- nCh(f) = size(rec_raw{f},1); % number of channes in raw file
- rawLen(f) = size(rec_raw{f},2); % number of samples in each channel of raw file
- end
- pBlckRaw = round(SOA.*nResp.*fs); % length of one block WITHOUT additional stim delay added --> required for subsequent calculations
- pBlck = pBlckRaw+pts2begin; % length of one block in samples; PLUS stim delay at the end to make sure that all responses are included
- pIBI = round(IBI.*fs);
- pUnitRaw = pBlckRaw+pIBI;
- pUnit = pUnitRaw+pts2begin;
- pRecRaw = pUnitRaw*nBlcks;
- pRec = pRecRaw+pts2begin;
- pSiResp = pBlckRaw/nResp; % number of samples of each single response
- timetrUnit = (0:pUnit-1)/fs; % time trace of one trial
- timetrBlck = (0:pBlck-1)/fs; % time trace of one trial
- timetrSiResp = (0:pSiResp-1)/fs; % time trace of one trial
- if channels=="all"
- nameCh = chLbl;
- nCh_s = nCh;
- else
- nameCh = channels;
- nCh_s = size(channels,2);
- end
- timetr = (0:pBlck-1)/fs; % time trace of one trial
- % triggers
- trigs_all = zeros(nFiles,nBlcks); % preallocate
- for f = 1:nFiles % extract trigger events for each file individually
- eventsTemp = struct2cell(cat(1,data{f,5})); % extract all events from struct array "data" and convert it to cell array
- eventsTemp = eventsTemp(:,:,eventsTemp(1,1,:)=="Stimulus"); % find all triggers "Stimulus" within events array
- trigsIdx = eventsTemp(2,1,:)=="S 1"; % find all triggers "S 1" within events array
- trigsTemp = eventsTemp(3,1,trigsIdx(1,1,:)); % apply logical array on events array to extract triggers
- switch c
- case {1,2} % for multiple stimuli per block
- trigsTemp = trigsTemp(1,1,1:10:end); % use every 10th trigger only (first trigger of each block)
- end
- trigsTemp = cell2mat(trigsTemp); % convert trigger array to matrix
- trigs_all(f,:) = trigsTemp(:,:,1:nBlcks); % concatenate triggers of all files
- end
|