MATLAB Answers

LO
0

is there a way to obtain peak width after peak detection ?

Asked by LO
on 28 May 2019
Latest activity Commented on by Star Strider
on 28 May 2019
I have used the function findpeaks to detect spikes in a signal
however I have initially used the halfprominence as width-reference
is there a way to obtain widths using half-height after such peak detection, having the peak timestamps and their amplitude values ?

  0 Comments

Sign in to comment.

Tags

3 Answers

Answer by Star Strider
on 28 May 2019
 Accepted Answer

Not a stupid question at all.
You simply need to ask findpeaks to return them as outputs:
[pks,locs,widths,proms] = findpeaks(PeakSig,x);
See the documentation section on Peak Prominences (link) for an illustration and discussion. The ‘widths’ are defined as the full width at half of the maximum amplitude (FWHM).

  2 Comments

thanks, I should have probably posted at the beginning the command I was using.
I know you get them as outputs. I was just wondering whether the width values (in heights) can be calculated from those values obtained using half prominence ([pks,locs,widths,proms])
or whether a new peak detection has to be made using half height.
I guess this now is the stupid question :)
I am not certain what you are asking.
The ‘height’ (and related ‘width’) and ‘prominence’ values are different, and only loosely related, at least as I read the documentation. The Prominence (link) property seems difficult to define. I would just use the FWHM value to characterise the peaks.
In other applications, I have used both ‘widths’ and ‘proms’ to select particular peaks, defining a desired peak by ‘(width > wv) & (prom > pv)’, where ‘wv’ and ‘pv’ were values determined elsewhere in the code. Perhaps you can combine them that way.

Sign in to comment.


Answer by Adam Danz
on 28 May 2019
Edited by Adam Danz
on 28 May 2019

Use the "halfheight" width reference. There's an example here: https://www.mathworks.com/help/signal/ref/findpeaks.html#buhd6xj
[pks,locs,w,p] = findpeaks(PeakSig,x,'Annotate','extents','WidthReference','halfheight')

  1 Comment

LO's comment moved here:
"I know that, thanks. What I wanted to know is whether one could get those values without doing the peak detection again"
Why would you need to run it twice? The widths are returned in the 3rd output.
[pks,locs,w,p] = findpeaks(PeakSig,x,'Annotate','extents','WidthReference','halfheight')

Sign in to comment.


Answer by LO
on 28 May 2019

I know that, thanks.
what I wanted to know is whether one could get those values without doing the peak detection again
but I guess there is no way. stupid question most likely

  0 Comments

Sign in to comment.