How to calculate the peak areas of every single peak from the mass spectrum?
14 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
A. Sawas
2019-4-5
编辑:A. Sawas
2019-4-5
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 个评论
Maria Basile
2022-1-27
@A. Sawas hi!
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!