function sta=sta(wave,fs,window,overlap,lagstep)
%STA=STA(WAVE,FS,WINDOW,OVERLAP,LAGSTEP)    Autocorrelation. 
%  Autocorrelation of WAVE using Hamming windows of size WINSIZE overlapping by OVERLAP.
% 
%  Author: Stuart N Wrigley       
%  MAD - Matlab Auditory Demonstrations
%  (c) University of Sheffield 1998
%  Revision 0.01: 8 July 1998

error(nargchk(1,5,nargin));
wave=normalise(wave);
winSize=length(window);
bases=enframe(wave,window,overlap)';           % one windowed base per column
movers=enframe(wave,winSize*2,overlap)';       % one unwindowed mover per column 
numcol=min(size(bases,2),size(movers,2));
bases=bases(:,1:numcol);
movers=movers(:,1:numcol);

for i=1:numcol
   for k=1:lagstep:winSize
      sta(k,i)=sum(bases(:,i).*(movers(k:k+winSize-1,i).*window));
   end   
end


