DD_OrgData.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. %% Subscript: Organises data from datasets in multiple variables
  2. % subdivide dataset into its components
  3. if remI==1
  4. data(remRec,:) = []; % remove certain recordings from analysis
  5. end
  6. filenames = cat(1,data{:,1});
  7. bsPos = cell2mat(strfind(filenames,'\')); % find positions of back slashes in filename
  8. startPos = bsPos(:,end); % use last back slash position as starting point
  9. ptPos = cell2mat(strfind(filenames,'.')); % find positions of points in filename (here only one)
  10. endPos = ptPos; % use point position as ending point
  11. recID = extractBetween(filenames,startPos,endPos,'Boundaries','Exclusive'); % extract between Positions
  12. switch runType
  13. case 1
  14. recID_oddb{c} = recID; % save recIDs for each oddball stimulus-combination
  15. fileI_Oddb = 0; % file index is empty for runType 1 (oddball)
  16. fileI_Ctrl = 0; % file index is empty for runType 1 (oddball)
  17. case {2,3}
  18. insect = intersect(recID_oddb{c},recID); % create array containing only those recordings that are available for both the oddball and the respective control paradigm
  19. fileI_Oddb = ismember(recID_oddb{c},insect); % create logical array containing those oddball recordings that have a matching control recording
  20. fileI_Ctrl = ismember(recID,insect);% create logical array containing those control recordings that have a matching oddball recording
  21. data = data(fileI_Ctrl,:); % use only those control responses that have a matching oddball response
  22. filenames = filenames(fileI_Ctrl); % use only those control filenames that have a matching oddball response
  23. end
  24. param = cat(1,data{:,2});
  25. seq = cat(1,data{:,4});
  26. rec_raw = cat(1,data(:,5));
  27. nFiles = size(data,1); % number of files within the variable
  28. %% define some additional parameters that are needed for calculations
  29. % stimulation-parameters; ATTENTION: always uses the parameters of first
  30. % file --> parameters must be consistent across all files!
  31. fs = param(1,4);
  32. fdown = param(1,17);
  33. fsDwn = fs/fdown;
  34. fIndx = param(1,2);
  35. switch runType
  36. case {1,2} % Oddball, 50Per
  37. Alvl = param(1,9);
  38. Afrq = param(1,10);
  39. Blvl = param(1,26);
  40. Bfrq = param(1,25);
  41. AfrqI = 999; % frequency index in MR control --> redundant but required in other runTypes
  42. BfrqI = 999;
  43. end
  44. nDev = param(1,23);
  45. devProb = param(1,24);
  46. nTrials = param(1,12);
  47. nStd = nTrials-nDev;
  48. switch runType
  49. case {1,2} % Oddball, 50Per
  50. nBlcks = 2; % number of blocks (AB and BA)
  51. case 3 % MR
  52. nBlcks = 1; % only one block
  53. end
  54. stimDur = round(param(1,7),4);
  55. trDel = spDis/343.2; % travelling delay time of stimulus in s (343.2 is the speed of sound in air)
  56. stimDelay = round(param(1,13)+trDel,4); % stimulus delay in s (corrected for sound travelling delay)
  57. stimDelay = stimDelay+0.001; % add additional tone delay to stim delay
  58. pts2begin = round(stimDelay.*fsDwn); % samples before stimulus onset
  59. repper = round(param(1,8),4);
  60. recdur = repper;
  61. % additional parameters
  62. rawLen = zeros(1,nFiles); % preallocate
  63. for f = 1:nFiles
  64. rawLen(f) = size(rec_raw{f},2); % number of samples in each channel of raw file
  65. end
  66. blockLenBuff = rawLen./nBlcks; % % length of one block (AB or BA) in samples, INCLUDING buffers
  67. blockLen = round(recdur.*nTrials.*fsDwn); % length of one block (AB or BA) in samples, WITHOUT buffers
  68. pSmpl = blockLen(1)/nTrials(1); % number of samples of each single response
  69. timetr = (0:pSmpl-1)/fsDwn(1); % time trace of one trial