Asked by Diego R
on 6 Sep 2019

I'd like to analyze this graph (is a vector) to have an answer like this:

for 1 to number of peaks:

PEAK_1=[start of peak_1, finish of peak_1, maximum, area under peak_1]

PEAK_2=[start of peak_2, finish of peak_2, maximum, area under peak_2]

...

...

PEAK_N=[start of peak_N, finish of peak_N, maximum, area under peak_N]

I am planning to do a "for" loop checking each value and its predecesor to determine when does a peak start and finish and a while to take the actions. My question is, is there any easier way to determine when does each peak star and finish?

Also, if anybody has any imaginative way better than mine it will be welcome.

Answer by darova
on 7 Sep 2019

Accepted Answer

How i found start and end of each peak

% generate some data

x = linspace(-1,17);

y = sin(x);

y = y.*(y>0);

thresh = 0.1;

ind = find(abs(y) < thresh); % find 'zeros' points

i = find( diff(ind)>1 ); % find breaks

i = [i; i+1]; % add 'end' points for each peak

i = reshape(i,2,[])';

ind = ind(i); % two columns: start - end points

plot(x,y,'.-b')

hold on

plot(x(ind),y(ind),'or')

plot([min(x) max(x)],[1 1]*thresh)

Use finpeaks() to get max value for each peak

Use trapz() to calculate area

Sign in to comment.

Answer by Image Analyst
on 7 Sep 2019

If you have the Image Processing Toolbox, you could use regionprops

props = regionprops(signal < 0, 'PixelIdxList');

It will give you, for each peak, the starting and stopping point. You could also ask for MeanIntensity and Area and multiply those together to get the area under the curve. Let me know if you can't figure it out, and attach your signal in a .mat file.

Sign in to comment.

Answer by Fabio Freschi
on 7 Sep 2019

If the signal is not too noisy you can work with ‘diff’ and look for the change of sign

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## dpb (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/479230-sort-of-peak-analysis#comment_743076

## Diego R (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/479230-sort-of-peak-analysis#comment_743183

## dpb (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/479230-sort-of-peak-analysis#comment_743193

## Image Analyst (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/479230-sort-of-peak-analysis#comment_743481

## darova (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/479230-sort-of-peak-analysis#comment_743484

Sign in to comment.