% simulate a gaussian-shaped peak with finite counting statistics and

% define the center position, width of the peak, and count rate at the
% center of the peak
clear;
center = 0.0;
width = 1.0;
peak_counts = 20.0;

% create vectors for the average counts as a function of angle
angles = double(center-3*width:width/10.0:center+3*width);
average_counts = peak_counts*exp(-(center-angles).^2/width^2);

% plot this so we can see the target
hold off;
plot(angles,average_counts);
hold on;

% simulate a measurement using a poisson distribution
% and compare the results to the target
simul_counts = poissrnd(average_counts);
plot(angles,simul_counts,'o');

% fit the data to a gaussian (need x and y as column vectors)
pfit = fit(angles',simul_counts','gauss1');
pfit

% and plot the fit with comparison to the data and target
plot(angles, pfit(angles),'r');