M = length(w); % Window length Mh = (M-1)/2; % Assume M is odd N = 2^nextpow2(M); % FFT length Xtwz = zeros(N,nframes);% pre-allocate STFT output array zp = zeros(N-M,1); % zero padding (to be inserted) xoff = 0; % current offset in input signal for m=1:nframes xt = x(xoff+1:xoff+M); % extract frame of input data xtw = w .* xt; % apply window to current frame xtwz = [xtw(Mh+1:M); zp; xtw(1:Mh)]; % insert 0-padding Xtwz(:,m) = fft(xtwz); % STFT for frame m xoff = xoff + R; % advance in-ptr by hop-size R end