- refactored

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@446 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-05-23 17:17:29 +00:00
parent 8cf7726af8
commit 124def841f
+21 -19
View File
@@ -93,27 +93,29 @@ for k=1:numFrames
gate_peak = (Xs-Xm) >= Ad; gate_peak = (Xs-Xm) >= Ad;
peak_count = gate_peak.*peak_count + gate_peak; peak_count = gate_peak.*peak_count + gate_peak;
peaks = peak_count > 0;
peak_pos = find(peaks);
% Output % Output
numPeaksLast = 0; numPeaksLast = 0;
while(1) while(1)
numPeaks = 0; numPeaks = 0;
for x = find(peak_count > 0), for x = peak_pos,
_x = x;
while(1) while(1)
y0 = X(_x); y0 = X(x);
xp = min(Nh, _x+1); xp = min(Nh, x+1);
xn = max(1, _x-1); xn = max(1, x-1);
if X(xp) > y0 if X(xp) > y0
peak_count(_x) = 0; peaks(x) = 0;
peak_count(xn) = 0; peaks(xn) = 0;
_x = xp; x = xp;
elseif X(xn) > y0 elseif X(xn) > y0
peak_count(_x) = 0; peaks(x) = 0;
peak_count(xp) = 0; peaks(xp) = 0;
_x = xn; x = xn;
else else
peak_count(xn) = 0; peaks(xn) = 0;
peak_count(xp) = 0; peaks(xp) = 0;
numPeaks = numPeaks + 1; numPeaks = numPeaks + 1;
break; break;
end end
@@ -124,15 +126,15 @@ for k=1:numFrames
end end
numPeaksLast = numPeaks; numPeaksLast = numPeaks;
end end
peak_cand = find(peak_count > 0); peak_pos = find(peaks);
% Sort peaks % Sort peaks
[v, n] = sort(X(peak_cand), 'descend'); [v, n] = sort((Xs-Xm)(peak_pos), 'descend');
peak_cand_sorted = peak_cand(n); peak_cand_sorted = peak_pos(n);
% Construct peak boxes % Construct peak boxes
peak_final = []; peak_pos = [];
peak_boxes_rel = zeros(1, Nh); peak_boxes_rel = zeros(1, Nh);
peak_boxes_abs = zeros(1, Nh); peak_boxes_abs = zeros(1, Nh);
for x = peak_cand_sorted, for x = peak_cand_sorted,
@@ -191,7 +193,7 @@ for k=1:numFrames
if does_intersect == 0 if does_intersect == 0
peak_boxes_rel(pbox_start:pbox_end) = box_height_rel * ones(1, pbox_end - pbox_start + 1); peak_boxes_rel(pbox_start:pbox_end) = box_height_rel * ones(1, pbox_end - pbox_start + 1);
peak_boxes_abs(pbox_start:pbox_end) = box_height_abs * ones(1, pbox_end - pbox_start + 1); peak_boxes_abs(pbox_start:pbox_end) = box_height_abs * ones(1, pbox_end - pbox_start + 1);
peak_final = [peak_final x]; peak_pos = [peak_pos x];
end end
endfor endfor
@@ -214,7 +216,7 @@ for k=1:numFrames
% Output % Output
subplot(2, 1, 1) subplot(2, 1, 1)
plot(1:Nh, X, peak_final, X(peak_final), 'ro', 1:Nh, peak_box_values, 'm-'); grid; axis([0, Nh, -60, 40]); plot(1:Nh, X, peak_pos, X(peak_pos), 'ro', 1:Nh, peak_box_values, 'm-'); grid; axis([0, Nh, -60, 40]);
subplot(2, 1, 2) subplot(2, 1, 2)
plot(1:Nh, Xs-Xm, 1:Nh, Xm); grid; axis([0, Nh, -60, 40]); plot(1:Nh, Xs-Xm, 1:Nh, Xm); grid; axis([0, Nh, -60, 40]);
pause(1/30); pause(1/30);