2013-06-18 77 views
-1

我只是有一個簡單的問題,就是如何對數據點進行高斯裝倉。可以說,在X = 100時,我檢測到5000個電子,但是我的FWHM是4點。是否有可能在matlab中以高斯中心在X = 100處對5000個電子進行分箱。就像X = 99和X = 101之間的2500個電子以及95和105之間的5000個電子?數據的高斯裝倉

回答

1

這聽起來像你有一個單一的測量點(X=100,e=5000),並且也知道FWHM(FWHM = 4)的值。

如果情況確實如此,你可以計算standard deviationsigma像這樣:

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)]; 
+0

我覺得這聽起來像我想做的事情。我對FWHM有一個近似的想法,並希望將電子分離在離散點的邊界之間。我會嘗試這個並回復你。謝謝! – thecuriousone

+0

如果數字真的很大,該怎麼辦。讓我們說如果e = 12345678.當我嘗試裝入如此大的數字時,我的matlab崩潰。 – thecuriousone

+0

@ thecuriousone:看我最近的編輯。 –