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!