69 views (last 30 days)

A. Sawas
on 5 Apr 2019

Edited: A. Sawas
on 5 Apr 2019

The function findpeaks can find the peak values and locations.

data = importdata('Example.txt');

plot(data);

[pks,loc] = findpeaks(data);

findpeaks(data); %Use findpeaks without output arguments to display the peaks

Then you can find the boundaries around that peaks in order to find the area.

for k = 1:length(loc)

i = loc(k);

while i > 1 && data(i-1) <= data(i)

i = i - 1;

end

b_min(k) = i;

i = loc(k);

while i < length(data) && data(i+1) <= data(i)

i = i + 1;

end

b_max(k) = i;

end

%b_min: minimum boundary

%b_max: maximum boundary

To find the area under the first peak:

A = trapz(data([b_min(1):b_max(1)]));

You can find the area under all the peaks then the one with maxium area as follows:

for k=1:length(b_min)

A(k) = trapz(X([b_min(k):b_max(k)]),Y([b_min(k):b_max(k)]));

end

[max_area, i] = max(A);

max_peak = loc(i);

A. Sawas
on 9 Apr 2019

Ok, so now the problem is with the input data. Since your data is in two columns format the first being the X and second is Y. You need to add this line and replace data in the remainng code with Y

X = data(:,1);

Y = data(:,2);

[pks,loc] = findpeaks(Y);

% the rest of the code after changing data to Y

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.