-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpeak_pick.m
76 lines (51 loc) · 1.93 KB
/
peak_pick.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
% Peak picking algorithm %
% Input : nov_fn -> Novelty function
% : md -> Median filter length
% : me -> Mean filter length
% : Thresh_search -> Vicinity to search for the peak in the original
% nov_fn from the dtected peaks in smootened nov_fn
% : thres -> Percentage w.r.t highest peak to consider as valid peak (say 0.1)
% Output: Valid location of the peak
% : Height of the peak
function peaks_detected=peak_pick(timestamp,nov_fn,md,me,th_search,thres)
med_nov=medfilt1(nov_fn,md); % Taken as 40
me_nov=movavg(med_nov,me,me); % Taken as 30
% Detect peaks in the original contour
ct=0;
for i=3:length(nov_fn)-2
if(nov_fn(i)>nov_fn(i-1) && nov_fn(i)>nov_fn(i-2) && nov_fn(i)>=nov_fn(i+1) && nov_fn(i)>=nov_fn(i+2))
ct=ct+1;
orig_peak(ct,1)=i;
orig_peak(ct,2)=nov_fn(i);
end
end
orig_peak_locn=zeros(1,length(nov_fn));
orig_peak_locn(orig_peak(:,1))=nov_fn(orig_peak(:,1));
% Detect peaks in the smoothened contour
ct=0;
for i=2:length(nov_fn)-1
% if(me_nov(i)>me_nov(i-1) && me_nov(i)>me_nov(i-2) && me_nov(i)>=me_nov(i+1) && me_nov(i)>=me_nov(i+2))
if( me_nov(i)>me_nov(i-1) && me_nov(i)>=me_nov(i+1) )
ct=ct+1;
coarse_peak(ct,1)=timestamp(i);
coarse_peak(ct,2)=me_nov(i);
end
end
% Detect peaks in the original contour from the ones found in the smoothed
% contour
fct=0;
for k=1:ct
temp_loc=coarse_peak(k,1);
if(temp_loc+th_search<length(orig_peak_locn))
temp_nov=orig_peak_locn(temp_loc-th_search:temp_loc+th_search);
[max_val max_loc]=max(temp_nov);
if(max_val>=thres*max(orig_peak_locn))
fct=fct+1;
peaks_detected_init(fct,1)=timestamp(temp_loc+max_loc-th_search-1);
peaks_detected_init(fct,2)=max_val;
end
end
end
peaks_new=unique(peaks_detected_init,'rows');
no_zr_pk=peaks_new(:,1)~=0;
peaks_detected=peaks_new(no_zr_pk==1,:);