function s=ricker(npts,freq,dt,nsw)
% Function ricker.m computes a symmetric Ricker wavelet of predominant
% frequency freq.  The number of points in the wavelet is npts.  The 
% sampling interval is dt (be sure npts and dt are large enough to
% adequately represent the entire wavelet).  Be sure dt is small enough 
% to avoid aliasing.  nsw is the number of points on each end of the
% wavelet for applying a taper to smooth any possible edge effects of the
% wavelet.  In general, to determine dt and npts for a given frequency:
% dt >= 1/(10*freq);  npts ~ (3/freq)/dt
% The wavelet is shifted by half the wavelet length so that the travel
% times for reflections are located at the center of the wavelet.
timesh=npts*dt/2;
pi2=sqrt(pi)/2;
b=sqrt(6)/(pi*freq);
const=2*sqrt(6)/b;
s=zeros(npts,1);
for i=1:npts
	tim1=(i-1)*dt;
	tim2=tim1-timesh;
	u=const*tim2;
	amp=(((u^2)/4)-(0.5))*pi2*(exp(-u^2/4));
	s(i)=-amp;
end
sm=max(abs(s));
s=s/sm;
if nsw>0
	for i=1:nsw
		j=nsw-i;
		fac=0.5*(cos((pi*j)/nsw) +1);
		s(i)=s(i)*fac;
	end
	for i=1:nsw
		j=i-1;
		fac=0.5*(cos((pi*j)/nsw) +1);
		k=npts-nsw+i;
		s(k)=s(k)*fac;
	end
end

