Selecting which prominence to use with findpeaks
Show older comments
HelloI am using findpeaks to find the prominence of my peaks in the attached imaged. However the prominence for peak 4 is instead the entire height of the function. How can I change this to match the other peaks (1,2,3,5) and why is this behaviour happening?
Thanks
HP
Code:
prominance = max(xDose(:,2))/3;
[pks,locs,widths,proms] = findpeaks(xDose(:,2),xDose(:,1),'MinPeakProminence', prominance);
findpeaks(xDose(:,2),xDose(:,1), 'MinPeakProminence', prominance,'Annotate','extents')
text(locs+1,pks,num2str((1:numel(pks))'))
Accepted Answer
More Answers (1)
Hi @Henry
Since you did not provide the data for the 5-peak graph, I created one that resembles the Five-Finger Mountain. According to Chinese mythology and the novel Journey to the West, the Monkey King was imprisoned there after a series of rebellions against the heavens. The documentation of findpeaks() explains how the prominence of a peak is measured (see Peak #6).

x = linspace(0, 100, 1001)';
c = 30:10:70;
y1 = exp(- 1/2*(0.23*(x - c(1))).^2);
y2 = exp(- 1/2*(0.23*(x - c(2))).^2);
y3 = exp(- 1/2*(0.23*(x - c(3))).^2);
y4 = exp(- 1/2*(0.23*(x - c(4))).^2);
y5 = exp(- 1/2*(0.23*(x - c(5))).^2);
p1 = 0.8; % peak 1 (leftmost)
p2 = 1.1; % peak 2
p3 = 1.3; % peak 3
p4 = 1.2; % peak 4
p5 = 1.0; % peak 5
y = p1*y1.^2 + p2*y2.^2 + p3*y3.^2 + p4*y4.^2 + p5*y5.^2;
figure
plot(x, y)
xlabel('x'), ylabel('y')
title('Five-Finger Mountain')
grid on
figure
prominance = max(y)/5;
[pks, locs, widths, proms] = findpeaks(y, x, 'MinPeakProminence', prominance);
findpeaks(y, x, 'MinPeakProminence', prominance, 'Annotate', 'extents')
text(locs+1, pks, num2str((1:numel(pks))'))
xlabel('x'), ylabel('y')
6 Comments
Henry
on 24 Apr 2025
Mathieu NOE
on 24 Apr 2025
I have the feeling you would have wished to have a "MaxProminence" parameter with findpeaks ?
but that does not exist or you have to use the other available parameters or use a differen function - depends on what your fianl goal is - which is what btw ?
Hi @Henry
I aimed to explain the observation and how prominence is measured according to the documentation and the diagram. Here, you can manually estimate the prominence at the 3rd peak.
x = linspace(0, 100, 1001)';
c = 30:10:70;
y1 = exp(- 1/2*(0.23*(x - c(1))).^2);
y2 = exp(- 1/2*(0.23*(x - c(2))).^2);
y3 = exp(- 1/2*(0.23*(x - c(3))).^2);
y4 = exp(- 1/2*(0.23*(x - c(4))).^2);
y5 = exp(- 1/2*(0.23*(x - c(5))).^2);
p1 = 0.8; % peak 1 (leftmost)
p2 = 1.1; % peak 2
p3 = 1.3; % peak 3
p4 = 1.2; % peak 4
p5 = 1.0; % peak 5
y = p1*y1.^2 + p2*y2.^2 + p3*y3.^2 + p4*y4.^2 + p5*y5.^2;
figure
prominance = max(y)/5;
[pks, locs, widths, proms] = findpeaks(y, x, 'MinPeakProminence', prominance);
proms(3) = pks(3) - (pks(4) - proms(4))
hold on
plot(x, y), grid on
% plot Peaks
d = 0.03;
plot(locs(1), pks(1)+d, "v", 'Color', "#0072BD", 'MarkerFaceColor', "blue")
plot(locs(2), pks(2)+d, "v", 'Color', "#0072BD", 'MarkerFaceColor', "blue")
plot(locs(3), pks(3)+d, "v", 'Color', "#0072BD", 'MarkerFaceColor', "blue")
plot(locs(4), pks(4)+d, "v", 'Color', "#0072BD", 'MarkerFaceColor', "blue")
plot(locs(5), pks(5)+d, "v", 'Color', "#0072BD", 'MarkerFaceColor', "blue")
% plot Prominences
p1 = line([locs(1) locs(1)], [(pks(1)-proms(1)) pks(1)], 'Color', 'red');
p2 = line([locs(2) locs(2)], [(pks(2)-proms(2)) pks(2)], 'Color', 'red');
p3 = line([locs(3) locs(3)], [(pks(3)-proms(3)) pks(3)], 'Color', 'red');
p4 = line([locs(4) locs(4)], [(pks(4)-proms(4)) pks(4)], 'Color', 'red');
p5 = line([locs(5) locs(5)], [(pks(5)-proms(5)) pks(5)], 'Color', 'red');
text(locs+1, pks, num2str((1:numel(pks))'))
xlabel('x'), ylabel('y'), title('Five-Finger Mountain')
hold off
Henry
on 24 Apr 2025
Image Analyst
on 24 Apr 2025
@Sam Chak I think @Henry is wanting a verbal explanation of prominence. For example, explain using the colored peaks, like why does peak 7 stop at point g, while peak 6 does not stop at point f? Is it because peak 6 is taller in absolute (and relative) height than peak 7? Is the prominence equal to the area of the colored peaks+bases?
Sam Chak
on 24 Apr 2025
Thanks @Image Analyst. To be honest, I believe that the procedure for measuring the prominence of the local highest peak is flawed. I did not notice this issue until @Henry posed the question.
The prominence is measured against a reference level, which is defined as the highest minimum between two minimum levels determined by evaluating the left and right intervals from the peak until a higher peak is encountered or until the end of the signal.
Let us take Peak 6 as an example and start by evaluating the left interval. Peak 2 is higher than Peak 6 in the left interval. The minimum point in the left interval must lie between Peak 6 and the crossing due to Peak 2, as indicated at trough 'd'. In the right interval, there is no peak higher than Peak 6; thus, the minimum point on the right side is at trough 'h'. The reference level is determined by identifying the highest minimum between trough 'd' and trough 'h'. Since trough 'd' is higher than trough 'h', it is selected as the reference level. The prominence of Peak 6 is measured against the reference level at 'd', which is nearly at the base of the signal.
Should there be any If–Else conditions to identify the reference level between trough 'e' and trough 'f'?

Categories
Find more on General Applications in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


