function[sx,f,d,jj]=larry(x,sm,nn,nint)
%function[sx,f,d,jj]=larry(x,sm,nn,nint)
%  This program calculates the spectrum s of series x at the
%  frequencies f, using the smoother sm.
%  A trapezoidal taper of length nn is used.  The covariogram is computed
%  and stored in d.  To plot the covariogram, use the command
%  plot(jj,d).  To plot the spectrum, type semilogy(f,sx).
%
%  The smoother sm might be of the box form
%
%      sm=[1 1 1 1 ... 1 1]/mm
%  where mm is the number of elements of sm.
%  You can also choose a "tent" smoother.
%  The parameter nn governs the length of the taper.
%
%  The paramter nint controls the sampling interval for PLOTTING, set equal
%  to 1 if you want all of the points 
%
%  The mean of the spectral density is the variance of the process;
%  Things are scaled correctly, as of May 29, 1992.

mm=mean(x);x=x-mm;
x=taper(x,nn);
f=fft(x);
ix=f.*conj(f);
s1=length(x);
s2=length(sm);
s3=(s2-1)/2;
s4=s3+1;
iz=[ix(s4:-1:2);ix;ix(1:s4)];
s=conv(iz,sm);
s7=length(s);
r1=length(iz);
r2=r1-s1;
s8=(s7-s1-1)/2;
sx=s(s8+1:s7-s8);
n=length(x);
f=2*pi*(0:n)'/n;
n2=n/2+1;sx=sx./(length(sx));
semilogy(f(1:nint:n2),sx(1:nint:n2))
										
										
c=real(ifft(2*sx/n));
nn=max(size(c));
n=nn/2;
d=[c(n+1:2*n);c(1:n)];d=d*length(sx)/2;
jj=[(-n:-1),(0:n-1)]';
