MATLAB环境下基于LSTM模型的癫痫发作检测方法-提出一种基于LSTM模型的癫痫发作检测方法,算法程序运行环境为MATLAB R2021b,执行基于深度学习(LSTM)的癫痫发作自动检测,程序运行需要GPU,需要一定内存,部分代码如下:

时间:2024-04-15 09:28:05
clc;clear all;close all
% Load in data 
load('0190_channel2_input(1) (1).mat')
load('0190_channel2_output(1) (1).mat')
Seizure_points=sum(channel2_output==1);

channel2_section=channel2;
channel2_output_section=channel2_output;

% Convert Time for x_axis
timepoint = 285.2/855605;
time = [timepoint:timepoint:timepoint*855605];

% Create Plot with Seizures highlighted
plot(time, channel2_section, 'b')
hold on 
plot(time(channel2_output_section==1),channel2_section(channel2_output_section==1), 'r')
xlabel('Time (ms)')
ylabel('Signal')
title('Local field potential with seizure events')

% Define Model 
numFeatures=1;
numHiddenUnits=200;
numClasses=2;
layers = [...
    sequenceInputLayer(numFeatures)
    lstmLayer(numHiddenUnits, 'OutputMode','sequence')
    fullyConnectedLayer(numClasses)
    softmaxLayer
    classificationLayer];
options =trainingOptions("adam",...
    "MaxEpochs",45,...
    "GradientThreshold", 2,...
    "Verbose",0,...
    "Plots",'training-progress')

出图如下:

完整代码:MATLAB环境下基于LSTM模型的癫痫发作检测方法