- Accessing findpeaks Code:To better understand the inner workings of the findpeaks function, you can run findpeaks in the MATLAB command window. This will grant you access to the source code.
- Creating a Modified Version:Once you have the findpeaks code, copy the entire content and paste it into a new MATLAB script file. You can name this new script, say, findpeaks2. This modified version will allow you to make changes as needed.
- Focus on findpeaks2.m:Within the findpeaks2 script, navigate to the relevant section. You'll find the following lines:
Finding index/location of 'WidthReference','halfheight' after using findpeaks
3 views (last 30 days)
Show older comments
Hello all,
As the title briefly describes, I am looking to find either the index or location of the yellow Width line that can be found in the example here:
The image I am particularly observing is this one which is about 3/4 down the page.
Basically, I am looking to recreate the width line, and obtain its points in a dataset.
To clarify, I am looking to obtain the location or index of the yellow width line. What is of most interest is the third peak from the left; the Height line is not centered about the Width line. When I was trying to recreate the width line, I assumed the peak to be in the middle of this width line, and take the width from the findpeaks function as follows:
[pks,locs,widths,proms] = findpeaks(y,x,'WidthReference','halfheight');
I then halved the width, and put it on both sides. However, as mentioned, because the height line is right in the middle of the width line, this results in an offset recreation of this width line.
Please help! I am not permitted to post code for this particular problem. Thank you.
1 Comment
Cheng-Yu Huang
on 28 Aug 2023
Hello there,
While it's possible that you've already found a solution since you posed this question in 2021, I'd like to share a potential solution for anyone who may encounter the same issue. If you were seeking to recreate the yellow width line and obtain its points in a dataset, here's how you could approach it:
if needWidth
% obtain the indices of each peak (iPk), the prominence base (bPk), and
% the x- and y- coordinates of the peak base (bxPk, byPk) and the width
% (wxPk)
[iPk,bPk,bxPk,byPk,wxPk] = findExtents(y,x,iPk,iFinite,iInfinite,iInflect,minP,minW,maxW,refW);
else
% combine finite and infinite peaks into one list
[iPk,bPk,bxPk,byPk,wxPk] = combinePeaks(iPk,iInfinite);
end
The value wxPk represents what you are seeking: the width of the peak.
4. Enhancing Output:To extract this width information, you can modify the function's output. At the very beginning of the findpeaks2 function, where the outputs are defined, include wxPk as the fifth output. This will make it accessible when you use findpeaks2.
function [Ypk,Xpk,Wpk,Ppk,wxPk] = findpeaks2(Yin,varargin)
With this enhanced version of the findpeaks function, now termed findpeaks2, you can utilize it just as you would the original function. The difference is that now you'll have access to the width start and end information (wxPk) as the fifth output.
I hope this explanation clarifies the process. If you have any further questions, feel free to ask!
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!