OSCR

Multivariate Pattern Analysis Identifies Potential Intertrial Resting-State EEG Biomarkers in Fibromyalgia.

Code ↔ Paper

2 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 2 matches
  1. [1] § Materials and Methods › Paradigm and Data Acquisition › EEG Data Acquisition and Preprocessing ↔ eegPreproc.m, lines 375–418 · score 0.68 · pop_eegfiltnew, Independent Component, preprocessing, filtered, event, rejection
  2. [2] § Materials and Methods › Paradigm and Data Acquisition › EEG Data Acquisition and Preprocessing ↔ unfoldERPData.m, lines 39–163 · score 0.63 · voltage thresholds, artifacts, filtered, event, rejection, stimuli

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 898 lines · 37 KB · MIT · 1 match

  1. %
  2. % This script processes EEG data exported from BrainVision in .dat or .eeg format
  3. % to MVPAlab format. It requires corresponding .vhdr, .dat/.eeg, and .vmrk files for.
  4. % The script can handle segmented data and allows the user to specify various
  5. % cleaning and preprocessing steps, including channel removal, resampling,
  6. % filtering, epoching, baseline correction, ICA, interpolation, and more.
  7. % The final data can be saved in .set (EEGLAB format), .mat (MATLAB format), or both.
  8. %
  9. % If channel coordinates are detected to be missing, the user can load them
  10. % from a BrainVision .bvef or .vhdr file, or use layouts present in EEGLAB or
  11. % FieldTrip source files. This requires the additional eegImportChanlocs.m
  12. % script available in the same github repository.
  13. %
  14. % Once the data is saved in either .set or .mat it can be inputed once
  15. % again into the script to perform additional steps if needed.
  16. %
  17. % The script performs the following steps:
  18. % 1. Prompts the user to select cleaning steps.
  19. % 2. Prompts the user for necessary parameters for the selected steps.
  20. % 3. Selects files for processing.
  21. % 4. Processes each selected file according to the specified steps.
  22. % 5. Saves the processed data in the specified format.
  23. %
  24. % Note: If ICA and/or automatic rejection are selected, a checkpoint save
  25. % will be created in the selected format for each one before rejecting
  26. % components/trials.
  27. %
  28. % Ensure you have EEGLAB installed and added to the MATLAB path.
  29. %
  30. % Author: Dino Soldic
  31. % Email: [email hidden]
  32. % Date: 2026-04-24
  33. %
  34. % See also: eegPlotERP
  35. %% Clean Matlab
  36. clear; clc;
  37. %% Ask user for parameters
  38. cleanoptions = {'Resample', 'Single EEG filter', 'Multi EEG filter', 'ERP epoch data', 'RS epoch data', 'Correct baseline', 'Reject with ICA', ...
  39. 'Interpolate', 'Reject voltage outliers', 'Reject abnormal spectra', 'Re-reference', 'Plot ERPs', 'Transform to Fieldtrip', ...
  40. 'Transform to LORETA (RS)', 'Transform to BV'};
  41. [cleanselection, ~] = listdlg('ListString', cleanoptions, 'PromptString', 'Select cleaning steps:', 'SelectionMode', 'multiple');
  42. if isempty(cleanselection), fprintf('Operation canceled. Shutting down\n'); return, end
  43. if any(cleanselection == 1)
  44. % Enter new fsample
  45. resampleValue = inputdlg('Enter new sampling frequency', 'Sampling Frequency', 1, "250");
  46. resampleValue = str2double(resampleValue);
  47. if isempty(resampleValue) || any(isnan(resampleValue))
  48. fprintf('Enter valid numeric value. Shutting down\n');
  49. return
  50. end
  51. end
  52. if any(cleanselection == 2)
  53. % Prompt filter type
  54. filterTypeOptions = {'Low-pass', 'High-pass', 'Pass band', 'Notch'};
  55. [filterType, ~] = listdlg('ListString', filterTypeOptions, 'PromptString', {'Select the filter that you want to', 'apply to your EEG data:'}, 'SelectionMode', 'single');
  56. if isempty(filterType), fprintf('Operation canceled. Shutting down\n'); return, end
  57. doNotchFilter = false;
  58. while true
  59. % Enter filter freq value
  60. switch filterType
  61. case 1
  62. filterVal = inputdlg('Enter frequency cutoff (Hz)', 'Low-Pass Filter', 1)';
  63. filterVal = str2double(filterVal);
  64. filterValues.low = [];
  65. filterValues.high = filterVal;
  66. case 2
  67. filterVal = inputdlg('Enter frequency cutoff (Hz)', 'High-Pass Filter', 1)';
  68. filterVal = str2double(filterVal);
  69. filterValues.low = filterVal;
  70. filterValues.high = [];
  71. case 3
  72. filterVal = inputdlg({'Enter low frequency cutoff (Hz)', 'Enter high frequency cutoff (Hz)'}, 'Pass Band Filter', 1)';
  73. filterVal = str2double(filterVal);
  74. filterValues.low = filterVal(1);
  75. filterValues.high = filterVal(2);
  76. case 4
  77. filterVal = inputdlg({'Enter low frequency cutoff (Hz)', 'Enter high frequency cutoff (Hz)'}, 'Notch Filter', 1)';
  78. filterVal = str2double(filterVal);
  79. filterValues.low = filterVal(1);
  80. filterValues.high = filterVal(2);
  81. doNotchFilter = true;
  82. end
  83. % Check values
  84. if ~isnumeric(filterVal) || any(isnan(filterVal)) || isempty(filterVal) || any(filterVal < 0)
  85. fprintf('Enter valid values for filtering\n');
  86. else
  87. break
  88. end
  89. end
  90. end
  91. if any(cleanselection == 6)
  92. baselineThreshold = inputdlg({'Enter baseline correction start point in milliseconds (ms)', 'Enter baseline correction end point in milliseconds (ms)'}, 'Baseline Correction', 1, {'-200', '0'});
  93. baselineThreshold = str2double(baselineThreshold);
  94. if isempty(baselineThreshold) || any(isnan(baselineThreshold))
  95. fprintf('Enter valid numeric value. Shutting down\n');
  96. return
  97. end
  98. end
  99. if any(cleanselection == 7)
  100. icaTypeOptions = {'runica', 'SOBI'};
  101. [icaType, ~] = listdlg('ListString', icaTypeOptions, 'PromptString', {'Select the ICA algorithm that you', 'want to apply to your EEG data:'}, 'SelectionMode', 'single');
  102. if isempty(icaType), fprintf('Operation canceled. Shutting down\n'); return, end
  103. end
  104. if any(cleanselection == 9)
  105. amplitudeThreshold = inputdlg('Enter maximum voltage threshold for automatic voltage epoch rejection', 'Voltage Threshold', 1, "75");
  106. amplitudeThreshold = str2double(amplitudeThreshold);
  107. if isempty(amplitudeThreshold) || isnan(amplitudeThreshold)
  108. fprintf('Enter valid numeric value. Shutting down\n');
  109. return
  110. end
  111. end
  112. if any(cleanselection == 10)
  113. rejSpecSettings = cell(1);
  114. spectraIdx = 1;
  115. while true
  116. while true
  117. % Set spectrum settings
  118. spectraOptions = {'Enter power rejection threshold (dB)', ...
  119. 'Enter low frequency limit (Hz)', 'Enter high frequency limit (Hz)'};
  120. rejSpecValues = inputdlg(spectraOptions, 'Spectra Thresholds', 1, {'50', '0', '2'});
  121. rejSpecValues = str2double(rejSpecValues);
  122. % Check values
  123. if isempty(rejSpecValues) || any(isnan(rejSpecValues))
  124. fprintf('Enter valid values for epoching\n');
  125. else
  126. break
  127. end
  128. end
  129. % Save values to cell
  130. rejSpecSettings{spectraIdx} = rejSpecValues;
  131. spectraIdx = spectraIdx + 1;
  132. % Prompt to redo spectra with other options
  133. addSpectra = questdlg('Do you wish to add more spectra reject options?', 'Reject spectra', 'Yes', 'No', 'No');
  134. if strcmpi(addSpectra, 'no'), break, end
  135. end
  136. end
  137. % Select files to load
  138. [loadfiles, loadpath] = uigetfile({'*.vhdr;*.ahdr', 'Brain Vision files (*.vhdr, *.ahdr)'; '*.mat;*.set', 'MATLAB-EEGLAB files (*.mat, *.set)'}, 'Select files with raw EEG data to load', 'MultiSelect', 'on');
  139. if loadpath == 0, fprintf('Operation canceled. Shutting down\n'); return, end
  140. filelist = fullfile(loadpath, loadfiles);
  141. if ~iscell(filelist), filelist = {filelist}; end
  142. % Define savepath
  143. rawSavepath = uigetdir(pwd, 'Select path to save the data');
  144. if rawSavepath == 0, fprintf('Operation canceled. Shutting down\n'); return, end
  145. % make mat ft folder if selected
  146. if any(cleanselection == 13)
  147. % Set save path
  148. savepath_ft = fullfile(rawSavepath, 'ft_mat_files');
  149. % Check folder
  150. if ~exist(savepath_ft, 'dir'), mkdir(savepath_ft); end
  151. end
  152. % Prompt save format
  153. saveformat = questdlg('Do you want to save as .set (EEGLAB dataset), .mat (MATLAB data) file or both?', 'Choose format', 'set', 'mat', 'both', 'mat');
  154. % Check the user's response
  155. if strcmpi(saveformat, 'set')
  156. fprintf('Data will be saved as .set file.\n');
  157. % Set save path
  158. savepath_set = fullfile(rawSavepath, 'set_files');
  159. icaSaveFolderPath = fullfile(savepath_set, 'preIca');
  160. rejSaveFolderPath = fullfile(savepath_set, 'preRej');
  161. % Check folder
  162. if ~exist(savepath_set, 'dir'), mkdir(savepath_set); end
  163. if ~exist(icaSaveFolderPath, 'dir'), mkdir(icaSaveFolderPath); end
  164. if ~exist(rejSaveFolderPath, 'dir'), mkdir(rejSaveFolderPath); end
  165. % Update the savepath
  166. savepath = savepath_set;
  167. elseif strcmpi(saveformat, 'mat')
  168. fprintf('Data will be saved as .mat file.\n');
  169. % Set save path
  170. savepath_mat = fullfile(rawSavepath, 'mat_files');
  171. icaSaveFolderPath = fullfile(savepath_mat, 'preIca');
  172. rejSaveFolderPath = fullfile(savepath_mat, 'preRej');
  173. % Check folder
  174. if ~exist(savepath_mat, 'dir'), mkdir(savepath_mat); end
  175. if ~exist(icaSaveFolderPath, 'dir'), mkdir(icaSaveFolderPath); end
  176. if ~exist(rejSaveFolderPath, 'dir'), mkdir(rejSaveFolderPath); end
  177. % Update savepath
  178. savepath = savepath_mat;
  179. elseif strcmpi(saveformat, 'both')
  180. fprintf('Data will be saved as both .set and .mat file.\n');
  181. % Set save path
  182. savepath_mat = fullfile(rawSavepath, 'mat_files');
  183. savepath_set = fullfile(rawSavepath, 'set_files');
  184. % Update savepath
  185. savepath = struct();
  186. icaSaveFolderPath = struct();
  187. rejSaveFolderPath = struct();
  188. savepath.mat = savepath_mat;
  189. savepath.set = savepath_set;
  190. icaSaveFolderPath.mat = fullfile(savepath.mat, 'preIca');
  191. icaSaveFolderPath.set = fullfile(savepath.set, 'preIca');
  192. rejSaveFolderPath.mat = fullfile(savepath.mat, 'preRej');
  193. rejSaveFolderPath.set = fullfile(savepath.set, 'preRej');
  194. % Check folder
  195. if ~exist(savepath.mat, 'dir'), mkdir(savepath.mat); end
  196. if ~exist(icaSaveFolderPath.mat, 'dir'), mkdir(icaSaveFolderPath.mat); end
  197. if ~exist(rejSaveFolderPath.mat, 'dir'), mkdir(rejSaveFolderPath.mat); end
  198. if ~exist(savepath.set, 'dir'), mkdir(savepath.set); end
  199. if ~exist(icaSaveFolderPath.set, 'dir'), mkdir(icaSaveFolderPath.set); end
  200. if ~exist(rejSaveFolderPath.set, 'dir'), mkdir(rejSaveFolderPath.set); end
  201. end
  202. % set warning for missing chanlocs
  203. warnMissChan = true;
  204. % disable new eeglab version check to run faster
  205. eeglab('nogui');
  206. pop_editoptions('option_checkversion', false);
  207. %% Process data
  208. while true
  209. for i = 1:numel(filelist)
  210. try
  211. %% Load data
  212. % Get the file
  213. file = filelist{i};
  214. % Get filename to save it later
  215. [ogFolderpath, ogfilename, ogExtension] = fileparts(file);
  216. fileNameSave = ogfilename;
  217. % Run EEGlab in the background and call it again for each iteration
  218. % so it clears previous unnecesary data.
  219. eeglab;
  220. close all
  221. % Load EEG data from .vhdr or .ahdr file or other
  222. if strcmp(ogExtension, '.vhdr') || strcmp(ogExtension, '.ahdr')
  223. EEG = pop_loadbv(ogFolderpath, [ogfilename, ogExtension], [], []);
  224. else
  225. EEG = pop_loadset(file);
  226. end
  227. % Check chanlocs
  228. if warnMissChan
  229. isChanLocsEmpty = isempty([EEG.chanlocs.X]) || isempty([EEG.chanlocs.Y]) || isempty([EEG.chanlocs.Z]) || isempty([EEG.chanlocs.theta]);
  230. if isChanLocsEmpty
  231. doLoadCoords = questdlg('The coordinates for your channels/electrodes are missing. Do you wish to load a file with their coordinates?', 'Missing Coordinates', 'Yes', 'No', 'Yes');
  232. % get file and extension
  233. if strcmp(doLoadCoords, 'Yes')
  234. [chanlocsFile, chanlocsDir] = uigetfile('*.*', 'Select file containing EEG layout', 'MultiSelect', 'off');
  235. chanlocsPath = fullfile(chanlocsDir, chanlocsFile);
  236. [~, ~, chanlocsExt] = fileparts(chanlocsPath);
  237. end
  238. end
  239. warnMissChan = false;
  240. end
  241. % import chanlocs
  242. if exist('doLoadCoords', 'var')
  243. if strcmp(doLoadCoords, 'Yes')
  244. while true
  245. try
  246. fprintf('Loading channel coordinates...\n');
  247. EEG = eegImportChanlocs(EEG, chanlocsPath, chanlocsExt);
  248. fprintf('Channel coordinates loaded successfully.\n');
  249. break
  250. catch
  251. reChanlocsLoad = questdlg('Channels could not be loaded. Try again?', 'Channel Error', 'Yes', 'No', 'Yes');
  252. if ~strcmp(reChanlocsLoad, 'Yes'), fprintf('Proceeding without loading channel coordinates...\n'); break, end
  253. end
  254. end
  255. else
  256. dialToWait = warndlg('The data will be processed without channel locations. Please note that you will not be able to use functions that require channel coordinates, such as "Topoplot".', 'Channel Omission');
  257. uiwait(dialToWait);
  258. end
  259. end
  260. %% Clean EEG data using EEGLAB functions
  261. while true
  262. % Step 1 visualize raw data
  263. pop_eegplot(EEG, 1, 0, 0); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  264. uiwait(gcf);
  265. close all
  266. % Step 2 Remove channels before cleaning data
  267. if ~exist('doRemoveChans', 'var')
  268. doRemoveChans = questdlg('Do you wish to remove channels from your data?', 'Remove Channels', 'Yes', 'No', 'Yes');
  269. if strcmpi(doRemoveChans, 'yes'), doRemoveChans = true; else, doRemoveChans = false; end
  270. end
  271. if doRemoveChans
  272. if ~exist('selectChansToRemove', 'var')
  273. [selectChansToRemove, ~] = listdlg('ListString', {EEG.chanlocs.labels}, 'PromptString', 'Select channels to remove:', 'SelectionMode', 'multiple');
  274. % Find chanlabels from indices
  275. chansToRemove = {EEG.chanlocs(selectChansToRemove).labels};
  276. end
  277. % Use EEGLAB function to remove them
  278. EEG = pop_select(EEG, 'nochannel', selectChansToRemove);
  279. % Update EEG
  280. EEG = eeg_checkset(EEG);
  281. % Completion msg
  282. fprintf('Removed channel(s) {%s} from EEG data.\n', strjoin(chansToRemove, ', '));
  283. else
  284. fprintf('No channels removed from EEG data.\n');
  285. end
  286. % Step 3 Resample
  287. if any(cleanselection == 1)
  288. % Resample
  289. EEG = pop_resample(EEG, resampleValue);
  290. % Plot
  291. pop_eegplot(EEG, 1, 0, 0); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  292. uiwait(gcf);
  293. close all
  294. end
  295. % Step 4 filter data and visualize
  296. % Single
  297. if any(cleanselection == 2)
  298. EEG = pop_eegfiltnew(EEG, 'locutoff', filterValues.low, 'hicutoff', filterValues.high, 'revfilt', doNotchFilter);
  299. end
  300. % Multi
  301. if any(cleanselection == 3)
  302. while true
  303. try
  304. EEG = pop_eegfiltnew(EEG);
  305. pop_eegplot(EEG, 1, 0, 0); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  306. uiwait(gcf);
  307. close all
  308. catch
  309. warning('Input at least one value valid numeric value to filter the data.')
  310. end
  311. % Ask to filter again
  312. refilter = questdlg('Do you wish to filter again your data?', 'Filter data', 'Yes', 'No', 'No');
  313. if strcmpi(refilter, 'No'), break, end
  314. end
  315. end
  316. % Step 5.1 Split data in epochs for ERPs
  317. if any(cleanselection == 4)
  318. if ~exist('epochSettings', 'var')
  319. while true
  320. % Select stimulus
  321. selectStimuli = unique({EEG.event.type});
  322. [epochSettings.stimuli, ~] = listdlg('ListString', selectStimuli, 'PromptString', 'Select Stimuli for Epoch:', 'SelectionMode', 'multiple');
  323. % Select time window
  324. epochSettings.time = inputdlg({'Enter epoch start point in seconds (s)', 'Enter epoch end point in seconds (s)'}, 'Split in Epochs', 1)';
  325. epochSettings.time = str2double(epochSettings.time);
  326. % init suffix
  327. % Check values
  328. if ~isnumeric(epochSettings.time) || any(isnan(epochSettings.time)) || isempty(epochSettings.stimuli) || isempty(epochSettings.time)
  329. fprintf('Enter valid values for epoching\n');
  330. else
  331. break
  332. end
  333. end
  334. end
  335. % Epoch with eeglab
  336. EEG = pop_epoch(EEG, selectStimuli(epochSettings.stimuli), epochSettings.time);
  337. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  338. uiwait(gcf);
  339. close all
  340. end
  341. % Step 5.2 Split data in epochs for RS
  342. if any(cleanselection == 5)
  343. if ~exist('epochSettings', 'var')
  344. while true
  345. % Select stimulus
  346. selectStimuli = unique({EEG.event.type});
  347. [epochSettings.stimuli.start, ~] = listdlg('ListString', selectStimuli, 'PromptString', {'Select start mark for epoching:', ''}, 'SelectionMode', 'single');
  348. [epochSettings.stimuli.end, ~] = listdlg('ListString', selectStimuli, 'PromptString', {'Select end mark for epoching:', ''}, 'SelectionMode', 'single');
  349. % Select time window
  350. epochSettings.time = inputdlg('Enter epoch length in seconds (s)', 'RS Epoch length', 1)';
  351. epochSettings.time = str2double(epochSettings.time);
  352. % Check values
  353. if ~isnumeric(epochSettings.time) || isnan(epochSettings.time) || isempty(epochSettings.stimuli.start) || isempty(epochSettings.stimuli.end) || isempty(epochSettings.time)
  354. fprintf('Enter valid values for epoching\n');
  355. else
  356. break
  357. end
  358. end
  359. end
  360. % Find start and end for epochs in timepoints
  361. startEpochTmpt = EEG.event(find(strcmp({EEG.event.type}, selectStimuli(epochSettings.stimuli.start)))).latency;
  362. endEpochTmpt = EEG.event(find(strcmp({EEG.event.type}, selectStimuli(epochSettings.stimuli.end)))).latency;
  363. % First raw epoch
  364. EEG.data = EEG.data(:, startEpochTmpt:endEpochTmpt);
  365. % Get tmpts/trial
  366. epochTmpts = EEG.srate * epochSettings.time;
  367. nEpochs = floor(size(EEG.data, 2) / epochTmpts);
  368. % Second epoching
  369. EEG.data = reshape(EEG.data(:, 1:epochTmpts * nEpochs), size(EEG.data, 1), epochTmpts, nEpochs);
  370. % Fix EEG struct
  371. EEG.trials = size(EEG.data, 3);
  372. EEG.pnts = size(EEG.data, 2);
  373. EEG.xmax = epochSettings.time;
  374. EEG.times = EEG.times(1:epochTmpts);
  375. EEG.event = [];
  376. EEG.urevent = [];
  377. EEG.eventdescription = {};
  378. EEG = eeg_checkset(EEG);
  379. % Plot
  380. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  381. uiwait(gcf);
  382. close all
  383. end
  384. if ~exist('stimuliLabel', 'var')
  385. % Enter labels for epoching
  386. stimuliLabel = inputdlg('Enter label for file''s name', 'Epoch Labels');
  387. if isempty(stimuliLabel), stimuliLabel = ''; end
  388. end
  389. % Change filename for saving
  390. if isempty(stimuliLabel)
  391. fileNameSave = ogfilename;
  392. else
  393. fileNameSave = [ogfilename, '_', stimuliLabel{:}];
  394. end
  395. % Step 6 Correct baseline
  396. if any(cleanselection == 6)
  397. EEG = pop_rmbase(EEG, baselineThreshold');
  398. end
  399. % step 7(8) Remove bad channel
  400. if any(cleanselection == 8)
  401. chansToInterpolate = [];
  402. while true
  403. if ~exist('doRemoveBadChans', 'var')
  404. doRemoveBadChans = questdlg('Do you wish to interpolate any channels?', 'Interpolate Channels', 'Yes', 'No', 'Yes');
  405. if strcmpi(doRemoveBadChans, 'yes'), doRemoveBadChans = true; else, doRemoveBadChans = false; end
  406. end
  407. if ~doRemoveBadChans
  408. fprintf('No channels to interpolate.\n');
  409. break;
  410. end
  411. [selectBadChansToRemove, ~] = listdlg('ListString', {EEG.chanlocs.labels}, 'PromptString', 'Select channels to remove:', 'SelectionMode', 'multiple');
  412. % update chanm to interpo idx on each iteration
  413. chansToInterpolate = [chansToInterpolate, selectBadChansToRemove]; %#ok<AGROW>
  414. % Find chanlabels from indices
  415. chansToRemoveLabel = {EEG.chanlocs(selectBadChansToRemove).labels};
  416. % Update EEG
  417. EEG = eeg_checkset(EEG);
  418. % Completion msg
  419. fprintf('Channel(s) {%s} will be interpolated.\n', strjoin(chansToRemoveLabel, ', '));
  420. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  421. uiwait(gcf);
  422. close all
  423. % Ask to interpolate again
  424. interpochan = questdlg('Do you wish to interpolate more channels?', 'Interpolation', 'Yes', 'No', 'No');
  425. if strcmpi(interpochan, 'No'), break, end
  426. end
  427. end
  428. % Step 7(11) Re-reference before ICA following eeglab suggestion
  429. if any(cleanselection == 11)
  430. if ~exist('trialRef', 'var')
  431. while true
  432. trialRef = questdlg('How do you wish to re-reference the data?', 'Re-reference', 'Average', 'Channel', 'Average');
  433. if strcmpi(trialRef, 'channel')
  434. % Select channel for ref
  435. chanlabels = {EEG.chanlocs.labels};
  436. [rerefChan, ~] = listdlg('ListString', chanlabels, 'PromptString', 'Select channel for Re-reference:', 'SelectionMode', 'single');
  437. % Check input
  438. if isempty(rerefChan), fprintf('Select a valid channel.\n'), else, break, end
  439. end
  440. % Check input
  441. if isempty(trialRef), fprintf('Select an option.\n'), else, break, end
  442. end
  443. end
  444. % Re-ref func
  445. if strcmpi(trialRef, 'average')
  446. EEG = pop_reref(EEG, [], 'exclude', chansToInterpolate);
  447. fprintf('Computing average reference of the data.\n');
  448. elseif strcmpi(trialRef, 'channel')
  449. EEG = pop_reref(EEG, rerefChan, 'exclude', chansToInterpolate);
  450. fprintf('Referencing data to channel "%s".\n', EEG.chanlocs(rerefChan).labels);
  451. end
  452. end
  453. % Step 7 run ICA
  454. if any(cleanselection == 7)
  455. while true
  456. try
  457. switch icaType
  458. case 1
  459. EEG = pop_runica(EEG, 'icatype', 'runica', 'extended', 1, 'interrupt', 'off', 'chanind', setdiff(1:EEG.nbchan, chansToInterpolate));
  460. case 2
  461. EEG = pop_runica(EEG, 'icatype', 'sobi', 'chanind', setdiff(1:EEG.nbchan, chansToInterpolate));
  462. end
  463. break
  464. catch
  465. opts = struct('WindowStyle', 'non-modal', 'Interpreter', 'tex');
  466. errordlg('\color{red} \fontsize{13} ICA was interrupted. Running again', 'ICA Error', opts);
  467. end
  468. end
  469. % Review and label ICA components
  470. EEG = iclabel(EEG, 'default');
  471. pop_viewprops(EEG, 0);
  472. if ~isempty(findall(0, 'Type', 'figure'))
  473. uiwait(gcf);
  474. close all
  475. end
  476. % Save checkpoint
  477. EEG.comments = [];
  478. if strcmpi(saveformat, 'mat')
  479. save(fullfile(icaSaveFolderPath, fileNameSave), 'EEG');
  480. elseif strcmpi(saveformat, 'set')
  481. EEG = pop_saveset(EEG, char(fileNameSave), char(icaSaveFolderPath), 'savemode', 'onefile');
  482. elseif strcmpi(saveformat, 'both')
  483. save(fullfile(icaSaveFolderPath.mat, fileNameSave), 'EEG');
  484. EEG = pop_saveset(EEG, char(fileNameSave), char(icaSaveFolderPath.set), 'savemode', 'onefile');
  485. end
  486. % IC Artifact Rejection
  487. while true
  488. EEG = pop_selectcomps(EEG); % Manually inspect and select
  489. if ~isempty(findall(0, 'Type', 'figure'))
  490. uiwait(gcf);
  491. close all
  492. end
  493. EEG = pop_subcomp(EEG, [], 1, 0); % Remove components from data
  494. EEG = eeg_checkset(EEG);
  495. % Plot channel data
  496. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  497. uiwait(gcf);
  498. close all
  499. % Ask to reject componentes again
  500. reICA = questdlg('Do you wish to reject ICA components once more?', 'Reject ICA', 'Yes', 'No', 'No');
  501. if strcmpi(reICA, 'No'), break, end
  502. end
  503. end
  504. % Step 8 Interpolate bad channels if necessary
  505. if any(cleanselection == 8)
  506. EEG = pop_interp(EEG, chansToInterpolate);
  507. end
  508. % Step 9 Auto Reject abnormal voltage epochs
  509. if any(cleanselection == 9)
  510. % Save checkpoint
  511. EEG.comments = [];
  512. if strcmpi(saveformat, 'mat')
  513. save(fullfile(rejSaveFolderPath, fileNameSave), 'EEG');
  514. elseif strcmpi(saveformat, 'set')
  515. EEG = pop_saveset(EEG, char(fileNameSave), char(rejSaveFolderPath), 'savemode', 'onefile');
  516. elseif strcmpi(saveformat, 'both')
  517. save(fullfile(rejSaveFolderPath.mat, fileNameSave), 'EEG');
  518. EEG = pop_saveset(EEG, char(fileNameSave), char(rejSaveFolderPath.set), 'savemode', 'onefile');
  519. end
  520. % Mark trials to reject
  521. EEG = pop_eegthresh(EEG, 1, 1:length(EEG.chanlocs), -abs(amplitudeThreshold), abs(amplitudeThreshold), EEG.times(1) / 1000, EEG.times(end) / 1000, 1, 0);
  522. % Update thresholds
  523. if ~isempty(EEG.reject.rejmanual)
  524. EEG.reject.rejmanual = EEG.reject.rejmanual | EEG.reject.rejthresh;
  525. EEG.reject.rejmanualE = EEG.reject.rejmanualE | EEG.reject.rejthreshE;
  526. else
  527. EEG.reject.rejmanual = EEG.reject.rejthresh;
  528. EEG.reject.rejmanualE = EEG.reject.rejthreshE;
  529. end
  530. % Decide epoch rej
  531. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  532. uiwait(gcf);
  533. close all
  534. end
  535. % Step 10 Auto reject abnormal spectra
  536. if any(cleanselection == 10)
  537. % Save checkpoint
  538. if ~any(cleanselection == 8)
  539. EEG.comments = [];
  540. if strcmpi(saveformat, 'mat')
  541. save(fullfile(rejSaveFolderPath, fileNameSave), 'EEG');
  542. elseif strcmpi(saveformat, 'set')
  543. EEG = pop_saveset(EEG, char(fileNameSave), char(rejSaveFolderPath), 'savemode', 'onefile');
  544. elseif strcmpi(saveformat, 'both')
  545. save(fullfile(rejSaveFolderPath.mat, fileNameSave), 'EEG');
  546. EEG = pop_saveset(EEG, char(fileNameSave), char(rejSaveFolderPath.set), 'savemode', 'onefile');
  547. end
  548. end
  549. % Mark trials to reject
  550. for spectraIdx = 1:numel(rejSpecSettings)
  551. rejSpecSettingsFunc = rejSpecSettings{spectraIdx};
  552. EEG = pop_rejspec(EEG, 1, 'elecrange', 1:length(EEG.chanlocs), 'method', 'fft', ...
  553. 'threshold', [-abs(rejSpecSettingsFunc(1)) abs(rejSpecSettingsFunc(1))], ...
  554. 'freqlimits', [rejSpecSettingsFunc(2), rejSpecSettingsFunc(3)], ...
  555. 'eegplotreject', 0, 'eegplotplotallrej', 1);
  556. % Update thresholds
  557. if ~isempty(EEG.reject.rejmanual)
  558. EEG.reject.rejmanual = EEG.reject.rejmanual | EEG.reject.rejfreq;
  559. EEG.reject.rejmanualE = EEG.reject.rejmanualE | EEG.reject.rejfreqE;
  560. else
  561. EEG.reject.rejmanual = EEG.reject.rejfreq;
  562. EEG.reject.rejmanualE = EEG.reject.rejfreqE;
  563. end
  564. % Decide epoch rej
  565. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  566. uiwait(gcf);
  567. close all
  568. end
  569. end
  570. % Step 11 Re-reference again after ICA
  571. if any(cleanselection == 11)
  572. % Re-ref func
  573. if strcmpi(trialRef, 'average')
  574. EEG = pop_reref(EEG, []);
  575. fprintf('Computing average reference of the data.\n');
  576. elseif strcmpi(trialRef, 'channel')
  577. EEG = pop_reref(EEG, rerefChan);
  578. fprintf('Referencing data to channel "%s".\n', EEG.chanlocs(rerefChan).labels);
  579. end
  580. end
  581. % Step 12 final data inspection
  582. while true
  583. pop_eegplot(EEG, 1, 1, 1); % [1 channel data or 0 independent components], [1 for channel interpolation, 0 to skip interpolation], [1 to allow manual rejection]
  584. uiwait(gcf);
  585. close all
  586. % Ask to inspect again
  587. re_rej = questdlg('Do you wish to inspect the data once again?', 'Data Inspection', 'Yes', 'No', 'No');
  588. if strcmpi(re_rej, 'No'), break, end
  589. end
  590. % Step 13 Plot ERPs
  591. if any(cleanselection == 12)
  592. topoTitle = sprintf('ERPs for %s', fileNameSave);
  593. pop_plottopo(EEG, 1:length(EEG.chanlocs), char(topoTitle), 0);
  594. uiwait(gcf);
  595. close all
  596. end
  597. % Ask to redo all preproc
  598. redoclean = questdlg('Do you wish to redo data processing or continue?', 'Finish cleaning', 'Redo', 'Finish', 'Finish');
  599. if ~strcmpi(redoclean, 'redo')
  600. fprintf('Proceeding to save data ... \n');
  601. break
  602. else
  603. fprintf ('Deleting current dataset and importing raw data\n');
  604. % Run eeglab and reset vars
  605. EEG = [];
  606. ALLEEG = [];
  607. ALLCOM = {};
  608. eeglab;
  609. close all
  610. % Load EEG data from .vhdr or .ahdr file or other
  611. if strcmp(ogExtension, '.vhdr') || strcmp(ogExtension, '.ahdr')
  612. EEG = pop_loadbv(ogFolderpath, [ogfilename, ogExtension], [], []);
  613. else
  614. EEG = pop_loadset(file);
  615. end
  616. end
  617. end
  618. % Step 14 Save data and remove comments
  619. EEG.comments = [];
  620. if strcmpi(saveformat, 'mat')
  621. % Save "EEG" var
  622. save(fullfile(savepath, fileNameSave), 'EEG');
  623. elseif strcmpi(saveformat, 'set')
  624. % Save dataset
  625. EEG = pop_saveset(EEG, char(fileNameSave), char(savepath), 'savemode', 'onefile');
  626. elseif strcmpi(saveformat, 'both')
  627. % Save "EEG" var
  628. save(fullfile(savepath.mat, fileNameSave), 'EEG');
  629. % Save dataset
  630. EEG = pop_saveset(EEG, char(fileNameSave), char(savepath.set), 'savemode', 'onefile');
  631. end
  632. % transform and save to FT
  633. if any(cleanselection == 13)
  634. fprintf('Exporting to FieldTrip...\n');
  635. data = eeglab2fieldtrip(EEG, 'raw', 'none');
  636. save(fullfile(savepath_ft, fileNameSave), 'data');
  637. end
  638. % transform and save to LORETA
  639. if any(cleanselection == 14)
  640. fprintf('Exporting to LORETA...\n');
  641. loretaDir = fullfile(rawSavepath, fileNameSave);
  642. if ~isfolder(loretaDir), mkdir(loretaDir); end
  643. for epIdx = 1:size(EEG.data, 3)
  644. writematrix(EEG.data(:, :, epIdx)', sprintf("%s\\%s_%d.asc", loretaDir, fileNameSave, epIdx), "FileType", "text", "Delimiter", "\t"); % loreta needs text tab delimited
  645. end
  646. end
  647. if any(cleanselection == 15)
  648. fprintf('Exporting to BrainVision...\n');
  649. bvDir = fullfile(rawSavepath, 'BrainVision');
  650. if ~isfolder(bvDir), mkdir(bvDir); end
  651. EEG = pop_writebva(EEG, fullfile(bvDir, fileNameSave), 'DataOrientation', 'MULTIPLEXED');
  652. end
  653. % Display completion
  654. fprintf('\n-----Subject %s finished-----\n\n', fileNameSave);
  655. clear doRemoveBadChans
  656. catch subject_loop_error
  657. % Display error message
  658. warning('Error found in %s.\n%s (line %d): \n %s\n\nSkipping to next subject...', ogfilename, subject_loop_error.stack(end).name, subject_loop_error.stack(end).line, subject_loop_error.message);
  659. % Skip to next subject
  660. continue
  661. end
  662. end
  663. % Display completion
  664. fprintf('\n-------Successfully completed %d files-------\n', numel(filelist));
  665. %% Ask to run script on a different condition
  666. askConditionRerun = questdlg('Do you wish to clean a different condition?', 'Clean new condition', 'Yes', 'No', 'No');
  667. if strcmpi(askConditionRerun, 'yes')
  668. fprintf ('Preparing to run on new condition...\n');
  669. clear epochSettings stimuliLabel
  670. else
  671. break
  672. end
  673. end
  674. % re-enable new eeglab version check
  675. pop_editoptions('option_checkversion', true);
  676. % Display completion
  677. fprintf('\n\t\t /\\_/\\ \t /\\_/\\ \n\t\t ( o.o )\t ( ^.^ )\n\t\t > ^ <\t\t > ^ <\n');

eegPreproc.m at commit 9697559, under MIT · at the source

Overview

Authors: Dino Soldic1,2, María Carmen Martín‐Buro1,2, David López‐García3, Ana Belén del Pino1,2, Roberto Fernandes‐Magalhaes1,2, David Ferrera1,2, Irene Peláez1,2, Luis Carretié4, Francisco Mercado1,2
  1. Department of Psychology, Faculty of Health Sciences, Rey Juan Carlos University, Madrid, Spain
  2. Research group in Cognitive Neuroscience, Pain and Rehabilitation (NECODOR), Rey Juan Carlos University, Madrid, Spain
  3. Mind, Brain and Behavior Research Center, University of Granada, Granada, Andalucía, Spain
  4. Faculty of Psychology, Autonomous University of Madrid, Madrid, Spain
Journal: The European journal of neuroscience, volume 63, issue 9, article e70521
Dates: received 22 January 2026; accepted 16 April 2026; published online 27 April 2026; in print May 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1111/ejn.70521 · PMID 42045133 · PMCID PMC13121099 · OpenAlex W7156076361
Open access: hybrid, a free copy (OpenAlex)
Status: code verified
Categories: EEG (modality), human (organism), other condition (population), pain (population), clinical / translational (subfield)
Methods: Spectral & time-frequency, Statistics, Smoothing, state filtering, decompositions, Machine learning, Preprocessing, Evoked potentials, Physiology & signal measures
Keywords: chronic pain, decoding, discriminant analysis, multivariate analysis, neural markers, support vector machine
MeSH: Brain*, Electroencephalography*, Fibromyalgia*, Adult, Aged, Anxiety, Biomarkers, Female, Humans, Middle Aged, Multivariate Analysis, Rest (* major topic)
Topic: Fibromyalgia and Chronic Fatigue Syndrome Research (Psychiatry and Mental health, Medicine), according to OpenAlex
Funding: Ministerio de Ciencia e Innovación of Spain (PID2020-115463RB-I00)
Citations: cited by 2 papers (Europe PMC); 78 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 2 matches between paragraphs and lines of code.

dinosoldic/eeg-preproc-erp

License: MIT
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 9697559bb6e9537941528cb45e3a96d183d0aded, 28 May 2026
Languages: MATLAB (7)
Size: 10 files, 7 scripts
Software Heritage: not archived
Found in: the text, “EEG Data Acquisition and Preprocessing”
Holds: README, license file, documentation
Not found: CITATION.cff, environment file, tests, continuous integration
Tools: EEGLAB (4 files), ICLabel (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
9 files

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 7 scripts, each with its path and the digest of its content;
  • 2 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1111/ejn.70521.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 2, 28 September 2026

  • Publisher: n/a → Wiley

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 9 authors, 6 keywords, 12 MeSH terms, 1 funder, 76 references.

Cite

This paper

Soldic, D., Martín‐Buro, M. C., López‐García, D., del Pino, A. B., Fernandes‐Magalhaes, R., Ferrera, D., Peláez, I., Carretié, L., & Mercado, F. (2026). Multivariate Pattern Analysis Identifies Potential Intertrial Resting-State EEG Biomarkers in Fibromyalgia. The European journal of neuroscience, 63(9), e70521. https://doi.org/10.1111/ejn.70521

BibTeX

@article{soldic2026multivariate,
author = {Soldic, Dino and Martín‐Buro, María Carmen and López‐García, David and del Pino, Ana Belén and Fernandes‐Magalhaes, Roberto and Ferrera, David and Peláez, Irene and Carretié, Luis and Mercado, Francisco},
title = {{Multivariate Pattern Analysis Identifies Potential Intertrial Resting-State EEG Biomarkers in Fibromyalgia}},
journal = {The European journal of neuroscience},
year = {2026},
month = may,
volume = {63},
number = {9},
pages = {e70521},
publisher = {Wiley},
issn = {0953-816X},
doi = {10.1111/ejn.70521},
url = {https://doi.org/10.1111/ejn.70521},
pmid = {42045133},
pmcid = {PMC13121099}
}

RIS

TY - JOUR
AU - Soldic, Dino
AU - Martín‐Buro, María Carmen
AU - López‐García, David
AU - del Pino, Ana Belén
AU - Fernandes‐Magalhaes, Roberto
AU - Ferrera, David
AU - Peláez, Irene
AU - Carretié, Luis
AU - Mercado, Francisco
TI - Multivariate Pattern Analysis Identifies Potential Intertrial Resting-State EEG Biomarkers in Fibromyalgia
T2 - The European journal of neuroscience
J2 - Eur J Neurosci
PY - 2026
DA - 2026/05/01
VL - 63
IS - 9
SP - e70521
SN - 0953-816X
PB - Wiley
DO - 10.1111/ejn.70521
UR - https://doi.org/10.1111/ejn.70521
LA - en
ER -

CSL-JSON

{
"id": "10.1111/ejn.70521",
"type": "article-journal",
"title": "Multivariate Pattern Analysis Identifies Potential Intertrial Resting-State EEG Biomarkers in Fibromyalgia",
"container-title": "The European journal of neuroscience",
"author": [
{
"family": "Soldic",
"given": "Dino"
},
{
"family": "Martín‐Buro",
"given": "María Carmen"
},
{
"family": "López‐García",
"given": "David"
},
{
"family": "del Pino",
"given": "Ana Belén"
},
{
"family": "Fernandes‐Magalhaes",
"given": "Roberto"
},
{
"family": "Ferrera",
"given": "David"
},
{
"family": "Peláez",
"given": "Irene"
},
{
"family": "Carretié",
"given": "Luis"
},
{
"family": "Mercado",
"given": "Francisco"
}
],
"container-title-short": "Eur J Neurosci",
"volume": "63",
"issue": "9",
"page": "e70521",
"DOI": "10.1111/ejn.70521",
"PMID": "42045133",
"PMCID": "PMC13121099",
"ISSN": "0953-816X",
"publisher": "Wiley",
"URL": "https://doi.org/10.1111/ejn.70521",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
1
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1002/ejp.70331
Structural and Functional Neuroimaging Findings in Fibromyalgia: A Systematic Review.
Journal: European journal of pain (London, England)
In common: pain, 4 references
[2] doi:10.1111/psyp.70370 [code]
Song Familiarity Relies on Evidence Accumulation.
Journal: Psychophysiology
In common: ICLabel, EEGLAB, EEG, 3 references
[3] doi:10.7554/elife.107088 [code]
Development of auditory and spontaneous movement responses to music over the first postnatal year.
Journal: eLife
In common: ICLabel, EEGLAB, EEG, 3 references
[4] doi:10.1038/s41598-026-47785-z [code]
Modulations of the P3b effect as a function of bilingual language experience.
Journal: Scientific reports
In common: ICLabel, EEGLAB, EEG, 3 references
[5] doi:10.1162/imag.a.1224 [code]
Test-retest reliability analysis of resting-state EEG measures and their association with long-term memory in children and adults.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: ICLabel, EEGLAB, EEG, 1 reference
[6] doi:10.1186/s12984-026-02041-3 [code]
Mental tasks induce common modulations of oscillations in cortex and spinal cord.
Journal: Journal of neuroengineering and rehabilitation
In common: EEG, 5 references
[7] doi:10.3389/fneur.2026.1791834 [code]
Minimum data requirements and automated preprocessing for reliable EEG biomarkers in Rett syndrome.
Journal: Frontiers in neurology
In common: ICLabel, EEGLAB, EEG, clinical / translational, other condition, 1 reference
[8] doi:10.1038/s41467-026-73878-4 [code]
Neural Response to Familiar Names Predicts Outcome of Comatose ICU Patients: A Prospective Observational Cohort Study.
Journal: Nature communications
In common: ICLabel, EEGLAB, EEG, clinical / translational, other condition, 1 reference
[9] doi:10.1093/braincomms/fcag351 [code]
Time-resolved aperiodic dynamics in event segmentation in attention-deficit/hyperactivity disorder.
Journal: Brain communications
In common: ICLabel, EEGLAB, EEG, 2 references
[10] doi:10.1038/s41598-026-46182-w [code]
How the influence of cingulate-lingual interactions on event segmentation changes from early to late adolescence.
Journal: Scientific reports
In common: ICLabel, EEGLAB, EEG, 2 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.