# Gaussian Energy Broadening implementation to meet detector response

Respected Coding experts,

I am trying to perform Gaussian broadening on an energy spectrum. The final result should convert "specrum.png" to a similar form of "Exp.png". The method is explained in the "snap.jpg". In "snap.jpg" each bin is converted in a Gaussian where the "μ" is the mean, and sigma of the Gaussian is a polynomial function dependent on the energy i.e. x-axis (see code). Here each bin is converted to a Gaussian in a for loop and I want that the second bin gaussian includes a pileup from the Gaussian of the first bin. Similarly, the third Gaussian should include the pileup from second and first. The I am using for this is below:

E=linspace(0,10,1026);    % Energy bins
for i=1:1026
sigma(i) = (-0.00789) + (0.06769)*E(i) + (0.021159)*(E(i)^2);                          % Sigma polynomial function
gaussFilter(i) = (1/sqrt(2*pi* (sigma(i)^2)))*exp(-((E(i)-0.5)))/(2*(sigma(i)^2));   % Gaussian function
gaussFilter(i) = gaussFilter(i) / sum (gaussFilter(i));
AAA=W_NAIF/sum(W_NAIF);
newSPECU(i) = conv(AAA(i),gaussFilter(i));
end
figure(1);
stairs(E,newSPECU);
set(gca,'YScale','log');
xlabel('Energy Deposited (MeV)');
ylabel('Counts');
title('Geant4 Gamma energy spectra (NaI NEAR - Tap Water)');
grid minor;
grid on;
ylim([1 1e6]); The data for this plot can be downloaded at DATA  