Label predicted seizures in EEG data
Show older comments
I used a deep learning model to predict seizures in EEG data. I want to plot a graph to show where the model predicted the seizures on the EEG data and where the actual seizures are. The predicted values are categorical values 1 for seizure and -1 for no seizure. The EEG signal can be ploted using plot(channel).
Accepted Answer
More Answers (1)
Image Analyst
on 18 Apr 2022
You can use patch():
numSamples = 30;
x = linspace(0, 2*pi, numSamples);
eegData = 5 + 10 * sin(2 * pi * x / 3);
threshold = 6;
predictedValues = eegData > threshold;
subplot(2, 1, 1);
plot(x, eegData, 'b.-', 'LineWidth', 2, 'MarkerSize', 18);
yline(threshold, 'LineWidth', 2)
yl = ylim;
title('EEG Signal. Red Zones = Seizures')
grid on;
subplot(2, 1, 2);
plot(x, predictedValues, 'b.-', 'LineWidth', 2, 'MarkerSize', 18);
grid on;
title('Is Seizure')
ylim([0, 1.2])
% Shade regions
subplot(2, 1, 1); % Switch back to the EEG axes.
for k = 2 : numSamples
if (predictedValues(k) == 1 && predictedValues(k-1) == 1)
% Shade this region
x1 = x(k-1);
x2 = x(k);
y1 = yl(1);
y2 = yl(2);
xData = [x1; x1; x2; x2; x1];
yData = [y1; y2; y2; y1; y1];
patch(xData, yData, 'r', 'FaceAlpha', 0.2, 'EdgeColor', 'none')
end
end

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!