-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_local_max.m
39 lines (33 loc) · 943 Bytes
/
find_local_max.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
function [time_occurs, max_values] = find_local_max(ecg, threshold)
%Input :
%Find R peaks for a given ecg
%Threshold defines if it is wether or not you consider the peak as an R
%peak.
%Fs : frequency of sampling
%tmin : at what time the ecg given starts
%Output :
%time_occurs is a vector which contains the time at which the R peaks
%occur
%min_values is a vector which contains the values of the different local
%minima
R_waves = ecg > threshold;
R_waves = R_waves.*ecg;
wave = zeros(1,10000);
k = 1;
i = 1;
while i<length(ecg)
if R_waves(i) ~= 0
j = 1;
while R_waves(i+(j-1)) ~= 0 && (i+(j-1)) < length(ecg)
wave(j) = R_waves(i+(j-1));
j = j + 1;
end
[max_values(k), time_occurs(k)] = max(wave); % max(ecg([i:j]))
time_occurs(k) = time_occurs(k) + i-1;
wave = zeros(1,10000);
k = k + 1;
i = i + j;
end
i = i + 1;
end
end