function y=GaussTriangle(x,pos,wid1,wid2)
% Unit height peak shape that is defined as a Gaussian of width 'wid1'
% convoluted with a triangle of width 'wid2'. The halfwidth is approximately
% sqrt(wid1^2+wid2^2)
%
% Example
%  x=1:400;
%  clf
%  for wid1=1:20:100
%      hold on
%      plot(x,GaussTriangle(x,200,wid1,10))
%  end
%  hold off

c=gaussian(x,pos,wid1); 
t=triangle(x,pos,wid2);
yc=conv(t,c,'same')./sum(c); % yc = t convoluted with c
y=yc./max(yc);

function g = triangle(x,pos,wid)
%triangle function.  pos=position; wid=half-width (both scalar)
%triangle(x,pos,wid), where x may be scalar or vector,
%pos=position; wid=half-width (both scalar)
% T. C. O'Haver, 1991
% Example
% x=[0:.1:10];plot(x,triangle(x,5.5,2.3),'.')
g=1-(1./wid) .*abs(x-pos);
for i=1:length(x)
if g(i)<0,g(i)=0;end
end

function g = gaussian(x,pos,wid)
%  gaussian(x,pos,wid) = gaussian peak centered on pos, half-width=wid
%  x may be scalar, vector, or matrix, pos and wid both scalar
%  T. C. O'Haver, 1988
% Examples: gaussian([0 1 2],1,2) gives result [0.5000    1.0000    0.5000]
% plot(gaussian([1:100],50,20)) displays gaussian band centered at 50 with width 20.
g = exp(-((x-pos)./(0.60056120439323.*wid)) .^2);