How to calculate the peak areas of every single peak from the mass spectrum?

13 vues (au cours des 30 derniers jours)
Maggie Chen
Maggie Chen le 5 Avr 2019
Commenté : Maria Basile le 27 Jan 2022
Hi, I am wondering any toolboxs or codes could be used to calculate the peak areas of every single peak from the txt file or fig file. I know how to integrate the peak area in the excel using the txt file, but have to find the tails from the baseline manually. The picture showed how peak area was identified. I also attached a txt file from the mass spectrum. For the output, the centroid mass and peak area of every peak will be needed.Peak Area.jpg

Réponses (1)

A. Sawas
A. Sawas le 5 Avr 2019
Modifié(e) : A. Sawas le 5 Avr 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);
  10 commentaires
Jawaher Seddiq
Jawaher Seddiq le 25 Nov 2020
I tried this but getting an error can you check please
Maria Basile
Maria Basile le 27 Jan 2022
I know it's been a while since your comment (sorry for my bad english), but I'm trying to use your code below and it works pretty well until locs indices are non integers, that is my situation. I can't figure out how to fix it, because even if I change "while i>1" with "while i>0" then the indices of data will be a non integer and I'll get an error. I'm new at this type of analysis.. could you help me, please?
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

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by