From 80c6a697a64b47db815e9e1d59631bd5ea72b68a Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Fri, 24 May 2019 18:09:11 +0000 Subject: [PATCH] - refactored variables - added comments git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@455 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- matlab/peak_detect.m | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/matlab/peak_detect.m b/matlab/peak_detect.m index 12e0c27..1fa98f8 100644 --- a/matlab/peak_detect.m +++ b/matlab/peak_detect.m @@ -107,32 +107,33 @@ for k=1:numFrames end end - gate_peak = (X-Xm) >= Ad; - peak_count = gate_peak.*peak_count + gate_peak; - - peaks = peak_count > 0; + % Create peak distances by subtracting Xm + peak_dist = (X-Xm); + + % Find peak candidates by thresholding + peaks = peak_dist >= Ad; peak_pos = find(peaks); - % Output + % Search true maximum peak using hill climbing numPeaksLast = 0; while(1) numPeaks = 0; - for x = peak_pos, + for pos = peak_pos, while(1) - y0 = X(x); - xp = min(Nh, x+1); - xn = max(1, x-1); - if X(xp) > y0 - peaks(x) = 0; - peaks(xn) = 0; - x = xp; - elseif X(xn) > y0 - peaks(x) = 0; - peaks(xp) = 0; - x = xn; + y0 = X(pos); + pos_p = min(Nh, pos+1); + pos_n = max(1, pos-1); + if X(pos_p) > y0 + peaks(pos) = 0; + peaks(pos_n) = 0; + pos = pos_p; + elseif X(pos_n) > y0 + peaks(pos) = 0; + peaks(pos_p) = 0; + pos = pos_n; else - peaks(xn) = 0; - peaks(xp) = 0; + peaks(pos_n) = 0; + peaks(pos_p) = 0; numPeaks = numPeaks + 1; break; end