Time to peak using findpeaks
12 views (last 30 days)
Show older comments
David Santos
on 14 Sep 2025
Commented: Star Strider
on 16 Sep 2025
I'm using findpeaks to locate multiple peaks in my function but I want to know the rising time to the peak.
Findpeaks gives you the 'width' output but its not working because it suposses that the peak is in the middle of the valleys (and its based on the prominece, it would be nice to be referenced to lowestPoint/left valley) but most of these peaks are not symetric so its not working properly, any ideas?

0 Comments
Accepted Answer
Star Strider
on 14 Sep 2025
I usually have findpeaks return the indices of the peaks.
Your definition of the start time point isnot obvious. I would use interp1 to define it as a function of its amplitude, then subtract the time returned from the time of the peak.
Example --
t = datetime('07:00:00', InputFormat='HH:mm:ss') : minutes(1) : datetime('08:00:00', InputFormat='HH:mm:ss');
t.Format = 'HH:mm:ss';
t = t(:);
mp = round(numel(t)/2);
f = exp(-minutes(t - t(mp)).^2/50) * 1000 + 2500; % Create Data (Curve)
[pks,locs] = findpeaks(f) % Peak & Index
thrshld = 2550; % Amplitude Threshold
idxrng = 1 : locs; % Index Rnage For Interpolation
thrshld_time = interp1(f(idxrng), t(idxrng), thrshld) % Interpolate To Find Associated Time
t_interval = t(locs) - thrshld_time
figure
plot(t, f)
hold on
plot([thrshld_time thrshld_time], [2550 2750], ":r")
plot([thrshld_time t(locs)], 2750*[1 1], '|-r')
hold off
grid
yline(thrshld, '--r')
xline(t(locs), '--r')
text(thrshld_time+t_interval/2, 2750, sprintf('\\leftarrow \\Delta = %s', t_interval), Rotation=45)
axis('padded')
.
8 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






