Area under each peak

14 vues (au cours des 30 derniers jours)
camila
camila le 8 Juil 2016
Commenté : Star Strider le 21 Fév 2021
Hi, I have a TGA derivative plot with three peaks (two prominant peaks and one shoulder) and I want to get individual gaussian functions to get the area under each peak (which tells how much mass is reduces during heating), could you please tell me how get area under each curve. and also how to get full width half maximum, FWHM and peak center values too.
Thanks

Réponse acceptée

Star Strider
Star Strider le 8 Juil 2016
This was certainly an interesting challenge!
The loop first selects a range of x and y values to make the fit easier, then uses fminsearch to do the fit, calculates the area under the respective Gaussian using trapz and saves it to ‘AUC’, then uses fzero to calculate the full-width-half-maximum value and saves it to ‘FWHM’. The plot simply shows the fitted Gaussians, not ‘AUC’ or ‘FWHM’.
The code:
[d,s,r] = xlsread('chamila De Silva Q16N2.csv');
x = d(:,1);
y = d(:,2);
gausfcn = @(b,x) b(1) .* exp(-((x-b(2)).^2)./b(3)); % Gaussian Function
SSECF = @(b,x,y) sum((y - gausfcn(b,x)).^2); % Sum-Squared-Error Cost Function
[pks,locs] = findpeaks(y, 'MinPeakDist',30, 'MinPeakHeight',0.05); % Find Centres
q = x(locs);
for k1 = 1:size(pks,1)
idxrng = locs(k1)-25 : locs(k1)+25;
[Parms(:,k1), SSE(k1)] = fminsearch(@(b)SSECF(b,x(idxrng),y(idxrng)), [pks(k1); x(locs(k1)); 1]);
AUC(k1) = trapz(x, gausfcn(Parms(:,k1),x));
FWHM(k1) = 2*(x(locs(k1)) - fzero(@(x) gausfcn(Parms(:,k1),x) - pks(k1)/2, x(locs(k1))-5));
end
figure(1)
plot(x, y, 'LineWidth',1.5)
hold on
plot(x(locs), pks, '^r')
for k1 = 1:size(pks,1)
plot(x, gausfcn(Parms(:,k1),x), 'LineWidth',1)
end
hold off
grid
The plot:
  7 commentaires
Thor
Thor le 20 Fév 2021
Hi star strider, could you please define the meaning of lims? I have tried to applied your code to my data. However, the error " Array indices must be positive integers or logical values." appears. Many thanks @Star Strider
Star Strider
Star Strider le 21 Fév 2021
The ‘lims’ constant simply defines the range (±frame length) of ‘idxrng’.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by