1 %> @brief Peak Detector
8 %> =0. Minimum vertical distance between peak and zero
10 %> =0. Minimum vertical distance between peak and closest trough
12 %> Minimum distance between peaks, expressed in number of points.
14 %> Minimum distance between peaks, expressed in native units.
16 %> =1. Whether minaltitude and minheight are expressed in percentage. If
true, the actual minimum altitude and
17 %> minimum height will be calculated
as a percentage of max(abs(y)).
19 %> =Inf. Maximum number of peaks to be returned. If used, peak are returned in ranked order of height.
21 %> =1. Whether absolute value of the signal should be used. If 0, negative parts of the signal are made into
22 %>
"lakes", i.e., replaced by zeroes
26 properties(SetAccess=
protected)
27 %> Horizontal spacing between points, expressed in native units.
36 o.classtitle = 'Peak Detector';
37 o.color = [170, 189, 193]/255;
42 %> If the peak detector is going to be used many times, it is better to boot it first. Otherwise it will be internally booted
43 %> every time it is used.
45 %> The peak detector will be internally booted when:
46 %> @arg @c x is not empty, or
47 %> @arg @c the peak detector hasn't been booted before
49 %> @param x x-axis values. If not empty, the peak detector will be internally booted.
50 %> @param y curve to detect peaks from
51 function idxs = use(o, x, y)
53 if ~o.flag_booted || ~isempty(x)
61 if ~isempty(o.mindist)
64 if ~isempty(o.mindist_units)
65 mindist_ = ceil(o.mindist_units/o.spacing);
67 irerror('Minimum distance between points not specified: specify either mindist or mindist_units');
76 y(y == Inf) = realmax;
80 if o.no_max > 0 && length(idxs) > o.no_max
81 [dummy, idx] = sort(y(idxs), 'descend');
82 idxs = idxs(idx(1:o.no_max));
88 function o = boot(o, x, y)
89 o.spacing = abs(x(2)-x(1));
92 if o.minaltitude > 1 || o.minaltitude < 0
93 irerror('Invalid percentual minimum altitude!');
95 if o.minheight > 1 || o.minheight < 0
96 irerror('Invalid percentual minimum height!');
99 top(top == Inf) = realmax;
100 o.minalt = o.minaltitude*top;
101 o.minhei = o.minheight*top;
103 o.minalt = o.minaltitude;
104 o.minhei = o.minheight;
function detect_peaks(in y, in minalt, in minhei, in mindist)
Analysis Session (AS) base class.