-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRSClassify1.m
More file actions
65 lines (60 loc) · 2.08 KB
/
QRSClassify1.m
File metadata and controls
65 lines (60 loc) · 2.08 KB
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
function [classifications] = QRSClassify1(record, beats, Fs)
signalFileName = sprintf("%sm.mat", record);
S = load(signalFileName);
sig = S.val(1,:);
Fc = 2;
fsig = HPFilter(sig, Fc, 1/Fs);
averageBeat = getAverageBeat(fsig ,beats, Fs);
if isnan(averageBeat)
classifications = NaN;
return
end
threshold = max(abs(averageBeat-(averageBeat*0.5)));
limLower = floor(Fs*0.06);
limUpper = round(Fs*0.1);
fpPoints = beats(:,1);
classifications = [];
for i = 1:length(fpPoints)
currFp = fpPoints(i);
if currFp+limUpper <= length(fsig)
currBeat = fsig(currFp-limLower:currFp+limUpper);
currLabel = classifyBeat(currBeat, averageBeat, threshold);
classifications = [classifications, currLabel];
else
currBeat = fsig(currFp-limLower:end);
tempAverageBeat = averageBeat(1:length(currBeat));
currLabel = classifyBeat(currBeat, tempAverageBeat, threshold);
classifications = [classifications, currLabel];
end
end
end
function [averageBeat] = getAverageBeat(sig, beats, Fs)
maxSample = Fs*300;
fpPointsAll = beats(:,1);
fpPointsAll = fpPointsAll(beats(:,2)==0);
fpPoints = fpPointsAll(fpPointsAll<=maxSample);
if isempty(fpPoints) % couldn't learn a representation of normal beat
averageBeat = NaN;
return
end
averageBeat = zeros(1,round(Fs*0.16));
limLower = floor(Fs*0.06);
limUpper = round(Fs*0.1);
for i=1:length(fpPoints)
currFp = fpPoints(i);
currBeat = sig(currFp-limLower:currFp+limUpper);
averageBeat = averageBeat + currBeat;
end
averageBeat = averageBeat ./ length(fpPoints);
end
function [class] = classifyBeat(currBeat, averageBeat, threshold)
N = length(averageBeat);
%dist = (1/N) * sum(abs(currBeat-averageBeat)); %d1
%dist = sqrt((1/N)*sum(abs(currBeat-averageBeat)).^2); %d2
dist = max(abs(currBeat-averageBeat)); %dInf
if dist > threshold
class = 1; % V
else
class = 0; % N
end
end