-
Notifications
You must be signed in to change notification settings - Fork 7
/
SimMetricsECG.m
174 lines (143 loc) · 4.96 KB
/
SimMetricsECG.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This source file contains several similarity metrics:
%
% - Maximum Absolute Distance Metric (MAD)
% - Sum Square Distance Metric (SSD)
% - Percentage Root-Mean-Square Difference Metric (PRD)
%
%
% All these methods were programmed according the literature information.
% The reference to these papers appear in the header information of each method
%
% Author: Francisco Perdigon Romero
% email: fperdigon88@gmail.com
% year: 2018
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function SimMetricsECG = SimMetricsECG
SimMetricsECG.MAD = @MAD;
SimMetricsECG.SSD = @SSD;
SimMetricsECG.PRD = @PRD;
SimMetricsECG.MAD_XY = @MAD_XY; % get the position off max diference
end
function [mad] = MAD(ECG1, ECG2)
% Maximum Absolute Distance Metric
%
% ECG1: This is the Groun truth signal
% ECG2: This is the Processed signal to be compared with
% the Groun truth signal
% mad: The output value of MAD metric
%
% Reference:
% R. Nygaard, G. Melnikov, A.K. Katsaggelos, A rate distortion optimal ECG coding
% algorithm,% IEEE Trans. Biomed. Eng. 48 (2001) 28–40. doi:10.1109/10.900246.
%
% implemented by: Francisco Perdigon Romero
% email: fperdigon88@gmail.com
if (size(ECG1) == size(ECG2))
% We are interest in the shape of signals, then we have to
% eliminate the bias due to DC components runnin metrics on
% the derivate of the signals
%dECG1 = diff(ECG1);
%dECG2 = diff(ECG2);
dECG1 = ECG1;
dECG2 = ECG2;
% Measure implementation
ds = abs(dECG1 - dECG2);
mad = max(ds);
else
disp('The signals have diferent size')
end
end
function [ssd] = SSD(ECG1, ECG2)
% Sum Square Distance Metric
%
% ECG1: This is the Groun truth signal
% ECG2: This is the Processed signal to be compared with
% the Groun truth signal
% ssd: The output value of ssd metric
%
% Reference:
% R. Nygaard, G. Melnikov, A.K. Katsaggelos, A rate distortion optimal ECG coding
% algorithm,% IEEE Trans. Biomed. Eng. 48 (2001) 28–40. doi:10.1109/10.900246.
%
% implemented by: Francisco Perdigon Romero
% email: fperdigon88@gmail.com
if (size(ECG1) == size(ECG2))
% We are interest in the shape of signals, then we have to
% eliminate the bias due to DC components runnin metrics on
% the derivate of the signals
%dECG1 = diff(ECG1);
%dECG2 = diff(ECG2);
dECG1 = ECG1;
dECG2 = ECG2;
% Measure implementation
ds = (dECG1 - dECG2).^2;
ssd = sum(ds);
else
disp('The signals have diferent size')
end
end
function [prd] = PRD(ECG1, ECG2)
% Percentage Root-Mean-Square Difference (PRD) Metric
%
% ECG1: This is the Groun truth signal
% ECG2: This is the Processed signal to be compared with
% the Groun truth signal
% prd: The output value of MAD metric
%
% Reference:
% R. Nygaard, G. Melnikov, A.K. Katsaggelos, A rate distortion optimal ECG coding
% algorithm,% IEEE Trans. Biomed. Eng. 48 (2001) 28–40. doi:10.1109/10.900246.
%
% implemented by: Francisco Perdigon Romero
% email: fperdigon88@gmail.com
if (size(ECG1) == size(ECG2))
dECG1 = ECG1;
dECG2 = ECG2;
% Measure implementation
meandECG1 = mean(dECG1);
numerator = sum((dECG1 - dECG2).^2);
denominator = sum((dECG1 - meandECG1).^2);
prd = sqrt(numerator/denominator) * 100;
else
disp('The signals have diferent size')
end
end
function [mad,xmax, ymax, xmin, ymin] = MAD_XY(ECG1, ECG2)
% Maximum Absolute Distance Metric
%
% ECG1: This is the Groun truth signal
% ECG2: This is the Processed signal to be compared with
% the Groun truth signal
% mad: The output value of MAD metric
%
% Reference:
% R. Nygaard, G. Melnikov, A.K. Katsaggelos, A rate distortion optimal ECG coding
% algorithm,% IEEE Trans. Biomed. Eng. 48 (2001) 28–40. doi:10.1109/10.900246.
%
% implemented by: Francisco Perdigon Romero
% email: fperdigon88@gmail.com
% This version also return the position off maximum and minimum
if (size(ECG1) == size(ECG2))
% We are interest in the shape of signals, then we have to
% eliminate the bias due to DC components runnin metrics on
% the derivate of the signals
%dECG1 = diff(ECG1);
%dECG2 = diff(ECG2);
dECG1 = ECG1;
dECG2 = ECG2;
% Measure implementation
ds = abs(dECG1 - dECG2);
mad = max(ds);
% Find the point of maximum and minimum of the metric
indexmin = find(min(ds) == ds);
xmin = indexmin;
ymin = ds(indexmin);
indexmax = find(max(ds) == ds);
xmax = indexmax;
ymax = ds(indexmax);
else
disp('The signals have diferent size')
end
end