- fixed messed up peak_box_abs
- refactored var names git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@457 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+33
-27
@@ -108,10 +108,10 @@ for k=1:numFrames
|
|||||||
end
|
end
|
||||||
|
|
||||||
% Create peak distances by subtracting Xm
|
% Create peak distances by subtracting Xm
|
||||||
peak_dist = (X-Xm);
|
Xd = (X-Xm);
|
||||||
|
|
||||||
% Find peak candidates by thresholding
|
% Find peak candidates by thresholding
|
||||||
peaks = peak_dist >= Ad;
|
peaks = Xd >= Ad;
|
||||||
peak_pos = find(peaks);
|
peak_pos = find(peaks);
|
||||||
|
|
||||||
% Search true maximum peak using hill climbing
|
% Search true maximum peak using hill climbing
|
||||||
@@ -147,60 +147,70 @@ for k=1:numFrames
|
|||||||
peak_pos = find(peaks);
|
peak_pos = find(peaks);
|
||||||
|
|
||||||
% Sort peaks
|
% Sort peaks
|
||||||
[v, n] = sort((X-Xm)(peak_pos), 'descend');
|
[v, n] = sort((Xd)(peak_pos), 'descend');
|
||||||
|
|
||||||
peak_pos_sorted = peak_pos(n);
|
peak_pos_sorted = peak_pos(n);
|
||||||
|
|
||||||
% Construct peak boxes
|
% Construct peak boxes
|
||||||
peak_pos = [];
|
peak_pos = [];
|
||||||
|
peak_boxes_abs = Xm;
|
||||||
peak_boxes_rel = zeros(1, Nh);
|
peak_boxes_rel = zeros(1, Nh);
|
||||||
peak_boxes_abs = zeros(1, Nh);
|
for pos = peak_pos_sorted,
|
||||||
for x = peak_pos_sorted,
|
|
||||||
|
|
||||||
% Find peak widths
|
% Find peak widths
|
||||||
left = x;
|
left = pos;
|
||||||
right = x;
|
right = pos;
|
||||||
nom = X(x) - 10;
|
nom = Xd(pos) - 10;
|
||||||
left_found = 0;
|
left_found = 0;
|
||||||
right_found = 0;
|
right_found = 0;
|
||||||
|
pbh = 0;
|
||||||
while(~(left_found & right_found))
|
while(~(left_found & right_found))
|
||||||
% Determine peak width left from center (x)
|
% Determine peak width left from center (pos)
|
||||||
if X(left) > nom
|
if Xd(left) > nom
|
||||||
if left > 1
|
if left > 1
|
||||||
left = left - 1;
|
left = left - 1;
|
||||||
else
|
else
|
||||||
left_found = 1;
|
break;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
left_found = 1;
|
left_found = 1;
|
||||||
endif
|
endif
|
||||||
% Determine peak width right from center (x)
|
% Determine peak width right from center (pos)
|
||||||
if X(right) > nom
|
if Xd(right) > nom
|
||||||
if right < Nh
|
if right < Nh
|
||||||
right = right + 1;
|
right = right + 1;
|
||||||
else
|
else
|
||||||
right_found = 1;
|
break;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
right_found = 1;
|
right_found = 1;
|
||||||
endif
|
endif
|
||||||
pbh_left = x - left;
|
pbh_left = pos - left;
|
||||||
pbh_right = right - x;
|
pbh_right = right - pos;
|
||||||
|
|
||||||
% Take larger peak width
|
% Take larger peak width
|
||||||
pbh = max(pbh_left, pbh_right);
|
pbh = max(pbh_left, pbh_right);
|
||||||
|
|
||||||
% Ensure peak box is at least pb_min
|
% Ensure peak box is at least pb_min
|
||||||
pbh = max(pbh, pb_min);
|
pbh = max(pbh, pb_min);
|
||||||
|
|
||||||
|
if pbh > pb_max
|
||||||
|
pbh = 0;
|
||||||
|
break;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if pbh == 0
|
||||||
|
continue;
|
||||||
|
endif
|
||||||
|
|
||||||
% Use peak width for peak box
|
% Use peak width for peak box
|
||||||
pbox_start = max(1, x-pbh);
|
pbox_start = max(1, pos-pbh);
|
||||||
pbox_end = min(Nh, x+pbh);
|
pbox_end = min(Nh, pos+pbh);
|
||||||
|
|
||||||
% Find intersection
|
% Find intersection
|
||||||
box_height_rel = X(x) - Xm(x);
|
box_height_abs = X(pos);
|
||||||
box_height_abs = X(x);
|
box_height_rel = Xd(pos);
|
||||||
does_intersect = 0;
|
does_intersect = 0;
|
||||||
for n=pbox_start:pbox_end
|
for n=pbox_start:pbox_end
|
||||||
if peak_boxes_rel(n) > box_height_rel
|
if peak_boxes_rel(n) > box_height_rel
|
||||||
@@ -209,19 +219,15 @@ for k=1:numFrames
|
|||||||
end
|
end
|
||||||
endfor
|
endfor
|
||||||
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_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_pos = [peak_pos x];
|
peak_boxes_rel(pbox_start:pbox_end) = box_height_rel * ones(1, pbox_end - pbox_start + 1);
|
||||||
|
peak_pos = [peak_pos pos];
|
||||||
end
|
end
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
% Create peak boxes with correct absolute height
|
|
||||||
peak_box_values = Xm;
|
|
||||||
peak_box_values((peak_boxes_rel > 0)) = peak_boxes_abs(peak_boxes_rel > 0);
|
|
||||||
|
|
||||||
% Output
|
% Output
|
||||||
subplot(2, 1, 1)
|
subplot(2, 1, 1)
|
||||||
plot(1:Nh, X, peak_pos, X(peak_pos), 'ro', 1:Nh, peak_box_values, 'm-'); grid; axis([0, Nh, -60, 60]); legend('X', 'Peaks', 'Peak Box')
|
plot(1:Nh, X, peak_pos, X(peak_pos), 'ro', 1:Nh, peak_boxes_abs, 'm-'); grid; axis([0, Nh, -60, 60]); legend('X', 'Peaks', 'Peak Box')
|
||||||
subplot(2, 1, 2)
|
subplot(2, 1, 2)
|
||||||
plot(1:Nh, Xs-Xm, 1:Nh, Xm); grid; axis([0, Nh, -60, 60]); legend('X_s - Xm', 'X_m')
|
plot(1:Nh, Xs-Xm, 1:Nh, Xm); grid; axis([0, Nh, -60, 60]); legend('X_s - Xm', 'X_m')
|
||||||
pause(1/30);
|
pause(1/30);
|
||||||
|
|||||||
Reference in New Issue
Block a user