How can I modify the findpeaks command to give me a width at 80% of peak height (instead of at the build in 'halfheight')?
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
David Zimmerman
am 27 Mai 2017
Kommentiert: David Zimmerman
am 4 Feb. 2019
I am trying to analyze peaks but and need to determine the width of signal at 80% of the peak height. Matlab has a built in criterion when you specify findpeaks(...,'WidthReference",'halfheight') and this gives you 50%.
I have tried to modify the code but have so far been unsuccessful. If anybody can help I would really appreciate it.
Thank you
0 Kommentare
Akzeptierte Antwort
dpb
am 28 Mai 2017
Bearbeitet: dpb
am 28 Mai 2017
I'd suggest not modifying findpeaks but to postprocess the results instead--a sample from one of the examples of the basic process I'd undertake:
load mtlb % a sample dataset
select = mtlb(1001:1200); % a subsection that's got a few peaks...
x=1:length(select); % corollary variable of bin locations
[pks,locs,wdths]=findpeaks(select,x,'MinPeakHeight',2); % the result for just a few >2
% The "engine" to postprocess...
fnInterpL=@(p,l,w) interp1(select(l-fix(w):l),l-fix(w):l,0.8*p); % interpolate lower side
fnInterpH=@(p,l,w) interp1(select(l:l+fix(w)),l:l+fix(w),0.8*p); % and upper...
This can be used as:
>> [arrayfun(fnInterpL,pks,locs.',wdths.') arrayfun(fnInterpH,pks,locs.',wdths.')]
ans =
51.3944 53.5555
82.5567 84.8145
145.4656 146.3182
>>
NB: the transpose on the locations/widths vectors; for some reason findpeaks doesn't return all three in same orientation as arrayfun needs.
One could generalize the above a little more by passing in the limit percent as well. Also note the above has the anonymous functions with the builtin signal; probably in a general case would be best to just go ahead and do an m-file where can pass it as well...
ADDENDUM
The above are the boundaries; the width is the difference of course:
>> w80=[arrayfun(fnInterpH,pks,locs.',wdths.')-arrayfun(fnInterpL,pks,locs.',wdths.') ]
w80 =
2.1611
2.2578
0.8526
>>
4 Kommentare
Poonam Thakur
am 14 Nov. 2018
Hi,
I understand this is an old thread but taking my chance here. I am intersted in finding peak width at threshold. I tried to use the above code using my threshold value instead of 0.8*p. However, it returned me arrays full of NaN. My data consists of very long arrays and has multiple peaks.
Thank you.
dpb
am 14 Nov. 2018
Would probably be best to post new Q? with the specific data (representative subset, of course).
Would need to see the specific code you tried, obviously, to see if could spot any problems there; NaN is a typical result from interp1 when it tries to extrapolate so one could infer that perhaps the ranges to it in the above anonymous function aren't bounding the input points being looked for...
Weitere Antworten (1)
David Zimmerman
am 14 Nov. 2018
2 Kommentare
MARWA NOOR
am 4 Feb. 2019
hi,
i tried this code ,it is correct but i do not understand how zeros function work here
..i know that is to generate matrix of zeros ,
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!