How to calculate the width that contains 60% of the total area of peaks?

1 回表示 (過去 30 日間)
Lope
Lope 2022 年 4 月 25 日
コメント済み: Lope 2022 年 4 月 25 日
So starting from the center (where the max peak always lies), I want to calculate automatically the width that contains 60% of the total area under multiple peaks. How can I do that? Attached is the normalized intensities and positions.
Below is the code to an attempt to get the contribution of the main peak only from the total area:
TotalArea=trapz(x2,Int);
lims = (x2>= -3.90625E-5 ) & (x2<= 3.90625E-5); %manually selected
MainPeakArea=trapz(x2(lims),Int(lims));
MainLobePower = (MainPeakArea/TotalArea)*100;

採用された回答

Chunru
Chunru 2022 年 4 月 25 日
load position
load Intensity
whos
Name Size Bytes Class Attributes Int 1x2048 16384 double ans 1x38 76 char cmdout 1x33 66 char x2 1x2048 16384 double
plot(x2, Int); hold on
% find the max
[maxI, idx] = max(Int);
maxX = x2(idx)
maxX = 0
n = length(x2);
Atotal = trapz(x2, Int);
for w=1:length(x2)
ii = max(idx-w, 1):min(idx+w, n);
A = trapz(x2(ii), Int(ii));
if A/Atotal>=0.6
break
end
end
area(x2(ii), Int(ii));
plot(x2(idx), Int(idx), 'r^');
xlim([-1 1]*1e-3)
title(sprintf('Width: %g - %g', x2(ii(1)), x2(ii(end)) ));

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2022 年 4 月 25 日
編集済み: Bruno Luong 2022 年 4 月 25 日
load Intensity.mat
load position.mat
ifun=@(x) interp1(x2,Int,x,'linear','extrap');
I0=integral(ifun,x2(1),x2(end))
I0 = 5.6250e-05
x = fzero(@(x) integral(ifun,-x,x)-0.6*I0,0) % the interval is (-x,x) width is 2*x
x = 3.1468e-05

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by