Fieldtrip

Loading Mentalab Recordings to FieldTrip

This document provides a simple guide for loading Mentalab Explore device recordings into FieldTrip for ExG analysis and visualization.

Prerequisites

Before using this guide, you need:

  1. A Mentalab Explore device
  2. ExplorePy installed and configured
  3. MATLAB with FieldTrip toolbox installed

Step 1: Recording Data with Mentalab

Record your EEG data using ExplorePy CLI, Explore Desktop, or Explore Mobile.

Step 2: Setting Up FieldTrip

  1. Download FieldTrip from fieldtriptoolbox.org
  2. Add FieldTrip to your MATLAB path:
% Add FieldTrip to your MATLAB path
addpath('/path/to/fieldtrip');  % Replace with your FieldTrip path
ft_defaults;  % Initialize FieldTrip

Step 3: Prepare Your Data Files

After recording, you should have these files in your working directory:

  • my_recording_ExG.csv - EEG data
  • my_recording_Meta.csv - Recording metadata
  • my_recording_ORN.csv - Orientation data
  • my_recording_Marker.csv - Event markers

In order to load ExG data to FieldTrip we will use *_ExG.csv and *_Meta.csv files.

Step 4: Loading and Visualizing Data

Using the Provided MATLAB Script

Run the script:

% --- CSV FILE LOADING ---

% Prompt user for CSV file name
filename = input('Enter CSV filename: ', 's');

% Prompt user for metadata file name
meta_filename = input('Enter metadata filename: ', 's');

% Prompt user for marker file name
marker_filename = input('Enter marker filename: ', 's');

% Load CSV
csv_data = readmatrix(filename);
time = csv_data(:,1);
eeg  = csv_data(:,2:end);

% Load meta data and get sampling rate
meta_data = readtable(meta_filename);
sampling_rate = meta_data.sr(1);

% Load marker file
marker_table = readtable(marker_filename);

% Convert marker timestamps to sample indices
marker_samples = round((marker_table.TimeStamp - time(1)) * sampling_rate) + 1;

% Build event structure
events = struct('type', {}, 'sample', {}, 'value', {}, 'duration', {}, 'offset', {});
for i = 1:height(marker_table)
    events(i).type = 'trigger';
    events(i).sample = marker_samples(i);
    events(i).value = marker_table.Code{i};
    events(i).duration = 0;
    events(i).offset = 0;
end

% Build FieldTrip data structure
data_csv = [];
data_csv.fsample = sampling_rate;
data_csv.time = {time' - time(1)};
data_csv.trial = {eeg'};
data_csv.label = arrayfun(@(x) sprintf('ch%d', x), 1:size(eeg,2), 'UniformOutput', false);

% Add events to FieldTrip data structure
data_csv.cfg = [];
data_csv.cfg.event = events;

fprintf('Sampling rate (fsample): %.2f Hz\n', data_csv.fsample);

% Visualize
cfg = [];
cfg.viewmode = 'vertical';
ft_databrowser(cfg, data_csv);
  • Run the script
  • When prompted, enter your ExG CSV filename (e.g., ‘my_recording_ExG.csv’)
  • When prompted, enter your Meta CSV filename (e.g., ‘my_recording_Meta.csv’)
  • When prompted, enter your Marker CSV filename (e.g., ‘my_recording_Marker.csv’)

The script will:

  1. Load the CSV data
  2. Create a FieldTrip-compatible data structure
  3. Display the data using ft_databrowser
Fieldtrip vizualization example

References

Copyright © 2025 Mentalab