我只是有一个关于如何对数据点进行高斯分级的简单问题。让我们说在X = 100时我检测到5000个电子但我的FWHM就像4个点。在matlab中是否有可能用以X = 100为中心的高斯分组来容纳5000个电子。像X = 99和X = 101之间的2500个电子和95到105之间的5000个电子?
答案 0 :(得分:1)
听起来您在单个点(X=100
,e=5000
)进行单次测量,并且还知道FWHM(FWHM = 4
)的值。
如果情况确实如此,您可以像这样计算standard deviation sigma
:
sigma = FWHM/ 2/sqrt(2*log(2));
你可以像这样制作垃圾箱:
[N, binCtr] = hist(sigma*randn(e,1) + X, Nbins);
其中N
是每个箱子中的电子数量,binCtr
是箱子中心,Nbins
是您想要使用的箱子数量。
如果电子数量大,则可能会耗尽内存。在这种情况下,最好做同样的事情,但是在较小的批次中,如下:
% Example data
FWHM = 4;
e = 100000;
X = 100;
Nbins = 100;
% your std. dev.
sigma = FWHM/ 2/sqrt(2*log(2));
% Find where to start with the bin edges. That is, find the point
% where the PDF indicates that at most 1 electron is expected to fall
f = @(x, mu, sigma) exp(-0.5*((x-mu)/sigma).^2)/sigma/sqrt(2*pi);
g = @(y) quadgk(@(x)f(x,X,sigma), -inf, y)*e - 1;
h = fzero(g, X-FWHM*3);
% Create initial bin edges
binEdges = [-inf linspace(h, 2*X-h, Nbins-2) +inf];
% Bin electrons in batches
c = e;
done = false;
step = 5e3;
Nout = zeros(Nbins,1);
while ~done
% electrons still to be binned
c = c - step;
% Last step
if c <= 0
step = c+step;
c = 0;
done = true;
end
% Bin the next batch
N = histc(sigma*randn(step,1) + X, binEdges);
Nout = Nout + N;
end
% Bin edges must now be re-defined
binEdges =[...
2*binEdges(2)-binEdges(3),...
binEdges(2:end-1),...
2*binEdges(end-1)-binEdges(end-2)];