-
Notifications
You must be signed in to change notification settings - Fork 2
/
Convolution_SBP.m
110 lines (85 loc) · 2.86 KB
/
Convolution_SBP.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
%% A multistage deep neural network model for blood pressure estimation using photoplethysmogram signals
% This program uses Convolutional Deep Neural Network to extract features and estimate Systolic Blood Pressure.
% Trained CNN: SystolicNet_Stage1
% J. Esmaelpoor- Sep 2019
%% Load and prepare Train and Test Data
clc, close all, clear all
load TrainSeq;
load ValidationSeq;
load TestSeq;
CntTrain = 0;
for i = 1:length(TrainSeq)
SeqData = TrainSeq{1,i};
for j = 1:size(SeqData,1)
CntTrain = CntTrain + 1;
XTrain(1,1:250,1,CntTrain) = SeqData(j,3:252);
YTrain(CntTrain,1) = SeqData(j,253);
end
end
CntValidation = 0;
for i = 1:length(ValidationSeq)
SeqData = ValidationSeq{1,i};
for j = 1:size(SeqData,1)
CntValidation = CntValidation + 1;
XValidation(1,1:250,1,CntValidation) = SeqData(j,3:252);
YValidation(CntValidation,1) = SeqData(j,253);
end
end
CntTest = 0;
for i = 1:length(TestSeq)
SeqData = TestSeq{1,i};
for j = 1:size(SeqData,1)
CntTest = CntTest + 1;
XTest(1,1:250,1,CntTest) = SeqData(j,3:252);
YTest(CntTest,1) = SeqData(j,253);
end
end
%% Craete Network Layers
layers = [
imageInputLayer([1 250 1],'Name','PPG_seq')
convolution2dLayer([1 25],8,'Padding','same')
batchNormalizationLayer
reluLayer
averagePooling2dLayer([1 6],'Stride',4)
convolution2dLayer([1 25],16,'Padding','same')
batchNormalizationLayer
reluLayer
averagePooling2dLayer([1 6],'Stride',4)
convolution2dLayer([1 25],8,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer([1 25],4,'Padding','same')
batchNormalizationLayer
reluLayer
dropoutLayer(0.2)
fullyConnectedLayer(1)
regressionLayer];
%% Train Network
miniBatchSize = 64;
validationFrequency = floor(numel(YTrain)/miniBatchSize);
options = trainingOptions('sgdm', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',60, ...
'InitialLearnRate',1e-3, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.1, ...
'LearnRateDropPeriod',20, ...
'Shuffle','every-epoch', ...
'ValidationData',{XValidation,YValidation}, ...
'ValidationFrequency',validationFrequency, ...
'Plots','training-progress', ...
'Verbose',false);
SystolicNet_Stage1 = trainNetwork(XTrain,YTrain,layers,options);
save('SystolicNet_Stage1','SystolicNet_Stage1')
%% Test Network
YPredicted = predict(SystolicNet_Stage1,XTest);
predictionError = YTest - YPredicted;
STD = std(predictionError)
squares = predictionError.^2;
rmse = sqrt(mean(squares))
MAE = mean(abs(predictionError))
ME = mean(predictionError)
plot(YPredicted), hold on, plot(YTest)
figure
plotregression(YTest,YPredicted)
axis([80 200 80 200])