Adding Event Markers to Imported EEG Data - Stacked Plot
10 views (last 30 days)
Show older comments
Christina Diersing
on 27 Oct 2021
Commented: Christina Diersing
on 3 Nov 2021
Hello!
I am currently working with Matlab to analyze EEG data from an Emotiv EPOC. I have it all imported and I have several plots made from the csv files. However, is there any way I can add (preferably manually) event markers to these plots? I have a stacked plot with all channels individually shown, a figure with all channels shown in tiled layout, and a plot with all channels shown. I've included the code below and attached the relating data files. I'm grateful for any help you can offer!
%% Importing_and_Plotting_EEG_Example
close all; clear all; clc;
% look to 300 ms for peak after stimulation
% ### EDIT: I commented out the next 4 lines so your code can be run in Answers
% % add folder with csv file to path
% addpath 'C:\Users\chris\Documents\College\Sixth Year\DAGSI\Data\EMOTIV Recordings\Event Marker Try 4'
% % change current directory to where this Matlab file is
% cd 'C:\Users\chris\Documents\College\Sixth Year\DAGSI\Data\EMOTIV Recordings'
% stops Matlab from rounding numbers
format long;
% Importing csv data
T=readtable('Try 4.csv'); %This reads the csv data into a table named T
timestampOrig=T.Timestamp; %this makes timestampOrig equal to the original Timestamp
T.Timestamp=T.Timestamp-T.Timestamp(1); %This changes the official Timestamp column so it is 0 at the start of the recording
% Changes the sensor names from EEG_<sensor> to <sensor>
T.Properties.VariableNames(2:end)=extractAfter(T.Properties.VariableNames(2:end),'_');
T5=head(T, 5) %shows first 5 rows of table T
%% Stacked Plot
% Plot all electrode readings on the same plot (vs timestamp)
fig0=figure('Name', 'EEG Signals - Stacked Plot');
%creates a stacked plot with Timestamp as x-axis and the values of the variables in
%columns 2:end as the y-axis
stackedplot(T,T.Properties.VariableNames(2:end),'XVariable','Timestamp')
grid on; xlabel('Timestamp (s)'); %turns on grid and labels the x-axis
title('EEG Signals - Stacked Plot');
fig0.WindowState = 'maximize'; %maximizes the figure window -> easier to see
%% Tiled Layout - Same Prominence
fig1=figure('Name', 'EEG Signals and Peaks (Prominence=100)');
%Sets the plots to have a tiled layout (7 rows, 2 cols) with tight
%spacing
hTL=tiledlayout(7,2,'TileSpacing',"tight");
% for loop to establish the plots
for i=2:width(T) %1 plot for each sensor
nexttile %moves to next plot
%finds the peaks for each sensor. The peak is currently defined as as
%point that is at least 100 uV above the values directly to the left
%and right of the peak value; this also plots the peaks
findpeaks(T{:,i},T.Timestamp, 'MinPeakProminence', 100)
%creates ylabel as the sensor names, in bold font
ylabel(T.Properties.VariableNames(i), 'FontWeight', 'bold')
xticklabels('') %removes x-tick labels from the plots
if i==14 %for the bottom left plot
xticklabels(xticks) %x-tick labels are present
xlabel('Timestamp (s)'); %xlabel is present
end %ends if loop
end %ends for loop
xticklabels(xticks) %adds x-tick labels to bottom right graph
grid on;
xlabel('Timestamp (s)');
fig1.WindowState = 'maximize';
%% Reg Plot - all EEG Signals and peaks on same plot
%Plot EEG signals on same plot and find their peaks (when the peak is at
%least 100 above the nearest values
fig2=figure('Name', 'EEG Signals and Peaks - Same Plot');
%sets color order to 14 different colors
newcolors={'#0072BD', '#D95319', '#EDB120', '#7E2F8E','#77AC30','#4DBEEE', '#A2142F', '#FF0000', '#00FF00', '#0000FF', '#00FFFF', '#FF00FF', '#FFFF00', '#000000'};
colororder(newcolors); %sets the new color order to use
%Next 15 lines plot findpeaks for all sensors on the same plot - can
%adjust each prominence as desired
findpeaks(T.AF3, T.Timestamp,'MinPeakProminence',100);
grid on; hold on; %turns on grid and plots all peaks on same plot
findpeaks(T.F7, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.F3, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.FC5, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.T7, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.P7, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.O1, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.O2, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.P8, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.T8, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.FC6, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.F4, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.F8, T.Timestamp,'MinPeakProminence',100);
findpeaks(T.AF4, T.Timestamp,'MinPeakProminence',100);
%Creates legend for the plot
legend({'AF3', 'AF3 Peaks', 'F7', 'F7 Peaks', 'F3', 'F3 Peaks', 'FC5', 'FC5 Peaks', 'T7', 'T7 Peaks', 'P7', 'P7 Peaks', 'O1', 'O1 Peaks', 'O2', 'O2 Peaks', 'P8', 'P8 Peaks', 'T8', 'T8 Peaks', 'FC6', 'FC6 Peaks', 'F4', 'F4 Peaks', 'F8', 'F8 Peaks', 'AF4', 'AF4 Peaks'}, 'NumColumns', 2);
title('All Peaks on Same Graph');
xlabel('Timestamp (s)');
ylabel('EEG Value (uV)');
fig2.WindowState = 'maximize';
0 Comments
Accepted Answer
Cris LaPierre
on 27 Oct 2021
Edited: Cris LaPierre
on 27 Oct 2021
I guess it depends on what you want your markers to be, and how you want to select them. You can manually annotate your plot using the Figure Palette
More Answers (0)
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!