% Demonstration that, for a signal of two overlapping Gaussians, the result
% of raising the signal to a power is not the same as adding two
% power-narrowed Gaussians, unless the resolution of the peaks is
% sufficiently high.
x=-1:.1:13;
width=2.7; % Initial peak width (FWHM). 
sigma=width/(2*log(2)); % peak width (sigma)
position1=4; % x-axis position of peak 1
position2=7.5; % x-axis position of peak 2
Resolution=(position2-position1)/(4*sigma);
y1=2.*gaussian(x,position1,width); % Peak 1 (fixed height)
y2=gaussian(x,position2,width);
y=y1+y2;

figure(1)
datamatrix=[x;y];
[FitResults,FitError]=peakfit(datamatrix,5.995,13.99,2,1,0,10,0,0)
subplot(2,1,1)
title(['Fitting a 2-Gaussian model to y with resolution = ' num2str(Resolution) ' : a "perfect fit" '])


figure(2)
datamatrix=[x;y.^2];
[FitResults,FitError]=peakfit(datamatrix,5.995,13.99,2,1,0,10,0,0)
subplot(2,1,1)
title('Fitting a 2-Gaussian model to y^2')

figure(3)
datamatrix=[x;y.^5];
[FitResults,FitError]=peakfit(datamatrix,5.995,13.99,2,1,0,10,0,0)
subplot(2,1,1)
title('Fitting a 2-Gaussian model to y^5')
