function S = sfft(s, window, shift)
% 
% short time FFT, S = sfft(s, window, shift)
% 

frameSize = length(window);
sLength = length(s);
%nFrame = ceil( (sLength-frameSize)/shift )+1;
nFrame = ceil( (sLength-frameSize)/shift );

if ( nFrame < 1 ), nFrame = 1; end % for the case sLength < frameSize
% adjusting the length of s, padding zero
adjustLength = shift*(nFrame-1) + frameSize; 
s = [s; zeros(adjustLength-sLength,1)]; % column vector

S=zeros(frameSize, nFrame); 

begintime=1;
endtime=frameSize;

for i=1:nFrame,
 windowed_signal = s(begintime:endtime) .* window;
 S(:,i) = fft(windowed_signal); % rows = frequency bins, columns = number of frames
 begintime = begintime + shift;
 endtime = endtime + shift;
end;
