2 views (last 30 days)

If we have a dataset "y" which consists of a sum of 5 gaussian peaks as function of time t, there will be 5 local maximum values in the whole y values. Basically, I would like to obtain the y axis maximum values and their corresponding t axis values. For example peak 1, has a maximum value 5 and it corresponds to t value of 19.

One can individually find the maximum values by giving a range say

[a ,i]=max(y(1:20));% locating maxima in a given range of the first peak

value_1= t(i); % Corresponding value of time for index i1.

One can repeat this 5 times by specifying the ranges for all peaks. Is there a better way to achieve the same result as an output in a single vector, and the corresponding time for those maxima in another vector . Thanks.

Star Strider
on 27 Sep 2019

Use the Signal Processing Toolbox findpeaks function, or the islocalmax (R2017b and later) function.

Star Strider
on 27 Sep 2019

It doesn’t calculate peak area. The closest it’s possible to get is the full-width-half-maximum calculation, the ‘w’ (peak widths) output in the documentation.

Some of your peaks overlap, so they may represent different (I assume Gaussian) functions. It might be best to use the information that findpeaks returns to fit multiple Gaussians to your data, and then calculate those areas.

Another option is to negate your signal and use findpeaks to find the valleys (peaks of the negated signal), and then use those to determine the dividing lines between the peaks. Then use the cumtrapz function and the ‘locs’ output of using findpeaks on the negated signal to determine the areas between the valley indices.

It all depends on what you want to do and how you want to define your peaks.

MW
on 28 Sep 2019

Star Strider
on 28 Sep 2019

Thank you.

‘I hope Matlab includes peak area determination just like OriginPro where one can pan the area of interest and determine its area.’

I doubt that’s an option, or if it is, I’ve not heard of it.

Fitting Gaussians is not difficult. See: Area under each peak for an illustration, including findpeaks calls. You can probably use that code with a few tweaks to use your own data. (I will help as necesary, since it’s my code. That code uses trapz, however it would probably not be very difficult to tweak it to use integral to calculate the areas, once the parameters of the Gaussians are known.)

Image Analyst
on 28 Sep 2019

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/482390-finding-several-local-maximum-values-in-a-given-range-and-corresponding-indices#comment_750436

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/482390-finding-several-local-maximum-values-in-a-given-range-and-corresponding-indices#comment_750436

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/482390-finding-several-local-maximum-values-in-a-given-range-and-corresponding-indices#comment_750545

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/482390-finding-several-local-maximum-values-in-a-given-range-and-corresponding-indices#comment_750545

Sign in to comment.