1 | NB = 10000; %Number of bins
|
---|
2 |
|
---|
3 |
|
---|
4 | for x = 1:200
|
---|
5 | lam(x) = exp((x-75.0)/10); %Expected rate
|
---|
6 | Xarr = 1:NB; %Time bins
|
---|
7 | Yarr = randraw('po',lam(x),NB); %Actual Counts
|
---|
8 | Earr = sqrt(Yarr); %Errors
|
---|
9 | [rate(x), ~] = fminbnd(@(A) flatBG(Xarr,Yarr,Earr,A),0,10*lam(x)); %Fit using Gaussian Cost function
|
---|
10 | [ratePo(x),~] = fminbnd(@(A) flatBGpo(Xarr,Yarr,Earr,A),0,10*lam(x)); %Fit using Poisson Cost Function
|
---|
11 | end
|
---|
12 | figure;
|
---|
13 | %Plot differences
|
---|
14 | diff = lam-rate;
|
---|
15 | diffPo = lam-ratePo;
|
---|
16 | ratio = lam./rate;
|
---|
17 | ratioPo = lam./ratePo;
|
---|
18 | subplot(2,1,1);
|
---|
19 | semilogx(lam,diff);
|
---|
20 | hold on
|
---|
21 | semilogx(lam,diffPo,'r');
|
---|
22 | title('Poisson Fit Difference')
|
---|
23 | xlabel('count rate')
|
---|
24 | ylabel('count rate - calculated rate');
|
---|
25 | legend('Least Squares', 'Poisson')
|
---|
26 | subplot(2,1,2);
|
---|
27 | semilogx(lam,ratio);
|
---|
28 | hold on
|
---|
29 | semilogx(lam,ratioPo,'r');
|
---|
30 | title('Poisson Fit Ratio')
|
---|
31 | xlabel('count rate')
|
---|
32 | ylabel('count rate/calculated rate');
|
---|
33 | legend('Least Squares', 'Poisson')
|
---|
34 |
|
---|