-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecgdemowinmax.m
102 lines (94 loc) · 3.26 KB
/
ecgdemowinmax.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
% ECGDEMO ECG PROCESSING DEMONSTRATION - R-PEAKS DETECTION
function Filtered=ecgdemowinmax(Original, WinSize)
%initialising variables
WinHalfSize = floor(WinSize/2);
WinHalfSizePlus = WinHalfSize+1;
WinSizeSpec = WinSize-1;
FrontIterator = 1;
WinPos = WinHalfSize;
WinMaxPos = WinHalfSize;
WinMax = Original(1);
OutputIterator = 0;
% Finding the postion of the largest value in window
for LengthCounter = 0:1:WinHalfSize-1
if Original(FrontIterator+1) > WinMax
WinMax = Original(FrontIterator+1);
WinMaxPos = WinHalfSizePlus + LengthCounter;
end
FrontIterator=FrontIterator+1;
end
% if the first point is the highest, set ouput 1
if WinMaxPos == WinHalfSize
Filtered(OutputIterator+1)=WinMax;
else
Filtered(OutputIterator+1)=0;
end
OutputIterator = OutputIterator+1;
% search next half of signal
for LengthCounter = 0:1:WinHalfSize-1
if Original(FrontIterator+1)>WinMax
WinMax=Original(FrontIterator+1);
WinMaxPos=WinSizeSpec;
else
WinMaxPos=WinMaxPos-1;
end
if WinMaxPos == WinHalfSize
Filtered(OutputIterator+1)=WinMax;
else
Filtered(OutputIterator+1)=0;
end
FrontIterator = FrontIterator+1;
OutputIterator = OutputIterator+1;
end
for FrontIterator=FrontIterator:1:length(Original)-1
if Original(FrontIterator+1)>WinMax
WinMax=Original(FrontIterator+1);
WinMaxPos=WinSizeSpec;
else
WinMaxPos=WinMaxPos-1;
if WinMaxPos < 0
WinIterator = FrontIterator-WinSizeSpec;
WinMax = Original(WinIterator+1);
WinMaxPos = 0;
WinPos=0;
for WinIterator = WinIterator:1:FrontIterator
if Original(WinIterator+1)>WinMax
WinMax = Original(WinIterator+1);
WinMaxPos = WinPos;
end
WinPos=WinPos+1;
end
end
end
if WinMaxPos==WinHalfSize
Filtered(OutputIterator+1)=WinMax;
else
Filtered(OutputIterator+1)=0;
end
OutputIterator=OutputIterator+1;
end
WinIterator = WinIterator-1;
WinMaxPos = WinMaxPos-1;
for LengthCounter=1:1:WinHalfSizePlus-1
if WinMaxPos<0
WinIterator=length(Original)-WinSize+LengthCounter;
WinMax=Original(WinIterator+1);
WinMaxPos=0;
WinPos=1;
for WinIterator=WinIterator+1:1:length(Original)-1
if Original(WinIterator+1)>WinMax
WinMax=Original(WinIterator+1);
WinMaxPos=WinPos;
end
WinPos=WinPos+1;
end
end
if WinMaxPos==WinHalfSize
Filtered(OutputIterator+1)=WinMax;
else
Filtered(OutputIterator+1)=0;
end
FrontIterator=FrontIterator-1;
WinMaxPos=WinMaxPos-1;
OutputIterator=OutputIterator+1;
end